[PR #13679] [CLOSED] perf: implement multi-tenancy for Qdrant vector store client #23263

Closed
opened 2026-04-20 04:43:31 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/13679
Author: @loitragg
Created: 5/8/2025
Status: Closed

Base: devHead: apply-multitenant-for-qdrant


📝 Commits (3)

  • 8c6fb34 perf: implement multi-tenancy support in QdrantClient with tenant ID handling and collection management
  • fbd0b18 perf: check collection exists will be turn to try-catch to make 1 less request to Qdrant
  • 06805e2 fix: enhance error handling for collection creation in QdrantClient to manage "already exists" conflicts

📊 Changes

1 file changed (+605 additions, -108 deletions)

View changed files

📝 backend/open_webui/retrieval/vector/dbs/qdrant.py (+605 -108)

📄 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: This pull request migrates Open WebUI to Qdrant's multi-tenancy feature to address excessive RAM usage and performance issues caused by the previous model of one collection per entity. It consolidates collections by entity type (Memories, Files, Knowledge, Web Search, YouTube) and uses tenant IDs for data partitioning.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests to validate the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following: (Suggested: refactor)
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Discussions

Description

  • Background: In the discussion above, we were using a separate Qdrant collection for each entity (memory, knowledge base, file), which led to thousands of collections. This approach is an anti-pattern according to Qdrant documentation and causes excessive RAM usage.

  • Solution: Qdrant recommends using multi-tenancy with payload-based partitioning for efficient resource usage when dealing with a large number of logical collections (https://qdrant.tech/documentation/guides/multiple-partitions/). This change migrates the Qdrant database to utilize its multi-tenancy feature. Collections are now consolidated by entity type (Memories, Files, Knowledge, Web Search, YouTube), and data within these collections is partitioned using a tenant_id field in payloads.

Changed

  • Updated the existing QdrantClient class to use Qdrant's multi-tenancy feature while maintaining the same interface to avoid breaking changes in the application.
  • Consolidated numerous individual Qdrant collections into five main entity-specific collections: Memories Collection, Files Collection, Knowledge Collection, Web Search Collection, and Hash Based Collection(for Youtube and Web URL).
  • Implemented payload-based partitioning using a tenant_id field for data isolation within the new collections.
  • Configured Qdrant collections for multi-tenancy, including settings like payload_m=16 (per-tenant indexing), m=0 (disabled global index), and a keyword payload index for tenant_id with is_tenant=true.

Additional Information

Migration

The existing API interface of the QdrantClient class is maintained to avoid breaking changes in the application, ensuring a seamless transition. However, Open WebUI will unable to access all the old Qdrant collections. Go to: Admin Settings > Documents > Reindex Knowledge Base Vectors to migrating knowledge

Rollback

Before running the migration in production:

  1. Backup your database: Create a snapshot of your Qdrant database
  2. Test in a staging environment: Try the migration in a non-production environment first

If you need to roll back, restore from your backup.

Benefits of Multi-Tenancy

  • Reduced RAM usage: Significant decrease from ~14MB overhead per collection
  • Improved performance: Better resource utilization
  • Optimized storage: Data from the same tenant is co-located
  • Simplified management: Fewer collections to manage

Before

single-tenancy

After

multi-tenancy

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant QdrantClient
    participant QdrantDB

    Client->>QdrantClient: insert(collection_name, items)
    QdrantClient->>QdrantClient: _get_collection_and_tenant_id(collection_name)
    QdrantClient->>QdrantClient: _create_multi_tenant_collection_if_not_exists(mt_collection_name)
    QdrantClient->>QdrantDB: Insert items with tenant_id in payload

    Client->>QdrantClient: search(collection_name, vectors, limit)
    QdrantClient->>QdrantClient: _get_collection_and_tenant_id(collection_name)
    QdrantClient->>QdrantDB: Search in mt_collection_name with tenant_id filter

    Client->>QdrantClient: delete(collection_name, ids/filter)
    QdrantClient->>QdrantClient: _get_collection_and_tenant_id(collection_name)
    QdrantClient->>QdrantDB: Delete points with tenant_id (and optional filters)

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.


🔄 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/13679 **Author:** [@loitragg](https://github.com/loitragg) **Created:** 5/8/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `apply-multitenant-for-qdrant` --- ### 📝 Commits (3) - [`8c6fb34`](https://github.com/open-webui/open-webui/commit/8c6fb34c4399e08c39da529ec346cc275b0a98d2) perf: implement multi-tenancy support in QdrantClient with tenant ID handling and collection management - [`fbd0b18`](https://github.com/open-webui/open-webui/commit/fbd0b18d659ce93dd2cc0d88e1fedec1c3e04e7f) perf: check collection exists will be turn to try-catch to make 1 less request to Qdrant - [`06805e2`](https://github.com/open-webui/open-webui/commit/06805e22649377e105482a0903fe3cda30a2487a) fix: enhance error handling for collection creation in QdrantClient to manage "already exists" conflicts ### 📊 Changes **1 file changed** (+605 additions, -108 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/retrieval/vector/dbs/qdrant.py` (+605 -108) </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:** This pull request migrates Open WebUI to Qdrant's multi-tenancy feature to address excessive RAM usage and performance issues caused by the previous model of one collection per entity. It consolidates collections by entity type (Memories, Files, Knowledge, Web Search, YouTube) and uses tenant IDs for data partitioning. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [x] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [ ] **Testing:** Have you written and run sufficient tests to validate the changes? - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [x] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: (Suggested: `refactor`) - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry ### Discussions - https://github.com/open-webui/open-webui/discussions/10008 ### Description - Background: In the discussion above, we were using a separate Qdrant collection for each entity (memory, knowledge base, file), which led to thousands of collections. This approach is an anti-pattern according to Qdrant documentation and causes excessive RAM usage. - Solution: Qdrant recommends using multi-tenancy with payload-based partitioning for efficient resource usage when dealing with a large number of logical collections (https://qdrant.tech/documentation/guides/multiple-partitions/). This change migrates the Qdrant database to utilize its multi-tenancy feature. Collections are now consolidated by entity type (Memories, Files, Knowledge, Web Search, YouTube), and data within these collections is partitioned using a `tenant_id` field in payloads. ### Changed - Updated the existing `QdrantClient` class to use Qdrant's multi-tenancy feature while maintaining the same interface to avoid breaking changes in the application. - Consolidated numerous individual Qdrant collections into five main entity-specific collections: `Memories Collection`, `Files Collection`, `Knowledge Collection`, `Web Search Collection`, and `Hash Based Collection`(for Youtube and Web URL). - Implemented payload-based partitioning using a `tenant_id` field for data isolation within the new collections. - Configured Qdrant collections for multi-tenancy, including settings like `payload_m=16` (per-tenant indexing), `m=0` (disabled global index), and a keyword payload index for `tenant_id` with `is_tenant=true`. --- ### Additional Information #### Migration The existing API interface of the `QdrantClient` class is maintained to avoid breaking changes in the application, ensuring a seamless transition. However, Open WebUI will unable to access all the old Qdrant collections. Go to: Admin Settings > Documents > Reindex Knowledge Base Vectors to migrating knowledge #### Rollback **Before running the migration in production:** 1. **Backup your database**: Create a snapshot of your Qdrant database 2. **Test in a staging environment**: Try the migration in a non-production environment first If you need to roll back, restore from your backup. #### Benefits of Multi-Tenancy - **Reduced RAM usage**: Significant decrease from ~14MB overhead per collection - **Improved performance**: Better resource utilization - **Optimized storage**: Data from the same tenant is co-located - **Simplified management**: Fewer collections to manage #### Before ![single-tenancy](https://github.com/user-attachments/assets/5bac4742-23fa-4ac6-ac84-92c1f4385404) #### After ![multi-tenancy](https://github.com/user-attachments/assets/ae15633a-9fb2-47ca-9ed5-9dc5347350fe) #### Sequence Diagram(s) ```mermaid sequenceDiagram participant Client participant QdrantClient participant QdrantDB Client->>QdrantClient: insert(collection_name, items) QdrantClient->>QdrantClient: _get_collection_and_tenant_id(collection_name) QdrantClient->>QdrantClient: _create_multi_tenant_collection_if_not_exists(mt_collection_name) QdrantClient->>QdrantDB: Insert items with tenant_id in payload Client->>QdrantClient: search(collection_name, vectors, limit) QdrantClient->>QdrantClient: _get_collection_and_tenant_id(collection_name) QdrantClient->>QdrantDB: Search in mt_collection_name with tenant_id filter Client->>QdrantClient: delete(collection_name, ids/filter) QdrantClient->>QdrantClient: _get_collection_and_tenant_id(collection_name) QdrantClient->>QdrantDB: Delete points with tenant_id (and optional filters) ``` --- ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <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 04:43:31 -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#23263