mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
Merge pull request #8499 from juananpe/file-cleanup-knowledge
fix: complete file cleanup when removing from Knowledge Base
This commit is contained in:
commit
8e08c218c5
@ -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 New Issue
Block a user