microsoft/semantic-kernel · error · ServiceResourceNotFoundError

Record with key '{key}' does not exist

Error message

Record with key '{key}' does not exist

What it means

Raised in PineconeMemoryStore.get() when collection.fetch([key]) returns an empty vectors map (len(fetch_response.vectors) == 0). ServiceResourceNotFoundError indicates the specific record key is absent even though the collection exists.

Source

Thrown at python/semantic_kernel/connectors/memory_stores/pinecone/pinecone_memory_store.py:244

    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.
        """
        if not await self.does_collection_exist(collection_name):
            raise ServiceResourceNotFoundError(f"Collection '{collection_name}' does not exist")

        collection = self.pinecone.Index(collection_name)
        fetch_response = collection.fetch([key])

        if len(fetch_response.vectors) == 0:
            raise ServiceResourceNotFoundError(f"Record with key '{key}' does not exist")

        return parse_payload(fetch_response.vectors[key], with_embedding)

    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.
        """
        if not await self.does_collection_exist(collection_name):
            raise ServiceResourceNotFoundError(f"Collection '{collection_name}' does not exist")

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Verify the key was produced by a prior upsert (upsert returns record._id).
  2. Treat absence as a non-error by catching ServiceResourceNotFoundError and returning None.
  3. Check the key casing/format against what was stored.
  4. Use does_collection_exist first to distinguish collection-missing from record-missing.

Example fix

// before
rec = await store.get("my_col", key)

// after
try:
    rec = await store.get("my_col", key)
except ServiceResourceNotFoundError:
    rec = None
Defensive patterns

Strategy: try-catch

Validate before calling

# no pre-check for record existence; fetch is the check — keep the read cheap and handle absence
return await store.get(collection_name, key)

Type guard

def is_valid_key(key: str) -> bool:
    return isinstance(key, str) and len(key) > 0

Try / catch

from semantic_kernel.exceptions import ServiceResourceNotFoundError
try:
    return await store.get(collection_name, key)
except ServiceResourceNotFoundError:
    return None  # treat missing record as not-found, not an error

Prevention

When it happens

Trigger: Fetching a key that was never upserted, was deleted, or is mistyped. The collection exists but the id is unknown.

Common situations: Reading a stale id; the record was removed by remove()/remove_batch(); id format mismatch (e.g., extra prefix/suffix).

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/4eab7f7b2e79b7cb. Report an issue: GitHub.