{"record":{"id":"8a0e70dfa4ea55d7","repo":"cocoindex-io/cocoindex","slug":"invalid-vector-dimension-for-name-r-vector-sch","errorCode":null,"errorMessage":"Invalid vector dimension for {name!r}: {vector_schema.size}","messagePattern":"Invalid vector dimension for (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/zvec/_target.py","lineNumber":368,"sourceCode":"    if override is not None:\n        annotations.append(override)\n    annotations.extend(type_info.annotations)\n\n    vector_schema: res_schema.VectorSchema | None = None\n    for annot in annotations:\n        vs = await res_schema.get_vector_schema(annot)\n        if vs is not None:\n            vector_schema = vs\n            break\n\n    vector_def = next((a for a in annotations if isinstance(a, ZvecVectorDef)), None)\n    zvec_type = next((a for a in annotations if isinstance(a, ZvecType)), None)\n    fts_type = next((a for a in annotations if isinstance(a, ZvecFtsType)), None)\n\n    # Dense vector: NumPy ndarray with a VectorSchema.\n    if vector_schema is not None:\n        if vector_schema.size <= 0:\n            raise ValueError(\n                f\"Invalid vector dimension for {name!r}: {vector_schema.size}\"\n            )\n        vd = vector_def or ZvecVectorDef()\n        return _Column(\n            name=name,\n            kind=\"dense\",\n            data_type=_dense_vector_data_type(vector_schema.dtype),\n            nullable=type_info.nullable,\n            dimension=vector_schema.size,\n            metric=vd.metric,\n            quantize=vd.quantize,\n        )\n\n    # Sparse vector: explicitly marked via ZvecVectorDef(sparse=True).\n    if vector_def is not None and vector_def.sparse:\n        return _Column(\n            name=name,\n            kind=\"sparse\",","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/zvec/_target.py#L350-L386","documentation":"Raised in _resolve_column while translating a record field into a zvec column schema. A dense-vector column (np.ndarray with a VectorSchema annotation) must have a valid positive dimension; the size comes from VectorSchema resolved via the field's annotations or a column override. When that size is invalid, no corresponding zvec vector type can be built, so this ValueError fires for the named column. Provide a VectorSchema with a positive dimension.","triggerScenarios":"Annotating an ndarray column with VectorSchema(size=0) or a negative size, or computing size from an empty/unset variable, when calling from_class.","commonSituations":"Embedding dimension not yet known at declaration time (placeholder 0); a config variable that failed to resolve; copy-paste leaving size unset.","solutions":["Set VectorSchema.size to the actual embedding dimension (e.g. 768, 1536)","Ensure the dimension variable is resolved before from_class is called","Validate size > 0 in your own config loading"],"exampleFix":"// before\nAnnotated[np.ndarray, VectorSchema(size=0)]\n// after\nAnnotated[np.ndarray, VectorSchema(size=768)]","handlingStrategy":"validation","validationCode":"assert size > 0, \"VectorSchema.size must be positive; set it to the embedding dimension\"","typeGuard":null,"tryCatchPattern":"try:\n    schema = ZvecCollection.from_class(Row)\nexcept ValueError as e:\n    if \"Invalid vector dimension\" in str(e):\n        raise ConfigError(\"Fix VectorSchema.size in your row class\") from e\n    raise","preventionTips":["Resolve the embedding dimension before declaring the schema","Avoid placeholder size=0 defaults","Add a startup assertion that dimension matches the model"],"tags":["python","validation","vector","zvec"],"backgroundTag":"value-out-of-range","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"}