{"record":{"id":"c0527ed067bd552b","repo":"cocoindex-io/cocoindex","slug":"unsupported-pgvector-metric-metric-for-postgre","errorCode":null,"errorMessage":"Unsupported pgvector metric '{metric}' for PostgreSQL type '{pg_type}'.","messagePattern":"Unsupported pgvector metric '(.+?)' for PostgreSQL type '(.+?)'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/postgres/_target.py","lineNumber":476,"sourceCode":"    \"halfvec\": {\n        \"cosine\": \"halfvec_cosine_ops\",\n        \"l2\": \"halfvec_l2_ops\",\n        \"ip\": \"halfvec_ip_ops\",\n    },\n}\n\n\ndef _pgvector_op_class(column: str, pg_type: str, metric: str) -> str:\n    type_base = _pgvector_type_base(pg_type)\n    if type_base is None:\n        raise ValueError(\n            f\"Column '{column}' has PostgreSQL type '{pg_type}', which is not a pgvector type.\"\n        )\n\n    try:\n        return _PGVECTOR_OP_CLASS[type_base][metric]\n    except KeyError as e:\n        raise ValueError(\n            f\"Unsupported pgvector metric '{metric}' for PostgreSQL type '{pg_type}'.\"\n        ) from e\n\n\nclass _VectorIndexSpec(NamedTuple):\n    column: str\n    metric: str\n    op_class: str\n    method: str\n    lists: int | None\n    m: int | None\n    ef_construction: int | None\n\n\n_VectorIndexFingerprint = bytes\n\n\nclass _VectorIndexAction(NamedTuple):","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/postgres/_target.py#L458-L494","documentation":"Raised by `_pgvector_op_class` when the requested similarity metric has no entry in `_PGVECTOR_OP_CLASS` for the column's pgvector type base (`vector` or `halfvec`). Each pgvector type supports a fixed set of metrics (cosine, l2, ip); anything else (e.g. 'dot', 'euclidean', 'hamming') is rejected.","triggerScenarios":"Calling `declare_vector_index(column=..., metric='dot')` or any metric string other than exactly 'cosine', 'l2', or 'ip' on a vector/halfvec column; a typo like 'cosine_distance' or mixed-case 'Cosine'.","commonSituations":"Translating metric names from another vector database (Qdrant's 'Euclid'/'Dot') into this API; case-sensitivity mistakes; passing an enum's repr instead of the string.","solutions":["Use one of the supported metric strings: 'cosine', 'l2', or 'ip'.","Map your desired metric: dot product -> 'ip', euclidean -> 'l2', cosine similarity -> 'cosine'.","Lowercase the metric string before passing it.","Check `_PGVECTOR_OP_CLASS` in the connector source for the exact supported matrix."],"exampleFix":"// before\ntable.declare_vector_index(column=\"embedding\", metric=\"Euclid\")\n// after\ntable.declare_vector_index(column=\"embedding\", metric=\"l2\")","handlingStrategy":"validation","validationCode":"SUPPORTED_METRICS = {\"cosine\", \"l2\", \"ip\"}\n# before calling:\n# assert metric.lower() in SUPPORTED_METRICS","typeGuard":"from typing import Literal\nMetric = Literal[\"cosine\", \"l2\", \"ip\"]\ndef is_metric(m: str) -> bool:\n    return m in {\"cosine\", \"l2\", \"ip\"}","tryCatchPattern":"try:\n    table.declare_vector_index(column=col, metric=metric)\nexcept ValueError as e:\n    if \"Unsupported pgvector metric\" in str(e):\n        logger.error(\"Metric %r invalid; use cosine/l2/ip\", metric)\n    else:\n        raise","preventionTips":["Define metric names once as module-level constants and reuse them.","Map vendor-specific metric names (Euclid/Dot) to pgvector names in one helper.","Always lowercase and normalize the metric string."],"tags":["postgres","pgvector","metric","invalid-enum"],"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"}