refactor(db): 优化ChromaDB查询参数处理

将查询参数动态构建,仅在`where`条件存在时才将其添加到查询中。此举增强了代码的健壮性和灵活性,避免了传入空的`where`字典可能引发的潜在问题。
This commit is contained in:
minecraft1024a
2025-08-30 11:26:21 +08:00
parent 7cb5c3844e
commit ec82f2b4e7

View File

@@ -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 {}