Document Ingestion and Management
Ingest Files
Ingest files or directories into your R2R system:
file_paths = [ 'path/to/file1.txt' , 'path/to/file2.txt' ]
metadatas = [{ 'key1' : 'value1' }, { 'key2' : 'value2' }]
ingest_response = client.ingest_files(
file_paths =file_paths,
metadatas =metadatas,
# optionally override chunking settings at runtime
ingestion_config ={
"provider" : "unstructured_local" ,
"strategy" : "auto" ,
"chunking_strategy" : "by_title" ,
"new_after_n_chars" : 256 , # soft maximum
"max_characters" : 512 , # hard maximum
"combine_under_n_chars" : 64 , # hard minimum
"overlap" : 100 ,
}
)
A list of file paths or directory paths to ingest. If a directory path is provided, all files within the directory and its subdirectories will be ingested.
An optional list of metadata dictionaries corresponding to each file. If provided, the length should match the number of files being ingested.
document_ids
Optional[list[Union[UUID, str]]]
An optional list of document IDs to assign to the ingested files. If provided, the length should match the number of files being ingested.
An optional list of version strings for the ingested files. If provided, the length should match the number of files being ingested.
ingestion_config
Optional[Union[dict, ChunkingConfig]]
The ingestion config override parameter enables developers to customize their R2R chunking strategy at runtime.
provider
str
default: "unstructured_local"
Which chunking provider to use. Options are “r2r”, “unstructured_local”, or “unstructured_api”.
max_chunk_size
Optional[int]
default: "None"
Sets a maximum size on output chunks.
Combine chunks smaller than this number of characters.
Maximum number of characters per chunk.
Whether to include coordinates in the output.
Encoding to use for text files.
Types of image blocks to extract.
gz_uncompressed_content_type
Content type for uncompressed gzip files.
Name of the high-resolution model to use.
include_orig_elements
Optional[bool]
default: "False"
Whether to include original elements in the output.
Whether to include page breaks in the output.
List of languages to consider for text processing.
Whether to allow sections to span multiple pages.
Start a new chunk after this many characters.
Languages to use for OCR.
output_format
str
default: "application/json"
Number of characters to overlap between chunks.
Whether to overlap all chunks.
pdf_infer_table_structure
Whether to infer table structure in PDFs.
Threshold for considering chunks similar.
Types of tables to skip inferring.
split_pdf_concurrency_level
Concurrency level for splitting PDFs.
Whether to split PDFs by page.
Page number to start processing from.
Strategy for processing. Options are “auto”, “fast”, or “hi_res”.
chunking_strategy
Optional[str]
default: "by_title"
Strategy for chunking. Options are “by_title” or “basic”.
Whether to generate unique IDs for elements.
Whether to keep XML tags in the output.
Update Files
Update existing documents:
file_paths = [ "/path/to/r2r/examples/data/aristotle_v2.txt" ]
document_ids = [ "9fbe403b-c11c-5aae-8ade-ef22980c3ad1" ]
update_response = client.update_files(
file_paths =file_paths,
document_ids =document_ids,
metadatas =[{ "x" : "y" }] # to overwrite the existing metadata
)
A list of file paths to update.
document_ids
Optional[list[Union[UUID, str]]]
required
A list of document IDs corresponding to the files being updated. When not provided, an attempt is made to generate the correct document id from the given user id and file path.
An optional list of metadata dictionaries for the updated files.
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:
documents_overview = client.documents_overview()
document_ids
Optional[list[Union[UUID, str]]]
An optional list of document IDs to filter the overview.
Document Chunks
Fetch chunks for a particular document:
document_id = "9fbe403b-c11c-5aae-8ade-ef22980c3ad1"
chunks = client.document_chunks(document_id)
The ID of the document to retrieve chunks for.
Delete Documents
Delete a document by its ID:
delete_response = client.delete(
{
"document_id" :
{ "$eq" : "9fbe403b-c11c-5aae-8ade-ef22980c3ad1" }
}
)
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": "9fbe403b-c11c-5aae-8ade-ef22980c3ad1"}}
). Logical operations might include variables such as "user_id"
or "title"
and filters like neq
, gte
, etc.