{"record":{"id":"401bf9478c4402c7","repo":"microsoft/semantic-kernel","slug":"vector-dimensions-must-be-a-positive-number","errorCode":null,"errorMessage":"Vector dimensions must be a positive number.","messagePattern":"Vector dimensions must be a positive number\\.","errorType":"validation","errorClass":"MemoryConnectorInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/azure_cosmosdb/azure_cosmos_db_memory_store.py","lineNumber":66,"sourceCode":"    ef_construction = None\n    ef_search = None\n\n    def __init__(\n        self,\n        cosmosStore: AzureCosmosDBStoreApi,\n        database_name: str,\n        index_name: str,\n        vector_dimensions: int,\n        num_lists: int = 100,\n        similarity: CosmosDBSimilarityType = CosmosDBSimilarityType.COS,\n        kind: CosmosDBVectorSearchType = CosmosDBVectorSearchType.VECTOR_HNSW,\n        m: int = 16,\n        ef_construction: int = 64,\n        ef_search: int = 40,\n    ):\n        \"\"\"Initializes a new instance of the AzureCosmosDBMemoryStore class.\"\"\"\n        if vector_dimensions <= 0:\n            raise MemoryConnectorInitializationError(\"Vector dimensions must be a positive number.\")\n        if database_name is None:\n            raise MemoryConnectorInitializationError(\"Database Name cannot be empty.\")\n        if index_name is None:\n            raise MemoryConnectorInitializationError(\"Index Name cannot be empty.\")\n\n        self.cosmos_store = cosmosStore\n        self.index_name = index_name\n        self.num_lists = num_lists\n        self.similarity = similarity\n        self.kind = kind\n        self.m = m\n        self.ef_construction = ef_construction\n        self.ef_search = ef_search\n\n    @staticmethod\n    async def create(\n        database_name: str,\n        collection_name: str,","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/azure_cosmosdb/azure_cosmos_db_memory_store.py#L48-L84","documentation":"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.","triggerScenarios":"Instantiating `AzureCosmosDBMemoryStore(...)` with `vector_dimensions=0` or a negative number, or with an uninitialized/None-derived dimension value that evaluates to <= 0.","commonSituations":"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.","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."],"exampleFix":"// before\nstore = AzureCosmosDBMemoryStore(cosmos_store, \"db\", \"idx\", vector_dimensions=0)\n\n// after\nstore = AzureCosmosDBMemoryStore(cosmos_store, \"db\", \"idx\", vector_dimensions=1536)","handlingStrategy":"validation","validationCode":"def valid_vector_dim(d) -> bool:\n    return isinstance(d, int) and d > 0\n\n# assert valid_vector_dim(vector_dimensions) before constructing the store","typeGuard":"def is_positive_int(d) -> bool:\n    return isinstance(d, int) and d > 0","tryCatchPattern":"from semantic_kernel.exceptions import MemoryConnectorInitializationError\ntry:\n    store = AzureCosmosDBMemoryStore(cs, \"db\", \"idx\", vector_dimensions=dim)\nexcept MemoryConnectorInitializationError as e:\n    if \"positive number\" in str(e):\n        raise SystemExit(\"vector_dimensions must be > 0\") from e\n    raise","preventionTips":["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."],"tags":["azure-cosmos-db","vector-dimension","validation","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}