From 61b147441c59959957c5b7bf7c724a62c3853e5a Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 5 Oct 2024 10:05:12 -0700 Subject: [PATCH] refac --- backend/open_webui/apps/retrieval/main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/apps/retrieval/main.py b/backend/open_webui/apps/retrieval/main.py index d5096a9b2..5c5b55e4e 100644 --- a/backend/open_webui/apps/retrieval/main.py +++ b/backend/open_webui/apps/retrieval/main.py @@ -738,12 +738,18 @@ def process_file( collection_name = f"file-{file.id}" if form_data.content: + VECTOR_DB_CLIENT.delete( + collection_name=f"file-{file.id}", + filter={"file_id": file.id}, + ) + docs = [ Document( page_content=form_data.content, metadata={ "name": file.meta.get("name", file.filename), "created_by": file.user_id, + "file_id": file.id, **file.meta, }, ) @@ -755,7 +761,7 @@ def process_file( collection_name=f"file-{file.id}", filter={"file_id": file.id} ) - if result: + if len(result.ids[0]) > 0: docs = [ Document( page_content=result.documents[0][idx], @@ -770,6 +776,7 @@ def process_file( metadata={ "name": file.meta.get("name", file.filename), "created_by": file.user_id, + "file_id": file.id, **file.meta, }, ) @@ -795,6 +802,7 @@ def process_file( metadata={ "name": file.filename, "created_by": file.user_id, + "file_id": file.id, **file.meta, }, )