{"record":{"id":"358b71efa10e6b1a","repo":"microsoft/semantic-kernel","slug":"memory-record-not-found","errorCode":null,"errorMessage":"Memory record not found","messagePattern":"Memory record not found","errorType":"exception","errorClass":"MemoryConnectorResourceNotFound","httpStatus":null,"severity":"warning","filePath":"python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/azure_cognitive_search_memory_store.py","lineNumber":285,"sourceCode":"\n        Args:\n            collection_name (str): The name of the collection to get the record from.\n            key (str): The unique database key of the record.\n            with_embedding (bool): Whether to include the embedding in the result. (default: {False})\n\n        Returns:\n            MemoryRecord: The record.\n        \"\"\"\n        # Look up Search client class to see if exists or create\n        search_client = self._search_index_client.get_search_client(collection_name.lower())\n\n        try:\n            search_result = await search_client.get_document(\n                key=encode_id(key), selected_fields=get_field_selection(with_embedding)\n            )\n        except ResourceNotFoundError as exc:\n            await search_client.close()\n            raise MemoryConnectorResourceNotFound(\"Memory record not found\") from exc\n\n        await search_client.close()\n\n        # Create Memory record from document\n        return dict_to_memory_record(search_result, with_embedding)\n\n    async def get_batch(\n        self, collection_name: str, keys: list[str], with_embeddings: bool = False\n    ) -> list[MemoryRecord]:\n        \"\"\"Gets a batch of records.\n\n        Args:\n            collection_name (str): The name of the collection to get the records from.\n            keys (List[str]): The unique database keys of the records.\n            with_embeddings (bool): Whether to include the embeddings in the results. (default: {False})\n\n        Returns:\n            List[MemoryRecord]: The records.","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/azure_cognitive_search_memory_store.py#L267-L303","documentation":"Raised in `AzureCognitiveSearchMemoryStore.get` when the Azure Search `get_document` call throws `ResourceNotFoundError` (the document key does not exist in the index). The search client is closed and the exception is re-raised as `MemoryConnectorResourceNotFound` (chained via `from exc`). It is the equivalent of a key-not-found for this store.","triggerScenarios":"Calling `get(collection_name, key)` for a record whose encoded id (`encode_id(key)`) is not present in the Azure Search index; the record was never upserted, was deleted, or the id encoding differs between write and read.","commonSituations":"Read before write; querying the wrong index; `encode_id` produces different base64 for the same logical key due to whitespace/encoding changes; record deleted out-of-band; race during indexing lag (Azure Search is eventually consistent).","solutions":["Confirm the record was upserted into that index and the key matches (account for `encode_id`).","Catch `MemoryConnectorResourceNotFound` to handle missing records gracefully.","Account for indexing latency: retry shortly after a fresh upsert, or check the index is ready.","Verify you query the same collection/index name used at write time."],"exampleFix":"// before\nrec = await store.get(\"idx\", key)  # MemoryConnectorResourceNotFound\n\n// after\nfrom semantic_kernel.exceptions import MemoryConnectorResourceNotFound\ntry:\n    rec = await store.get(\"idx\", key)\nexcept MemoryConnectorResourceNotFound:\n    rec = None","handlingStrategy":"try-catch","validationCode":"# optional existence pre-check via batch (does not raise on miss)\nasync def acs_exists_or_none(store, collection, key):\n    recs = await store.get_batch(collection, [key], with_embeddings=False)\n    return recs[0] if recs else None","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import MemoryConnectorResourceNotFound\ntry:\n    rec = await store.get(\"idx\", key)\nexcept MemoryConnectorResourceNotFound:\n    rec = None","preventionTips":["Catch `MemoryConnectorResourceNotFound` to treat missing records as normal control flow.","Use `get_batch` when missing keys are expected.","Account for `encode_id` and Azure Search indexing lag after upserts.","Confirm the key/collection used at read matches the write."],"tags":["azure-cognitive-search","key-not-found","lookup","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}