microsoft/semantic-kernel · error · ServiceResponseException
Search failed: {e}
Error message
Search failed: {e} What it means
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.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py:429
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
return [
(milvus_dict_to_memoryrecord(result.fields), result.distance)
for result in results
if result.distance >= min_relevance_score
]
async def get_nearest_match(
self,
collection_name: str,
embedding: ndarray,
min_relevance_score: float = 0.0,
with_embedding: bool = False,
) -> tuple[MemoryRecord, float] | None:
"""Find the nearest match for an embedding.
Args:
collection_name (str): The collection to search.
embedding (ndarray): The embedding to search for.View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before
matches = await store.get_nearest_matches('docs', embedding, limit=5) # ServiceResponseException: Search failed: ...
// after
try:
matches = await store.get_nearest_matches('docs', embedding, limit=5)
except ServiceResponseException as e:
logging.error('Milvus search failed: %s', e)
matches = [] Defensive patterns
Strategy: try-catch
Validate before calling
import numpy as np
def embedding_matches_dim(emb: np.ndarray, expected_dim: int) -> bool:
return emb is not None and emb.size == expected_dim
if not embedding_matches_dim(embedding, expected_dim=1536):
raise ValueError('Embedding dimension mismatch') Try / catch
from semantic_kernel.exceptions import ServiceResponseException
try:
matches = await store.get_nearest_matches('docs', embedding, limit=5)
except ServiceResponseException as e:
logging.error('Milvus search failed: %s', e)
matches = [] Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Upsert failed due to: {e}
- Get failed due to: {e}
- Remove failed due to: {e}
- Collection {collection_name} does not exist, cannot search.
- Python nodes are not supported in the dotnet runtime.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/4db07969bb6449fb.
Report an issue: GitHub.