Skip to main content
RAG Prepare stage showing document formatting for LLM context
The RAG Prepare stage formats search results for LLM consumption by managing token budgets, formatting documents, and adding citations. This is a preparation stage that does NOT call an LLM - it prepares content for downstream LLM stages or external LLM calls.
Stage Category: APPLYTransformation:
  • single_context mode: N documents → 1 combined context document
  • formatted_list mode: N documents → N formatted documents

When to Use

When NOT to Use

Parameters

Truncation Strategies

Output Modes

Configuration Examples

Template Placeholders

Citation Styles

Output Schema

single_context Mode

formatted_list Mode

Each document gets:

Citing Timestamped Source Clips (Video / Audio)

The default citation object is {index, title, document_id} — enough to name the source, but it does not inline the timestamp or a link back to the source clip. For investigative / RAG use cases where every claim must resolve to a timestamped, clickable source (e.g. “watch this at 03:12”), surface the anchor yourself — the data is already on every document, so this needs no new stage or endpoint: Reference those fields directly in document_template so the timestamp travels into the LLM context (and into any answer the LLM cites):
Timestamped clip citations
To render a clickable clip link, hydrate the document_id returned in the citations[] array (or the root_object_id above) into a playable URL with GET /v1/documents/{id}?expand=root_object — see Lineage Traversal. Do this in the app layer after execute; the timestamp and source object are preserved end-to-end in the document, they are simply not inlined into the structured citations[] array by default.
Citations attach at the document level. rag_prepare (and summarize’s source_document_ids) cite the set of source documents behind the context, not individual sentences — per-claim/per-sentence attribution is up to the downstream LLM prompt. Ask the LLM to emit the [n] marker inline with each claim so the numbered citation resolves back to the timestamped clip above.

Performance

This stage does NOT call an LLM. It only formats content for LLM consumption. Use the summarize stage if you want LLM-generated summaries.

Common Pipeline Patterns

Search + Prepare + External LLM

The output rag_context can then be passed to an external LLM call.

vs Summarize Stage