diff --git a/backend/open_webui/apps/retrieval/utils.py b/backend/open_webui/apps/retrieval/utils.py
index 80b0ce2a0..153bd804f 100644
--- a/backend/open_webui/apps/retrieval/utils.py
+++ b/backend/open_webui/apps/retrieval/utils.py
@@ -411,13 +411,14 @@ def get_rag_context(
)
if "metadatas" in context:
- citations.append(
- {
- "source": context["file"],
- "document": context["documents"][0],
- "metadata": context["metadatas"][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)
diff --git a/backend/open_webui/apps/retrieval/vector/dbs/chroma.py b/backend/open_webui/apps/retrieval/vector/dbs/chroma.py
index 84f80b253..c6d95bd52 100644
--- a/backend/open_webui/apps/retrieval/vector/dbs/chroma.py
+++ b/backend/open_webui/apps/retrieval/vector/dbs/chroma.py
@@ -109,7 +109,10 @@ class ChromaClient:
def insert(self, collection_name: str, items: list[VectorItem]):
# Insert the items into the collection, if the collection does not exist, it will be created.
- collection = self.client.get_or_create_collection(name=collection_name)
+ collection = self.client.get_or_create_collection(
+ name=collection_name,
+ metadata={"hnsw:space": "cosine"}
+ )
ids = [item["id"] for item in items]
documents = [item["text"] for item in items]
@@ -127,7 +130,10 @@ class ChromaClient:
def upsert(self, collection_name: str, items: list[VectorItem]):
# Update the items in the collection, if the items are not present, insert them. If the collection does not exist, it will be created.
- collection = self.client.get_or_create_collection(name=collection_name)
+ collection = self.client.get_or_create_collection(
+ name=collection_name,
+ metadata={"hnsw:space": "cosine"}
+ )
ids = [item["id"] for item in items]
documents = [item["text"] for item in items]
diff --git a/src/lib/components/chat/Messages/Citations.svelte b/src/lib/components/chat/Messages/Citations.svelte
index 2c23e87a4..0a09b3b55 100644
--- a/src/lib/components/chat/Messages/Citations.svelte
+++ b/src/lib/components/chat/Messages/Citations.svelte
@@ -1,67 +1,219 @@
-