refactor(db): 优化ChromaDB查询参数处理
将查询参数动态构建,仅在`where`条件存在时才将其添加到查询中。此举增强了代码的健壮性和灵活性,避免了传入空的`where`字典可能引发的潜在问题。
This commit is contained in:
@@ -92,12 +92,14 @@ class ChromaDBImpl(VectorDBBase):
|
||||
collection = self.get_or_create_collection(collection_name)
|
||||
if collection:
|
||||
try:
|
||||
return collection.query(
|
||||
query_embeddings=query_embeddings,
|
||||
n_results=n_results,
|
||||
where=where or {},
|
||||
query_params = {
|
||||
"query_embeddings": query_embeddings,
|
||||
"n_results": n_results,
|
||||
**kwargs,
|
||||
)
|
||||
}
|
||||
if where:
|
||||
query_params["where"] = where
|
||||
return collection.query(**query_params)
|
||||
except Exception as e:
|
||||
logger.error(f"查询集合 '{collection_name}' 失败: {e}")
|
||||
return {}
|
||||
|
||||
Reference in New Issue
Block a user