{"record":{"id":"8c3c84a5e054443d","repo":"microsoft/semantic-kernel","slug":"distance-function-field-distance-function-is-n","errorCode":null,"errorMessage":"Distance function '{field.distance_function}' is not supported by Azure Cosmos DB NoSQL.","messagePattern":"Distance function '(.+?)' is not supported by Azure Cosmos DB NoSQL\\.","errorType":"exception","errorClass":"VectorStoreModelException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_cosmos_db.py","lineNumber":178,"sourceCode":"\n    A default vector embedding policy is created based on the data model definition.\n\n    Args:\n        definition (VectorStoreRecordDefinition): The definition of the data model.\n\n    Returns:\n        dict[str, Any]: The vector embedding policy.\n\n    Raises:\n        VectorStoreModelException: If the datatype or distance function is not supported by Azure Cosmos DB NoSQL.\n\n    \"\"\"\n    vector_embedding_policy: dict[str, Any] = {\"vectorEmbeddings\": []}\n\n    for field in definition.fields:\n        if field.field_type == FieldTypes.VECTOR:\n            if field.distance_function not in DISTANCE_FUNCTION_MAP_NOSQL:\n                raise VectorStoreModelException(\n                    f\"Distance function '{field.distance_function}' is not supported by Azure Cosmos DB NoSQL.\"\n                )\n            if field.type_ and field.type_ not in VECTOR_DATATYPES_MAP:\n                raise VectorStoreModelException(\n                    f\"Vector property type '{field.type_}' is not supported by Azure Cosmos DB NoSQL.\"\n                )\n\n            vector_embedding_policy[\"vectorEmbeddings\"].append({\n                \"path\": f'/\"{field.storage_name or field.name}\"',\n                \"dataType\": VECTOR_DATATYPES_MAP[field.type_ or \"default\"],\n                \"distanceFunction\": DISTANCE_FUNCTION_MAP_NOSQL[field.distance_function],\n                \"dimensions\": field.dimensions,\n            })\n\n    return vector_embedding_policy\n\n\ndef _get_key(key: str | CosmosNoSqlCompositeKey) -> str:","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_cosmos_db.py#L160-L196","documentation":"This error is raised by the Azure Cosmos DB NoSQL vector embedding policy builder when a vector field's distance function is not in the supported set. Cosmos DB NoSQL only supports cosine similarity, dot product, and Euclidean distance (plus DEFAULT). The check happens at policy-construction time, before any data is written, so it surfaces a data-model definition mismatch.","triggerScenarios":"Raised in _get_vector_embedding_policy when field.field_type == FieldTypes.VECTOR and field.distance_function not in DISTANCE_FUNCTION_MAP_NOSQL. This runs when a CosmosNoSqlCollection constructs its container policy (collection creation / protocol negotiation). It triggers when the VectorStoreCollectionDefinition declares a vector field with an unsupported DistanceFunction enum value (e.g. MANHATTAN, JACCARD, HAMMING).","commonSituations":"Reusing a data model definition written for a different vector store (e.g. Pinecone, Weaviate, Redis) that supports a wider distance-function set. Copying a sample model from another connector. Upgrading semantic-kernel and a previously-tolerated custom distance value is now enumerated.","solutions":["Set the vector field's distance_function to DistanceFunction.COSINE_SIMILARITY, DistanceFunction.DOT_PROD, DistanceFunction.EUCLIDEAN_DISTANCE, or DistanceFunction.DEFAULT.","If your data genuinely needs an unsupported metric, choose the closest supported one (most embeddings use cosine) or switch to a connector that supports it.","Check the field annotation in your VectorStoreRecordVectorField and correct the distance_function argument."],"exampleFix":"// before\nVectorStoreRecordVectorField(name=\"embedding\", dimensions=1536, distance_function=DistanceFunction.HAMMING)\n// after\nVectorStoreRecordVectorField(name=\"embedding\", dimensions=1536, distance_function=DistanceFunction.COSINE_SIMILARITY)","handlingStrategy":"validation","validationCode":"from semantic_kernel.data.vector import DistanceFunction\nfrom semantic_kernel.connectors.azure_cosmos_db import DISTANCE_FUNCTION_MAP_NOSQL\n\nSUPPORTED = set(DISTANCE_FUNCTION_MAP_NOSQL)\nbad = [f for f in definition.vector_fields if f.distance_function not in SUPPORTED]\nif bad:\n    raise ValueError(f\"Unsupported distance functions: {[f.name for f in bad]}\")\ncollection = CosmosNoSqlCollection(...)\n","typeGuard":"def is_supported_nosql_distance(fn: DistanceFunction) -> bool:\n    return fn in DISTANCE_FUNCTION_MAP_NOSQL\n","tryCatchPattern":"try:\n    collection = await CosmosNoSqlCollection(...).create()\nexcept VectorStoreModelException as e:\n    # fix the data model distance_function\n    ...\n","preventionTips":["Validate the data model against the connector's supported maps before instantiation.","Centralize vector-field definitions so distance functions are set once and reviewed.","Write a unit test asserting your model's fields are all supported by each connector you use."],"tags":["azure-cosmos-db","vector-store","data-model","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}