From 797afd0b72f625759de56a7cfb2f2083b25f0a9a Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 13 Oct 2024 03:25:11 -0700 Subject: [PATCH] fix: embedding metadata issue --- backend/open_webui/apps/retrieval/main.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/apps/retrieval/main.py b/backend/open_webui/apps/retrieval/main.py index 73dc08624..815f18276 100644 --- a/backend/open_webui/apps/retrieval/main.py +++ b/backend/open_webui/apps/retrieval/main.py @@ -678,7 +678,19 @@ def save_docs_to_vector_db( raise ValueError(ERROR_MESSAGES.EMPTY_CONTENT) texts = [doc.page_content for doc in docs] - metadatas = [{**doc.metadata, **(metadata if metadata else {})} for doc in docs] + metadatas = [ + { + **doc.metadata, + **(metadata if metadata else {}), + "embedding_config": json.dumps( + { + "engine": app.state.config.RAG_EMBEDDING_ENGINE, + "model": app.state.config.RAG_EMBEDDING_MODEL, + } + ), + } + for doc in docs + ] # ChromaDB does not like datetime formats # for meta-data so convert them to string. @@ -717,13 +729,7 @@ def save_docs_to_vector_db( "id": str(uuid.uuid4()), "text": text, "vector": embeddings[idx], - "metadata": { - **metadatas[idx], - "embedding": { - "engine": app.state.config.RAG_EMBEDDING_ENGINE, - "model": app.state.config.RAG_EMBEDDING_MODEL, - }, - }, + "metadata": metadatas[idx], } for idx, text in enumerate(texts) ]