chroma-core/chroma · error · ChromaValueError
Unequal lengths for fields ${lengths.map(([field, _]) => fie
Error message
Unequal lengths for fields ${lengths.map(([field, _]) => field).join(", ")} What it means
ChromaValueError thrown by validateRecordSetLengthConsistency (utils.ts:110-116) from Collection.prepareRecords when the provided record-set arrays have different lengths — e.g. 3 ids but 2 documents. Chroma records are row-wise, so every array in one add/update call must contain the same number of rows.
Source
Thrown at clients/new-js/packages/chromadb/src/utils.ts:111
.map(([field, value]) => [field, value.length]);
if (lengths.length === 0) {
throw new ChromaValueError(
`At least one of ${recordSetFields.join(", ")} must be provided`,
);
}
const zeroLength = lengths
.filter(([_, length]) => length === 0)
.map(([field, _]) => field);
if (zeroLength.length > 0) {
throw new ChromaValueError(
`Non-empty lists are required for ${zeroLength.join(", ")}`,
);
}
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}`,
);View on GitHub (pinned to aecdd12c8a)
Solutions
- Compute n = ids.length once and assert every other provided array has that length before calling add/update
- Build all fields from a single rows.forEach loop so they cannot diverge
- Fix the upstream producer that dropped/duplicated rows in one field
Example fix
// before
await collection.add({ ids, documents, metadatas }); // documents has 2, ids has 3
// after
const n = ids.length;
if (documents.length !== n || metadatas.length !== n) throw new Error('row mismatch');
await collection.add({ ids, documents, metadatas }); Defensive patterns
Strategy: validation
Validate before calling
function equalLengths(rs) {
const lens = Object.entries(rs).filter(([, v]) => v !== undefined).map(([, v]) => v.length);
return lens.length > 0 && new Set(lens).size === 1;
} Type guard
function isRowAligned(rs) { const n = rs.ids?.length; if (!n) return false; return ['embeddings','metadatas','documents','uris'].every(f => rs[f] === undefined || rs[f].length === n); } Try / catch
try { await collection.add(rs); } catch (e) { if (e instanceof ChromaValueError && /Unequal lengths/.test(e.message)) throw new Error('Upstream row drift: rebuild arrays from one loop'); else throw e; } Prevention
- Build every per-row array in a single pass over the rows
- Assert one shared length before calling add/update
- Never let optional per-row transforms drop entries silently
When it happens
Trigger: collection.add({ ids: ['a','b','c'], documents: ['d1','d2'] }); collection.update({ ids, metadatas }) where metadatas was built from a shorter source; any combination of ids/embeddings/metadatas/documents/uris whose .length values are not all equal.
Common situations: Deriving one array from a different loop or dataset than the others; a row failing an optional transform (try/catch skipping one document) so arrays drift; appending to ids in one code path but not documents in another.
Related errors
- At least one of ${recordSetFields.join(", ")} must be provid
- Non-empty lists are required for ${zeroLength.join(", ")}
- ids, embeddings, metadatas, and documents must all be the sa
- 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/bdfb797f0ce9ceed.
Report an issue: GitHub.