microsoft/semantic-kernel · error · VectorStoreOperationException

{field.distance_function} not supported in Azure AI Search.

Error message

{field.distance_function} not supported in Azure AI Search.

What it means

Raised in _definition_to_azure_ai_search_index when a VECTOR field's distance_function is not a key in DISTANCE_FUNCTION_MAP. Azure AI Search supports COSINE_DISTANCE, DOT_PROD, EUCLIDEAN_DISTANCE, HAMMING, and DEFAULT. Other functions in the DistanceFunction enum (COSINE_SIMILARITY, EUCLIDEAN_SQUARED_DISTANCE, MANHATTAN) are not accepted by Azure AI Search, so index creation fails with a VectorStoreOperationException.

Source

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

                )
            )
        elif field.field_type == FieldTypes.KEY:
            fields.append(
                SimpleField(
                    name=field.storage_name or field.name,
                    type="Edm.String",  # hardcoded, only allowed type for key
                    key=True,
                    filterable=True,
                    searchable=True,
                )
            )
        elif field.field_type == FieldTypes.VECTOR:
            if not field.type_:
                logger.debug(f"Field {field.name} has not specified type, defaulting to Collection(Edm.Single).")
            if field.index_kind not in INDEX_ALGORITHM_MAP:
                raise VectorStoreOperationException(f"{field.index_kind} not supported in Azure AI Search.")
            if field.distance_function not in DISTANCE_FUNCTION_MAP:
                raise VectorStoreOperationException(f"{field.distance_function} not supported in Azure AI Search.")

            profile_name = f"{field.storage_name or field.name}_profile"
            algo_name = f"{field.storage_name or field.name}_algorithm"
            fields.append(
                SearchField(
                    name=field.storage_name or field.name,
                    type=TYPE_MAP_VECTOR[field.type_ or "default"],
                    searchable=True,
                    vector_search_dimensions=field.dimensions,
                    vector_search_profile_name=profile_name,
                    hidden=False,
                )
            )
            search_profiles.append(
                VectorSearchProfile(
                    name=profile_name,
                    algorithm_configuration_name=algo_name,
                )

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Switch the distance_function to DistanceFunction.COSINE_DISTANCE (Azure AI Search's cosine option), DOT_PROD, EUCLIDEAN_DISTANCE, or DEFAULT.
  2. Note the semantic flip: COSINE_SIMILARITY is 'higher is better' while COSINE_DISTANCE is 'lower is closer' — adjust any score thresholds accordingly.
  3. Validate vector field distance functions against DISTANCE_FUNCTION_MAP before creating the collection.

Example fix

// before
field(type_='float', name='embedding', distance_function=DistanceFunction.COSINE_SIMILARITY)

// after
field(type_='float', name='embedding', distance_function=DistanceFunction.COSINE_DISTANCE)
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.connectors.azure_ai_search import DISTANCE_FUNCTION_MAP

def validate_vector_distance_functions(definition) -> list[str]:
    bad = []
    for f in definition.fields:
        if f.field_type.value == "vector" and f.distance_function not in DISTANCE_FUNCTION_MAP:
            bad.append(f"{f.name}: {f.distance_function}")
    return bad

assert not validate_vector_distance_functions(definition)

Try / catch

from semantic_kernel.exceptions import VectorStoreOperationException
try:
    await collection.ensure_collection_exists()
except VectorStoreOperationException as e:
    if "not supported in Azure AI Search" in str(e) and "distance" in str(e).lower():
        # switch to COSINE_DISTANCE / DOT_PROD / EUCLIDEAN_DISTANCE / HAMMING
        ...
    raise

Prevention

When it happens

Trigger: Calling ensure_collection_exists() with a vector field whose distance_function is DistanceFunction.COSINE_SIMILARITY, EUCLIDEAN_SQUARED_DISTANCE, or MANHATTAN. Fires at index-build time, after the index_kind check.

Common situations: Using COSINE_SIMILARITY (a common choice in other stores) instead of COSINE_DISTANCE; copying a definition from a store that supports squared-Euclidean or Manhattan metrics.

Related errors


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