{"record":{"id":"0da248d999cd621e","repo":"cocoindex-io/cocoindex","slug":"invalid-vector-dimension-vector-schema-size-0da248","errorCode":null,"errorMessage":"Invalid vector dimension: {vector_schema.size}","messagePattern":"Invalid vector dimension: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/sqlite/_target.py","lineNumber":261,"sourceCode":"\n    # Check for SqliteType annotation override\n    for annotation in type_info.annotations:\n        if isinstance(annotation, SqliteType):\n            return _TypeMapping(annotation.sqlite_type, annotation.encoder)\n\n    base_type = type_info.base_type\n\n    # Check direct leaf type mappings\n    if base_type in _LEAF_TYPE_MAPPINGS:\n        return _LEAF_TYPE_MAPPINGS[base_type]\n\n    # NumPy ndarray: serialize to sqlite-vec compatible format\n    if base_type is np.ndarray:\n        if vector_schema is None:\n            raise ValueError(\"VectorSchemaProvider is required for NumPy ndarray type.\")\n\n        if vector_schema.size <= 0:\n            raise ValueError(f\"Invalid vector dimension: {vector_schema.size}\")\n\n        # sqlite-vec uses float[N] type (e.g., float[384])\n        import sqlite_vec  # type: ignore\n\n        return _TypeMapping(\n            f\"float[{vector_schema.size}]\", sqlite_vec.serialize_float32\n        )\n\n    elif vector_schema is not None:\n        raise ValueError(\n            f\"VectorSchemaProvider is only supported for NumPy ndarray type. Got type: {python_type}\"\n        )\n\n    # Complex types that need JSON encoding\n    if isinstance(\n        type_info.variant, (SequenceType, MappingType, RecordType, UnionType, AnyType)\n    ):\n        return _JSON_MAPPING","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/sqlite/_target.py#L243-L279","documentation":"When an ndarray field has a VectorSchemaProvider, its `size` defines the sqlite-vec column type `float[N]`. A size of zero or negative cannot yield a valid vector type, so `_get_type_mapping` raises this ValueError. It guards against misconfigured or uninitialized vector schemas.","triggerScenarios":"Declaring a field with `VectorSchemaProvider(size=0)` (or a negative size), or constructing the provider dynamically from an empty/failed dimension lookup.","commonSituations":"Computing the dimension from an empty model config, copy-pasting a placeholder size=0, or reading the dimension from an uninitialized embedding model.","solutions":["Set the provider's size to the actual positive embedding dimension (e.g. 384, 768).","Read the dimension from the embedding model at startup and assert it's > 0 before building the target.","Fix the constant/config supplying the size if it defaults to 0."],"exampleFix":"// before\nembedding: Annotated[np.ndarray, VectorSchemaProvider(size=0)]\n// after\nembedding: Annotated[np.ndarray, VectorSchemaProvider(size=384)]","handlingStrategy":"validation","validationCode":"dim = embedding_model.get_sentence_embedding_dimension()\nassert dim and dim > 0, f\"Bad embedding dimension: {dim}\"","typeGuard":null,"tryCatchPattern":"try:\n    target = sqlite.table_target(record_type=Row, ...)\nexcept ValueError as e:\n    if \"Invalid vector dimension\" in str(e):\n        raise ConfigError(\"VectorSchemaProvider size must be a positive integer\") from e\n    raise","preventionTips":["Set VectorSchemaProvider(size=...) from the embedding model's reported dimension.","Assert the dimension is a positive int before constructing the provider.","Avoid placeholder values like 0 in configuration defaults."],"tags":["sqlite","vector","dimension","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"}