mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
fix: complete file cleanup when removing from Knowledge Base
This commit is contained in:
parent
b1bcca90b5
commit
913e0d391b
1 changed files with 13 additions and 1 deletions
|
|
@ -17,7 +17,7 @@ from open_webui.routers.retrieval import (
|
||||||
process_files_batch,
|
process_files_batch,
|
||||||
BatchProcessFilesForm,
|
BatchProcessFilesForm,
|
||||||
)
|
)
|
||||||
|
from open_webui.storage.provider import Storage
|
||||||
|
|
||||||
from open_webui.constants import ERROR_MESSAGES
|
from open_webui.constants import ERROR_MESSAGES
|
||||||
from open_webui.utils.auth import get_verified_user
|
from open_webui.utils.auth import get_verified_user
|
||||||
|
|
@ -420,6 +420,18 @@ def remove_file_from_knowledge_by_id(
|
||||||
collection_name=knowledge.id, filter={"file_id": form_data.file_id}
|
collection_name=knowledge.id, filter={"file_id": form_data.file_id}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Remove the file's collection from vector database
|
||||||
|
file_collection = f"file-{form_data.file_id}"
|
||||||
|
if VECTOR_DB_CLIENT.has_collection(collection_name=file_collection):
|
||||||
|
VECTOR_DB_CLIENT.delete_collection(collection_name=file_collection)
|
||||||
|
|
||||||
|
# Delete physical file
|
||||||
|
if file.path:
|
||||||
|
Storage.delete_file(file.path)
|
||||||
|
|
||||||
|
# Delete file from database
|
||||||
|
Files.delete_file_by_id(form_data.file_id)
|
||||||
|
|
||||||
if knowledge:
|
if knowledge:
|
||||||
data = knowledge.data or {}
|
data = knowledge.data or {}
|
||||||
file_ids = data.get("file_ids", [])
|
file_ids = data.get("file_ids", [])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue