{"record":{"id":"e1fc7b68cc81a5fa","repo":"chroma-core/chroma","slug":"expected-each-embedding-to-be-an-array-of-numbers","errorCode":null,"errorMessage":"Expected each embedding to be an array of numbers","messagePattern":"Expected each embedding to be an array of numbers","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"warning","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":139,"sourceCode":"  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};\n\nconst validateDocuments = ({\n  documents,\n  nullable = false,\n  fieldName = \"documents\",\n}: {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L121-L157","documentation":"Intended to be thrown by validateEmbeddings (utils.ts:138) when any element of the embeddings array is not itself an array of numbers. IMPORTANT: as written, the condition is `if (!embeddings.filter(e => e.every(...)))` — filter() always returns a (truthy) array, so this branch is unreachable and the error will practically never fire; malformed inner vectors pass through to the per-vector empty check or to the server. This is a client bug: the check should use embeddings.every(...) with Array.isArray.","triggerScenarios":"Only hypothetically: passing embeddings like [[0.1,'x']] or [0.1, 0.2] (flat numbers). Because of the filter/every bug, these actually slip past this guard instead of raising this message.","commonSituations":"Hitting corrupt vector data downstream (server-side 400s) and finding this message in a search; reading the source and assuming the guard works; mixing scalar rows into the embeddings matrix from a flaky producer.","solutions":["Add your own check before calling the API: embeddings.every(v => Array.isArray(v) && v.every(n => typeof n === 'number'))","Fix/patch the client guard locally if you control the vendored copy (replace .filter(...) truthiness with .every(...))","Sanitize vectors from ML pipelines (tensor → number[][]) at the boundary"],"exampleFix":"// before (client bug: never throws)\nif (!embeddings.filter((e) => e.every((n: any) => typeof n === \"number\"))) { throw ... }\n// after (correct guard)\nif (!embeddings.every((e) => Array.isArray(e) && e.every((n: any) => typeof n === \"number\"))) { throw ... }","handlingStrategy":"validation","validationCode":"const isNumericMatrix = (m) => m.every(row => Array.isArray(row) && row.length > 0 && row.every(n => typeof n === 'number'));\nif (!isNumericMatrix(embeddings)) throw new TypeError('embeddings must be number[][]');","typeGuard":"function isValidEmbeddings(v): v is number[][] { return Array.isArray(v) && v.every(e => Array.isArray(e) && e.every(n => typeof n === 'number')); }","tryCatchPattern":"// Unreachable in current client (guard bug); rely on your own pre-check and catch server 400s: try { await collection.add(rs); } catch (e) { if (/embedding/i.test(String(e?.message))) throw new Error('Bad embedding matrix'); else throw e; }","preventionTips":["Do not trust this client guard — validate the matrix shape yourself","Coerce tensor outputs to plain number[][] before ingest","Add a boundary assertion in test fixtures for vector shape"],"tags":["chromadb","validation","embeddings","client-bug","dead-code"],"backgroundTag":"invalid-embeddings-format","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}