{"record":{"id":"1f4f8cc050832473","repo":"microsoft/semantic-kernel","slug":"record-with-key-key-does-not-exist-in-collecti","errorCode":null,"errorMessage":"Record with key '{key}' does not exist in collection '{collection_name}'","messagePattern":"Record with key '(.+?)' does not exist in collection '(.+?)'","errorType":"exception","errorClass":"ServiceResourceNotFoundError","httpStatus":404,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/chroma/chroma_memory_store.py","lineNumber":208,"sourceCode":"        # upsert is checking collection existence\n        return [await self.upsert(collection_name, record) for record in records]\n\n    async def get(self, collection_name: str, key: str, with_embedding: bool = False) -> MemoryRecord:\n        \"\"\"Gets a record.\n\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        records = await self.get_batch(collection_name, [key], with_embedding)\n        try:\n            return records[0]\n        except IndexError as exc:\n            raise ServiceResourceNotFoundError(\n                f\"Record with key '{key}' does not exist in collection '{collection_name}'\"\n            ) from exc\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.\n        \"\"\"\n        collection = await self.get_collection(collection_name)\n        if collection is None:","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/chroma/chroma_memory_store.py#L190-L226","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\nrecord = await store.get('docs', key)  # ServiceResourceNotFoundError\n// after\ntry:\n    record = await store.get('docs', key)\nexcept ServiceResourceNotFoundError:\n    record = None  # handle absence gracefully","handlingStrategy":"try-catch","validationCode":"records = await store.get_batch('docs', [key], with_embedding=False)\nrecord = records[0] if records else None","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceResourceNotFoundError\n\ntry:\n    record = await store.get('docs', key)\nexcept ServiceResourceNotFoundError:\n    record = None  # absent record is a valid application state","preventionTips":["Prefer get_batch and check list length when absence is expected.","Verify the key matches the id used during upsert (record._id).\n        ","Treat a missing record as a non-error business case where appropriate.","Log missing keys to detect stale references."],"tags":["chroma","resource-not-found","get","record","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}