microsoft/semantic-kernel · error · ServiceResourceNotFoundError
Record with key '{key}' does not exist in collection '{colle
Error message
Record with key '{key}' does not exist in collection '{collection_name}' What it means
Raised as a ServiceResourceNotFoundError in ChromaMemoryStore.get when the requested key is absent. get delegates to get_batch and then indexes into the result list; an IndexError (empty result) is caught and re-raised as this error, identifying the missing key and collection.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/chroma/chroma_memory_store.py:208
# upsert is checking collection existence
return [await self.upsert(collection_name, record) for record in records]
async def get(self, collection_name: str, key: str, with_embedding: bool = False) -> MemoryRecord:
"""Gets a record.
Args:
collection_name (str): The name of the collection to get the record from.
key (str): The unique database key of the record.
with_embedding (bool): Whether to include the embedding in the result. (default: {False})
Returns:
MemoryRecord: The record.
"""
records = await self.get_batch(collection_name, [key], with_embedding)
try:
return records[0]
except IndexError as exc:
raise ServiceResourceNotFoundError(
f"Record with key '{key}' does not exist in collection '{collection_name}'"
) from exc
async def get_batch(
self, collection_name: str, keys: list[str], with_embeddings: bool = False
) -> list[MemoryRecord]:
"""Gets a batch of records.
Args:
collection_name (str): The name of the collection to get the records from.
keys (List[str]): The unique database keys of the records.
with_embeddings (bool): Whether to include the embeddings in the results. (default: {False})
Returns:
List[MemoryRecord]: The records.
"""
collection = await self.get_collection(collection_name)
if collection is None:View on GitHub (pinned to c028a0c7dc)
Solutions
- Check existence first by calling get_batch and inspecting the list length, or catch ServiceResourceNotFoundError.
- Verify the key matches the id used during upsert (record._key is set to record._id).
- If absence is a valid application state, handle it gracefully rather than treating it as an error.
- Log the missing key and collection to trace stale references.
Example fix
// before
record = await store.get('docs', key) # ServiceResourceNotFoundError
// after
try:
record = await store.get('docs', key)
except ServiceResourceNotFoundError:
record = None # handle absence gracefully Defensive patterns
Strategy: try-catch
Validate before calling
records = await store.get_batch('docs', [key], with_embedding=False)
record = records[0] if records else None Try / catch
from semantic_kernel.exceptions import ServiceResourceNotFoundError
try:
record = await store.get('docs', key)
except ServiceResourceNotFoundError:
record = None # absent record is a valid application state Prevention
- Prefer get_batch and check list length when absence is expected.
- Verify the key matches the id used during upsert (record._id).
- Treat a missing record as a non-error business case where appropriate.
- Log missing keys to detect stale references.
When it happens
Trigger: Calling await store.get('my_collection', key) where no record with that id/key exists in the Chroma collection. The key may have been deleted, never inserted, or is a stale reference from another store.
Common situations: Looking up a memory record by an id generated by a different embedding run. Deleting a record then querying it. Race condition where the record has not yet been flushed. Key format mismatch (e.g. the record._id vs record._key mapping).
Related errors
- Collection '{collection_name}' does not exist
- Collection {collection_name} does not exist, cannot get.
- Could not import chromadb python package. Please install it
- Invalid vectors, cannot compute cosine similarity scoresfor
- Collection {collection_name} does not exist, cannot insert.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/1f4f8cc050832473.
Report an issue: GitHub.