{"record":{"id":"2bb77a1d338f4942","repo":"chroma-core/chroma","slug":"at-least-one-of-embeddingsfield-and-docume","errorCode":null,"errorMessage":"At least one of '${embeddingsField}' and '${documentsField}' must be provided","messagePattern":"At least one of '(.+?)' and '(.+?)' must be provided","errorType":"validation","errorClass":"ChromaValueError","httpStatus":null,"severity":"error","filePath":"clients/new-js/packages/chromadb/src/utils.ts","lineNumber":493,"sourceCode":" * @param options.recordSet - The record set to validate\n * @param options.update - Whether this is for an update operation (relaxes requirements)\n * @param options.embeddingsField - Name of the embeddings field for error messages\n * @param options.documentsField - Name of the documents field for error messages\n * @throws ChromaValueError if validation fails\n */\nexport const validateBaseRecordSet = ({\n  recordSet,\n  update = false,\n  embeddingsField = \"embeddings\",\n  documentsField = \"documents\",\n}: {\n  recordSet: BaseRecordSet;\n  update?: boolean;\n  embeddingsField?: string;\n  documentsField?: string;\n}) => {\n  if (!recordSet.embeddings && !recordSet.documents && !update) {\n    throw new ChromaValueError(\n      `At least one of '${embeddingsField}' and '${documentsField}' must be provided`,\n    );\n  }\n\n  if (recordSet.embeddings) {\n    validateEmbeddings({\n      embeddings: recordSet.embeddings,\n      fieldName: embeddingsField,\n    });\n  }\n\n  if (recordSet.documents) {\n    validateDocuments({\n      documents: recordSet.documents,\n      fieldName: documentsField,\n    });\n  }\n","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/new-js/packages/chromadb/src/utils.ts#L475-L511","documentation":"validateBaseRecordSet (with update=false) throws when a record set has neither embeddings nor documents — every added record must carry content to embed or a precomputed vector. The check runs client-side before any request. It is relaxed in update mode (update=true), where partial record sets are legitimate.","triggerScenarios":"collection.add({ ids: ['1'], metadatas: [{ a: 1 }] }) — ids and metadata only. documents ending up undefined because a mapping step failed. Using add() when you meant to update existing records with partial data.","commonSituations":"Ingestion pipelines that pre-compute metadata but forget content; conditionally built option objects where both branches leave the fields unset; assuming the server will attach documents later.","solutions":["Include a documents array (one string per id) so the collection's embedding function runs.","Or include embeddings (one vector per id) when you pre-computed them.","If you intentionally modify existing records, use the update path (update/upsert semantics) rather than add()."],"exampleFix":"// before\nawait collection.add({ ids: ['1'], metadatas: [{ a: 1 }] });\n\n// after\nawait collection.add({ ids: ['1'], documents: ['text for record 1'], metadatas: [{ a: 1 }] });","handlingStrategy":"validation","validationCode":"if (!records.embeddings && !records.documents) {\n  throw new Error('add() requires documents or embeddings for every record');\n}\nawait collection.add(records);","typeGuard":"const hasRecordContent = (rs: { embeddings?: unknown; documents?: unknown }) =>\n  Boolean(rs.embeddings || rs.documents);","tryCatchPattern":"try {\n  await collection.add(records);\n} catch (e) {\n  if ((e as Error).message.includes('must be provided')) {\n    // attach documents or embeddings, then retry; or switch to an update path\n  } else {\n    throw e;\n  }\n}","preventionTips":["Treat documents-or-embeddings as a required field in your ingestion types.","Fail early in the pipeline when a record has neither content nor a vector.","Use upsert/update semantics for partial records, never add()."],"tags":["records","validation","embeddings","documents"],"backgroundTag":"missing-required-parameter","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}