microsoft/semantic-kernel · error · VectorStoreInitializationException

Failed to create Azure Cognitive Search settings.

Error message

Failed to create Azure Cognitive Search settings.

What it means

Raised in the AzureAISearchCollection constructor when a search_index_client is supplied (but no search_client) and constructing AzureAISearchSettings raises a pydantic ValidationError. Settings require a valid HTTPS endpoint (HttpsUrl) and, if index_name is involved, a non-empty name. The original ValidationError is chained via 'from exc'. The message still says 'Azure Cognitive Search' (the legacy product name).

Source

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

                search_endpoint=kwargs.get("search_endpoint"),
                search_credential=search_credential,
                managed_search_index_client=False,
                managed_client=False,
                embedding_generator=embedding_generator,
            )
            return

        if search_index_client:
            try:
                azure_ai_search_settings = AzureAISearchSettings(
                    env_file_path=kwargs.get("env_file_path"),
                    endpoint=kwargs.get("search_endpoint"),
                    api_key=kwargs.get("api_key"),
                    env_file_encoding=kwargs.get("env_file_encoding"),
                    index_name=collection_name,
                )
            except ValidationError as exc:
                raise VectorStoreInitializationException("Failed to create Azure Cognitive Search settings.") from exc
            endpoint = str(azure_ai_search_settings.endpoint)
            credential = search_credential or _resolve_credential(
                azure_ai_search_settings,
                azure_credential=kwargs.get("azure_credentials"),
                token_credential=kwargs.get("token_credentials"),
            )
            super().__init__(
                record_type=record_type,
                definition=definition,
                collection_name=azure_ai_search_settings.index_name,
                search_client=_get_search_client(
                    endpoint=endpoint,
                    collection_name=azure_ai_search_settings.index_name,
                    credential=credential,
                ),
                search_index_client=search_index_client,
                search_endpoint=endpoint,
                search_credential=credential,

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass search_endpoint='https://<svc>.search.windows.net' explicitly in kwargs, or set AZURE_AI_SEARCH_ENDPOINT.
  2. Inspect the chained ValidationError (__cause__) for the exact failing field — it names whether endpoint, index_name, or encoding is at fault.
  3. Ensure the endpoint scheme is https:// — HttpsUrl rejects http://.
  4. If using a .env file, confirm env_file_path and env_file_encoding are correct and the file is readable.

Example fix

// before
col = AzureAISearchCollection(
    record_type=MyModel,
    search_index_client=idx_client,  # endpoint missing
)

// after
col = AzureAISearchCollection(
    record_type=MyModel,
    search_index_client=idx_client,
    search_endpoint="https://mysvc.search.windows.net",
)
Defensive patterns

Strategy: try-catch

Validate before calling

import os

def ensure_endpoint_configured(**kwargs) -> str:
    ep = kwargs.get("search_endpoint") or os.getenv("AZURE_AI_SEARCH_ENDPOINT")
    if not ep or not ep.startswith("https://"):
        raise ValueError("Set search_endpoint or AZURE_AI_SEARCH_ENDPOINT to a valid https:// URL")
    return ep

ensure_endpoint_configured(search_index_client=idx_client)

Try / catch

from pydantic import ValidationError
from semantic_kernel.exceptions import VectorStoreInitializationException
try:
    col = AzureAISearchCollection(record_type=M, search_index_client=idx)
except VectorStoreInitializationException as e:
    cause = e.__cause__
    assert isinstance(cause, ValidationError)
    # cause.errors() lists the failing field, e.g. endpoint required
    raise

Prevention

When it happens

Trigger: Instantiating AzureAISearchCollection(search_index_client=client, ...) where AZURE_AI_SEARCH_ENDPOINT is unset and no search_endpoint kwarg is given (endpoint is a required HttpsUrl field); or the endpoint string is not a valid HTTPS URL; or env_file_encoding is misconfigured causing the env file to fail to parse.

Common situations: Passing a pre-built SearchIndexClient but forgetting the endpoint because it was assumed to come from the client; a malformed endpoint URL; a .env file with the wrong encoding; running in CI without env vars injected.

Related errors


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