{"record":{"id":"a58a64760b3152fa","repo":"cocoindex-io/cocoindex","slug":"unsupported-numpy-dtype-in-ndarray-dtype-suppo","errorCode":null,"errorMessage":"Unsupported NumPy dtype in NDArray: {dtype}. Supported dtypes: {cls._DTYPE_TO_KIND.keys()}","messagePattern":"Unsupported NumPy dtype in NDArray: (.+?)\\. Supported dtypes: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/_internal/datatype.py","lineNumber":89,"sourceCode":"\n    _DTYPE_TO_KIND: dict[Any, str] = {\n        np.float32: \"Float32\",\n        np.float64: \"Float64\",\n        np.int64: \"Int64\",\n    }\n\n    @classmethod\n    def validate_dtype_and_get_kind(cls, dtype: Any) -> str:\n        \"\"\"\n        Validate that the given dtype is supported, and get its CocoIndex kind by dtype.\n        \"\"\"\n        if dtype is Any:\n            raise TypeError(\n                \"NDArray for Vector must use a concrete numpy dtype, got `Any`.\"\n            )\n        kind = cls._DTYPE_TO_KIND.get(dtype)\n        if kind is None:\n            raise ValueError(\n                f\"Unsupported NumPy dtype in NDArray: {dtype}. \"\n                f\"Supported dtypes: {cls._DTYPE_TO_KIND.keys()}\"\n            )\n        return kind\n\n\nclass AnyType(NamedTuple):\n    \"\"\"\n    When the type annotation is missing or matches any type.\n    \"\"\"\n\n\nclass SequenceType(NamedTuple):\n    \"\"\"\n    Any list type, e.g. list[T], Sequence[T], NDArray[T], etc.\n    \"\"\"\n\n    elem_type: Any","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/_internal/datatype.py#L71-L107","documentation":"DtypeRegistry maps only np.float32, np.float64, and np.int64 to CocoIndex kinds. Any other concrete dtype (e.g. np.float16, np.int32, np.uint8, np.complex128) raises ValueError listing the supported dtypes.","triggerScenarios":"Annotating an NDArray-backed Vector with a supported-shaped but unsupported dtype such as npt.NDArray[np.float16] or npt.NDArray[np.int32] and having cocoindex analyze the type.","commonSituations":"Embedding pipelines producing float16 (common for ONNX/GPU models) or uint8 binary embeddings; integer IDs stored as int32; copying dtype from model output without conversion.","solutions":["Convert the array to a supported dtype before indexing, e.g. arr.astype(np.float32)","Change the annotation to npt.NDArray[np.float32] (or float64/int64)","Upcast at the producer side so the stored/declared dtype matches the registry"],"exampleFix":"// before\nembedding: npt.NDArray[np.float16]\n\n// after\nembedding: npt.NDArray[np.float32]  # or arr.astype(np.float32) before use","handlingStrategy":"validation","validationCode":"SUPPORTED = {np.float32, np.float64, np.int64}\nassert arr.dtype.type in SUPPORTED, f\"{arr.dtype} not supported; astype first\"","typeGuard":"def is_supported_dtype(a: np.ndarray) -> bool:\n    return a.dtype.type in (np.float32, np.float64, np.int64)","tryCatchPattern":"try:\n    kind = DtypeRegistry.validate_dtype_and_get_kind(dtype)\nexcept ValueError:\n    arr = arr.astype(np.float32)\n    dtype = np.float32","preventionTips":["Convert model outputs (often float16) with astype(np.float32) before indexing","Keep the dtype in the annotation in sync with the produced array","Check cocoindex's supported-dtype list when adding new embedding pipelines"],"tags":["python","numpy","dtype","unsupported"],"backgroundTag":"unsupported-dtype","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"}