[PR #8432] [MERGED] fix: Knowledge Base Detachment from Models #22222

Closed
opened 2026-04-20 03:59:36 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/8432
Author: @juananpe
Created: 1/9/2025
Status: Merged
Merged: 1/9/2025
Merged by: @tjbck

Base: devHead: kb-detachment-from-models


📝 Commits (3)

📊 Changes

2 files changed (+31 additions, -1 deletions)

View changed files

📝 backend/open_webui/routers/knowledge.py (+31 -0)
📝 src/lib/utils/index.ts (+0 -1)

📄 Description

Pull Request Checklist

Before submitting, make sure you've checked the following:

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry
  • Prefix: To cleary categorize this pull request, prefix the pull request title

Changelog Entry

Description

Fixed an issue where knowledge bases remained linked to models after being deleted from the Knowledge area. This ensures data consistency by properly cleaning up all references when a knowledge base is deleted, preventing orphaned references in models.

An explanation of the scenario before the patch:

When a user wanted to remove a knowledge base from their system, the following scenario would occur:

  1. Initial State:

    • A knowledge base (KB) exists in the "Knowledge" area
    • One or more models have this KB attached to them
    • The KB is stored in three places:
      • The knowledge base database table
      • The vector database (for storing embeddings)
      • References in models' metadata (model.meta.knowledge)
  2. User Action:

    • User goes to the "Knowledge" area
    • Selects a KB
    • Clicks delete
    • Confirms deletion
  3. What Actually Happened:

    • The KB would be deleted from the knowledge base database table
    • The vector database collection would be cleaned up
    • BUT: The references in models' metadata remained untouched
  4. Resulting Problems:

    • Models still showed the deleted KB in their knowledge list
    • These were now "ghost" references - pointing to a KB that no longer existed
    • The model's configuration became inconsistent with the actual system state
  5. Technical Issue:

    • The delete_knowledge_by_id endpoint only handled:
      • Deleting the KB from the database
      • Cleaning up the vector DB collection
    • It didn't:
      • Check which models referenced the KB
      • Update those models to remove the references

This created a data consistency issue where models maintained references to non-existent knowledge bases, leading to a confusing user experience and potential issues with model operation.

Fixed

  • Fixed knowledge base references remaining in models after deletion
  • Fixed model update process to use proper ModelForm structure
  • Fixed potential data inconsistency between Knowledge area and model references

The changes ensure that when a knowledge base is deleted:

  1. All models are checked for references to the deleted knowledge base
  2. Any found references are properly removed using Pydantic model attribute access
  3. Models are correctly updated using ModelForm
  4. Vector database collections are cleaned up
  5. The knowledge base itself is deleted only after all references are cleaned up

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/8432 **Author:** [@juananpe](https://github.com/juananpe) **Created:** 1/9/2025 **Status:** ✅ Merged **Merged:** 1/9/2025 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `kb-detachment-from-models` --- ### 📝 Commits (3) - [`5b616dd`](https://github.com/open-webui/open-webui/commit/5b616dd34fa4c19eba5f17be04597774695e0687) fix: Knowledge Base Detachment from Models - [`de735b3`](https://github.com/open-webui/open-webui/commit/de735b3c8c125a2e06ccd857bfbe0d2375c79887) fix format - [`f724900`](https://github.com/open-webui/open-webui/commit/f72490093aceecd2c6888f890212ccff09370d9f) fix frontend format ### 📊 Changes **2 files changed** (+31 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/routers/knowledge.py` (+31 -0) 📝 `src/lib/utils/index.ts` (+0 -1) </details> ### 📄 Description # Pull Request Checklist **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry - [x] **Prefix:** To cleary categorize this pull request, prefix the pull request title # Changelog Entry ### Description Fixed an issue where knowledge bases remained linked to models after being deleted from the Knowledge area. This ensures data consistency by properly cleaning up all references when a knowledge base is deleted, preventing orphaned references in models. An explanation of the scenario _before_ the patch: When a user wanted to remove a knowledge base from their system, the following scenario would occur: 1. **Initial State**: - A knowledge base (KB) exists in the "Knowledge" area - One or more models have this KB attached to them - The KB is stored in three places: - The knowledge base database table - The vector database (for storing embeddings) - References in models' metadata (`model.meta.knowledge`) 2. **User Action**: - User goes to the "Knowledge" area - Selects a KB - Clicks delete - Confirms deletion 3. **What Actually Happened**: - The KB would be deleted from the knowledge base database table - The vector database collection would be cleaned up - BUT: The references in models' metadata remained untouched 4. **Resulting Problems**: - Models still showed the deleted KB in their knowledge list - These were now "ghost" references - pointing to a KB that no longer existed - The model's configuration became inconsistent with the actual system state 5. **Technical Issue**: - The `delete_knowledge_by_id` endpoint only handled: - Deleting the KB from the database - Cleaning up the vector DB collection - It didn't: - Check which models referenced the KB - Update those models to remove the references This created a data consistency issue where models maintained references to non-existent knowledge bases, leading to a confusing user experience and potential issues with model operation. ### Fixed - Fixed knowledge base references remaining in models after deletion - Fixed model update process to use proper ModelForm structure - Fixed potential data inconsistency between Knowledge area and model references The changes ensure that when a knowledge base is deleted: 1. All models are checked for references to the deleted knowledge base 2. Any found references are properly removed using Pydantic model attribute access 3. Models are correctly updated using ModelForm 4. Vector database collections are cleaned up 5. The knowledge base itself is deleted only after all references are cleaned up --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 03:59:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#22222