microsoft/semantic-kernel · error · VectorStoreOperationException

Invalid index type supplied, should be a SearchIndex object.

Error message

Invalid index type supplied, should be a SearchIndex object.

What it means

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.

Source

Thrown at python/semantic_kernel/connectors/azure_ai_search.py:523

        return records

    @override
    async def ensure_collection_exists(self, **kwargs) -> None:
        """Create a new collection in Azure AI Search.

        Args:
            **kwargs: Additional keyword arguments.
                index (SearchIndex): The search index to create, if this is supplied
                    this is used instead of a index created based on the definition.
                encryption_key (SearchResourceEncryptionKey): The encryption key to use,
                    not used when index is supplied.
                other kwargs are passed to the create_index method.
        """
        if index := kwargs.pop("index", None):
            if isinstance(index, SearchIndex):
                await self.search_index_client.create_index(index=index, **kwargs)
                return
            raise VectorStoreOperationException("Invalid index type supplied, should be a SearchIndex object.")
        await self.search_index_client.create_index(
            index=_definition_to_azure_ai_search_index(
                collection_name=self.collection_name,
                definition=self.definition,
                encryption_key=kwargs.pop("encryption_key", None),
            ),
            **kwargs,
        )

    @override
    async def collection_exists(self, **kwargs) -> bool:
        if "params" not in kwargs:
            kwargs["params"] = {"select": ["name"]}
        return self.collection_name in [
            index_name async for index_name in self.search_index_client.list_index_names(**kwargs)
        ]

    @override

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass an actual azure.search.documents.indexes.models.SearchIndex instance built via that SDK's constructors.
  2. If you want the connector to build the index from your definition, simply omit the 'index' kwarg.
  3. Double-check the import path — ensure you imported SearchIndex from azure.search.documents.indexes.models.

Example fix

// before
await collection.ensure_collection_exists(index={"name": "myidx", "fields": [...]})

// after
from azure.search.documents.indexes.models import SearchIndex
si = SearchIndex(name="myidx", fields=[...])
await collection.ensure_collection_exists(index=si)
Defensive patterns

Strategy: type-guard

Validate before calling

from azure.search.documents.indexes.models import SearchIndex

def ensure_valid_index_kwarg(index):
    if index is not None and not isinstance(index, SearchIndex):
        raise TypeError(f"index must be a SearchIndex, got {type(index).__name__}")

ensure_valid_index_kwarg(my_index)

Type guard

from azure.search.documents.indexes.models import SearchIndex

def is_search_index(obj) -> bool:
    return isinstance(obj, SearchIndex)

Try / catch

from semantic_kernel.exceptions import VectorStoreOperationException
try:
    await collection.ensure_collection_exists(index=idx)
except VectorStoreOperationException as e:
    if "Invalid index type" in str(e):
        idx = SearchIndex(name=collection.collection_name, fields=build_fields())
        await collection.ensure_collection_exists(index=idx)
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/c984b21b5037bf9c. Report an issue: GitHub.