{"record":{"id":"f6d40cfaafd46d52","repo":"cocoindex-io/cocoindex","slug":"unsupported-metric-type-metric-r","errorCode":null,"errorMessage":"Unsupported metric type: {metric!r}","messagePattern":"Unsupported metric type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/zvec/_target.py","lineNumber":522,"sourceCode":"            )\n\n        record_info = RecordType(record_type)\n        columns: dict[str, _Column] = {}\n        for fld in record_info.fields:\n            override = column_overrides.get(fld.name) if column_overrides else None\n            columns[fld.name] = await _resolve_column(fld.name, fld.type_hint, override)\n        return cls(columns, primary_key[0], row_type=record_type)\n\n\ndef _metric_type(metric: str) -> Any:\n    key = metric.lower()\n    if key == \"cosine\":\n        return _zvec.MetricType.COSINE\n    if key == \"ip\":\n        return _zvec.MetricType.IP\n    if key == \"l2\":\n        return _zvec.MetricType.L2\n    raise ValueError(f\"Unsupported metric type: {metric!r}\")\n\n\ndef _quantize_type(quantize: str) -> Any | None:\n    key = quantize.lower()\n    if key == \"none\":\n        return None\n    if key == \"fp16\":\n        return _zvec.QuantizeType.FP16\n    if key == \"int8\":\n        return _zvec.QuantizeType.INT8\n    if key == \"int4\":\n        return _zvec.QuantizeType.INT4\n    raise ValueError(f\"Unsupported quantize type: {quantize!r}\")\n\n\ndef _build_zvec_schema(collection_name: str, schema: CollectionSchema[Any]) -> Any:\n    fields: list[Any] = []\n    vectors: list[Any] = []","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/zvec/_target.py#L504-L540","documentation":"Enum-style mapper guard in _metric_type, called while building the zvec collection schema. Only 'cosine', 'ip', and 'l2' (case-insensitive) map to zvec MetricType values; any other string would otherwise be passed through to zvec and fail deep inside the engine with an opaque error. This ValueError fires when a metric config value is misspelled or unsupported. Use one of cosine, ip, or l2.","triggerScenarios":"Declaring a zvec collection with a vector column whose metric is set to an unsupported name, e.g. 'euclidean', 'hamming', 'dot', or 'COSINE' with different casing than the accepted keys.","commonSituations":"Copying metric names from other vector DBs (pgvector/Qdrant/FAISS use different spellings like 'euclidean' or 'dot'); typo in config.","solutions":["Change the metric to one of: 'cosine', 'ip', 'l2'.","Use 'l2' for euclidean distance, 'ip' for dot/inner product.","Validate metric strings against the allowed set before declaring the collection."],"exampleFix":"// before\nColumn(kind=\"dense\", dim=768, metric=\"euclidean\")\n// after\nColumn(kind=\"dense\", dim=768, metric=\"l2\")","handlingStrategy":"validation","validationCode":"ALLOWED = {\"cosine\", \"ip\", \"l2\"}\nassert metric.lower() in ALLOWED, f\"metric must be one of {ALLOWED}\"","typeGuard":null,"tryCatchPattern":"try:\n    target = collection_target(...)\nexcept ValueError as e:\n    if \"metric\" in str(e): ...","preventionTips":["Only use 'cosine', 'ip', or 'l2' for zvec vector metrics.","Map foreign metric names (euclidean->l2, dot->ip) when porting configs.","Keep metric strings lowercase."],"tags":["python","vector-database","invalid-enum","metric"],"backgroundTag":"unsupported-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"}