{"record":{"id":"7f8536473095a63b","repo":"chroma-core/chroma","slug":"expected-each-embedding-to-be-a-non-empty-array-of","errorCode":null,"errorMessage":"Expected each embedding to be a non-empty array of numbers, but got an empty array at index ${i}","messagePattern":"Expected each embedding to be a non-empty array of numbers, but got an empty array at index (.+?)","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":146,"sourceCode":"      `Expected '${fieldName}' to be an array, but got ${typeof embeddings}`,\n    );\n  }\n\n  if (embeddings.length === 0) {\n    throw new ChromaValueError(\n      \"Expected embeddings to be an array with at least one item\",\n    );\n  }\n\n  if (!embeddings.filter((e) => e.every((n: any) => typeof n === \"number\"))) {\n    throw new ChromaValueError(\n      \"Expected each embedding to be an array of numbers\",\n    );\n  }\n\n  embeddings.forEach((embedding, i) => {\n    if (embedding.length === 0) {\n      throw new ChromaValueError(\n        `Expected each embedding to be a non-empty array of numbers, but got an empty array at index ${i}`,\n      );\n    }\n  });\n};\n\nconst validateDocuments = ({\n  documents,\n  nullable = false,\n  fieldName = \"documents\",\n}: {\n  documents: (string | null | undefined)[];\n  fieldName: string;\n  nullable?: boolean;\n}) => {\n  if (!Array.isArray(documents)) {\n    throw new ChromaValueError(\n      `Expected '${fieldName}' to be an array, but got ${typeof documents}`,","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L128-L164","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Filter or reject empty-source rows before embedding so no [] vectors are produced","Fall back to a placeholder vector (with your model's dim) for blank inputs, or skip those records","Check the reported index in the message to find the exact bad row in your batch"],"exampleFix":"// before\nconst embeddings = await Promise.all(texts.map(t => embed(t))); // embed('') -> []\nawait collection.add({ ids, embeddings, documents: texts });\n// after\nconst keep = texts.map((t, i) => t.trim().length > 0);\nawait collection.add({ ids: ids.filter((_, i) => keep[i]), embeddings: embeddings.filter((_, i) => keep[i]), documents: texts.filter((_, i) => keep[i]) });","handlingStrategy":"validation","validationCode":"const emptyIdx = embeddings.findIndex(e => Array.isArray(e) && e.length === 0);\nif (emptyIdx !== -1) throw new Error(`Empty embedding vector at index ${emptyIdx}`);","typeGuard":"const allVectorsNonEmpty = (m) => m.every(e => Array.isArray(e) && e.length > 0);","tryCatchPattern":"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; }","preventionTips":["Filter out rows whose source text embeds to nothing","Map blank inputs to [] and exclude them before the call","Parse the reported index to pinpoint the offending record"],"tags":["chromadb","validation","embeddings","empty-array"],"backgroundTag":"invalid-embeddings-format","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}