{"record":{"id":"49f2b8182ae5081d","repo":"microsoft/semantic-kernel","slug":"failed-to-create-container","errorCode":null,"errorMessage":"Failed to create container.","messagePattern":"Failed to create container\\.","errorType":"exception","errorClass":"VectorStoreOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_cosmos_db.py","lineNumber":1031,"sourceCode":"        return deserialized_records\n\n    @override\n    async def ensure_collection_exists(self, **kwargs) -> None:\n        indexing_policy = kwargs.pop(\"indexing_policy\", _create_default_indexing_policy_nosql(self.definition))\n        vector_embedding_policy = kwargs.pop(\n            \"vector_embedding_policy\", _create_default_vector_embedding_policy(self.definition)\n        )\n        database_proxy = await self._get_database_proxy(**kwargs)\n        try:\n            await database_proxy.create_container_if_not_exists(\n                id=self.collection_name,\n                partition_key=self.partition_key,\n                indexing_policy=indexing_policy,\n                vector_embedding_policy=vector_embedding_policy,\n                **kwargs,\n            )\n        except CosmosHttpResponseError as e:\n            raise VectorStoreOperationException(\"Failed to create container.\") from e\n\n    @override\n    async def collection_exists(self, **kwargs) -> bool:\n        container_proxy = await self._get_container_proxy(self.collection_name, **kwargs)\n        try:\n            await container_proxy.read(**kwargs)\n            return True\n        except CosmosHttpResponseError:\n            return False\n\n    @override\n    async def ensure_collection_deleted(self, **kwargs) -> None:\n        database_proxy = await self._get_database_proxy(**kwargs)\n        try:\n            await database_proxy.delete_container(self.collection_name)\n        except Exception as e:\n            raise VectorStoreOperationException(\"Container could not be deleted.\") from e\n","sourceCodeStart":1013,"sourceCodeEnd":1049,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_cosmos_db.py#L1013-L1049","documentation":"Raised when database_proxy.create_container_if_not_exists fails with a CosmosHttpResponseError during collection creation. The original HTTP error (with status code and message) is chained. This is a VectorStoreOperationException indicating the container/indexing/vector-embedding policy could not be applied server-side.","triggerScenarios":"Calling create_collection / ensure_collection_exists and the Cosmos service rejects the create request: invalid container name characters, a partition key definition that conflicts, an indexing/vector policy that violates limits (e.g. too many vector fields, unsupported vector index type), or insufficient permissions.","commonSituations":"Naming the collection with an illegal character, declaring a vector embedding policy whose dimensions or distance function are unsupported for the chosen vector index type (e.g. diskANN vs flat), or the principal lacking 'create container' RBAC.","solutions":["Inspect exc.__cause__ (the CosmosHttpResponseError) for the exact HTTP status and message — e.g. 400 bad request pinpoints the policy problem.","Correct the container name (alphanumeric, no reserved chars) and validate the indexing + vector embedding policy fields/dimensions/distance functions against Cosmos limits.","Confirm the configured identity/key has container-create permission on the database."],"exampleFix":"// before\nawait store.create_collection()  # raises 'Failed to create container.'\n// after\ntry:\n    await store.create_collection()\nexcept VectorStoreOperationException as e:\n    print(e.__cause__)  # CosmosHttpResponseError with status + reason\n","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import VectorStoreOperationException\n\ntry:\n    await store.create_collection()\nexcept VectorStoreOperationException as e:\n    cause = e.__cause__\n    status = getattr(cause, \"status_code\", None)\n    raise RuntimeError(f\"Container create failed (HTTP {status}): {cause}\") from e","preventionTips":["Validate container name characters and indexing/vector policy against Cosmos limits before creating.","Ensure the identity/key has container-create permission.","Inspect __cause__ status code to pinpoint policy vs permission failures."],"tags":["azure-cosmos-db","collection-management","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}