chroma-core/chroma · error · ChromaValueError

Expected each embedding to be a non-empty array of numbers,

Error message

Expected each embedding to be a non-empty array of numbers, but got an empty array at index ${i}

What it means

ChromaValueError thrown by validateEmbeddings (utils.ts:146) during the per-vector loop when the i-th embedding is an empty array. Each vector must carry at least one dimension, so a [] row inside the batch is rejected; the message includes the offending index.

Source

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

      `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",
}: {
  documents: (string | null | undefined)[];
  fieldName: string;
  nullable?: boolean;
}) => {
  if (!Array.isArray(documents)) {
    throw new ChromaValueError(
      `Expected '${fieldName}' to be an array, but got ${typeof documents}`,

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Filter or reject empty-source rows before embedding so no [] vectors are produced
  2. Fall back to a placeholder vector (with your model's dim) for blank inputs, or skip those records
  3. Check the reported index in the message to find the exact bad row in your batch

Example fix

// before
const embeddings = await Promise.all(texts.map(t => embed(t))); // embed('') -> []
await collection.add({ ids, embeddings, documents: texts });
// after
const keep = texts.map((t, i) => t.trim().length > 0);
await collection.add({ ids: ids.filter((_, i) => keep[i]), embeddings: embeddings.filter((_, i) => keep[i]), documents: texts.filter((_, i) => keep[i]) });
Defensive patterns

Strategy: validation

Validate before calling

const emptyIdx = embeddings.findIndex(e => Array.isArray(e) && e.length === 0);
if (emptyIdx !== -1) throw new Error(`Empty embedding vector at index ${emptyIdx}`);

Type guard

const allVectorsNonEmpty = (m) => m.every(e => Array.isArray(e) && e.length > 0);

Try / catch

try { await collection.add({ ids, embeddings, documents }); } catch (e) { if (e instanceof ChromaValueError && /empty array at index/.test(e.message)) { const i = Number(/index (\d+)/.exec(e.message)?.[1]); console.warn('Bad row:', i); } else throw e; }

Prevention

When it happens

Trigger: collection.add({ ids, embeddings: [[0.1,0.2], [], [0.3]] }) — the error reports 'empty array at index 1'; query({ queryEmbeddings: [[]] }); vectorizers that return [] for empty/blank input strings.

Common situations: Embedding an empty string '' when the model's tokenizer yields zero tokens; rows where source text is missing and the pipeline emits []; mapping over documents where some are null.

Related errors


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