?
dataSources.add
Adds a document from bytes and ingests it in the background, so re-adding identical bytes is free.
DataSource.add(content, { filename, contentType?, metadata? }) → { document, queued }
Adds a document and returns as soon as it is queued, since extraction and embedding run in the background and take a while, so poll documents() for status rather than assume the content is searchable on return. Documents are content-addressed, so re-adding the same bytes is a free no-op, and re-adding identical bytes with different metadata updates the tags in place, also free. Reach for this only when users upload documents that must become searchable (a build-time corpus loads from the CLI instead); supported formats are pdf, docx, pptx, xlsx, plain text, markdown, csv, and html.
Parameters
content
Buffer | Uint8Array | string
RequiredThe document contents.
filename
string
RequiredThe extension selects the extraction route, so it is required.
contentType
string
MIME type.
metadata
DocumentMetadata
Scalar tags, up to 16 keys, filterable at search time. Supplying metadata replaces the whole object.
Add an uploaded document
const { document } = await Policies.add(buffer, { filename: 'policy.pdf', contentType: 'application/pdf', metadata: { department: 'legal', year: 2026 }, }); // document.status is 3; poll documents() until 4