{"record":{"id":"353363675ed7cc6a","repo":"chroma-core/chroma","slug":"non-empty-lists-are-required-for-zerolength-join","errorCode":null,"errorMessage":"Non-empty lists are required for ${zeroLength.join(\", \")}","messagePattern":"Non-empty lists are required for (.+?)","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":105,"sourceCode":"export const validateRecordSetLengthConsistency = (recordSet: RecordSet) => {\n  const lengths: [string, number][] = Object.entries(recordSet)\n    .filter(\n      ([field, value]) =>\n        recordSetFields.includes(field) && value !== undefined,\n    )\n    .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[][];","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L87-L123","documentation":"ChromaValueError thrown by validateRecordSetLengthConsistency (utils.ts:100-106) from Collection.prepareRecords when at least one record-set field was provided but at least one of the provided arrays is empty ([]). An empty array cannot be aligned with any other array length, so the batch is rejected before the request is sent.","triggerScenarios":"collection.add({ ids: [], documents: ['a'] }) or any call where a provided field among ids/embeddings/metadatas/documents/uris has length 0 (e.g. await collection.add({ ids: filteredIds, documents: docs }) where filteredIds is []).","commonSituations":"A filter/map step upstream removes all elements of one array but not the others; early-return code omitted for empty pages from a paginator; conditionally building arrays where one branch pushes nothing.","solutions":["Guard the call: skip when any provided array is empty (if (!ids.length || !documents.length) return)","Make upstream filtering all-or-nothing so the arrays stay row-aligned","Log the offending field names from the error — the message lists exactly which arrays were empty"],"exampleFix":"// before\nawait collection.add({ ids, documents }); // ids === []\n// after\nif (ids.length === 0 || documents.length === 0) return;\nawait collection.add({ ids, documents });","handlingStrategy":"validation","validationCode":"function noEmptyArrays(rs) { return Object.entries(rs).every(([f, v]) => v === undefined || (Array.isArray(v) && v.length > 0)); }","typeGuard":"function isBatchable(rs) { return ['ids','embeddings','metadatas','documents','uris'].every(f => { const v = rs[f]; return v === undefined || (Array.isArray(v) && v.length > 0); }); }","tryCatchPattern":"try { await collection.add(rs); } catch (e) { if (e instanceof ChromaValueError && /Non-empty lists are required/.test(e.message)) { console.warn('Skipped empty batch'); return; } throw e; }","preventionTips":["Skip the call when any provided array is empty","Keep filtering all-or-nothing across row-aligned arrays","Log the field list from the message to locate the empty producer"],"tags":["chromadb","validation","recordset","empty-array"],"backgroundTag":"empty-array-argument","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}