From f4a6ea9300f130dc2f755d82d935f18160b8f5d2 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Fri, 10 Jul 2026 20:29:29 +0200 Subject: [PATCH] fix: Milvus multitenancy scalar index creation on Milvus Lite (#26911) Enabling ENABLE_MILVUS_MULTITENANCY_MODE with the default MILVUS_URI (embedded Milvus Lite at DATA_DIR/vector_db/milvus.db) fails on the first embedding write: _create_shared_collection calls collection.create_index(RESOURCE_ID_FIELD) with no index params. A Milvus server auto-selects a scalar index type in that case, but Milvus Lite rejects the call with "create_index missing required 'index_type' parameter", so shared collection creation raises and every embedding write 500s (memory add, file upload, knowledge writes). Keep the parameterless call as the first attempt so behavior on Milvus servers is unchanged, fall back to an explicit INVERTED scalar index, and if that also fails log a warning and continue. The scalar index only accelerates resource_id filters; inserts and filtered queries work without it, so a missing index must not break collection creation. Verified against embedded Milvus Lite: shared collections now create (with the warning), and memory add, file upload and memory query succeed end to end. Against a Milvus server the first attempt is identical to the current code, so nothing changes where it works today. --- .../retrieval/vector/dbs/milvus_multitenancy.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/retrieval/vector/dbs/milvus_multitenancy.py b/backend/open_webui/retrieval/vector/dbs/milvus_multitenancy.py index 6549c58c62..629acbcb64 100644 --- a/backend/open_webui/retrieval/vector/dbs/milvus_multitenancy.py +++ b/backend/open_webui/retrieval/vector/dbs/milvus_multitenancy.py @@ -146,7 +146,19 @@ class MilvusClient(VectorDBBase): index_params['params'] = {'nlist': MILVUS_IVF_FLAT_NLIST} collection.create_index('vector', index_params) - collection.create_index(RESOURCE_ID_FIELD) + try: + # A Milvus server auto-selects the scalar index type; embedded + # Milvus Lite requires an explicit one. + collection.create_index(RESOURCE_ID_FIELD) + except MilvusException: + try: + collection.create_index(RESOURCE_ID_FIELD, {'index_type': 'INVERTED'}) + except MilvusException as e: + # The index only accelerates resource_id filters; never fail + # collection creation over it. + log.warning( + f'Could not create {RESOURCE_ID_FIELD} index on {mt_collection_name}: {e}' + ) log.info(f'Created shared collection: {mt_collection_name}') return collection