Ver Fonte

fix: only append if distances are available

Jannik Streidl há 7 meses atrás
pai
commit
9fc813cfa6
1 ficheiros alterados com 8 adições e 8 exclusões
  1. 8 8
      backend/open_webui/apps/retrieval/utils.py

+ 8 - 8
backend/open_webui/apps/retrieval/utils.py

@@ -393,14 +393,14 @@ def get_rag_context(
                 )
 
                 if "metadatas" in context:
-                    citations.append(
-                        {
-                            "source": context["file"],
-                            "document": context["documents"][0],
-                            "metadata": context["metadatas"][0],
-                            "distances": context["distances"][0]
-                        }
-                    )
+                    citation = {
+                        "source": context["file"],
+                        "document": context["documents"][0],
+                        "metadata": context["metadatas"][0],
+                    }
+                    if "distances" in context and context["distances"]:
+                        citation["distances"] = context["distances"][0]
+                    citations.append(citation)
         except Exception as e:
             log.exception(e)