chroma-core/chroma · warning · ChromaValueError

Expected each embedding to be an array of numbers

Error message

Expected each embedding to be an array of numbers

What it means

Intended to be thrown by validateEmbeddings (utils.ts:138) when any element of the embeddings array is not itself an array of numbers. IMPORTANT: as written, the condition is `if (!embeddings.filter(e => e.every(...)))` — filter() always returns a (truthy) array, so this branch is unreachable and the error will practically never fire; malformed inner vectors pass through to the per-vector empty check or to the server. This is a client bug: the check should use embeddings.every(...) with Array.isArray.

Source

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

  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) {
      throw new ChromaValueError(
        `Expected each embedding to be a non-empty array of numbers, but got an empty array at index ${i}`,
      );
    }
  });
};

const validateDocuments = ({
  documents,
  nullable = false,
  fieldName = "documents",
}: {

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Add your own check before calling the API: embeddings.every(v => Array.isArray(v) && v.every(n => typeof n === 'number'))
  2. Fix/patch the client guard locally if you control the vendored copy (replace .filter(...) truthiness with .every(...))
  3. Sanitize vectors from ML pipelines (tensor → number[][]) at the boundary

Example fix

// before (client bug: never throws)
if (!embeddings.filter((e) => e.every((n: any) => typeof n === "number"))) { throw ... }
// after (correct guard)
if (!embeddings.every((e) => Array.isArray(e) && e.every((n: any) => typeof n === "number"))) { throw ... }
Defensive patterns

Strategy: validation

Validate before calling

const isNumericMatrix = (m) => m.every(row => Array.isArray(row) && row.length > 0 && row.every(n => typeof n === 'number'));
if (!isNumericMatrix(embeddings)) throw new TypeError('embeddings must be number[][]');

Type guard

function isValidEmbeddings(v): v is number[][] { return Array.isArray(v) && v.every(e => Array.isArray(e) && e.every(n => typeof n === 'number')); }

Try / catch

// Unreachable in current client (guard bug); rely on your own pre-check and catch server 400s: try { await collection.add(rs); } catch (e) { if (/embedding/i.test(String(e?.message))) throw new Error('Bad embedding matrix'); else throw e; }

Prevention

When it happens

Trigger: Only hypothetically: passing embeddings like [[0.1,'x']] or [0.1, 0.2] (flat numbers). Because of the filter/every bug, these actually slip past this guard instead of raising this message.

Common situations: Hitting corrupt vector data downstream (server-side 400s) and finding this message in a search; reading the source and assuming the guard works; mixing scalar rows into the embeddings matrix from a flaky producer.

Related errors


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