{"record":{"id":"b33634ea0f9f7386","repo":"microsoft/semantic-kernel","slug":"distance-function-field-distance-function-is-n-b33634","errorCode":null,"errorMessage":"Distance function '{field.distance_function}' is not supported. Supported functions are: {list(DISTANCE_FUNCTION_MAP.keys())}","messagePattern":"Distance function '(.+?)' is not supported\\. Supported functions are: (.+?)","errorType":"exception","errorClass":"VectorSearchExecutionException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/in_memory.py","lineNumber":677,"sourceCode":"    async def _inner_search(\n        self,\n        search_type: SearchType,\n        options: VectorSearchOptions,\n        values: Any | None = None,\n        vector: Sequence[float | int] | None = None,\n        **kwargs: Any,\n    ) -> KernelSearchResults[VectorSearchResult[TModel]]:\n        \"\"\"Inner search method.\"\"\"\n        if not vector:\n            vector = await self._generate_vector_from_values(values, options)\n        return_records: dict[TKey, float] = {}\n        field = self.definition.try_get_vector_field(options.vector_property_name)\n        if not field:\n            raise VectorStoreModelException(\n                f\"Vector field '{options.vector_property_name}' not found in the data model definition.\"\n            )\n        if field.distance_function not in DISTANCE_FUNCTION_MAP:\n            raise VectorSearchExecutionException(\n                f\"Distance function '{field.distance_function}' is not supported. \"\n                f\"Supported functions are: {list(DISTANCE_FUNCTION_MAP.keys())}\"\n            )\n        distance_func = DISTANCE_FUNCTION_MAP[field.distance_function]  # type: ignore[assignment]\n\n        for key, record in self._get_filtered_records(options).items():\n            if vector and field is not None:\n                return_records[key] = self._calculate_vector_similarity(\n                    vector,\n                    record[field.storage_name or field.name],\n                    distance_func,\n                    invert_score=field.distance_function == DistanceFunction.COSINE_SIMILARITY,\n                )\n        if field.distance_function == DistanceFunction.DEFAULT:\n            reverse_func = DISTANCE_FUNCTION_DIRECTION_HELPER[DistanceFunction.COSINE_DISTANCE]\n        else:\n            reverse_func = DISTANCE_FUNCTION_DIRECTION_HELPER[field.distance_function]  # type: ignore[assignment]\n        sorted_records = dict(","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/in_memory.py#L659-L695","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set the vector field's distance_function to a supported DistanceFunction enum value (e.g. DistanceFunction.COSINE_DISTANCE, DistanceFunction.EUCLIDEAN_DISTANCE, DistanceFunction.DOT_PROD).","If you used a raw string, switch to the DistanceFunction enum to avoid typos.","Check the library version's DISTANCE_FUNCTION_MAP for the exact supported set."],"exampleFix":"# before\nfield = VectorStoreRecordVectorField(name='embedding', distance_function='cosine')  # not a valid enum value\n# after\nfrom semantic_kernel.data.vector import DistanceFunction\nfield = VectorStoreRecordVectorField(name='embedding', distance_function=DistanceFunction.COSINE_DISTANCE)","handlingStrategy":"validation","validationCode":"from semantic_kernel.connectors.in_memory import DISTANCE_FUNCTION_MAP\nfrom semantic_kernel.data.vector import DistanceFunction\ndef is_supported_distance(fn) -> bool:\n    return fn in DISTANCE_FUNCTION_MAP or DistanceFunction(fn) in DISTANCE_FUNCTION_MAP","typeGuard":"from semantic_kernel.connectors.in_memory import DISTANCE_FUNCTION_MAP\ndef supported_distance(fn) -> bool:\n    return fn in DISTANCE_FUNCTION_MAP","tryCatchPattern":"from semantic_kernel.exceptions import VectorSearchExecutionException\ntry:\n    results = await collection.search(search_type=SearchType.VECTOR, options=opts, values='q')\nexcept VectorSearchExecutionException as e:\n    # set a supported distance_function on the vector field and retry\n    ...","preventionTips":["Always use the DistanceFunction enum, not raw strings, for distance_function.","Validate distance_function against DISTANCE_FUNCTION_MAP after upgrades.","Map custom metrics from other stores onto the closest supported function."],"tags":["in-memory","vector-search","configuration","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}