microsoft/semantic-kernel · error · ServiceResourceNotFoundError
Collection {collection_name} does not exist, cannot remove.
Error message
Collection {collection_name} does not exist, cannot remove. What it means
Raised as a ServiceResourceNotFoundError in MilvusMemoryStore.remove_batch when the collection name is not in utility.list_collections(). The remove path requires an existing collection to load and delete from.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/milvus/milvus_memory_store.py:368
collection_name (str): Collection to remove from.
key (str): The key to remove.
"""
await self.remove_batch(collection_name=collection_name, keys=[key])
async def remove_batch(self, collection_name: str, keys: list[str]) -> None:
"""Remove multiple records based on keys.
Args:
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,View on GitHub (pinned to c028a0c7dc)
Solutions
- Guard with utility.has_collection(collection_name) before calling remove/remove_batch.
- Catch ServiceResourceNotFoundError and treat removal of a non-existent collection as a no-op if idempotent deletion is desired.
- Verify collection name spelling and the target Milvus instance.
- Ensure create_collection ran in the current environment.
Example fix
// before
await store.remove('docs', key) # ServiceResourceNotFoundError
// after
try:
await store.remove_batch('docs', [key])
except ServiceResourceNotFoundError:
pass # collection already gone; nothing to remove Defensive patterns
Strategy: validation
Validate before calling
from pymilvus import utility
if collection_name in utility.list_collections():
await store.remove_batch('docs', keys)
else:
logging.info('Collection absent; skip remove') Try / catch
from semantic_kernel.exceptions import ServiceResourceNotFoundError
try:
await store.remove_batch('docs', keys)
except ServiceResourceNotFoundError:
pass # idempotent: collection already absent Prevention
- Guard remove/remove_batch with utility.has_collection for idempotent cleanup.
- Verify collection name and Milvus instance in teardown scripts.
- Treat removal of a missing collection as a no-op where appropriate.
- Run create_collection before any remove path in fresh environments.
When it happens
Trigger: Calling await store.remove('my_collection', key) or remove_batch on a collection that does not exist. Note remove delegates to remove_batch. The collection may have been dropped or never created.
Common situations: Cleanup/teardown code running against a collection already deleted. Collection name mismatch. Running remove in a fresh environment where create_collection was never called.
Related errors
- Collection {collection_name} does not exist, cannot insert.
- Collection {collection_name} does not exist, cannot get.
- Collection {collection_name} does not exist, cannot search.
- collection {collection_name} not found
- Collection '{collection_name}' does not exist
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/9ce86b4681ce4e6b.
Report an issue: GitHub.