{"record":{"id":"e0a8a9a75f44c3ac","repo":"chroma-core/chroma","slug":"expected-fieldname-to-be-an-array-but-got","errorCode":null,"errorMessage":"Expected '${fieldName}' to be an array, but got ${typeof embeddings}","messagePattern":"Expected '(.+?)' to be an array, but got (.+?)","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":127,"sourceCode":"\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    );\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) {","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L109-L145","documentation":"ChromaValueError thrown by the internal validateEmbeddings helper (utils.ts:129) via validateBaseRecordSet, reached from collection.add/update/upsert (fieldName 'embeddings') and collection.query (fieldName 'queryEmbeddings'). The embeddings value is not an Array — the message reports the actual typeof it received.","triggerScenarios":"Passing a flat number[] (one vector) instead of number[][]; passing a Tensor, TypedArray, or an object wrapper from an ML library; passing a string or undefined-typed value where the API expects number[][].","commonSituations":"Switching from ONNX/Transformers.js pipelines whose output is a Tensor rather than a plain array; forgetting to wrap a single query vector in [] in collection.query({ queryEmbeddings: vec }); APIs that return { embeddings: { ... } } objects.","solutions":["Wrap single vectors: queryEmbeddings: [vector]","Convert tensors/typed arrays to plain arrays first (Array.from(tensor.data) reshaped, or await tensor.toArray())","Type the field explicitly as number[][] so the compiler catches it before runtime"],"exampleFix":"// before\nawait collection.query({ queryEmbeddings: embedding, nResults: 5 });\n// after\nawait collection.query({ queryEmbeddings: [embedding], nResults: 5 });","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(embeddings)) throw new TypeError('embeddings must be number[][]');","typeGuard":"const isEmbeddingMatrix = (v) => Array.isArray(v) && v.every(e => Array.isArray(e));","tryCatchPattern":"try { await collection.query({ queryEmbeddings: embs, nResults: 5 }); } catch (e) { if (e instanceof ChromaValueError && /to be an array/.test(e.message)) throw new TypeError('Wrap single vectors in an array'); else throw e; }","preventionTips":["Declare embeddings/queryEmbeddings as number[][] in your own signatures","Convert tensors via toArray()/Array.from at the model boundary","Lint for passing Set/TypedArray where arrays are expected"],"tags":["chromadb","validation","embeddings","type-mismatch"],"backgroundTag":"invalid-embeddings-format","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}