microsoft/semantic-kernel · error · VectorSearchExecutionException

Distance function '{field.distance_function}' is not support

Error message

Distance function '{field.distance_function}' is not supported. Supported functions are: {list(DISTANCE_FUNCTION_MAP.keys())}

What it means

Thrown by _inner_search (in_memory.py:676-679) as VectorSearchExecutionException when the resolved vector field's distance_function is not in DISTANCE_FUNCTION_MAP. Supported functions: cosine_distance, cosine_similarity, euclidean_distance, euclidean_squared_distance, manhattan, hamming, dot_prod, and default.

Source

Thrown at python/semantic_kernel/connectors/in_memory.py:677

    async def _inner_search(
        self,
        search_type: SearchType,
        options: VectorSearchOptions,
        values: Any | None = None,
        vector: Sequence[float | int] | None = None,
        **kwargs: Any,
    ) -> KernelSearchResults[VectorSearchResult[TModel]]:
        """Inner search method."""
        if not vector:
            vector = await self._generate_vector_from_values(values, options)
        return_records: dict[TKey, float] = {}
        field = self.definition.try_get_vector_field(options.vector_property_name)
        if not field:
            raise VectorStoreModelException(
                f"Vector field '{options.vector_property_name}' not found in the data model definition."
            )
        if field.distance_function not in DISTANCE_FUNCTION_MAP:
            raise VectorSearchExecutionException(
                f"Distance function '{field.distance_function}' is not supported. "
                f"Supported functions are: {list(DISTANCE_FUNCTION_MAP.keys())}"
            )
        distance_func = DISTANCE_FUNCTION_MAP[field.distance_function]  # type: ignore[assignment]

        for key, record in self._get_filtered_records(options).items():
            if vector and field is not None:
                return_records[key] = self._calculate_vector_similarity(
                    vector,
                    record[field.storage_name or field.name],
                    distance_func,
                    invert_score=field.distance_function == DistanceFunction.COSINE_SIMILARITY,
                )
        if field.distance_function == DistanceFunction.DEFAULT:
            reverse_func = DISTANCE_FUNCTION_DIRECTION_HELPER[DistanceFunction.COSINE_DISTANCE]
        else:
            reverse_func = DISTANCE_FUNCTION_DIRECTION_HELPER[field.distance_function]  # type: ignore[assignment]
        sorted_records = dict(

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set the vector field's distance_function to a supported DistanceFunction enum value (e.g. DistanceFunction.COSINE_DISTANCE, DistanceFunction.EUCLIDEAN_DISTANCE, DistanceFunction.DOT_PROD).
  2. If you used a raw string, switch to the DistanceFunction enum to avoid typos.
  3. Check the library version's DISTANCE_FUNCTION_MAP for the exact supported set.

Example fix

# before
field = VectorStoreRecordVectorField(name='embedding', distance_function='cosine')  # not a valid enum value
# after
from semantic_kernel.data.vector import DistanceFunction
field = VectorStoreRecordVectorField(name='embedding', distance_function=DistanceFunction.COSINE_DISTANCE)
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.connectors.in_memory import DISTANCE_FUNCTION_MAP
from semantic_kernel.data.vector import DistanceFunction
def is_supported_distance(fn) -> bool:
    return fn in DISTANCE_FUNCTION_MAP or DistanceFunction(fn) in DISTANCE_FUNCTION_MAP

Type guard

from semantic_kernel.connectors.in_memory import DISTANCE_FUNCTION_MAP
def supported_distance(fn) -> bool:
    return fn in DISTANCE_FUNCTION_MAP

Try / catch

from semantic_kernel.exceptions import VectorSearchExecutionException
try:
    results = await collection.search(search_type=SearchType.VECTOR, options=opts, values='q')
except VectorSearchExecutionException as e:
    # set a supported distance_function on the vector field and retry
    ...

Prevention

When it happens

Trigger: Defining a vector field with distance_function set to a custom/unknown value or a string that is not a DistanceFunction enum member; a version change where a function was removed or the enum values shifted.

Common situations: Migrating a model from another vector DB with an unsupported metric; using a raw string instead of the DistanceFunction enum; library upgrade that renamed an enum member.

Related errors


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