{"record":{"id":"3fa82d2aef9ae8ce","repo":"cocoindex-io/cocoindex","slug":"vectorschemaprovider-is-required-for-numpy-ndarray","errorCode":null,"errorMessage":"VectorSchemaProvider is required for NumPy ndarray type.","messagePattern":"VectorSchemaProvider is required for NumPy ndarray type\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/doris/_target.py","lineNumber":305,"sourceCode":"\n\nasync 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","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/doris/_target.py#L287-L323","documentation":"Raised by _get_type_mapping in the Doris connector when a record column is a NumPy ndarray but no VectorSchemaProvider is supplied. Vector columns need an explicit dimension/element schema to map to a Doris ARRAY<FLOAT> type, so ndarrays require a vector schema.","triggerScenarios":"Declaring a Doris target whose record type includes an np.ndarray field without passing a VectorSchemaProvider for that column (via _columns_from_record_type during target setup).","commonSituations":"Embedding pipelines passing raw numpy vectors to a Doris table while forgetting the vector schema; refactors that change a field from a list (auto-mapped) to ndarray; copying table declarations between connectors with different schema requirements.","solutions":["Provide a VectorSchemaProvider (with the correct dimension) for the ndarray column in the target declaration.","Convert the column to a plain list[float] if no fixed vector schema is desired.","Check _get_type_mapping/_columns_from_record_type calls to ensure vector_schema is threaded through for every ndarray field."],"exampleFix":"// before\ntarget = doris.declare_table(db, \"tbl\", record_type)  # record has np.ndarray field\n// after\nfrom cocoindex.resources.chunk import VectorSchemaProvider\nschema = VectorSchemaProvider(size=768)\ntarget = doris.declare_table(db, \"tbl\", record_type, vector_schema=schema)","handlingStrategy":"validation","validationCode":"from cocoindex.resources.chunk import VectorSchemaProvider\nassert isinstance(vector_schema, VectorSchemaProvider), \"ndarray columns need VectorSchemaProvider\"","typeGuard":"def has_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=vs)\nexcept ValueError as e:\n    if \"VectorSchemaProvider is required\" in str(e):\n        # supply a VectorSchemaProvider for the ndarray column\n        ...","preventionTips":["Always pair np.ndarray columns with a VectorSchemaProvider","Prefer list[float] fields when no fixed vector schema exists","Check the connector's schema requirements when porting between connectors"],"tags":["doris","numpy","vector","schema"],"backgroundTag":"missing-required-argument","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"}