{"record":{"id":"c984b21b5037bf9c","repo":"microsoft/semantic-kernel","slug":"invalid-index-type-supplied-should-be-a-searchind","errorCode":null,"errorMessage":"Invalid index type supplied, should be a SearchIndex object.","messagePattern":"Invalid index type supplied, should be a SearchIndex object\\.","errorType":"exception","errorClass":"VectorStoreOperationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_ai_search.py","lineNumber":523,"sourceCode":"        return records\n\n    @override\n    async def ensure_collection_exists(self, **kwargs) -> None:\n        \"\"\"Create a new collection in Azure AI Search.\n\n        Args:\n            **kwargs: Additional keyword arguments.\n                index (SearchIndex): The search index to create, if this is supplied\n                    this is used instead of a index created based on the definition.\n                encryption_key (SearchResourceEncryptionKey): The encryption key to use,\n                    not used when index is supplied.\n                other kwargs are passed to the create_index method.\n        \"\"\"\n        if index := kwargs.pop(\"index\", None):\n            if isinstance(index, SearchIndex):\n                await self.search_index_client.create_index(index=index, **kwargs)\n                return\n            raise VectorStoreOperationException(\"Invalid index type supplied, should be a SearchIndex object.\")\n        await self.search_index_client.create_index(\n            index=_definition_to_azure_ai_search_index(\n                collection_name=self.collection_name,\n                definition=self.definition,\n                encryption_key=kwargs.pop(\"encryption_key\", None),\n            ),\n            **kwargs,\n        )\n\n    @override\n    async def collection_exists(self, **kwargs) -> bool:\n        if \"params\" not in kwargs:\n            kwargs[\"params\"] = {\"select\": [\"name\"]}\n        return self.collection_name in [\n            index_name async for index_name in self.search_index_client.list_index_names(**kwargs)\n        ]\n\n    @override","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_ai_search.py#L505-L541","documentation":"Raised by ensure_collection_exists when the caller passes an 'index' keyword argument that is not an instance of azure.search.documents.indexes.models.SearchIndex. The method accepts a caller-supplied index to bypass auto-generation from the definition, but only a genuine SearchIndex object is allowed; anything else (a dict, a string, a custom type) is rejected with a VectorStoreOperationException before reaching the SDK.","triggerScenarios":"Calling await collection.ensure_collection_exists(index=<not a SearchIndex>), e.g. passing a plain dict, a SearchIndex-like dataclass, a JSON string, or None wrapped in a truthy container. The isinstance check fails and the error fires.","commonSituations":"Passing a hand-built dict representation of an index expecting the SDK to coerce it; passing a SearchIndexer or other azure SDK model by mistake; copying an index config from another tool's format.","solutions":["Pass an actual azure.search.documents.indexes.models.SearchIndex instance built via that SDK's constructors.","If you want the connector to build the index from your definition, simply omit the 'index' kwarg.","Double-check the import path — ensure you imported SearchIndex from azure.search.documents.indexes.models."],"exampleFix":"// before\nawait collection.ensure_collection_exists(index={\"name\": \"myidx\", \"fields\": [...]})\n\n// after\nfrom azure.search.documents.indexes.models import SearchIndex\nsi = SearchIndex(name=\"myidx\", fields=[...])\nawait collection.ensure_collection_exists(index=si)","handlingStrategy":"type-guard","validationCode":"from azure.search.documents.indexes.models import SearchIndex\n\ndef ensure_valid_index_kwarg(index):\n    if index is not None and not isinstance(index, SearchIndex):\n        raise TypeError(f\"index must be a SearchIndex, got {type(index).__name__}\")\n\nensure_valid_index_kwarg(my_index)","typeGuard":"from azure.search.documents.indexes.models import SearchIndex\n\ndef is_search_index(obj) -> bool:\n    return isinstance(obj, SearchIndex)","tryCatchPattern":"from semantic_kernel.exceptions import VectorStoreOperationException\ntry:\n    await collection.ensure_collection_exists(index=idx)\nexcept VectorStoreOperationException as e:\n    if \"Invalid index type\" in str(e):\n        idx = SearchIndex(name=collection.collection_name, fields=build_fields())\n        await collection.ensure_collection_exists(index=idx)\n    raise","preventionTips":["Only pass a SearchIndex built via the azure SDK; never a dict or other type.","Omit the index kwarg entirely to let the connector generate the schema from the definition.","Add a type check in any wrapper that forwards an index argument."],"tags":["api-misuse","azure-ai-search","collection-creation","type-check"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}