fix: only append if distances are available

This commit is contained in:
Jannik Streidl 2024-10-07 21:13:13 +02:00
parent b105efa05f
commit 9fc813cfa6

View File

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