{"record":{"id":"15ad82f01f8f166e","repo":"chroma-core/chroma","slug":"got-empty-embedding-at-pos","errorCode":null,"errorMessage":"got empty embedding at pos","messagePattern":"got empty embedding at pos","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/utils.ts","lineNumber":162,"sourceCode":"      \"ids, embeddings, metadatas, and documents must all be the same length\",\n    );\n  }\n\n  const uniqueIds = new Set(ids);\n  if (uniqueIds.size !== ids.length) {\n    const duplicateIds = ids.filter(\n      (item, index) => ids.indexOf(item) !== index,\n    );\n    throw new Error(\n      `ID's must be unique, found duplicates for: ${duplicateIds}`,\n    );\n  }\n\n  if (\n    embeddingsArray &&\n    embeddingsArray.some((embedding) => embedding.length === 0)\n  ) {\n    throw new Error(\"got empty embedding at pos\");\n  }\n\n  return {\n    ids,\n    metadatas,\n    documents,\n    embeddings: embeddingsArray,\n  };\n}\n\nexport function wrapCollection(\n  api: ChromaClient,\n  collection: CollectionParams,\n): Collection {\n  return new Collection(\n    collection.name,\n    collection.id,\n    api,","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/utils.ts#L144-L180","documentation":"Thrown client-side by prepareRecordRequest when the embeddings array that will be sent contains at least one empty vector (length 0). Chroma cannot store a zero-dimensional embedding, and an empty vector almost always means the embedding function produced no output for that input or a placeholder [] slipped into your data. The check runs on both user-supplied embeddings and embeddings generated by the embedding function.","triggerScenarios":"Passing embeddings: [[0.1, 0.2], [], [0.3, 0.4]] to collection.add()/upsert(); an embedding function that returns [] for empty-string documents; a pre-processing step that maps failed embeds to [] instead of dropping them; mismatched slicing of an embeddings array that yields empty rows.","commonSituations":"Batching documents where some are empty strings after cleaning; partial API failures from a custom embedding function filled with [] placeholders; CSV rows with missing text mapped to empty embeddings; dimensions array misconfigured so some vectors get truncated to nothing.","solutions":["Find the empty vector position before sending: embeddings.findIndex(e => e.length === 0), then fix or remove that record.","Filter out empty/blank documents before calling add() so the embedding function never receives them.","If a custom embedding function returns [] on failure, make it throw instead, or drop the failed record from the batch.","Verify the embedding model's dimension is applied to every vector (e.g., truncated PCA output or slicing bugs)."],"exampleFix":"// before\nawait collection.add({\n  ids: [\"1\", \"2\"],\n  documents: [\"hello\", \"\"], // empty doc -> empty embedding\n});\n\n// after\nconst keep = documents.map((d, i) => [d, i]).filter(([d]) => d.trim() !== \"\");\nawait collection.add({\n  ids: keep.map(([, i]) => ids[i]),\n  documents: keep.map(([d]) => d),\n});","handlingStrategy":"validation","validationCode":"function hasEmptyEmbedding(embeddings: number[][]): boolean {\n  return embeddings.some((e) => !Array.isArray(e) || e.length === 0);\n}\n\nconst badIndex = embeddings.findIndex((e) => e.length === 0);\nif (badIndex !== -1) {\n  throw new Error(`Record at index ${badIndex} has an empty embedding; fix or drop it`);\n}\nawait collection.add({ ids, embeddings });","typeGuard":"function isNonEmptyEmbeddings(e: unknown): e is number[][] {\n  return (\n    Array.isArray(e) &&\n    e.length > 0 &&\n    e.every((v) => Array.isArray(v) && v.length > 0 && v.every((n) => typeof n === \"number\"))\n  );\n}","tryCatchPattern":null,"preventionTips":["Filter blank/empty documents before add() so the embedding function never sees them.","Make custom embedding functions throw on failure instead of returning [].","Validate every vector has the expected dimension before batching.","Log the index of the first empty vector when pre-checking large batches."],"tags":["embeddings","validation","empty-vector"],"backgroundTag":"empty-embedding-vector","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}