{"record":{"id":"777145651d0370ac","repo":"microsoft/semantic-kernel","slug":"distance-function-field-distance-function-is-not-777145","errorCode":null,"errorMessage":"Distance function {field.distance_function} is not supported for index kind {field.index_kind}.","messagePattern":"Distance function (.+?) is not supported for index kind (.+?)\\.","errorType":"exception","errorClass":"VectorStoreInitializationException","httpStatus":null,"severity":"warning","filePath":"python/semantic_kernel/connectors/faiss.py","lineNumber":59,"sourceCode":"    IndexKind.DEFAULT: True,\n}\n\n\ndef _create_index(field: VectorStoreField) -> faiss.Index:\n    \"\"\"Create a Faiss index.\"\"\"\n    if field.index_kind not in INDEX_KIND_MAP:\n        raise VectorStoreInitializationException(f\"Index kind {field.index_kind} is not supported.\")\n    if field.distance_function not in DISTANCE_FUNCTION_MAP:\n        raise VectorStoreInitializationException(f\"Distance function {field.distance_function} is not supported.\")\n    match field.index_kind:\n        case IndexKind.FLAT | IndexKind.DEFAULT:\n            match field.distance_function:\n                case DistanceFunction.EUCLIDEAN_SQUARED_DISTANCE | DistanceFunction.DEFAULT:\n                    return faiss.IndexFlatL2(field.dimensions)\n                case DistanceFunction.DOT_PROD:\n                    return faiss.IndexFlatIP(field.dimensions)\n                case _:\n                    raise VectorStoreInitializationException(\n                        f\"Distance function {field.distance_function} is \"\n                        f\"not supported for index kind {field.index_kind}.\"\n                    )\n        case _:\n            raise VectorStoreInitializationException(f\"Index with {field.index_kind} is not supported.\")\n\n\nclass FaissCollection(InMemoryCollection[TKey, TModel], Generic[TKey, TModel]):\n    \"\"\"Create a Faiss collection.\n\n    The Faiss Collection builds on the InMemoryVectorCollection,\n    it maintains indexes and mappings for each vector field.\n    \"\"\"\n\n    indexes: MutableMapping[str, faiss.Index] = Field(default_factory=dict)\n    indexes_key_map: MutableMapping[str, MutableMapping[TKey, int]] = Field(default_factory=dict)\n\n    def __init__(","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/faiss.py#L41-L77","documentation":"A VectorStoreInitializationException raised by the inner match in _create_index() for the FLAT/DEFAULT index_kind branch when the distance_function is supported by the outer map but has no case in the inner match (the inner match only handles EUCLIDEAN_SQUARED_DISTANCE/DEFAULT -> IndexFlatL2 and DOT_PROD -> IndexFlatIP, with a '_' fallback). Because the outer DISTANCE_FUNCTION_MAP and the inner match share the same supported set, this branch is effectively a secondary guard that fires only if the two sets ever diverge.","triggerScenarios":"Reachable only if a distance_function is present in DISTANCE_FUNCTION_MAP (passes the outer check at faiss.py:49-50) but lacks a case in the inner match. With the current maps these sets are identical, so it is defensive; would fire if the maps were edited inconsistently.","commonSituations":"Not encountered in normal usage. Could surface after a library upgrade that adds a distance function to the outer map but forgets the inner match.","solutions":["Check the library version / file an issue — the inner and outer distance-function maps should stay consistent.","As a workaround, supply a pre-built faiss.Index via the 'index'/'indexes' parameter to bypass _create_index entirely."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"from semantic_kernel.connectors.faiss import DISTANCE_FUNCTION_MAP\nSUPPORTED_INNER = {DistanceFunction.EUCLIDEAN_SQUARED_DISTANCE, DistanceFunction.DEFAULT, DistanceFunction.DOT_PROD}\nassert set(DISTANCE_FUNCTION_MAP) == SUPPORTED_INNER, \"Faiss distance maps are inconsistent; report a library bug\"","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import VectorStoreInitializationException\ntry:\n    FaissCollection(record_type=Doc)\nexcept VectorStoreInitializationException as e:\n    if \"not supported for index kind\" in str(e):\n        # supply a pre-built faiss.Index to bypass _create_index\n        ...","preventionTips":["Pin a known-good library version.","When in doubt, pass a pre-built faiss.Index instead of relying on auto-creation."],"tags":["faiss","vector-store","configuration","distance-function","defensive"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}