Skip to main content
The Streaming Retrieval API in R2R enables real-time data flow for Retrieval-Augmented Generation (RAG) and agent-based interactions. It delivers live updates as content is retrieved, processed, and generated, allowing client applications to display results incrementally. This streaming approach significantly improves the user experience for interactive and latency-sensitive applications by providing immediate, progressive feedback instead of waiting for full completion.

Key Capabilities

The Streaming Retrieval API supports:
  • Real-time event streaming for RAG and agent operations.
  • Progressive response generation with token-level updates.
  • Immediate access to intermediate results such as retrieved documents or citations.
  • Fine-grained event structure to handle reasoning steps, tool calls, and responses.
  • Improved responsiveness for conversational and research-oriented applications.

Streaming Events

During streaming, R2R emits structured event types that represent each stage of the retrieval and generation process:

Streaming RAG

Basic Streaming RAG

To use streaming with basic RAG functionality:
To include web search in your streaming RAG:

Streaming Agent

R2R provides powerful streaming agents that supports complex interactions with both document-based knowledge and web resources.

Basic Streaming Agent

Advanced Research Agent with Tools

The R2R agent can leverage multiple tools to perform in-depth research:

Streaming Citations

R2R streaming citations provide detailed attribution information that links specific parts of the response to source documents:
Each citation includes:
  • id: Unique identifier for the citation.
  • index: The display index (e.g., /[1], /[2]).
  • start_index and end_index: Character positions in the response.
  • source_type: The type of source (chunk, graph, web).
  • source_id: ID of the specific chunk/node.
  • document_id: ID of the parent document.
  • source_title: Title of the source document.

Implementing Streaming UI

To create a responsive UI with Streaming RAG, consider the following:

Frontend Implementation