microsoft/semantic-kernel · error · VectorStoreInitializationException

Distance function {vector_field.distance_function} is not su

Error message

Distance function {vector_field.distance_function} is not supported.

What it means

A VectorStoreInitializationException raised during Chroma collection creation when the first vector field's distance_function is not in DISTANCE_FUNCTION_MAP (chroma.py:49-54). Supported functions are COSINE_SIMILARITY ('cosine'), EUCLIDEAN_SQUARED_DISTANCE ('l2'), DOT_PROD ('ip'), and DEFAULT ('l2'). Any other DistanceFunction member (e.g. MANHATTAN, HAMMING, COSINE_NEGATIVE_SIMILARITY) is rejected because Chroma has no corresponding Space.

Source

Thrown at python/semantic_kernel/connectors/chroma.py:167

            configuration={"hnsw": {"max_neighbors": 16, "ef_construction": 200, "ef_search": 200}}
        )
        ```
        if the `space` is set, it will be overridden, by the distance function set in the data model.

        To use the built-in Chroma embedding functions, set the `embedding_func` parameter in the class constructor.

        Args:
            kwargs: Additional arguments are passed to the metadata parameter of the create_collection method.
                See the Chroma documentation for more details.
        """
        if self.definition.vector_fields:
            configuration = kwargs.pop("configuration", {})
            configuration = CreateCollectionConfiguration(**configuration)
            vector_field = self.definition.vector_fields[0]
            if vector_field.index_kind not in INDEX_KIND_MAP:
                raise VectorStoreInitializationException(f"Index kind {vector_field.index_kind} is not supported.")
            if vector_field.distance_function not in DISTANCE_FUNCTION_MAP:
                raise VectorStoreInitializationException(
                    f"Distance function {vector_field.distance_function} is not supported."
                )
            if "hnsw" not in configuration or configuration["hnsw"] is None:
                configuration["hnsw"] = CreateHNSWConfiguration(
                    space=DISTANCE_FUNCTION_MAP[vector_field.distance_function]
                )
            else:
                configuration["hnsw"]["space"] = DISTANCE_FUNCTION_MAP[vector_field.distance_function]
            kwargs["configuration"] = configuration
        if "get_or_create" not in kwargs:
            kwargs["get_or_create"] = True

        self.client.create_collection(name=self.collection_name, embedding_function=self.embedding_func, **kwargs)

    @override
    async def ensure_collection_deleted(self, **kwargs: Any) -> None:
        """Delete the collection."""
        try:

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set the vector field's distance_function to one of COSINE_SIMILARITY, EUCLIDEAN_SQUARED_DISTANCE, or DOT_PROD (the three Chroma spaces).
  2. If your embeddings require an unsupported metric, pick the closest supported one or switch to a connector that implements it.

Example fix

// before
VectorStoreRecordVectorField(name="embedding", distance_function=DistanceFunction.MANHATTAN, dimensions=1536)
// after
VectorStoreRecordVectorField(name="embedding", distance_function=DistanceFunction.COSINE_SIMILARITY, dimensions=1536)
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.connectors.chroma import DISTANCE_FUNCTION_MAP
assert all(f.distance_function in DISTANCE_FUNCTION_MAP for f in definition.vector_fields), (
    f"Chroma only supports distance functions: {[k.value for k in DISTANCE_FUNCTION_MAP]}"
)

Type guard

from semantic_kernel.data.vector import DistanceFunction
from semantic_kernel.connectors.chroma import DISTANCE_FUNCTION_MAP

def is_chroma_distance(df: DistanceFunction) -> bool:
    return df in DISTANCE_FUNCTION_MAP

Try / catch

from semantic_kernel.exceptions.vector_store_exceptions import VectorStoreInitializationException
try:
    await collection.ensure_collection_exists()
except VectorStoreInitializationException as e:
    if "Distance function" in str(e):
        # align the field's distance_function to cosine/l2/ip
        ...

Prevention

When it happens

Trigger: Defining VectorStoreRecordVectorField with a distance_function Chroma does not map (e.g. DistanceFunction.MANHATTAN) and constructing/creating a ChromaCollection with that definition.

Common situations: Reusing a model authored for a connector that supports more distance metrics; choosing a distance function based on the embedding model's recommendation without checking Chroma's supported spaces.

Related errors


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