chroma-core/chroma · error · ValueError

Expected each value in the embedding to be a int or float, g

Error message

Expected each value in the embedding to be a int or float, got an embedding with {embedding.dtype} - {embedding}

What it means

Each embedding's dtype must be one of np.float16, np.float32, np.float64, np.int32, np.int64. validate_embeddings rejects other dtypes — notably strings ('<U...'/'object'), bool, and unsigned/low-width ints like uint8/uint16/int8 — reporting the dtype and the array contents.

Source

Thrown at chromadb/api/types.py:1404

        )
    for i, embedding in enumerate(embeddings):
        if embedding.ndim == 0:
            raise ValueError(
                f"Expected a 1-dimensional array, got a 0-dimensional array {embedding}"
            )
        if embedding.size == 0:
            raise ValueError(
                f"Expected each embedding in the embeddings to be a 1-dimensional numpy array with at least 1 int/float value. Got a 1-dimensional numpy array with no values at pos {i}"
            )

        if embedding.dtype not in [
            np.float16,
            np.float32,
            np.float64,
            np.int32,
            np.int64,
        ]:
            raise ValueError(
                "Expected each value in the embedding to be a int or float, got an embedding with "
                f"{embedding.dtype} - {embedding}"
            )
    return embeddings


def validate_sparse_vectors(vectors: SparseVectors) -> SparseVectors:
    """Validates sparse vectors to ensure it is a non-empty list of SparseVector instances.

    This function validates the structure and types of sparse vectors returned by
    SparseEmbeddingFunction implementations. It ensures:
    - Vectors is a list
    - List is non-empty
    - All items are SparseVector instances

    Note: Individual SparseVector validation (sorted indices, non-negative values, etc.)
    happens automatically in SparseVector.__post_init__ when each instance is created.
    This function only validates the list structure and instance types.

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Cast explicitly: emb = np.asarray(e, dtype=np.float32)
  2. If rows were ragged (different lengths), fix the source — all embeddings must share the collection's dimensionality
  3. For string data, parse first: np.array([float(x) for x in row], dtype=np.float32)

Example fix

# before
emb = np.array(["0.1", "0.2", "0.3"])          # dtype '<U3'

# after
import numpy as np
emb = np.asarray([0.1, 0.2, 0.3], dtype=np.float32)
Defensive patterns

Strategy: validation

Validate before calling

import numpy as np

ALLOWED = (np.float16, np.float32, np.float64, np.int32, np.int64)

def cast_embeddings(embeddings):
    out = []
    for i, e in enumerate(embeddings):
        arr = np.asarray(e)
        if arr.dtype not in ALLOWED:
            arr = arr.astype(np.float32)  # parses '<U'/'object'/bool/uint8 safely
        out.append(arr)
    return out

Type guard

import numpy as np

ALLOWED = (np.float16, np.float32, np.float64, np.int32, np.int64)

def has_allowed_dtype(e) -> bool:
    return isinstance(e, np.ndarray) and e.dtype in ALLOWED

Try / catch

try:
    validate_embeddings(embeddings)
except ValueError as e:
    if "int or float" in str(e):
        embeddings = [e.astype(np.float32) for e in embeddings]
        validate_embeddings(embeddings)
    else:
        raise

Prevention

When it happens

Trigger: embeddings=[np.array(["0.1", "0.2"])] (string dtype from un-parsed data); np.array([True, False], dtype=bool); quantized uint8 embeddings from a binary/PQ index; object dtype created by np.array on a ragged nested list; float128 embeddings.

Common situations: Reading vectors from CSV/JSON where everything is strings; binary-quantized (uint8) embeddings from other toolchains (FAISS, sentence-transformers 'binary' modes); ragged lists silently becoming dtype=object; OLTP data loaded via pandas without astype.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/42cc6414a2dcabbe. Report an issue: GitHub.