microsoft/semantic-kernel · error · ServiceResourceNotFoundError
Collection {collection_name} does not exist
Error message
Collection {collection_name} does not exist What it means
Raised by USearchMemoryStore.get_batch (ServiceResourceNotFoundError) when the target collection is not in `self._collections`, before attempting to resolve keys to labels. Unlike get() (which raises per-key), this guards the whole collection; the message is the plain 'Collection X does not exist'.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py:397
keys=[key],
with_embeddings=with_embedding,
dtype=dtype,
)
if not result:
raise ServiceResourceNotFoundError(f"Key '{key}' not found in collection '{collection_name}'")
return result[0]
async def get_batch(
self,
collection_name: str,
keys: list[str],
with_embeddings: bool,
dtype: ScalarKind = ScalarKind.F32,
) -> list[MemoryRecord]:
"""Retrieve a batch of MemoryRecords using their keys."""
collection_name = collection_name.lower()
if collection_name not in self._collections:
raise ServiceResourceNotFoundError(f"Collection {collection_name} does not exist")
ucollection = self._collections[collection_name]
labels = [ucollection.embeddings_id_to_label[key] for key in keys if key in ucollection.embeddings_id_to_label]
if not labels:
return []
vectors = ucollection.embeddings_index.get(labels, dtype) if with_embeddings else None
return pyarrow_table_to_memoryrecords(ucollection.embeddings_data_table.take(pa.array(labels)), vectors)
async def remove(self, collection_name: str, key: str) -> None:
"""Remove a single MemoryRecord using its key."""
collection_name = collection_name.lower()
await self.remove_batch(collection_name=collection_name, keys=[key])
return
async def remove_batch(self, collection_name: str, keys: list[str]) -> None:
"""Remove a batch of MemoryRecords using their keys."""
collection_name = collection_name.lower()View on GitHub (pinned to c028a0c7dc)
Solutions
- Create/load the collection first with create_collection (or set persist_directory at construction).
- Guard with does_collection_exist / `'docs' in store._collections` before reading.
- Match the collection name exactly (case-insensitive).
Example fix
// before
recs = await store.get_batch('docs', keys, with_embeddings=True)
// after
if not await store.does_collection_exist('docs'):
recs = []
else:
recs = await store.get_batch('docs', keys, with_embeddings=True) Defensive patterns
Strategy: validation
Validate before calling
name = collection_name.lower()
if not await store.does_collection_exist(name):
return []
return await store.get_batch(name, keys, with_embeddings=True) Try / catch
from semantic_kernel.exceptions import ServiceResourceNotFoundError
try:
return await store.get_batch(collection_name, keys, with_embeddings=True)
except ServiceResourceNotFoundError:
return [] Prevention
- Check collection existence before batch reads.
- Keep names lowercased and consistent across create/read.
- Load from persist_directory at startup so expected collections are present.
When it happens
Trigger: Calling `await store.get_batch('docs', ['k1','k2'], with_embeddings=True)` against a collection that was never created/loaded in this process.
Common situations: Collection name typo or case mismatch (lowercased internally); in-memory store after restart; collection not loaded because persist_directory is unset; reading before any create_collection.
Related errors
- Collection {collection_name} does not exist, cannot insert.
- Collection '{collection_name}' does not exist
- Collection '{collection_name}' does not exist
- Collection "{collection_name}" does not exist
- Path of persist directory is not set
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/259d9521457be68e.
Report an issue: GitHub.