[GH-ISSUE #10823] Deleting a knowledge base does not delete file in storage #16042

Closed
opened 2026-04-19 22:05:10 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @almajo on GitHub (Feb 26, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/10823

Bug Report

Important Notes

  • Before submitting a bug report: Please check the Issues or Discussions section to see if a similar issue or feature request has already been posted. It's likely we're already tracking it! If you’re unsure, start a discussion post first. This will help us efficiently focus on improving the project.

  • Collaborate respectfully: We value a constructive attitude, so please be mindful of your communication. If negativity is part of your approach, our capacity to engage may be limited. We’re here to help if you’re open to learning and communicating positively. Remember, Open WebUI is a volunteer-driven project managed by a single maintainer and supported by contributors who also have full-time jobs. We appreciate your time and ask that you respect ours.

  • Contributing: If you encounter an issue, we highly encourage you to submit a pull request or fork the project. We actively work to prevent contributor burnout to maintain the quality and continuity of Open WebUI.

  • Bug reproducibility: If a bug cannot be reproduced with a :main or :dev Docker setup, or a pip install with Python 3.11, it may require additional help from the community. In such cases, we will move it to the "issues" Discussions section due to our limited resources. We encourage the community to assist with these issues. Remember, it’s not that the issue doesn’t exist; we need your help!

Note: Please remove the notes above when submitting your post. Thank you for your understanding and support!


Installation Method

[Describe the method you used to install the project, e.g., git clone, Docker, pip, etc.]

Environment

  • Open WebUI Version: 0.5.16
    Confirmation:

  • I have read and followed all the instructions provided in the README.md.

  • I am on the latest version of both Open WebUI and Ollama.

  • I have included the browser console logs.

  • I have included the Docker container logs.

  • I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below.

Expected Behavior:

When deleting files that were uploaded into a knowledge base, I expect them to be completely removed from the system when deleting the knowledge I uploaded them for.

Actual Behavior:

The files remain in storage, even though they were deleted from the database.

Reproduction Details

Steps to Reproduce:

  1. Create a knowledge base
  2. Upload a file
  3. Delete the knowledge base

Proposed solution

The following could be added to delete_knowledge_by_id to properly cleanup

    # Get associated file IDs
    file_ids = knowledge.data.get("file_ids", []) if knowledge.data else []
    
    # Delete each file from storage
    for file_id in file_ids:
        try:
            file = Files.get_file_by_id(file_id)
            if file and file.path:
                Storage.delete_file(file.path)
                # Also delete the file's vector DB collection
                file_collection = f"file-{file_id}"
                if VECTOR_DB_CLIENT.has_collection(collection_name=file_collection):
                    VECTOR_DB_CLIENT.delete_collection(collection_name=file_collection)
                # Delete file from database
                Files.delete_file_by_id(file_id)
        except Exception as e:
            log.error(f"Error deleting file {file_id}: {e}")
  
Originally created by @almajo on GitHub (Feb 26, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/10823 # Bug Report ## Important Notes - **Before submitting a bug report**: Please check the Issues or Discussions section to see if a similar issue or feature request has already been posted. It's likely we're already tracking it! If you’re unsure, start a discussion post first. This will help us efficiently focus on improving the project. - **Collaborate respectfully**: We value a constructive attitude, so please be mindful of your communication. If negativity is part of your approach, our capacity to engage may be limited. We’re here to help if you’re open to learning and communicating positively. Remember, Open WebUI is a volunteer-driven project managed by a single maintainer and supported by contributors who also have full-time jobs. We appreciate your time and ask that you respect ours. - **Contributing**: If you encounter an issue, we highly encourage you to submit a pull request or fork the project. We actively work to prevent contributor burnout to maintain the quality and continuity of Open WebUI. - **Bug reproducibility**: If a bug cannot be reproduced with a `:main` or `:dev` Docker setup, or a pip install with Python 3.11, it may require additional help from the community. In such cases, we will move it to the "issues" Discussions section due to our limited resources. We encourage the community to assist with these issues. Remember, it’s not that the issue doesn’t exist; we need your help! Note: Please remove the notes above when submitting your post. Thank you for your understanding and support! --- ## Installation Method [Describe the method you used to install the project, e.g., git clone, Docker, pip, etc.] ## Environment - **Open WebUI Version:** 0.5.16 **Confirmation:** - [X] I have read and followed all the instructions provided in the README.md. - [X] I am on the latest version of both Open WebUI and Ollama. - [ ] I have included the browser console logs. - [ ] I have included the Docker container logs. - [ ] I have provided the exact steps to reproduce the bug in the "Steps to Reproduce" section below. ## Expected Behavior: When deleting files that were uploaded into a knowledge base, I expect them to be completely removed from the system when deleting the knowledge I uploaded them for. ## Actual Behavior: The files remain in storage, even though they were deleted from the database. ## Reproduction Details **Steps to Reproduce:** 1. Create a knowledge base 2. Upload a file 3. Delete the knowledge base ## Proposed solution The following could be added to `delete_knowledge_by_id` to properly cleanup ```python # Get associated file IDs file_ids = knowledge.data.get("file_ids", []) if knowledge.data else [] # Delete each file from storage for file_id in file_ids: try: file = Files.get_file_by_id(file_id) if file and file.path: Storage.delete_file(file.path) # Also delete the file's vector DB collection file_collection = f"file-{file_id}" if VECTOR_DB_CLIENT.has_collection(collection_name=file_collection): VECTOR_DB_CLIENT.delete_collection(collection_name=file_collection) # Delete file from database Files.delete_file_by_id(file_id) except Exception as e: log.error(f"Error deleting file {file_id}: {e}") ```
Author
Owner

@tjbck commented on GitHub (Feb 26, 2025):

Intended behaviour for enterprise security reasons, you can use third party scripts.

<!-- gh-comment-id:2686271280 --> @tjbck commented on GitHub (Feb 26, 2025): Intended behaviour for enterprise security reasons, you can use third party scripts.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#16042