From 9fc813cfa6e1967afc1ee758725b60b6539679b2 Mon Sep 17 00:00:00 2001 From: Jannik Streidl Date: Mon, 7 Oct 2024 21:13:13 +0200 Subject: [PATCH] fix: only append if distances are available --- backend/open_webui/apps/retrieval/utils.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/apps/retrieval/utils.py b/backend/open_webui/apps/retrieval/utils.py index d9e82f362..53961be2c 100644 --- a/backend/open_webui/apps/retrieval/utils.py +++ b/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)