{"record":{"id":"7057fe033dec0e1e","repo":"cocoindex-io/cocoindex","slug":"vectorschemaprovider-is-only-supported-for-numpy-n-7057fe","errorCode":null,"errorMessage":"VectorSchemaProvider is only supported for NumPy ndarray type. Got type: {python_type}","messagePattern":"VectorSchemaProvider is only supported for NumPy ndarray type\\. Got type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/lancedb/_target.py","lineNumber":191,"sourceCode":"    # NumPy ndarray: map to fixed-size list; dimension is handled at the schema layer\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        # Default to float32 for vectors; use float16 for half-precision\n        pa_elem = (\n            pa.float16()\n            if vector_schema.dtype in (np.half, np.float16)\n            else pa.float32()\n        )\n        # Create fixed-size list type for vector\n        return _TypeMapping(pa.list_(pa_elem, list_size=vector_schema.size))\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\n\n    # Default fallback\n    return _JSON_MAPPING\n\n\nclass ColumnDef(NamedTuple):\n    \"\"\"Definition of a table column.\"\"\"\n\n    type: pa.DataType  # PyArrow type\n    nullable: bool = True","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/lancedb/_target.py#L173-L209","documentation":"VectorSchemaProvider overrides a column's Arrow type as a vector, which is only meaningful for np.ndarray columns. If a column_spec supplies a VectorSchemaProvider for any other Python type, _get_type_mapping raises a ValueError naming the offending type.","triggerScenarios":"Passing `column_specs={\"some_col\": VectorSchemaProvider(...)}` where `some_col` is a str/int/list/dataclass/etc. rather than np.ndarray in the record type.","commonSituations":"Copy-pasting a column spec from a vector column to another column; renaming fields so the vector spec lands on the wrong column; misunderstanding that the provider is only for ndarray embeddings.","solutions":["Remove the VectorSchemaProvider from the non-ndarray column's spec.","If the column should be a vector, change the record field type to np.ndarray and keep the provider.","Match spec keys to the actual ndarray field names in your record type."],"exampleFix":"// before\ncolumn_specs={\"title\": VectorSchemaProvider(size=10)}  # title is str\n// after\ncolumn_specs={\"embedding\": VectorSchemaProvider(size=768)}  # embedding: np.ndarray","handlingStrategy":"type-guard","validationCode":"from dataclasses import fields\nimport numpy as np\nndarray_names = {f.name for f in fields(MyRecord) if f.type is np.ndarray}\nfor k, v in column_specs.items():\n    if isinstance(v, VectorSchemaProvider) and k not in ndarray_names:\n        raise TypeError(f\"VectorSchemaProvider on non-ndarray column: {k}\")","typeGuard":"def is_vector_column(col: str, record_type: type) -> bool:\n    import numpy as np\n    from dataclasses import fields\n    return any(f.name == col and f.type is np.ndarray for f in fields(record_type))","tryCatchPattern":"try:\n    target = await LanceDbTarget.from_class(MyRecord, primary_key=[\"id\"], column_specs=column_specs)\nexcept ValueError as e:\n    if \"only supported for NumPy ndarray\" in str(e):\n        ...  # remove/relocate the misplaced spec\n    raise","preventionTips":["Only attach VectorSchemaProvider to fields typed np.ndarray.","Keep spec keys and record fields in sync; derive one from the other where possible.","Review column_specs when renaming record fields."],"tags":["python","lancedb","vector","type-mismatch","schema"],"backgroundTag":"incompatible-source-type","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"}