microsoft/semantic-kernel · error · ServiceResourceNotFoundError

Collection {collection_name} does not exist, cannot get.

Error message

Collection {collection_name} does not exist, cannot get.

What it means

Raised as a ServiceResourceNotFoundError in MilvusMemoryStore.get_batch when utility.has_collection(collection_name) returns False. This guards the query path: without the collection, no records can be retrieved.

Source

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

    async def get_batch(self, collection_name: str, keys: list[str], with_embeddings: bool) -> list[MemoryRecord]:
        """Get the MemoryRecords corresponding to the keys.

        Args:
            collection_name (str): _description_
            keys (List[str]): _description_
            with_embeddings (bool): _description_

        Raises:
            Exception: _description_
            e: _description_

        Returns:
            List[MemoryRecord]: _description_
        """
        # Check if the collection exists
        if not utility.has_collection(collection_name):
            logger.debug(f"Collection {collection_name} does not exist, cannot get.")
            raise ServiceResourceNotFoundError(f"Collection {collection_name} does not exist, cannot get.")

        try:
            self.collections[collection_name].load()
            gets = self.collections[collection_name].query(
                expr=f"{SEARCH_FIELD_ID} in {keys}",
                output_fields=OUTPUT_FIELDS_W_EMBEDDING if with_embeddings else OUTPUT_FIELDS_WO_EMBEDDING,
            )
        except Exception as e:
            logger.debug(f"Get failed due to: {e}")
            raise ServiceResponseException(f"Get failed due to: {e}") from e
        return [milvus_dict_to_memoryrecord(get) for get in gets]

    async def remove(self, collection_name: str, key: str) -> None:
        """Remove the specified record based on key.

        Args:
            collection_name (str): Collection to remove from.
            key (str): The key to remove.

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Ensure create_collection ran successfully before any get/get_batch call.
  2. Guard with utility.has_collection(collection_name) or store.does_collection_exist.
  3. Catch ServiceResourceNotFoundError and return None or an empty result for non-fatal missing collections.
  4. Verify the Milvus connection targets the right database/namespace.

Example fix

// before
record = await store.get('docs', key)  # ServiceResourceNotFoundError
// after
if not utility.has_collection('docs'):
    record = None
else:
    record = await store.get('docs', key)
Defensive patterns

Strategy: validation

Validate before calling

from pymilvus import utility

if not utility.has_collection('docs'):
    record = None
else:
    record = await store.get('docs', key)

Try / catch

from semantic_kernel.exceptions import ServiceResourceNotFoundError

try:
    record = await store.get('docs', key)
except ServiceResourceNotFoundError:
    record = None

Prevention

When it happens

Trigger: Calling await store.get('my_collection', key) or get_batch before the collection exists. Note get delegates to get_batch internally. Also triggered when the collection was dropped between creation and the read.

Common situations: Querying a collection name that was never created or was deleted. Connecting to a fresh Milvus instance. Collection name casing or whitespace mismatch.

Related errors


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