# R2R

> A RAG server with ingestion, hybrid search, and knowledge graphs behind a REST API

- Category: Retrieval & Knowledge (RAG) / RAG Frameworks & Platforms
- Language: Python
- Licence: MIT
- Repository: https://github.com/SciPhi-AI/R2R
- Canonical page: https://ai-tldr.dev/tools/r2r/

## In short

R2R (Reason to Retrieve) is an open-source retrieval system for building Retrieval-Augmented Generation (RAG) applications. It sits in the RAG Frameworks & Platforms category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python and licensed MIT. To get started: install and run in light mode.

## Overview

R2R (Reason to Retrieve) is an open-source retrieval system for building Retrieval-Augmented Generation (RAG) applications. It runs as a server with a RESTful API and handles the parts of a RAG pipeline you would otherwise wire together yourself: ingesting documents, searching over them, and generating answers with citations.

It is aimed at developers who need more than a single-file demo. Alongside basic search and RAG, it includes multimodal ingestion, hybrid (semantic plus keyword) search, automatic knowledge-graph extraction, user and access management, and an agentic Deep Research API that runs multi-step reasoning over your knowledge base and the web.

As a RAG framework, R2R sits between raw vector stores and your application. You talk to it through Python or JavaScript SDK clients (or the API directly), so the retrieval and document-management logic lives in one service rather than scattered across your app code.

## What it does

- Multimodal ingestion: parse .txt, .pdf, .json, .png, .mp3, and more file types
- Hybrid search combining semantic and keyword retrieval with reciprocal rank fusion
- Automatic knowledge graphs with entity and relationship extraction
- Agentic RAG, including a Deep Research API for multi-step reasoning over your data and the internet
- Built-in user and access management with authentication and collections
- RESTful API with Python (r2r) and JavaScript (r2r-js) SDK clients

## Getting started

Install R2R, start the server in light mode, then connect a client to ingest documents and run searches.

1. Install and run in light mode

   Install the Python package, set your OpenAI API key, and start the server. Light mode runs without Docker.

```bash
pip install r2r
export OPENAI_API_KEY=sk-...
python -m r2r.serve
```

2. Install the SDK

   Use the Python SDK, or install r2r-js for JavaScript projects.

```bash
pip install r2r  # Python
# or
npm i r2r-js    # JavaScript
```

3. Initialize the client

   Point the client at your running R2R server.

```python
from r2r import R2RClient
client = R2RClient(base_url="http://localhost:7272")
```

4. Ingest a document and search

   Add a document, then run a search or a RAG query with citations.

```python
# Ingest your own document
client.documents.create(file_path="/path/to/file")

# Basic search
results = client.retrieval.search(query="What is DeepSeek R1?")

# RAG with citations
response = client.retrieval.rag(query="What is DeepSeek R1?")
```

## When to use it

- Add a searchable knowledge base with cited answers to an internal app without building the RAG pipeline from scratch
- Ingest mixed file types (PDFs, images, audio, JSON) and query them through one API
- Build a knowledge graph from a document collection to surface entities and relationships
- Run multi-step Deep Research queries that reason over both your data and the web
