{"record":{"id":"177570eba2126b02","repo":"chroma-core/chroma","slug":"expected-embeddings-to-be-an-array-with-at-least-o","errorCode":null,"errorMessage":"Expected embeddings to be an array with at least one item","messagePattern":"Expected embeddings to be an array with at least one item","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":133,"sourceCode":"    );\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    );\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};","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L115-L151","documentation":"ChromaValueError thrown by validateEmbeddings (utils.ts:132) when the embeddings array exists but has zero elements ([].length === 0). An add/query batch with no vectors has nothing to send, so the client rejects it before contacting the server.","triggerScenarios":"collection.add({ ids, embeddings: [], documents }) — embeddings explicitly empty; query({ queryEmbeddings: [] }); a batching step that produced an empty vectors array for this chunk.","commonSituations":"Chunking code that emits a final empty chunk; filtering out failed embeddings leaving []; passing embeddings when you meant to let documents be embedded (omit the field instead).","solutions":["Omit the embeddings field entirely if you want Chroma to embed documents for you","Guard empty batches: if (!embeddings.length) return / continue","Fix the chunker to skip zero-length tail chunks"],"exampleFix":"// before\nawait collection.add({ ids, embeddings: [], documents });\n// after\nawait collection.add({ ids, documents }); // server/client embeds documents","handlingStrategy":"validation","validationCode":"if (Array.isArray(embeddings) && embeddings.length === 0) return; // skip empty batch","typeGuard":"const hasVectors = (embs) => Array.isArray(embs) && embs.length > 0;","tryCatchPattern":"try { await collection.query({ queryEmbeddings: embs, nResults: k }); } catch (e) { if (e instanceof ChromaValueError && /at least one item/.test(e.message)) return { results: [] }; else throw e; }","preventionTips":["Guard chunkers against emitting zero-length tail chunks","Omit embeddings entirely when you want documents auto-embedded","Return empty results early from search endpoints with no queries"],"tags":["chromadb","validation","embeddings","empty-array"],"backgroundTag":"empty-embeddings-array","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}