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
- Switch the distance_function to DistanceFunction.COSINE_DISTANCE (Azure AI Search's cosine option), DOT_PROD, EUCLIDEAN_DISTANCE, or DEFAULT.
- Note the semantic flip: COSINE_SIMILARITY is 'higher is better' while COSINE_DISTANCE is 'lower is closer' — adjust any score thresholds accordingly.
- 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
- Use DistanceFunction.COSINE_DISTANCE (not COSINE_SIMILARITY) for Azure AI Search.
- Remember score direction flips between similarity and distance metrics; adjust thresholds.
- Validate distance_function against DISTANCE_FUNCTION_MAP per store in a test.
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
- {field.index_kind} not supported in Azure AI Search.
- {field.type_} not supported in Azure AI Search.
- No searchable fields found for hybrid search.
- Index kind '{field.index_kind}' is not supported by Azure Co
- Field '{top_level}' not in data model (storage property name
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/b57be5e320b0ce62.
Report an issue: GitHub.