{"record":{"id":"4db07969bb6449fb","repo":"microsoft/semantic-kernel","slug":"search-failed-e","errorCode":null,"errorMessage":"Search failed: {e}","messagePattern":"Search failed: (.+?)","errorType":"exception","errorClass":"ServiceResponseException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py","lineNumber":429,"sourceCode":"            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\n        return [\n            (milvus_dict_to_memoryrecord(result.fields), result.distance)\n            for result in results\n            if result.distance >= min_relevance_score\n        ]\n\n    async def get_nearest_match(\n        self,\n        collection_name: str,\n        embedding: ndarray,\n        min_relevance_score: float = 0.0,\n        with_embedding: bool = False,\n    ) -> tuple[MemoryRecord, float] | None:\n        \"\"\"Find the nearest match for an embedding.\n\n        Args:\n            collection_name (str): The collection to search.\n            embedding (ndarray): The embedding to search for.","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py#L411-L447","documentation":"Raised as a ServiceResponseException in MilvusMemoryStore.get_nearest_matches when .load(), .index(), or .search() throws any Exception. The search involves loading the collection, reading the index metric_type, and executing the ANN search; failures at any step are wrapped with the original error chained.","triggerScenarios":"Search fails due to: embedding dimension mismatch with the index, missing vector index on SEARCH_FIELD_EMBEDDING, memory pressure during load(), invalid search parameters, or network/server errors.","commonSituations":"Querying an embedding whose dimension differs from the collection schema. Collection has no vector index built yet. Milvus query node out of memory. Connection drop during search. min_relevance_score filtering post-search.","solutions":["Inspect the interpolated {e} to pinpoint load vs index vs search failure.","Confirm the embedding dimension matches the collection's schema.","Ensure a vector index exists on SEARCH_FIELD_EMBEDDING before searching.","Retry on transient server/network errors with backoff; scale query nodes if OOM recurs."],"exampleFix":"// before\nmatches = await store.get_nearest_matches('docs', embedding, limit=5)  # ServiceResponseException: Search failed: ...\n// after\ntry:\n    matches = await store.get_nearest_matches('docs', embedding, limit=5)\nexcept ServiceResponseException as e:\n    logging.error('Milvus search failed: %s', e)\n    matches = []","handlingStrategy":"try-catch","validationCode":"import numpy as np\n\ndef embedding_matches_dim(emb: np.ndarray, expected_dim: int) -> bool:\n    return emb is not None and emb.size == expected_dim\n\nif not embedding_matches_dim(embedding, expected_dim=1536):\n    raise ValueError('Embedding dimension mismatch')","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceResponseException\n\ntry:\n    matches = await store.get_nearest_matches('docs', embedding, limit=5)\nexcept ServiceResponseException as e:\n    logging.error('Milvus search failed: %s', e)\n    matches = []","preventionTips":["Confirm embedding dimensions match the collection schema before searching.","Ensure a vector index exists on the embedding field.","Monitor query-node memory to avoid load() OOM.","Retry transient server errors with backoff."],"tags":["milvus","search","service-response","runtime","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}