{"record":{"id":"2c5f2dc2604f003d","repo":"microsoft/semantic-kernel","slug":"collection-collection-name-does-not-exist-canno-2c5f2d","errorCode":null,"errorMessage":"Collection {collection_name} does not exist, cannot search.","messagePattern":"Collection (.+?) does not exist, cannot search\\.","errorType":"exception","errorClass":"ServiceResourceNotFoundError","httpStatus":404,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py","lineNumber":411,"sourceCode":"\n        Args:\n            collection_name (str): The collection to search.\n            embedding (ndarray): The embedding to search.\n            limit (int): The total results to display.\n            min_relevance_score (float, optional): Minimum distance to include. Defaults to None.\n            with_embeddings (bool, optional): Whether to include embeddings in result. Defaults to False.\n\n        Raises:\n            Exception: Missing collection\n            e: Failure to search\n\n        Returns:\n            List[Tuple[MemoryRecord, float]]: MemoryRecord and distance tuple.\n        \"\"\"\n        # Check if collection exists\n        if collection_name not in utility.list_collections():\n            logger.debug(f\"Collection {collection_name} does not exist, cannot search.\")\n            raise ServiceResourceNotFoundError(f\"Collection {collection_name} does not exist, cannot search.\")\n        # Search requests takes a list of requests.\n        if len(embedding.shape) == 1:\n            embedding = expand_dims(embedding, axis=0)\n\n        try:\n            self.collections[collection_name].load()\n            metric = self.collections[collection_name].index(index_name=SEARCH_FIELD_EMBEDDING).params[\"metric_type\"]\n            # Try with passed in metric\n            results = self.collections[collection_name].search(\n                data=embedding,\n                anns_field=SEARCH_FIELD_EMBEDDING,\n                limit=limit,\n                output_fields=OUTPUT_FIELDS_W_EMBEDDING if with_embeddings else OUTPUT_FIELDS_WO_EMBEDDING,\n                param={\"metric_type\": metric},\n            )[0]\n        except Exception as e:\n            logger.debug(f\"Search failed: {e}\")\n            raise ServiceResponseException(f\"Search failed: {e}\") from e","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py#L393-L429","documentation":"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.","triggerScenarios":"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.","commonSituations":"Running a search before setup completed. Collection name typo. Searching a collection on a reset Milvus instance. Wrong Milvus database/namespace.","solutions":["Ensure create_collection and index creation ran before searching.","Guard with utility.has_collection or does_collection_exist.","Catch ServiceResourceNotFoundError and return an empty result list if appropriate.","Verify the embedding dimension matches the collection schema."],"exampleFix":"// before\nmatches = await store.get_nearest_matches('docs', embedding, limit=5)  # ServiceResourceNotFoundError\n// after\nif collection_name not in utility.list_collections():\n    matches = []\nelse:\n    matches = await store.get_nearest_matches('docs', embedding, limit=5)","handlingStrategy":"validation","validationCode":"from pymilvus import utility\n\nif collection_name not in utility.list_collections():\n    matches = []\nelse:\n    matches = await store.get_nearest_matches('docs', embedding, limit=5)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceResourceNotFoundError\n\ntry:\n    matches = await store.get_nearest_matches('docs', embedding, limit=5)\nexcept ServiceResourceNotFoundError:\n    matches = []","preventionTips":["Ensure create_collection and index creation completed before searching.","Guard search with utility.has_collection or does_collection_exist.","Verify embedding dimension matches the collection schema.","Return empty results for missing collections when non-fatal."],"tags":["milvus","collection","resource-not-found","search","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}