chroma-core/chroma · error · ChromaValueError

Expected '${fieldName}' to be an array, but got ${typeof emb

Error message

Expected '${fieldName}' to be an array, but got ${typeof embeddings}

What it means

ChromaValueError thrown by the internal validateEmbeddings helper (utils.ts:129) via validateBaseRecordSet, reached from collection.add/update/upsert (fieldName 'embeddings') and collection.query (fieldName 'queryEmbeddings'). The embeddings value is not an Array — the message reports the actual typeof it received.

Source

Thrown at clients/new-js/packages/chromadb/src/utils.ts:127

  if (new Set(lengths.map(([_, length]) => length)).size > 1) {
    throw new ChromaValueError(
      `Unequal lengths for fields ${lengths
        .map(([field, _]) => field)
        .join(", ")}`,
    );
  }
};

const validateEmbeddings = ({
  embeddings,
  fieldName = "embeddings",
}: {
  embeddings: number[][];
  fieldName: string;
}) => {
  if (!Array.isArray(embeddings)) {
    throw new ChromaValueError(
      `Expected '${fieldName}' to be an array, but got ${typeof embeddings}`,
    );
  }

  if (embeddings.length === 0) {
    throw new ChromaValueError(
      "Expected embeddings to be an array with at least one item",
    );
  }

  if (!embeddings.filter((e) => e.every((n: any) => typeof n === "number"))) {
    throw new ChromaValueError(
      "Expected each embedding to be an array of numbers",
    );
  }

  embeddings.forEach((embedding, i) => {
    if (embedding.length === 0) {

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Wrap single vectors: queryEmbeddings: [vector]
  2. Convert tensors/typed arrays to plain arrays first (Array.from(tensor.data) reshaped, or await tensor.toArray())
  3. Type the field explicitly as number[][] so the compiler catches it before runtime

Example fix

// before
await collection.query({ queryEmbeddings: embedding, nResults: 5 });
// after
await collection.query({ queryEmbeddings: [embedding], nResults: 5 });
Defensive patterns

Strategy: type-guard

Validate before calling

if (!Array.isArray(embeddings)) throw new TypeError('embeddings must be number[][]');

Type guard

const isEmbeddingMatrix = (v) => Array.isArray(v) && v.every(e => Array.isArray(e));

Try / catch

try { await collection.query({ queryEmbeddings: embs, nResults: 5 }); } catch (e) { if (e instanceof ChromaValueError && /to be an array/.test(e.message)) throw new TypeError('Wrap single vectors in an array'); else throw e; }

Prevention

When it happens

Trigger: Passing a flat number[] (one vector) instead of number[][]; passing a Tensor, TypedArray, or an object wrapper from an ML library; passing a string or undefined-typed value where the API expects number[][].

Common situations: Switching from ONNX/Transformers.js pipelines whose output is a Tensor rather than a plain array; forgetting to wrap a single query vector in [] in collection.query({ queryEmbeddings: vec }); APIs that return { embeddings: { ... } } objects.

Related errors


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