chroma-core/chroma · error · ValueError
Expected a 1-dimensional array, got a 0-dimensional array {e
Error message
Expected a 1-dimensional array, got a 0-dimensional array {embedding} What it means
Each embedding must be a 1-dimensional array. validate_embeddings checks embedding.ndim and raises when it equals 0 — a numpy scalar such as np.array(0.5) or np.float32(0.5), which has no length axis and cannot be a vector.
Source
Thrown at chromadb/api/types.py:1389
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,
np.int64,
]:
raise ValueError(
"Expected each value in the embedding to be a int or float, got an embedding with "
f"{embedding.dtype} - {embedding}"
)View on GitHub (pinned to aecdd12c8a)
Solutions
- Build vectors as 1-D arrays: np.asarray(values, dtype=np.float32) where values is a flat sequence
- Fix the reduction: use axis=0/axis=1 correctly, or arr.mean(axis=1) to keep one vector per row
- Index rows, not cells: use matrix[i] not matrix[i][j]
Example fix
# before emb = np.array(scores).mean() # 0-dim scalar embeddings = [emb] # after emb = np.asarray(scores, dtype=np.float32) # 1-D vector embeddings = [emb]
Defensive patterns
Strategy: type-guard
Validate before calling
import numpy as np
def ensure_1d(embeddings):
out = []
for i, e in enumerate(embeddings):
arr = np.asarray(e)
if arr.ndim != 1:
raise ValueError(f"embedding {i} has ndim={arr.ndim}, expected 1")
out.append(arr)
return out Type guard
import numpy as np
def is_1d_vector(e) -> bool:
return isinstance(e, np.ndarray) and e.ndim == 1 Try / catch
try:
validate_embeddings(embeddings)
except ValueError as e:
if "0-dimensional array" in str(e):
embeddings = [np.atleast_1d(np.asarray(e, dtype=np.float32)) for e in embeddings]
validate_embeddings(embeddings)
else:
raise Prevention
- Use reductions with an explicit axis so results keep a dimension: mean(axis=1)
- Index rows (arr[i]) not cells (arr[i, j]) when extracting vectors
- Build vectors from flat sequences via np.asarray(values, dtype=np.float32)
When it happens
Trigger: embeddings=[np.array(0.5)] or [np.float32(x) for x in values] — typically the result of reducing/aggregating per-dimension (e.g. taking mean over the wrong axis) or unrolling a matrix with scalars instead of rows.
Common situations: Averaging embeddings with .mean() without axis=1; indexing arr[i, j] instead of arr[i]; converting a single vector with np.array(value) where value is already a scalar.
Related errors
- Expected each embedding in the embeddings to be a numpy arra
- Expected each embedding in the embeddings to be a 1-dimensio
- Expected each value in the embedding to be a int or float, g
- Expected '${fieldName}' to be an array, but got ${typeof emb
- Expected embeddings to be an array with at least one item
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/31a91c2dd06e77f2.
Report an issue: GitHub.