{"record":{"id":"d52cde69844b53ed","repo":"cocoindex-io/cocoindex","slug":"invalid-metric-name-metric","errorCode":null,"errorMessage":"Invalid metric name: {metric}","messagePattern":"Invalid metric name: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/doris/_target.py","lineNumber":1416,"sourceCode":"        _validate_identifier(table_parts[1])\n        quoted_table = f\"`{table_parts[0]}`.`{table_parts[1]}`\"\n    elif len(table_parts) == 1:\n        _validate_identifier(table)\n        quoted_table = f\"`{table}`\"\n    else:\n        raise ValueError(f\"Invalid table name format: {table}\")\n\n    _validate_identifier(vector_field)\n\n    if metric == \"l2_distance\":\n        distance_fn = \"l2_distance_approximate\"\n        order = \"ASC\"\n    elif metric == \"inner_product\":\n        distance_fn = \"inner_product_approximate\"\n        order = \"DESC\"\n    else:\n        if not metric.isidentifier():\n            raise ValueError(f\"Invalid metric name: {metric}\")\n        distance_fn = metric\n        order = \"ASC\" if \"distance\" in metric else \"DESC\"\n\n    vector_literal = \"[\" + \", \".join(str(float(v)) for v in query_vector) + \"]\"\n\n    if select_columns:\n        quoted_columns = []\n        for col in select_columns:\n            _validate_identifier(col)\n            quoted_columns.append(f\"`{col}`\")\n        select = \", \".join(quoted_columns)\n    else:\n        select = \"*\"\n\n    query = f\"\"\"SELECT {select}, {distance_fn}(`{vector_field}`, {vector_literal}) as _distance\nFROM {quoted_table}\"\"\"\n\n    if where_clause:","sourceCodeStart":1398,"sourceCodeEnd":1434,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/doris/_target.py#L1398-L1434","documentation":"The metric argument must be 'l2_distance' or 'inner_product', or a custom Doris distance function name that is a valid Python identifier (used as distance_fn in the ORDER BY). Anything else — spaces, dashes, empty string — raises ValueError.","triggerScenarios":"Calling build_vector_search_query(metric='cosine') is fine only if 'cosine' is a valid identifier; errors occur for metric names like 'l2-distance', 'cosine similarity', '' or None passed by mistake.","commonSituations":"Copying metric names from other vector DBs (e.g. 'cosine_sim' with dashes, pgvector's '<->' operator); passing an enum's string repr like 'Metric.L2'; UI-supplied metric strings with spaces.","solutions":["Use one of the supported values: 'l2_distance' or 'inner_product'","For custom functions, pass a bare function identifier, e.g. metric='cosine_distance'","Sanitize/normalize the metric string before calling"],"exampleFix":"// before\nbuild_vector_search_query(..., metric=\"l2-distance\")\n// after\nbuild_vector_search_query(..., metric=\"l2_distance\")","handlingStrategy":"validation","validationCode":"assert metric in (\"l2_distance\", \"inner_product\") or metric.isidentifier(), f\"bad metric: {metric}\"","typeGuard":null,"tryCatchPattern":"try:\n    sql = build_vector_search_query(..., metric=metric)\nexcept ValueError as e:\n    logger.error(\"Unsupported metric %r\", metric); raise","preventionTips":["Restrict metric choices to 'l2_distance' and 'inner_product' in your app config","Normalize UI/config metric strings before passing them","If using custom distance functions, keep them valid SQL identifiers"],"tags":["doris","vector-search","enum","argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}