{"record":{"id":"178b6bdaaf118da3","repo":"microsoft/semantic-kernel","slug":"key-key-not-found-in-collection-collection-n","errorCode":null,"errorMessage":"Key '{key}' not found in collection '{collection_name}'","messagePattern":"Key '(.+?)' not found in collection '(.+?)'","errorType":"exception","errorClass":"ServiceResourceNotFoundError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py","lineNumber":384,"sourceCode":"        return all_records_id\n\n    async def get(\n        self,\n        collection_name: str,\n        key: str,\n        with_embedding: bool,\n        dtype: ScalarKind = ScalarKind.F32,\n    ) -> MemoryRecord:\n        \"\"\"Retrieve a single MemoryRecord using its key.\"\"\"\n        collection_name = collection_name.lower()\n        result = await self.get_batch(\n            collection_name=collection_name,\n            keys=[key],\n            with_embeddings=with_embedding,\n            dtype=dtype,\n        )\n        if not result:\n            raise ServiceResourceNotFoundError(f\"Key '{key}' not found in collection '{collection_name}'\")\n        return result[0]\n\n    async def get_batch(\n        self,\n        collection_name: str,\n        keys: list[str],\n        with_embeddings: bool,\n        dtype: ScalarKind = ScalarKind.F32,\n    ) -> list[MemoryRecord]:\n        \"\"\"Retrieve a batch of MemoryRecords using their keys.\"\"\"\n        collection_name = collection_name.lower()\n        if collection_name not in self._collections:\n            raise ServiceResourceNotFoundError(f\"Collection {collection_name} does not exist\")\n\n        ucollection = self._collections[collection_name]\n        labels = [ucollection.embeddings_id_to_label[key] for key in keys if key in ucollection.embeddings_id_to_label]\n        if not labels:\n            return []","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/usearch/usearch_memory_store.py#L366-L402","documentation":"Raised by USearchMemoryStore.get (ServiceResourceNotFoundError) after delegating to get_batch and receiving an empty result for the requested key. The collection exists, but no record with that key (id) is present in the collection's id-to-label map, so a lookup-by-key returns nothing.","triggerScenarios":"Calling `await store.get('docs', 'key123', with_embedding=True)` where 'key123' was never inserted, was already removed, or the key string differs from what was stored (the store maps record._id to a label).","commonSituations":"Reading a key that was deleted; key mismatch (e.g. stored as a generated id vs. the value you query with); querying immediately after an upsert that failed silently; case/format differences in the id.","solutions":["Use get_batch (which returns [] instead of raising) when absence is expected, then handle empty.","Verify the key against the ids returned by upsert_batch.","Guard/try-catch ServiceResourceNotFoundError for single-key lookups."],"exampleFix":"// before\nrec = await store.get('docs', key, with_embedding=True)\n// after\nrecs = await store.get_batch('docs', [key], with_embeddings=True)\nrec = recs[0] if recs else None","handlingStrategy":"try-catch","validationCode":"# prefer get_batch to avoid raising on miss\nrecs = await store.get_batch(collection_name, [key], with_embeddings=True)\nrec = recs[0] if recs else None","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceResourceNotFoundError\ntry:\n    rec = await store.get(collection_name, key, with_embedding=True)\nexcept ServiceResourceNotFoundError:\n    rec = None  # treat missing key as absent","preventionTips":["Use get_batch (returns []) instead of get when absence is normal.","Store the ids returned by upsert_batch and query with those exact ids.","Avoid single-key get() on data that may legitimately be missing."],"tags":["usearch","memory-store","key-not-found","resource-not-found"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}