microsoft/semantic-kernel · error · VectorStoreOperationException
Database '{self.database_name}' does not exist.
Error message
Database '{self.database_name}' does not exist. What it means
When the database does not exist and create_database is False (the default), _get_database_proxy refuses to auto-create it and raises VectorStoreInitializationException. This is a deliberate guard: the store will not silently provision a database unless told to.
Source
Thrown at python/semantic_kernel/connectors/azure_cosmos_db.py:642
try:
await self.cosmos_client.get_database_client(self.database_name).read()
return True
except CosmosResourceNotFoundError:
return False
except Exception as e:
raise VectorStoreOperationException(
f"Failed to check if database '{self.database_name}' exists, with message {e}"
) from e
async def _get_database_proxy(self, **kwargs) -> DatabaseProxy:
"""Gets the database proxy."""
try:
if await self._does_database_exist():
return self.cosmos_client.get_database_client(self.database_name)
if self.create_database:
return await self.cosmos_client.create_database(self.database_name, **kwargs)
raise VectorStoreOperationException(f"Database '{self.database_name}' does not exist.")
except Exception as e:
raise VectorStoreOperationException(f"Failed to get database proxy for '{id}'.") from e
async def _get_container_proxy(self, container_name: str, **kwargs) -> ContainerProxy:
"""Gets the container proxy."""
try:
database_proxy = await self._get_database_proxy(**kwargs)
return database_proxy.get_container_client(container_name)
except Exception as e:
raise VectorStoreOperationException(f"Failed to get container proxy for '{container_name}'.") from e
# region: NoSQL Collection
@release_candidate
class CosmosNoSqlCollection(
CosmosNoSqlBase,View on GitHub (pinned to c028a0c7dc)
Solutions
- Provision the database in the Azure portal/CLI/SDK before running.
- Or construct the store with create_database=True to auto-create it.
- Verify database_name spelling against what exists in the account.
Example fix
// before store = CosmosNoSqlStore(url=url, key=key, database_name="mydb") // after store = CosmosNoSqlStore(url=url, key=key, database_name="mydb", create_database=True)
Defensive patterns
Strategy: validation
Validate before calling
async def ensure_database(store):
if not await store._does_database_exist():
if not store.create_database:
raise RuntimeError(f"Database '{store.database_name}' missing; pass create_database=True or provision it")
Prevention
- Set create_database=True in dev/bootstrap scripts.
- Provision databases via IaC (Bicep/Terraform) in production.
- Document that create_database defaults to False to avoid silent provisioning.
When it happens
Trigger: Raised in _get_database_proxy when _does_database_exist() returns False and self.create_database is falsy. Triggered the first time you access the store/collection against a database name that was never provisioned, with create_database not set.
Common situations: New deployment pointing at a fresh Cosmos account where the database hasn't been created. Typo in database_name. Migrating environments (dev -> prod) without provisioning. Forgetting to pass create_database=True during setup.
Related errors
- The collection name is required, can be passed directly or t
- Failed to create Azure CosmosDB for MongoDB settings.
- The name of the Azure Cosmos DB NoSQL database is missing.
- Distance function '{field.distance_function}' is not support
- Failed to validate Azure Cosmos DB NoSQL settings.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/20c293c9298781c4.
Report an issue: GitHub.