{"record":{"id":"bdfb797f0ce9ceed","repo":"chroma-core/chroma","slug":"unequal-lengths-for-fields-lengths-map-field","errorCode":null,"errorMessage":"Unequal lengths for fields ${lengths.map(([field, _]) => field).join(\", \")}","messagePattern":"Unequal lengths for fields (.+?)","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":111,"sourceCode":"    .map(([field, value]) => [field, value.length]);\n\n  if (lengths.length === 0) {\n    throw new ChromaValueError(\n      `At least one of ${recordSetFields.join(\", \")} must be provided`,\n    );\n  }\n\n  const zeroLength = lengths\n    .filter(([_, length]) => length === 0)\n    .map(([field, _]) => field);\n  if (zeroLength.length > 0) {\n    throw new ChromaValueError(\n      `Non-empty lists are required for ${zeroLength.join(\", \")}`,\n    );\n  }\n\n  if (new Set(lengths.map(([_, length]) => length)).size > 1) {\n    throw new ChromaValueError(\n      `Unequal lengths for fields ${lengths\n        .map(([field, _]) => field)\n        .join(\", \")}`,\n    );\n  }\n};\n\nconst validateEmbeddings = ({\n  embeddings,\n  fieldName = \"embeddings\",\n}: {\n  embeddings: number[][];\n  fieldName: string;\n}) => {\n  if (!Array.isArray(embeddings)) {\n    throw new ChromaValueError(\n      `Expected '${fieldName}' to be an array, but got ${typeof embeddings}`,\n    );","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L93-L129","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait collection.add({ ids, documents, metadatas }); // documents has 2, ids has 3\n// after\nconst n = ids.length;\nif (documents.length !== n || metadatas.length !== n) throw new Error('row mismatch');\nawait collection.add({ ids, documents, metadatas });","handlingStrategy":"validation","validationCode":"function equalLengths(rs) {\n  const lens = Object.entries(rs).filter(([, v]) => v !== undefined).map(([, v]) => v.length);\n  return lens.length > 0 && new Set(lens).size === 1;\n}","typeGuard":"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); }","tryCatchPattern":"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; }","preventionTips":["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"],"tags":["chromadb","validation","recordset","length-mismatch"],"backgroundTag":"array-length-mismatch","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}