cocoindex-io/cocoindex · error · ValueError

Turbopuffer vectors only support float32 or float16, got {dt

Error message

Turbopuffer vectors only support float32 or float16, got {dt}.

What it means

Turbopuffer's ANN index supports only float32 (`f32`) and float16 (`f16`) vector element types. `_vector_type_str` renders the schema's dtype into turbopuffer's `[N]fXX` type string, and raises this ValueError if the VectorSchema's dtype is anything else (e.g. float64, bfloat16, int8), because no valid wire type string exists for it.

Source

Thrown at python/cocoindex/connectors/turbopuffer/_target.py:242

    reserved = {"id"} | vector_field_names
    if row.attributes:
        for k, v in row.attributes.items():
            if k in reserved:
                raise ValueError(f"Row {row.id!r}: attribute name {k!r} is reserved.")
            out[k] = v

    return out


def _vector_type_str(vs: res_schema.VectorSchema) -> str:
    """Render a VectorSchema as turbopuffer's ``[N]fXX`` type string."""
    dt = np.dtype(vs.dtype)
    if dt == np.float32:
        suffix = "f32"
    elif dt == np.float16:
        suffix = "f16"
    else:
        raise ValueError(
            f"Turbopuffer vectors only support float32 or float16, got {dt}."
        )
    return f"[{vs.size}]{suffix}"


def _build_write_schema(schema: NamespaceSchema) -> dict[str, Any]:
    """Build the explicit ``schema`` payload passed to ``namespace.write()``."""
    out: dict[str, Any] = {}
    if isinstance(schema.vectors, _ResolvedNamedVectorsDef):
        for name, vd in schema.vectors.vectors.items():
            out[name] = {"type": _vector_type_str(vd.schema), "ann": True}
    else:
        out[_DEFAULT_VECTOR_FIELD] = {
            "type": _vector_type_str(schema.vectors.schema),
            "ann": True,
        }
    return out

View on GitHub (pinned to e84aa99b32)

Solutions

  1. Cast the vector schema's dtype to float32 (or float16): np.asarray(embedding, dtype=np.float32) at the point vectors are produced.
  2. Set dtype=np.float32 when constructing the numpy array backing the VectorDef schema.
  3. If you need another precision (e.g. bfloat16 or int8 quantization), use a backend that supports it instead of turbopuffer.

Example fix

// before
vec = np.array(model.encode(text))  # float64

// after
vec = np.asarray(model.encode(text), dtype=np.float32)
Defensive patterns

Strategy: validation

Validate before calling

import numpy as _np
dt = _np.dtype(vec_schema.dtype)
assert dt in (_np.float32, _np.float16), f"Cast {dt} to float32/float16 for turbopuffer"

Type guard

def is_tp_supported_dtype(dt: _np.dtype) -> bool:
    return dt in (_np.float32, _np.float16)

Try / catch

try:
    target = await NamespaceSchema.create(vectors=vdef, ...)
except ValueError as e:
    if "only support float32 or float16" in str(e):
        raise ConfigError("Recast vector schema dtype to float32") from e
    raise

Prevention

When it happens

Trigger: Declaring a VectorDef whose schema produces vectors with dtype float64 (numpy's default `np.array([...])` without dtype=), or any non-float dtype, so that `_resolve_vector_def`/`_build_write_schema` calls `_vector_type_str` and fails.

Common situations: NumPy defaults: embeddings loaded via np.array(list) come out as float64; models/ONNX pipelines outputting bfloat16; int8-quantized embeddings being passed to turbopuffer directly.

Related errors


AI-assisted analysis of cocoindex-io/cocoindex@e84aa99b32 (2026-09-08). Data as JSON: /api/errors/55c7baecb7c563c4. Report an issue: GitHub.