chroma-core/chroma · error · ValueError
Expected each embedding in the embeddings to be a numpy arra
Error message
Expected each embedding in the embeddings to be a numpy array, got {list(set([type(e).__name__ for e in embeddings]))} What it means
Every element of the embeddings list must be a numpy ndarray. validate_embeddings checks isinstance(e, np.ndarray) for each element and reports the distinct offending type names. Plain Python lists/tuples inside embeddings are rejected by this specific check (the public client normally converts, so this fires on direct calls to validation or custom API/EF implementations that skip conversion).
Source
Thrown at chromadb/api/types.py:1383
if n_results <= 0:
raise TypeError(
f"Number of requested results {n_results}, cannot be negative, or zero."
)
return n_results
def validate_embeddings(embeddings: Embeddings) -> Embeddings:
"""Validates embeddings to ensure it is a list of numpy arrays of ints, or floats"""
if not isinstance(embeddings, (list, np.ndarray)):
raise ValueError(
f"Expected embeddings to be a list, got {type(embeddings).__name__}"
)
if len(embeddings) == 0:
raise ValueError(
f"Expected embeddings to be a list with at least one item, got {len(embeddings)} embeddings"
)
if not all([isinstance(e, np.ndarray) for e in embeddings]):
raise ValueError(
"Expected each embedding in the embeddings to be a numpy array, got "
f"{list(set([type(e).__name__ for e in embeddings]))}"
)
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,View on GitHub (pinned to aecdd12c8a)
Solutions
- Convert each item: embeddings=[np.asarray(e, dtype=np.float32) for e in embeddings]
- Convert wholesale: embeddings=list(np.array(embeddings, dtype=np.float32))
- Fix a custom EmbeddingFunction to return np.ndarray instances
Example fix
# before embeddings = [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]] # plain lists # after import numpy as np embeddings = [np.asarray(e, dtype=np.float32) for e in embeddings]
Defensive patterns
Strategy: type-guard
Validate before calling
import numpy as np
def normalize_embeddings(embeddings):
if isinstance(embeddings, np.ndarray):
embeddings = list(embeddings)
return [e if isinstance(e, np.ndarray) else np.asarray(e, dtype=np.float32) for e in embeddings]
embeddings = normalize_embeddings(embeddings) # every element now np.ndarray Type guard
import numpy as np
def all_ndarray(embeddings) -> bool:
return all(isinstance(e, np.ndarray) for e in embeddings) Try / catch
try:
validate_embeddings(embeddings)
except ValueError as e:
if "to be a numpy array" in str(e):
embeddings = [np.asarray(e, dtype=np.float32) for e in embeddings]
validate_embeddings(embeddings)
else:
raise Prevention
- Always np.asarray(..., dtype=np.float32) embeddings loaded from JSON/CSV/REST
- Custom embedding functions should return np.ndarray vectors, not lists
- Run validation once in a shared preprocessing helper instead of trusting every call site
When it happens
Trigger: Calling validate_embeddings (directly, or via a custom SegmentAPI/server or EmbeddingFunction path that does not np.array-convert) with embeddings=[[0.1, 0.2], [0.3, 0.4]] — raw lists of floats — or mixing one np.ndarray with plain lists.
Common situations: Custom embedding functions returning list-of-lists; loading embeddings from JSON and passing them unconverted; older Chroma versions or self-built server layers that call validation on raw input.
Related errors
- Expected '${fieldName}' to be an array, but got ${typeof emb
- Expected embeddings to be a list, got {type(embeddings).__na
- Expected a 1-dimensional array, got a 0-dimensional array {e
- Expected each embedding in the embeddings to be a 1-dimensio
- Expected each value in the embedding to be a int or float, g
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/bdd8bf3602ed3f17.
Report an issue: GitHub.