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