style: 格式化代码

This commit is contained in:
John Richard
2025-10-02 19:38:39 +08:00
parent d5627b0661
commit ecb02cae31
111 changed files with 2344 additions and 2316 deletions

View File

@@ -98,13 +98,13 @@ class ChromaDBImpl(VectorDBBase):
"n_results": n_results,
**kwargs,
}
# 修复ChromaDB的where条件格式
if where:
processed_where = self._process_where_condition(where)
if processed_where:
query_params["where"] = processed_where
return collection.query(**query_params)
except Exception as e:
logger.error(f"查询集合 '{collection_name}' 失败: {e}")
@@ -114,7 +114,7 @@ class ChromaDBImpl(VectorDBBase):
"query_embeddings": query_embeddings,
"n_results": n_results,
}
logger.warning(f"使用回退查询模式无where条件")
logger.warning("使用回退查询模式无where条件")
return collection.query(**fallback_params)
except Exception as fallback_e:
logger.error(f"回退查询也失败: {fallback_e}")
@@ -124,19 +124,19 @@ class ChromaDBImpl(VectorDBBase):
"""
处理where条件转换为ChromaDB支持的格式
ChromaDB支持的格式
- 简单条件: {"field": "value"}
- 简单条件: {"field": "value"}
- 操作符条件: {"field": {"$op": "value"}}
- AND条件: {"$and": [condition1, condition2]}
- OR条件: {"$or": [condition1, condition2]}
"""
if not where:
return None
try:
# 如果只有一个字段,直接返回
if len(where) == 1:
key, value = next(iter(where.items()))
# 处理列表值如memory_types
if isinstance(value, list):
if len(value) == 1:
@@ -146,7 +146,7 @@ class ChromaDBImpl(VectorDBBase):
return {key: {"$in": value}}
else:
return {key: value}
# 多个字段使用 $and 操作符
conditions = []
for key, value in where.items():
@@ -157,9 +157,9 @@ class ChromaDBImpl(VectorDBBase):
conditions.append({key: {"$in": value}})
else:
conditions.append({key: value})
return {"$and": conditions}
except Exception as e:
logger.warning(f"处理where条件失败: {e}, 使用简化条件")
# 回退到只使用第一个条件
@@ -189,7 +189,7 @@ class ChromaDBImpl(VectorDBBase):
processed_where = None
if where:
processed_where = self._process_where_condition(where)
return collection.get(
ids=ids,
where=processed_where,
@@ -202,7 +202,7 @@ class ChromaDBImpl(VectorDBBase):
logger.error(f"从集合 '{collection_name}' 获取数据失败: {e}")
# 如果获取失败尝试不使用where条件重新获取
try:
logger.warning(f"使用回退获取模式无where条件")
logger.warning("使用回退获取模式无where条件")
return collection.get(
ids=ids,
limit=limit,