Skip to main content

Documents

Once a job completes, the ingested file becomes a document — a record of everything RagPack indexed from that file. You can list, get, rename, update, and delete documents via collection.documents.

List documents

const docs = await collection.documents.list();

for (const doc of docs) {
console.log(doc.name ?? doc.file_uri, doc.chunk_count, doc.status);
}

Results are paginated. Use limit and offset to page through large collections:

const page2 = await collection.documents.list({ limit: 20, offset: 20 });
OptionTypeDescription
limitnumberMax documents to return. Defaults to 50.
offsetnumberPagination offset. Defaults to 0.

Each document contains:

FieldTypeDescription
idstringUnique document ID
namestring | undefinedDisplay name. Set at ingest time or via rename()/update().
file_uristringSource URI of the ingested file
mime_typestringDetected MIME type
external_idstring | undefinedCaller-supplied ID for correlating with an external system, set at ingest time
extra_jsonstring | undefinedFreeform JSON metadata, set at ingest time or via update()
chunk_countnumberNumber of chunks indexed
statusstringingesting | complete | failed
errorstring | undefinedError detail if status is failed
created_atstringISO 8601 timestamp

Response fields are returned exactly as the API sends them (snake_case).

Get a document

const doc = await collection.documents.get(id);

Get typed metadata

Returns the document's registered typed metadata field values. A field is only included if its value is identical across every chunk of the document — this avoids showing a value that's mid-sync.

const metadata = await collection.documents.metadata(id);

Rename a document

Sets the display name on a document. Useful for giving a human-readable label to a file ingested from a URI.

await collection.documents.rename(doc.id, "Q4 2024 Report");

Update a document

Update name, extraJson, and/or typed metadata in one call. metadata keys that aren't registered fields on this collection (or whose value doesn't match the field's declared type) are silently dropped by the server — the request still succeeds, with no signal for which keys landed. Register fields first via the metadata-fields admin API.

await collection.documents.update(doc.id, {
name: "Q4 2024 Report (final)",
extraJson: JSON.stringify({ source: "zendesk" }),
metadata: { reviewed: true },
});
OptionTypeDescription
namestring | undefinedNew display name
extraJsonstring | undefinedReplaces the document's freeform extra_json metadata
metadataRecord<string, unknown> | undefinedMerges values into the document's typed metadata fields

Delete a document

Removes the document and all its chunks from the index. This is irreversible.

await collection.documents.delete(doc.id);