{"record":{"id":"61c220080f192ce5","repo":"microsoft/semantic-kernel","slug":"distance-function-vector-field-distance-function-61c220","errorCode":null,"errorMessage":"Distance function {vector_field.distance_function} is not supported.","messagePattern":"Distance function (.+?) is not supported\\.","errorType":"exception","errorClass":"VectorStoreInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/chroma.py","lineNumber":167,"sourceCode":"            configuration={\"hnsw\": {\"max_neighbors\": 16, \"ef_construction\": 200, \"ef_search\": 200}}\n        )\n        ```\n        if the `space` is set, it will be overridden, by the distance function set in the data model.\n\n        To use the built-in Chroma embedding functions, set the `embedding_func` parameter in the class constructor.\n\n        Args:\n            kwargs: Additional arguments are passed to the metadata parameter of the create_collection method.\n                See the Chroma documentation for more details.\n        \"\"\"\n        if self.definition.vector_fields:\n            configuration = kwargs.pop(\"configuration\", {})\n            configuration = CreateCollectionConfiguration(**configuration)\n            vector_field = self.definition.vector_fields[0]\n            if vector_field.index_kind not in INDEX_KIND_MAP:\n                raise VectorStoreInitializationException(f\"Index kind {vector_field.index_kind} is not supported.\")\n            if vector_field.distance_function not in DISTANCE_FUNCTION_MAP:\n                raise VectorStoreInitializationException(\n                    f\"Distance function {vector_field.distance_function} is not supported.\"\n                )\n            if \"hnsw\" not in configuration or configuration[\"hnsw\"] is None:\n                configuration[\"hnsw\"] = CreateHNSWConfiguration(\n                    space=DISTANCE_FUNCTION_MAP[vector_field.distance_function]\n                )\n            else:\n                configuration[\"hnsw\"][\"space\"] = DISTANCE_FUNCTION_MAP[vector_field.distance_function]\n            kwargs[\"configuration\"] = configuration\n        if \"get_or_create\" not in kwargs:\n            kwargs[\"get_or_create\"] = True\n\n        self.client.create_collection(name=self.collection_name, embedding_function=self.embedding_func, **kwargs)\n\n    @override\n    async def ensure_collection_deleted(self, **kwargs: Any) -> None:\n        \"\"\"Delete the collection.\"\"\"\n        try:","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/chroma.py#L149-L185","documentation":"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.","triggerScenarios":"Defining VectorStoreRecordVectorField with a distance_function Chroma does not map (e.g. DistanceFunction.MANHATTAN) and constructing/creating a ChromaCollection with that definition.","commonSituations":"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.","solutions":["Set the vector field's distance_function to one of COSINE_SIMILARITY, EUCLIDEAN_SQUARED_DISTANCE, or DOT_PROD (the three Chroma spaces).","If your embeddings require an unsupported metric, pick the closest supported one or switch to a connector that implements it."],"exampleFix":"// before\nVectorStoreRecordVectorField(name=\"embedding\", distance_function=DistanceFunction.MANHATTAN, dimensions=1536)\n// after\nVectorStoreRecordVectorField(name=\"embedding\", distance_function=DistanceFunction.COSINE_SIMILARITY, dimensions=1536)","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.chroma import DISTANCE_FUNCTION_MAP\nassert all(f.distance_function in DISTANCE_FUNCTION_MAP for f in definition.vector_fields), (\n    f\"Chroma only supports distance functions: {[k.value for k in DISTANCE_FUNCTION_MAP]}\"\n)","typeGuard":"from semantic_kernel.data.vector import DistanceFunction\nfrom semantic_kernel.connectors.chroma import DISTANCE_FUNCTION_MAP\n\ndef is_chroma_distance(df: DistanceFunction) -> bool:\n    return df in DISTANCE_FUNCTION_MAP","tryCatchPattern":"from semantic_kernel.exceptions.vector_store_exceptions import VectorStoreInitializationException\ntry:\n    await collection.ensure_collection_exists()\nexcept VectorStoreInitializationException as e:\n    if \"Distance function\" in str(e):\n        # align the field's distance_function to cosine/l2/ip\n        ...","preventionTips":["Pick the Chroma space that matches your embedding model (cosine for normalized text embeddings).","Validate distance_function against DISTANCE_FUNCTION_MAP at model definition time."],"tags":["chroma","vector-store","configuration","distance-function"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}