{"record":{"id":"e758552d0c199329","repo":"cocoindex-io/cocoindex","slug":"ndarray-for-vector-must-use-a-concrete-numpy-dtype","errorCode":null,"errorMessage":"NDArray for Vector must use a concrete numpy dtype, got `Any`.","messagePattern":"NDArray for Vector must use a concrete numpy dtype, got `Any`\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/_internal/datatype.py","lineNumber":84,"sourceCode":"class DtypeRegistry:\n    \"\"\"\n    Registry for NumPy dtypes used in CocoIndex.\n    Maps NumPy dtypes to their CocoIndex type kind.\n    \"\"\"\n\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):","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/_internal/datatype.py#L66-L102","documentation":"DtypeRegistry.validate_dtype_and_get_kind rejects an `Any` dtype before consulting the registry: a Vector backed by NDArray must declare a concrete numpy scalar dtype so CocoIndex can map it to a Float32/Float64/Int64 kind. `typing.Any` as the dtype raises TypeError.","triggerScenarios":"Annotating a vector/embedding field as np.ndarray[Any, Any] or npt.NDArray[Any] (or Vector with dtype left as Any) so analyze_type_info ends with dtype=Any and validation runs against Any.","commonSituations":"Leaving the element type unparametrized because the array is created dynamically; using `Any` to silence a type checker; auto-generated annotations missing dtype info.","solutions":["Specify a concrete dtype: npt.NDArray[np.float32]","Use np.float64 or np.int64 if that matches the data and the target index","Normalize bare NDArray aliases to a parametrized form before handing the type to cocoindex"],"exampleFix":"// before\nembedding: npt.NDArray[Any]\n\n// after\nembedding: npt.NDArray[np.float32]","handlingStrategy":"type-guard","validationCode":"import typing\nfrom typing import Any as _Any\ndef dtype_is_concrete(annotation) -> bool:\n    args = typing.get_args(annotation)\n    return bool(args) and args[-1] is not _Any","typeGuard":null,"tryCatchPattern":"try:\n    kind = DtypeRegistry.validate_dtype_and_get_kind(dtype)\nexcept TypeError:\n    dtype = np.float32  # default to concrete dtype","preventionTips":["Never leave vector element types as Any; parametrize every NDArray","Pin the embedding dtype at model-load time (usually np.float32)","Validate annotations in a startup schema check rather than at index time"],"tags":["python","numpy","dtype","typing"],"backgroundTag":"dtype-mismatch","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"}