Преглед изворни кода

Merge pull request #19025 from krishna-medapati/fix-hybrid-search-17046-clean

fix: Handle AttributeError in hybrid search with reranking (#17046)
Tim Baek пре 3 месеци
родитељ
комит
284764e178
1 измењених фајлова са 9 додато и 1 уклоњено
  1. 9 1
      backend/open_webui/retrieval/utils.py

+ 9 - 1
backend/open_webui/retrieval/utils.py

@@ -160,10 +160,18 @@ def query_doc_with_hybrid_search(
     hybrid_bm25_weight: float,
 ) -> dict:
     try:
+        # First check if collection_result has the required attributes
         if (
             not collection_result
             or not hasattr(collection_result, "documents")
-            or not collection_result.documents
+            or not hasattr(collection_result, "metadatas")
+        ):
+            log.warning(f"query_doc_with_hybrid_search:no_docs {collection_name}")
+            return {"documents": [], "metadatas": [], "distances": []}
+        
+        # Now safely check the documents content after confirming attributes exist
+        if (
+            not collection_result.documents
             or len(collection_result.documents) == 0
             or not collection_result.documents[0]
         ):