{"record":{"id":"6d6b5827a67a4a41","repo":"microsoft/semantic-kernel","slug":"failed-to-get-collection-self-collection-name","errorCode":null,"errorMessage":"Failed to get collection {self.collection_name}","messagePattern":"Failed to get collection (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/chroma.py","lineNumber":127,"sourceCode":"                settings.is_persistent = True\n                settings.persist_directory = persist_directory\n            client = Client(settings)\n        super().__init__(\n            collection_name=collection_name,\n            record_type=record_type,\n            definition=definition,\n            client=client,\n            managed_client=managed_client,\n            embedding_func=embedding_func,\n            embedding_generator=embedding_generator,\n            **kwargs,\n        )\n\n    def _get_collection(self) -> Collection:\n        try:\n            return self.client.get_collection(name=self.collection_name, embedding_function=self.embedding_func)\n        except Exception as e:\n            raise RuntimeError(f\"Failed to get collection {self.collection_name}\") from e\n\n    @override\n    async def collection_exists(self, **kwargs: Any) -> bool:\n        \"\"\"Check if the collection exists.\"\"\"\n        try:\n            self.client.get_collection(name=self.collection_name, embedding_function=self.embedding_func)\n            return True\n        except Exception:\n            return False\n\n    @override\n    async def ensure_collection_exists(self, **kwargs: Any) -> None:\n        \"\"\"Create the collection.\n\n        Will create a metadata object with the hnsw arguments.\n        By default only the distance function will be set based on the data model.\n        To tweak the other hnsw parameters, pass them in the kwargs.\n","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/chroma.py#L109-L145","documentation":"Raised by ChromaCollection._get_collection() when the underlying chromadb client.get_collection() call throws any exception. This is a wrapper (RuntimeError) that masks the real chromadb cause via 'raise ... from e'. It fires whenever the named collection cannot be retrieved — most often because it does not exist on the client, or because the client connection (persistent path / host) is misconfigured.","triggerScenarios":"Calling any operation that internally calls _get_collection() (e.g. upsert, search, get) before ensure_collection_exists() has created the collection; or pointing the Chroma client at a persist_directory/tenant/database where the collection name is absent.","commonSituations":"Forgetting to call await collection.ensure_collection_exists() (or create_collection) before first read/write; switching persist_directory between runs; using a managed remote client where the collection lives in a different database/tenant; collection name typo or name derived from a model whose __semantic_kernel_collection_name__ differs from what was created.","solutions":["Call 'await collection.ensure_collection_exists()' before invoking any read/write/search operation on the collection.","Check the error's __cause__ (the original chromadb exception) to confirm whether the collection is truly missing vs. a connection/auth failure.","Verify self.collection_name matches the name used at creation and that the same ClientAPI instance (persist_directory / host / database) is used."],"exampleFix":"// before\nawait collection.upsert(records)  # collection not created yet\n// after\nawait collection.ensure_collection_exists()\nawait collection.upsert(records)","handlingStrategy":"try-catch","validationCode":"exists = await collection.collection_exists()\nif not exists:\n    await collection.ensure_collection_exists()","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.vector_store_exceptions import VectorStoreOperationException\ntry:\n    col = collection._get_collection()\nexcept RuntimeError as e:\n    cause = e.__cause__\n    # distinguish missing-collection vs connection failure via the chromadb cause","preventionTips":["Always call await collection.ensure_collection_exists() before any read/write/search.","Derive the collection name from the model consistently so creation and retrieval match.","Use the same ClientAPI (persist_directory/host/database) for create and access."],"tags":["chroma","vector-store","collection-not-found","lifecycle"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}