Document Ingestion and Management

Ingest Files

Ingest files or directories into your R2R system:

const files = [
  { path: 'path/to/file1.txt', name: 'file1.txt' },
  { path: 'path/to/file2.txt', name: 'file2.txt' }
];
const metadatas = [{ key1: 'value1' }, { key2: 'value2' }];

const ingestResponse = await client.ingestFiles(files, {
  metadatas,
  user_ids: ['user-id-1', 'user-id-2'],
});
files
Array<string | File | { path: string; name: string }>
required

An array of file paths, File objects, or objects with path and name properties to ingest.

options
object
metadatas
Record<string, any>

An optional array of metadata objects corresponding to each file.

document_ids
Array<string>

An optional array of document IDs to assign to the ingested files.

user_ids
Array<string | null>

An optional array of user IDs associated with the ingested files.

chunking_config
Optional[Union[dict, ChunkingConfig]]

The chunking config override parameter enables developers to customize their R2R chunking strategy at runtime.

Update Files

Update existing documents:

const files = [
  { path: '/path/to/updated_file1.txt', name: 'updated_file1.txt' }
];
const document_ids = ['document-id-1'];
const updateResponse = await client.updateFiles(files, {
  document_ids,
  metadatas: [{ key: 'updated_value' }] // to overwrite the existing metadata
});
files
Array<File | { path: string; name: string }>
required

An array of File objects or objects with path and name properties to update.

options
object
required
document_ids
Array<string>
required

An array of document IDs corresponding to the files being updated.

metadatas
Array<Record<string, any>>

An optional array of metadata objects for the updated files.

chunking_config
Record<string, any>

The chunking config override parameter enables developers to customize their R2R chunking strategy at runtime.

Documents Overview

Retrieve high-level document information, restricted to user files, except when called by a superuser where it will then return results from over all users:

const documentsOverview = await client.documentsOverview();
document_ids
Array<string>

An optional array of document IDs to filter the overview.

Document Chunks

Fetch chunks for a particular document:

const documentId = '93123a68-d668-51de-8291-92162730dc87';
const chunks = await client.documentChunks(documentId);
document_id
string
required

The ID of the document to retrieve chunks for.

Delete Documents

Delete a document by its ID:

const deleteResponse = await client.delete({ document_id: "91662726-7271-51a5-a0ae-34818509e1fd" });
filters
{ [key: string]: string | string[] }
required

A list of logical filters to perform over input documents fields which identifies the unique set of documents to delete (e.g., {"document_id": {"$eq": "db02076e-989a-59cd-98d5-e24e15a0bd27"}}). Logical operations might include variables such as "user_id" or "title" and filters like neq, gte, etc.