From fe56ab24f31e2905f48560d560ec8e72f1a5779c Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 22 Sep 2026 20:48:45 +0200 Subject: [PATCH] fix: page Chroma get() so hybrid search works on collections over 32k chunks (#30368) With Chroma as the vector DB, hybrid search on a knowledge base with more than 32766 chunks fails with HTTP 400 "Error querying knowledge base". The legacy hybrid path fetches the whole collection to build the BM25 index, and Chroma's unbounded collection.get() binds one SQLite variable per row, so any collection above SQLite's 32766 variable limit raises "too many SQL variables" (reproduced on chromadb 1.5.9 with both PersistentClient and HttpClient). Vector-only search on the same collection works, which makes it look like a hybrid-search bug. The Chroma adapter now reads the collection in pages of 10000 rows via limit/offset and concatenates them into the same GetResult shape as before. Verified on a 90000-row collection: every row returned exactly once with documents and metadata aligned to ids, page order stable across page sizes, empty and exactly-one-page collections unchanged, and query_doc_with_hybrid_search returns results where it previously raised. The tests repo unit suite is identical before and after. Fixes #30351 --- .../open_webui/retrieval/vector/dbs/chroma.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/retrieval/vector/dbs/chroma.py b/backend/open_webui/retrieval/vector/dbs/chroma.py index 2c51aeca93..5c5d9602e8 100755 --- a/backend/open_webui/retrieval/vector/dbs/chroma.py +++ b/backend/open_webui/retrieval/vector/dbs/chroma.py @@ -28,6 +28,8 @@ from open_webui.retrieval.vector.utils import process_metadata log = logging.getLogger(__name__) +GET_PAGE_SIZE = 10000 + class ChromaClient(VectorDBBase): def __init__(self): @@ -131,12 +133,18 @@ class ChromaClient(VectorDBBase): # Get all the items in the collection. collection = self.client.get_collection(name=collection_name, embedding_function=None) if collection: - result = collection.get() + ids, documents, metadatas = [], [], [] + # Unpaged get() exceeds SQLite's bind-variable limit on large collections + for offset in range(0, collection.count(), GET_PAGE_SIZE): + page = collection.get(limit=GET_PAGE_SIZE, offset=offset) + ids.extend(page['ids']) + documents.extend(page['documents']) + metadatas.extend(page['metadatas']) return GetResult( **{ - 'ids': [result['ids']], - 'documents': [result['documents']], - 'metadatas': [result['metadatas']], + 'ids': [ids], + 'documents': [documents], + 'metadatas': [metadatas], } ) return None