fix: large files fail to upload when Milvus is the vector database (#31990)

With Milvus as the vector database, all chunks of a file were sent to Milvus in one request. Large files exceeded Milvus's default 64 MB request size limit, so processing ran through the whole embedding step and then failed with the error RESOURCE_EXHAUSTED. With a 4096-dimension embedding model this already happened at about 4,000 chunks, which is a few MB of text. Chunks are now sent in batches of 128, with and without ENABLE_MILVUS_MULTITENANCY_MODE.

Fixes #31989
This commit is contained in:
Classic298 2026-10-07 13:05:25 +02:00 • committed by GitHub
parent 728f397ff4
commit 30dbf3256a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 9 deletions

View file

@ -86,6 +86,11 @@ def _truncate_text(text: str) -> str:
return text.encode()[:MILVUS_TEXT_MAX_LENGTH].decode(errors='ignore')
def _write_in_batches(write: Callable[..., Any], collection_name: str, rows: list[dict]) -> None:
for start in range(0, len(rows), BM25_BACKFILL_BATCH_SIZE):
write(collection_name=collection_name, data=rows[start : start + BM25_BACKFILL_BATCH_SIZE])
def _bm25_rows(rows: list[dict]) -> list[dict]:
return [
{
@ -580,10 +585,7 @@ class MilvusClient(VectorDBBase):
row['data'] = {'text': text}
data.append(row)
try:
return self.client.insert(
collection_name=f'{self.collection_prefix}_{collection_name}',
data=data,
)
_write_in_batches(self.client.insert, f'{self.collection_prefix}_{collection_name}', data)
except MilvusException as e:
log.error(f'Milvus insert failed for {self.collection_prefix}_{collection_name} ({len(items)} items): {e}')
raise
@ -626,10 +628,7 @@ class MilvusClient(VectorDBBase):
row['data'] = {'text': text}
data.append(row)
try:
return self.client.upsert(
collection_name=f'{self.collection_prefix}_{collection_name}',
data=data,
)
_write_in_batches(self.client.upsert, f'{self.collection_prefix}_{collection_name}', data)
except MilvusException as e:
log.error(f'Milvus upsert failed for {self.collection_prefix}_{collection_name} ({len(items)} items): {e}')
raise

View file

@ -26,6 +26,7 @@ from open_webui.retrieval.vector.dbs.milvus import (
_metadata_exprs,
_supports_bm25,
_truncate_text,
_write_in_batches,
)
from open_webui.retrieval.vector.main import (
GetResult,
@ -237,7 +238,7 @@ class MilvusClient(VectorDBBase):
)
try:
self.client.insert(collection_name=mt_collection, data=entities)
_write_in_batches(self.client.insert, mt_collection, entities)
except MilvusException as e:
log.error(
f'Milvus insert failed (collection={mt_collection}, '