microsoft/semantic-kernel · error · MemoryConnectorInitializationError
Vector dimensions must be a positive number.
Error message
Vector dimensions must be a positive number.
What it means
Constructor guard in `AzureCosmosDBMemoryStore.__init__`: if `vector_dimensions <= 0` it raises `MemoryConnectorInitializationError`. Cosmos DB vector indexes require a strictly positive dimension, so the store refuses to initialize with zero or negative dimensions.
Source
Thrown at python/semantic_kernel/connectors/memory_stores/azure_cosmosdb/azure_cosmos_db_memory_store.py:66
ef_construction = None
ef_search = None
def __init__(
self,
cosmosStore: AzureCosmosDBStoreApi,
database_name: str,
index_name: str,
vector_dimensions: int,
num_lists: int = 100,
similarity: CosmosDBSimilarityType = CosmosDBSimilarityType.COS,
kind: CosmosDBVectorSearchType = CosmosDBVectorSearchType.VECTOR_HNSW,
m: int = 16,
ef_construction: int = 64,
ef_search: int = 40,
):
"""Initializes a new instance of the AzureCosmosDBMemoryStore class."""
if vector_dimensions <= 0:
raise MemoryConnectorInitializationError("Vector dimensions must be a positive number.")
if database_name is None:
raise MemoryConnectorInitializationError("Database Name cannot be empty.")
if index_name is None:
raise MemoryConnectorInitializationError("Index Name cannot be empty.")
self.cosmos_store = cosmosStore
self.index_name = index_name
self.num_lists = num_lists
self.similarity = similarity
self.kind = kind
self.m = m
self.ef_construction = ef_construction
self.ef_search = ef_search
@staticmethod
async def create(
database_name: str,
collection_name: str,View on GitHub (pinned to c028a0c7dc)
Solutions
- Pass a positive `vector_dimensions` matching your embedding model's output size (e.g. 1536).
- Validate the dimension comes from a populated config field before constructing the store.
- If the dimension is sourced dynamically, assert it is a positive int before use.
Example fix
// before store = AzureCosmosDBMemoryStore(cosmos_store, "db", "idx", vector_dimensions=0) // after store = AzureCosmosDBMemoryStore(cosmos_store, "db", "idx", vector_dimensions=1536)
Defensive patterns
Strategy: validation
Validate before calling
def valid_vector_dim(d) -> bool:
return isinstance(d, int) and d > 0
# assert valid_vector_dim(vector_dimensions) before constructing the store Type guard
def is_positive_int(d) -> bool:
return isinstance(d, int) and d > 0 Try / catch
from semantic_kernel.exceptions import MemoryConnectorInitializationError
try:
store = AzureCosmosDBMemoryStore(cs, "db", "idx", vector_dimensions=dim)
except MemoryConnectorInitializationError as e:
if "positive number" in str(e):
raise SystemExit("vector_dimensions must be > 0") from e
raise Prevention
- Pass the embedding model's actual output dimension as a positive int.
- Validate config-sourced dimensions before construction.
- Add an assertion that the dimension is a positive int at startup.
When it happens
Trigger: Instantiating `AzureCosmosDBMemoryStore(...)` with `vector_dimensions=0` or a negative number, or with an uninitialized/None-derived dimension value that evaluates to <= 0.
Common situations: Passing an unset config value (e.g. `int(None)` producing 0, or a defaulted 0); a misconfigured embedding model dimension; copy-paste leaving the default unset; reading dimension from config that wasn't populated.
Related errors
- Dimensionality of {self._embedding_dim} exceeds the maximum
- Dimensionality of {dimension_num} exceeds the maximum allowe
- Database Name cannot be empty.
- Index Name cannot be empty.
- API type {cosmos_api} is not supported.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/401bf9478c4402c7.
Report an issue: GitHub.