llamaIndex - ✅(Solved) Fix [Bug]: MilvusVectorStore exception when instantiating if creating collection when using Pymilvus 2.6.8+ [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
run-llama/llama_index#20685Fetched 2026-04-08 00:31:30
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×2commented ×1cross-referenced ×1referenced ×1

Error Message

vector_store = MilvusVectorStore( ^^^^^^^^^^^^^^^^^^ File "/git/project/.venv/lib/python3.12/site-packages/llama_index/vector_stores/milvus/base.py", line 337, in init self._collection = Collection(collection_name, using=self.client._using) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/git/project/.venv/lib/python3.12/site-packages/pymilvus/orm/collection.py", line 148, in init raise SchemaNotReadyException( pymilvus.exceptions.SchemaNotReadyException: <SchemaNotReadyException: (code=1, message=Collection 'test_collection' not exist, or you can pass in schema to create one.)

Root Cause

When trying to instantiate a "MilvusVectorStore" to a database (not the "default") and the collection does not exist, an exception is thrown because the pymilvus connection is trying to work on the wrong database. This seems to be caused by mixing both the ORM and MilvusClient objects in the MilvusVectorStore. It looks like pymilvus is working on MilvusClient and not the ORM objects anymore which is causing incompatibilities (especially around the Connections object management).

Fix Action

Fixed

PR fix notes

PR #20696: fix: resolve incompatibility with Milvus ORM collection handling

Description (problem / solution / changelog)

Description

Resolves MilvusVectorStore exception (SchemaNotReadyException) when instantiating with pymilvus 2.6.8+ on non-default databases.

The root cause was that the code mixed pymilvus ORM Collection objects with MilvusClient API calls. In pymilvus 2.6.8+, these two APIs have incompatible connection/database management — the ORM Collection constructor fails because it resolves to the wrong database context when a non-default database is used via MilvusClient.

Changes:

  • base.py: Removed ORM Collection import and all usage. Replaced with pure MilvusClient API equivalents:
    • Collection(name, using=...)self._collection_initialized = True/False (boolean flag)
    • collection.schemaself.client.describe_collection() (returns dict)
    • collection.release()self.client.release_collection()
    • collection.set_properties()self.client.alter_collection_properties()
    • collection.load()self.client.load_collection()
  • utils.py: Updated get_default_sparse_embedding_function() to accept a dict (from describe_collection()) in addition to ORM Collection objects, with backward compatibility preserved.
  • tests: Removed obsolete Collection mock patch from test fixture.
  • pyproject.toml: Version bump 0.9.60.9.7.

Fixes #20685

New Package?

  • No

Version Bump?

  • Yes

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

All 22 existing unit tests pass locally (including collection creation, querying in all modes, deletion, index management, consistency level, and custom node format tests).

  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran uv run make format; uv run make lint to appease the lint gods

Changed files

  • llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/base.py (modified, +26/-12)
  • llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/llama_index/vector_stores/milvus/utils.py (modified, +23/-2)
  • llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/pyproject.toml (modified, +1/-1)
  • llama-index-integrations/vector_stores/llama-index-vector-stores-milvus/tests/test_vector_stores_milvus.py (modified, +7/-8)

Code Example

vector_store = MilvusVectorStore(
               ^^^^^^^^^^^^^^^^^^
File "/git/project/.venv/lib/python3.12/site-packages/llama_index/vector_stores/milvus/base.py", line 337, in __init__
  self._collection = Collection(collection_name, using=self.client._using)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/git/project/.venv/lib/python3.12/site-packages/pymilvus/orm/collection.py", line 148, in __init__
  raise SchemaNotReadyException(
pymilvus.exceptions.SchemaNotReadyException: <SchemaNotReadyException: (code=1, message=Collection 'test_collection' not exist, or you can pass in schema to create one.)
RAW_BUFFERClick to expand / collapse

Bug Description

When trying to instantiate a "MilvusVectorStore" to a database (not the "default") and the collection does not exist, an exception is thrown because the pymilvus connection is trying to work on the wrong database. This seems to be caused by mixing both the ORM and MilvusClient objects in the MilvusVectorStore. It looks like pymilvus is working on MilvusClient and not the ORM objects anymore which is causing incompatibilities (especially around the Connections object management).

Version

[email protected], [email protected], [email protected]

Steps to Reproduce

import asyncio

def create_database(): from pymilvus import MilvusClient client = MilvusClient(uri="http://0.0.0.0:19530/default") if not "test_database" in client.list_databases(): client.create_database(db_name="test_database") else: client.drop_database(db_name="test_database") client.create_database(db_name="test_database")

def reproduce_bug(): # Create MilvusVectorStore which should create a new collection from llama_index.vector_stores.milvus import MilvusVectorStore async def _create(): return MilvusVectorStore( uri="http://0.0.0.0:19530/test_database", token="", db_name="test_database", user="", password="", collection_name="test_collection", dim=1536, embedding_field="embedding", doc_id_field="doc_id", similarity_metric="IP", consistency_level="Bounded", overwrite=False, alias="abc", ) return asyncio.run(_create())

create_database() reproduce_bug()

Relevant Logs/Tracbacks

vector_store = MilvusVectorStore(
               ^^^^^^^^^^^^^^^^^^
File "/git/project/.venv/lib/python3.12/site-packages/llama_index/vector_stores/milvus/base.py", line 337, in __init__
  self._collection = Collection(collection_name, using=self.client._using)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/git/project/.venv/lib/python3.12/site-packages/pymilvus/orm/collection.py", line 148, in __init__
  raise SchemaNotReadyException(
pymilvus.exceptions.SchemaNotReadyException: <SchemaNotReadyException: (code=1, message=Collection 'test_collection' not exist, or you can pass in schema to create one.)

extent analysis

Fix Plan

To fix the issue, we need to ensure that the MilvusVectorStore is working with the correct database and collection. We can achieve this by creating the collection manually before instantiating the MilvusVectorStore. Here are the steps:

  • Create a MilvusClient object with the correct database name.
  • Check if the collection exists, and create it if it doesn't.
  • Instantiate the MilvusVectorStore with the correct database name and collection name.

Example Code

import asyncio
from pymilvus import MilvusClient, FieldSchema, CollectionSchema, DataType
from llama_index.vector_stores.milvus import MilvusVectorStore

def create_database_and_collection():
    client = MilvusClient(uri="http://0.0.0.0:19530/")
    if not "test_database" in client.list_databases():
        client.create_database(db_name="test_database")
    else:
        client.drop_database(db_name="test_database")
        client.create_database(db_name="test_database")

    # Create collection schema
    fields = [
        FieldSchema(name="doc_id", dtype=DataType.INT64, is_primary=True),
        FieldSchema(name="embedding", dtype=DataType.FLOAT_VECTOR, dim=1536)
    ]
    schema = CollectionSchema(fields=fields, description="test collection")

    # Create collection
    client = MilvusClient(uri="http://0.0.0.0:19530/test_database")
    if not "test_collection" in client.list_collections():
        client.create_collection(collection_name="test_collection", schema=schema)

def create_milvus_vector_store():
    async def _create():
        return MilvusVectorStore(
            uri="http://0.0.0.0:19530/test_database",
            token="",
            db_name="test_database",
            user="",
            password="",
            collection_name="test_collection",
            dim=1536,
            embedding_field="embedding",
            doc_id_field="doc_id",
            similarity_metric="IP",
            consistency_level="Bounded",
            overwrite=False,
            alias="abc",
        )
    return asyncio.run(_create())

create_database_and_collection()
vector_store = create_milvus_vector_store()

Verification

To verify that the fix worked, you can check if the MilvusVectorStore is created successfully and if the collection exists in the database. You can also try to insert data into the collection and query it to ensure that it's working as expected.

Extra Tips

  • Make sure to handle exceptions properly when working with the MilvusClient and MilvusVectorStore to avoid any unexpected errors.
  • Consider using a try-except block to catch any exceptions that may occur during the creation of the database and collection.
  • You can also use the

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING