{"record":{"id":"186bcc3162124bf2","repo":"microsoft/semantic-kernel","slug":"vectorindexes-cannot-be-null-or-empty-in-the-index","errorCode":null,"errorMessage":"vectorIndexes cannot be null or empty in the indexing_policy.","messagePattern":"vectorIndexes cannot be null or empty in the indexing_policy\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/azure_cosmosdb_no_sql/azure_cosmosdb_no_sql_memory_store.py","lineNumber":49,"sourceCode":"    container: ContainerProxy\n    database_name: str = None\n    partition_key: str = None\n    vector_embedding_policy: dict[str, Any] | None = None\n    indexing_policy: dict[str, Any] | None = None\n    cosmos_container_properties: dict[str, Any] | None = None\n\n    def __init__(\n        self,\n        cosmos_client: CosmosClient,\n        database_name: str,\n        partition_key: str,\n        vector_embedding_policy: dict[str, Any] | None = None,\n        indexing_policy: dict[str, Any] | None = None,\n        cosmos_container_properties: dict[str, Any] | None = None,\n    ):\n        \"\"\"Initializes a new instance of the AzureCosmosDBNoSQLMemoryStore class.\"\"\"\n        if indexing_policy[\"vectorIndexes\"] is None or len(indexing_policy[\"vectorIndexes\"]) == 0:\n            raise ValueError(\"vectorIndexes cannot be null or empty in the indexing_policy.\")\n        if vector_embedding_policy is None or len(vector_embedding_policy[\"vectorEmbeddings\"]) == 0:\n            raise ValueError(\"vectorEmbeddings cannot be null or empty in the vector_embedding_policy.\")\n\n        self.cosmos_client = cosmos_client\n        self.database_name = database_name\n        self.partition_key = partition_key\n        self.vector_embedding_policy = vector_embedding_policy\n        self.indexing_policy = indexing_policy\n        self.cosmos_container_properties = cosmos_container_properties\n\n    @override\n    async def create_collection(self, collection_name: str) -> None:\n        # Create the database if it already doesn't exist\n        self.database = await self.cosmos_client.create_database_if_not_exists(id=self.database_name)\n\n        # Create the collection if it already doesn't exist\n        self.container = await self.database.create_container_if_not_exists(\n            id=collection_name,","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/azure_cosmosdb_no_sql/azure_cosmosdb_no_sql_memory_store.py#L31-L67","documentation":"Raised in AzureCosmosDBNoSQLMemoryStore.__init__ when the provided indexing_policy dict has a 'vectorIndexes' key that is None or an empty list. Azure Cosmos DB NoSQL vector search requires at least one vector index definition (e.g. flat, diskANN) to perform ANN queries; without it the container cannot be created with vector capabilities. Note the code accesses indexing_policy[\"vectorIndexes\"] directly, so a missing key produces a KeyError instead, and passing None for the whole indexing_policy produces a TypeError before this check.","triggerScenarios":"Constructing AzureCosmosDBNoSQLMemoryStore with indexing_policy={'vectorIndexes': None} or indexing_policy={'vectorIndexes': []}. The check at line 48 runs unconditionally in __init__, so any instantiation path that passes a dict lacking a populated vectorIndexes array hits it. If indexing_policy is left as the default None, a TypeError ('NoneType' is not subscriptable) fires first on the same line.","commonSituations":"Copying a minimal Azure Cosmos config snippet that omits the vectorIndexes block. Migrating from the newer AzureCosmosDBNoSQLStore API where the policy shape changed. Providing an indexing_policy dict built from a template that left vectorIndexes as a placeholder empty list.","solutions":["Supply an indexing_policy with a non-empty vectorIndexes list, e.g. indexing_policy={'indexingMode': 'consistent', 'includedPaths': [{'path': '/*'}], 'vectorIndexes': [{'path': '/embedding', 'type': 'diskANN'}]}.","Ensure the vectorIndexes path matches the vectorEmbeddings path in vector_embedding_policy (line 50 checks that separately).","If you pass None for indexing_policy intentionally, note the current code does NOT guard against it — you must always pass a fully-formed dict.","Consider migrating to the non-deprecated AzureCosmosDBNoSQLStore / Collection classes as indicated by the @deprecated marker on this class."],"exampleFix":"// before\nstore = AzureCosmosDBNoSQLMemoryStore(\n    cosmos_client=client,\n    database_name='db',\n    partition_key='/pk',\n    vector_embedding_policy={'vectorEmbeddings': [...]},\n    indexing_policy={'vectorIndexes': []},  # triggers ValueError\n)\n// after\nindexing_policy = {\n    'indexingMode': 'consistent',\n    'includedPaths': [{'path': '/*'}],\n    'vectorIndexes': [{'path': '/embedding', 'type': 'diskANN'}],\n}\nstore = AzureCosmosDBNoSQLMemoryStore(\n    cosmos_client=client,\n    database_name='db',\n    partition_key='/pk',\n    vector_embedding_policy={'vectorEmbeddings': [...]},\n    indexing_policy=indexing_policy,\n)","handlingStrategy":"validation","validationCode":"def validate_indexing_policy(policy: dict | None) -> None:\n    if policy is None:\n        raise ValueError('indexing_policy must not be None')\n    vi = policy.get('vectorIndexes')\n    if vi is None or len(vi) == 0:\n        raise ValueError('indexing_policy[\"vectorIndexes\"] must be a non-empty list')\n\n# call before constructing the store\nvalidate_indexing_policy(indexing_policy)","typeGuard":"from typing import Any\n\ndef is_valid_indexing_policy(policy: Any) -> bool:\n    return (\n        isinstance(policy, dict)\n        and isinstance(policy.get('vectorIndexes'), list)\n        and len(policy['vectorIndexes']) > 0\n    )","tryCatchPattern":"try:\n    store = AzureCosmosDBNoSQLMemoryStore(..., indexing_policy=indexing_policy)\nexcept ValueError as e:\n    logging.error('Invalid indexing policy: %s', e)\n    raise","preventionTips":["Always pass a fully-formed indexing_policy dict; do not rely on the None default.","Validate the policy dict shape in a config-loading function before store construction.","Keep the vectorIndexes path in sync with the vectorEmbeddings path.","Migrate to the non-deprecated AzureCosmosDBNoSQLStore API."],"tags":["azure-cosmosdb","vector-search","configuration","validation","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}