{"record":{"id":"883e199517a6e6c9","repo":"cocoindex-io/cocoindex","slug":"invalid-vector-dimension-vector-schema-size","errorCode":null,"errorMessage":"Invalid vector dimension: {vector_schema.size}","messagePattern":"Invalid vector dimension: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/doris/_target.py","lineNumber":307,"sourceCode":"async def _get_type_mapping(\n    python_type: Any, *, vector_schema: res_schema.VectorSchema | None = None\n) -> _TypeMapping:\n    type_info = analyze_type_info(python_type)\n\n    for annotation in type_info.annotations:\n        if isinstance(annotation, DorisType):\n            return _TypeMapping(annotation.doris_type, annotation.encoder)\n\n    base_type = type_info.base_type\n\n    if base_type in _LEAF_TYPE_MAPPINGS:\n        return _LEAF_TYPE_MAPPINGS[base_type]\n\n    if base_type is np.ndarray:\n        if vector_schema is None:\n            raise ValueError(\"VectorSchemaProvider is required for NumPy ndarray type.\")\n        if vector_schema.size <= 0:\n            raise ValueError(f\"Invalid vector dimension: {vector_schema.size}\")\n        return _TypeMapping(\n            \"ARRAY<FLOAT>\",\n            lambda v: v.tolist() if hasattr(v, \"tolist\") else list(v),\n        )\n    elif vector_schema is not None:\n        raise ValueError(\n            f\"VectorSchemaProvider only supported for ndarray. Got: {python_type}\"\n        )\n\n    if isinstance(\n        type_info.variant, (SequenceType, MappingType, RecordType, UnionType, AnyType)\n    ):\n        return _JSON_MAPPING\n\n    return _JSON_MAPPING\n\n\n# ============================================================","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/doris/_target.py#L289-L325","documentation":"Validation during Doris column type resolution in _get_type_mapping. An np.ndarray field maps to a Doris vector/array column whose element count must come from a VectorSchema (via an Annotated NDArray or column override). When a vector annotation exists but declares a non-positive/invalid size, no valid DORIS type can be emitted, so this ValueError fires. Declare the vector field with a VectorSchema specifying a positive dimension.","triggerScenarios":"Constructing VectorSchemaProvider(size=0) (or negative) and passing it with an np.ndarray column to a Doris target declaration.","commonSituations":"Computing the embedding dimension from an uninitialized variable or an empty model output; typos like size=-1 as a sentinel; config where dimension comes from an env var defaulting to 0.","solutions":["Pass the actual embedding dimension (positive integer), e.g. 384/768 depending on the model.","Validate the size before constructing the provider: `if dim <= 0: raise ...` or assert at config load time.","Fix the source of the dimension (model config, env var default) so it isn't 0."],"exampleFix":"// before\nprovider = VectorSchemaProvider(size=len(embeds) if embeds else 0)\n// after\ndim = 768\nassert dim > 0\nprovider = VectorSchemaProvider(size=dim)","handlingStrategy":"validation","validationCode":"dim = get_embedding_dim(model)\nif dim <= 0:\n    raise ValueError(f\"embedding dimension must be positive, got {dim}\")\nprovider = VectorSchemaProvider(size=dim)","typeGuard":"def valid_vector_schema(s) -> bool:\n    return s is not None and getattr(s, \"size\", 0) > 0","tryCatchPattern":"try:\n    target = doris.declare_table(db, \"tbl\", record_type, vector_schema=provider)\nexcept ValueError as e:\n    if \"Invalid vector dimension\" in str(e):\n        # fix the dimension source before retrying\n        ...","preventionTips":["Validate the embedding dimension at config load time","Avoid deriving dimension from empty/uninitialized data","Sanity-check env-var-supplied dimensions with a positive-int check"],"tags":["doris","numpy","vector","validation"],"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"}