microsoft/semantic-kernel · error · ServiceResourceNotFoundError

Collection {collection_name} does not exist, cannot search.

Error message

Collection {collection_name} does not exist, cannot search.

What it means

Raised as a ServiceResourceNotFoundError in MilvusMemoryStore.get_nearest_matches when the collection name is not in utility.list_collections(). Vector similarity search requires an existing, indexed collection to load and search against.

Source

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

        Args:
            collection_name (str): The collection to search.
            embedding (ndarray): The embedding to search.
            limit (int): The total results to display.
            min_relevance_score (float, optional): Minimum distance to include. Defaults to None.
            with_embeddings (bool, optional): Whether to include embeddings in result. Defaults to False.

        Raises:
            Exception: Missing collection
            e: Failure to search

        Returns:
            List[Tuple[MemoryRecord, float]]: MemoryRecord and distance tuple.
        """
        # Check if collection exists
        if collection_name not in utility.list_collections():
            logger.debug(f"Collection {collection_name} does not exist, cannot search.")
            raise ServiceResourceNotFoundError(f"Collection {collection_name} does not exist, cannot search.")
        # Search requests takes a list of requests.
        if len(embedding.shape) == 1:
            embedding = expand_dims(embedding, axis=0)

        try:
            self.collections[collection_name].load()
            metric = self.collections[collection_name].index(index_name=SEARCH_FIELD_EMBEDDING).params["metric_type"]
            # Try with passed in metric
            results = self.collections[collection_name].search(
                data=embedding,
                anns_field=SEARCH_FIELD_EMBEDDING,
                limit=limit,
                output_fields=OUTPUT_FIELDS_W_EMBEDDING if with_embeddings else OUTPUT_FIELDS_WO_EMBEDDING,
                param={"metric_type": metric},
            )[0]
        except Exception as e:
            logger.debug(f"Search failed: {e}")
            raise ServiceResponseException(f"Search failed: {e}") from e

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Ensure create_collection and index creation ran before searching.
  2. Guard with utility.has_collection or does_collection_exist.
  3. Catch ServiceResourceNotFoundError and return an empty result list if appropriate.
  4. Verify the embedding dimension matches the collection schema.

Example fix

// before
matches = await store.get_nearest_matches('docs', embedding, limit=5)  # ServiceResourceNotFoundError
// after
if collection_name not in utility.list_collections():
    matches = []
else:
    matches = await store.get_nearest_matches('docs', embedding, limit=5)
Defensive patterns

Strategy: validation

Validate before calling

from pymilvus import utility

if collection_name not in utility.list_collections():
    matches = []
else:
    matches = await store.get_nearest_matches('docs', embedding, limit=5)

Try / catch

from semantic_kernel.exceptions import ServiceResourceNotFoundError

try:
    matches = await store.get_nearest_matches('docs', embedding, limit=5)
except ServiceResourceNotFoundError:
    matches = []

Prevention

When it happens

Trigger: Calling await store.get_nearest_matches('my_collection', embedding, limit) before create_collection, or after the collection was dropped. Also via get_nearest_match which delegates here with limit=1.

Common situations: Running a search before setup completed. Collection name typo. Searching a collection on a reset Milvus instance. Wrong Milvus database/namespace.

Related errors


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