microsoft/semantic-kernel · error · ServiceResponseException
Remove failed due to
Error message
Remove failed due to: {e} What it means
Raised as a ServiceResponseException in MilvusMemoryStore.remove_batch when .load(), .delete(), or .flush() throws any Exception during record deletion. The original exception is chained and its message interpolated, exposing the underlying Milvus SDK error.
Solutions
- Read the interpolated {e} to find the root cause.
- Ensure keys form a valid Milvus 'in' expression.
- Retry on transient connection/server errors with backoff.
- Check Milvus server logs and query-node health.
Example fix
// before
await store.remove_batch('docs', keys) # ServiceResponseException: Remove failed due to: ...
// after
try:
await store.remove_batch('docs', keys)
except ServiceResponseException as e:
logging.error('Milvus remove failed: %s', e)
raise Defensive patterns
Strategy: try-catch
Validate before calling
def valid_milvus_keys(keys: list[str]) -> bool:
return bool(keys) and all(isinstance(k, str) and k for k in keys)
if not valid_milvus_keys(keys):
raise ValueError('Invalid keys for Milvus delete expression') Try / catch
from semantic_kernel.exceptions import ServiceResponseException
try:
await store.remove_batch('docs', keys)
except ServiceResponseException as e:
logging.error('Milvus remove failed: %s', e)
raise Prevention
- Ensure keys form a valid Milvus 'in' expression for delete.
- Retry transient connection/server errors with backoff.
- Check Milvus query-node health for load() failures.
- Log the chained exception to classify the failure.
When it happens
Trigger: Milvus delete fails due to connection errors, an invalid delete expression (built as expr=f'{SEARCH_FIELD_ID} in {keys}'), server-side issues, or flush timeouts.
Common situations: Network interruption during delete/flush. Malformed keys list producing an invalid expression. Milvus query node under memory pressure during load(). SDK/server version mismatch.
Related errors
- Get failed due to
- Search failed
- Upsert failed due to
- Collection does not exist, cannot remove.
- Failed to remove all keys
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/83999b32d96fccbe.
Report an issue: GitHub.
Appendix: source
Thrown at python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py:377
collection_name (str): Collection to remove from
keys (List[str]): The list of keys.
Raises:
Exception: Collection doesnt exist.
e: Failure to remove key.
"""
if collection_name not in utility.list_collections():
logger.debug(f"Collection {collection_name} does not exist, cannot remove.")
raise ServiceResourceNotFoundError(f"Collection {collection_name} does not exist, cannot remove.")
try:
self.collections[collection_name].load()
result = self.collections[collection_name].delete(
expr=f"{SEARCH_FIELD_ID} in {keys}",
)
self.collections[collection_name].flush()
except Exception as e:
logger.debug(f"Remove failed due to: {e}")
raise ServiceResponseException(f"Remove failed due to: {e}") from e
if result.delete_count != len(keys):
logger.debug(f"Failed to remove all keys, {result.delete_count} removed out of {len(keys)}")
raise ServiceResponseException(
f"Failed to remove all keys, {result.delete_count} removed out of {len(keys)}"
)
async def get_nearest_matches(
self,
collection_name: str,
embedding: ndarray,
limit: int,
min_relevance_score: float = 0.0,
with_embeddings: bool = False,
) -> list[tuple[MemoryRecord, float]]:
"""Find the nearest `limit` matches for an embedding.
Args:
collection_name (str): The collection to search.View on GitHub (pinned to c028a0c7dc)