microsoft/semantic-kernel · error · ServiceResourceNotFoundError

Collection {collection_name} does not exist, cannot insert.

Error message

Collection {collection_name} does not exist, cannot insert.

What it means

Raised as a ServiceResourceNotFoundError in MilvusMemoryStore.upsert_batch when the collection name is not found in utility.list_collections(). Milvus requires a collection (with schema and index) to exist before data can be upserted; the store does not auto-create it.

Source

Thrown at python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py:290

        """_summary_.

        Args:
            collection_name (str): The collection name.
            records (List[MemoryRecord]): A list of memory records.
            batch_size (int, optional): Batch size of the insert, 0 is a batch
                size of total size. Defaults to 100.

        Raises:
            Exception: Collection doesnt exist.
            e: Failed to upsert a record.

        Returns:
            List[str]: A list of inserted ID's.
        """
        # Check if the collection exists.
        if collection_name not in utility.list_collections():
            logger.debug(f"Collection {collection_name} does not exist, cannot insert.")
            raise ServiceResourceNotFoundError(f"Collection {collection_name} does not exist, cannot insert.")
        # Convert the records to dicts
        insert_list = [memoryrecord_to_milvus_dict(record) for record in records]
        try:
            ids = self.collections[collection_name].upsert(data=insert_list).primary_keys
            self.collections[collection_name].flush()
            return ids
        except Exception as e:
            logger.debug(f"Upsert failed due to: {e}")
            raise ServiceResponseException(f"Upsert failed due to: {e}") from e

    async def get(self, collection_name: str, key: str, with_embedding: bool) -> MemoryRecord:
        """Get the MemoryRecord corresponding to the key.

        Args:
            collection_name (str): The collection to get from.
            key (str): The ID to grab.
            with_embedding (bool): Whether to include the embedding in the results.

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Call await store.create_collection(...) for the collection before upserting.
  2. Verify collection_name against utility.list_collections() output.
  3. Catch ServiceResourceNotFoundError, create the collection, and retry the upsert.
  4. Confirm you are connected to the correct Milvus host/port and database.

Example fix

// before
ids = await store.upsert_batch('docs', records)  # ServiceResourceNotFoundError
// after
try:
    ids = await store.upsert_batch('docs', records)
except ServiceResourceNotFoundError:
    await store.create_collection('docs', ...)
    ids = await store.upsert_batch('docs', records)
Defensive patterns

Strategy: validation

Validate before calling

from pymilvus import utility

def collection_exists(name: str) -> bool:
    return name in utility.list_collections()

if not collection_exists('docs'):
    await store.create_collection('docs', ...)
ids = await store.upsert_batch('docs', records)

Try / catch

from semantic_kernel.exceptions import ServiceResourceNotFoundError

try:
    ids = await store.upsert_batch('docs', records)
except ServiceResourceNotFoundError:
    await store.create_collection('docs', ...)
    ids = await store.upsert_batch('docs', records)

Prevention

When it happens

Trigger: Calling await store.upsert_batch('my_collection', records) before create_collection. Also when the Milvus instance was reset/redeployed, dropping all collections, but the application still references old names.

Common situations: Forgetting to call create_collection during setup. Collection name typo. Milvus server restart with ephemeral storage. Connecting to a different Milvus instance/namespace than expected.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/81e49a6406f771f6. Report an issue: GitHub.