{"record":{"id":"2478431121226a42","repo":"cocoindex-io/cocoindex","slug":"invalid-vector-definition-vectors-247843","errorCode":null,"errorMessage":"Invalid vector definition: {vectors}","messagePattern":"Invalid vector definition: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/turbopuffer/_target.py","lineNumber":161,"sourceCode":"            resolved = await _resolve_vector_def(vectors)\n        elif isinstance(vectors, dict):\n            if not vectors:\n                raise ValueError(\n                    \"Named-vectors dict is empty; declare at least one vector field.\"\n                )\n            reserved = _RESERVED_VECTOR_FIELD_NAMES & set(vectors)\n            if reserved:\n                raise ValueError(\n                    f\"Vector field name {sorted(reserved)[0]!r} is reserved \"\n                    f\"(it collides with the row id at the wire level).\"\n                )\n            resolved = _ResolvedNamedVectorsDef(\n                vectors={\n                    name: await _resolve_vector_def(vd) for name, vd in vectors.items()\n                }\n            )\n        else:\n            raise ValueError(f\"Invalid vector definition: {vectors}\")\n        return cls(resolved, distance)\n\n    @property\n    def vectors(self) -> _ResolvedVectorDef | _ResolvedNamedVectorsDef:\n        return self._vectors\n\n    @property\n    def distance(self) -> DistanceMetric:\n        return self._distance\n\n\n@dataclass(slots=True)\nclass Row:\n    \"\"\"A document to write to a turbopuffer namespace.\n\n    Args:\n        id: Document id (string or integer).\n        vector: Vector data — for an unnamed-vector schema pass a single sequence;","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/turbopuffer/_target.py#L143-L179","documentation":"The `vectors` argument of turbopuffer target `create()` must be either a `VectorDef` (single vector) or a non-empty dict of named `VectorDef`s. Anything else (wrong type, None, a string) falls through to the final `else` and raises ValueError showing the offending value.","triggerScenarios":"Passing `vectors=None`, a list, a string schema name, a raw dict of non-VectorDef values that somehow bypassed earlier branches (e.g. wrong-typed object), or any non-VectorDef/non-dict value to `create()`.","commonSituations":"Confusing the vector schema name (string) with a VectorDef object; passing a config dict straight through without constructing VectorDef entries; refactors changing the expected argument type.","solutions":["Wrap the definition in a `VectorDef` (single vector) or a dict mapping names to `VectorDef` instances.","Do not pass the schema name string directly — resolve it into a VectorDef first.","Check the function signature/docs for the accepted `VectorDef | dict[str, VectorDef]` shape."],"exampleFix":"// before\nawait Target.create(vectors=\"embedding_vec\")\n// after\nawait Target.create(vectors=VectorDef(schema=\"embedding_vec\", dimension=1536))","handlingStrategy":"type-guard","validationCode":"from cocoindex.connectors.turbopuffer._target import VectorDef\nif not isinstance(vectors, (VectorDef, dict)):\n    raise TypeError(\"vectors must be a VectorDef or dict[str, VectorDef]\")","typeGuard":"def is_valid_vectors_arg(v) -> bool:\n    from cocoindex.connectors.turbopuffer._target import VectorDef\n    if isinstance(v, VectorDef):\n        return True\n    return isinstance(v, dict) and bool(v) and all(isinstance(x, VectorDef) for x in v.values())","tryCatchPattern":"try:\n    spec = await Target.create(vectors=vectors, distance=metric)\nexcept ValueError as e:\n    if \"Invalid vector definition\" in str(e):\n        raise TypeError(f\"vectors must be VectorDef or dict[str, VectorDef], got {type(vectors)}\") from e\n    raise","preventionTips":["Construct VectorDef objects explicitly; never pass schema name strings.","Type-annotate the vectors argument as VectorDef | dict[str, VectorDef] and run mypy.","Wrap raw config into VectorDef at the config-loading boundary."],"tags":["python","type-error","vector","turbopuffer"],"backgroundTag":"invalid-argument-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"}