{"record":{"id":"8fb8c2e85dbcae31","repo":"microsoft/semantic-kernel","slug":"collection-collection-name-does-not-exist","errorCode":null,"errorMessage":"Collection '{collection_name}' does not exist","messagePattern":"Collection '(.+?)' does not exist","errorType":"exception","errorClass":"ServiceResourceNotFoundError","httpStatus":404,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/chroma/chroma_memory_store.py","lineNumber":159,"sourceCode":"\n        Returns:\n            bool: True if the collection exists; otherwise, False.\n        \"\"\"\n        return await self.get_collection(collection_name) is not None\n\n    async def upsert(self, collection_name: str, record: MemoryRecord) -> str:\n        \"\"\"Upsert a single MemoryRecord.\n\n        Args:\n            collection_name (str): The name of the collection to upsert the record into.\n            record (MemoryRecord): The record to upsert.\n\n        Returns:\n            List[str]: The unique database key of the record.\n        \"\"\"\n        collection = await self.get_collection(collection_name)\n        if collection is None:\n            raise ServiceResourceNotFoundError(f\"Collection '{collection_name}' does not exist\")\n\n        record._key = record._id\n        metadata = {\n            \"timestamp\": record._timestamp or \"\",\n            \"is_reference\": str(record._is_reference),\n            \"external_source_name\": record._external_source_name or \"\",\n            \"description\": record._description or \"\",\n            \"additional_metadata\": record._additional_metadata or \"\",\n            \"id\": record._id or \"\",\n        }\n\n        collection.add(\n            metadatas=metadata,\n            # by providing embeddings, we can skip the chroma's embedding function call\n            embeddings=record.embedding.tolist(),\n            documents=record._text,\n            ids=record._key,\n        )","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/chroma/chroma_memory_store.py#L141-L177","documentation":"Raised as a ServiceResourceNotFoundError in ChromaMemoryStore.upsert when get_collection returns None, meaning no Chroma collection with the given name exists. Chroma requires a collection to exist before records can be added; upsert does not auto-create it.","triggerScenarios":"Calling await store.upsert('my_collection', record) before await store.create_collection('my_collection'). Also if the collection name casing differs (Chroma lowercases internally) or if a persisted store lost its data directory.","commonSituations":"Skipping the create_collection step in a fresh run. Typo or case mismatch in the collection name. Using an ephemeral Chroma client (no persist_directory) so collections vanish on restart. Calling upsert on a collection that was deleted.","solutions":["Call await store.create_collection(collection_name) before upserting, or guard with await store.does_collection_exist(collection_name).","Verify the collection name matches exactly what was passed to create_collection.","If using persistence, ensure persist_directory points to the same path across runs.","Wrap the upsert call in try/except ServiceResourceNotFoundError and create-then-retry."],"exampleFix":"// before\nawait store.upsert('docs', record)  # ServiceResourceNotFoundError\n// after\nif not await store.does_collection_exist('docs'):\n    await store.create_collection('docs')\nawait store.upsert('docs', record)","handlingStrategy":"validation","validationCode":"async def ensure_collection(store, name: str) -> None:\n    if not await store.does_collection_exist(name):\n        await store.create_collection(name)\n\nawait ensure_collection(store, 'docs')\nawait store.upsert('docs', record)","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceResourceNotFoundError\n\ntry:\n    await store.upsert('docs', record)\nexcept ServiceResourceNotFoundError:\n    await store.create_collection('docs')\n    await store.upsert('docs', record)","preventionTips":["Always call create_collection during application startup before any upsert.","Use consistent collection name constants to avoid typos.","If using persistence, keep persist_directory stable across restarts.","Guard every upsert with does_collection_exist in shared helper code."],"tags":["chroma","collection","resource-not-found","upsert","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}