mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-28 05:27:35 +00:00
Update milvus_multitenancy.py (#25857)
This commit is contained in:
parent
819ad1d904
commit
d501e3d6b5
1 changed files with 33 additions and 11 deletions
|
|
@ -31,10 +31,15 @@ from pymilvus import (
|
|||
connections,
|
||||
utility,
|
||||
)
|
||||
from pymilvus.exceptions import MilvusException
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
RESOURCE_ID_FIELD = 'resource_id'
|
||||
# Milvus VARCHAR hard cap for the `text` field (see _create_shared_collection).
|
||||
# Chunks longer than this are truncated before insert so one oversized chunk
|
||||
# can't fail the whole batch (and leave the file with zero embeddings).
|
||||
MILVUS_TEXT_MAX_LENGTH = 65535
|
||||
|
||||
# Milvus expressions are SQL-like strings with no parameterized-query API;
|
||||
# values get interpolated into single-quoted literals. Reject anything that
|
||||
|
|
@ -169,17 +174,34 @@ class MilvusClient(VectorDBBase):
|
|||
self._ensure_collection(mt_collection, dimension)
|
||||
collection = Collection(mt_collection)
|
||||
|
||||
entities = [
|
||||
{
|
||||
'id': item['id'],
|
||||
'vector': item['vector'],
|
||||
'text': item['text'],
|
||||
'metadata': item['metadata'],
|
||||
RESOURCE_ID_FIELD: resource_id,
|
||||
}
|
||||
for item in items
|
||||
]
|
||||
collection.insert(entities)
|
||||
entities = []
|
||||
for item in items:
|
||||
text = item['text'] or ''
|
||||
if len(text) > MILVUS_TEXT_MAX_LENGTH:
|
||||
log.warning(
|
||||
f'Milvus: truncating text id={item["id"]} '
|
||||
f'{len(text)}->{MILVUS_TEXT_MAX_LENGTH} chars '
|
||||
f'(collection={mt_collection}, resource_id={resource_id})'
|
||||
)
|
||||
text = text[:MILVUS_TEXT_MAX_LENGTH]
|
||||
entities.append(
|
||||
{
|
||||
'id': item['id'],
|
||||
'vector': item['vector'],
|
||||
'text': text,
|
||||
'metadata': item['metadata'],
|
||||
RESOURCE_ID_FIELD: resource_id,
|
||||
}
|
||||
)
|
||||
|
||||
try:
|
||||
collection.insert(entities)
|
||||
except MilvusException as e:
|
||||
log.error(
|
||||
f'Milvus insert failed (collection={mt_collection}, '
|
||||
f'resource_id={resource_id}, items={len(entities)}): {e}'
|
||||
)
|
||||
raise
|
||||
|
||||
def search(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue