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
This commit is contained in:
Classic298
2026-09-22 14:48:45 -04:00
committed by GitHub
parent e93a59f4dd
commit fe56ab24f3
@@ -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