R2R
SoTA production-ready AI retrieval system. Agentic Retrieval-Augmented Generation (RAG) with a RESTful API.
Top Related Projects
🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
Tensors and Dynamic neural networks in Python with strong GPU acceleration
TensorFlow code and pre-trained models for BERT
An Open Source Machine Learning Framework for Everyone
Facebook AI Research Sequence-to-Sequence Toolkit written in Python.
Quick Overview
R2R (Research to Reality) is an open-source project aimed at accelerating the transition of research ideas into practical applications. It provides a framework for researchers and developers to collaborate on implementing and testing cutting-edge AI and machine learning concepts, with a focus on natural language processing and large language models.
Pros
- Bridges the gap between academic research and real-world applications
- Encourages collaboration between researchers and developers
- Provides a structured approach to implementing and testing new AI concepts
- Offers a growing collection of implemented research papers and techniques
Cons
- May have a steep learning curve for newcomers to AI research
- Documentation could be more comprehensive for some components
- Limited support for non-NLP AI domains
- Requires familiarity with PyTorch and other AI libraries
Code Examples
Here are a few code examples demonstrating the usage of R2R:
- Loading a pre-trained model:
from r2r import load_model
model = load_model("gpt2-medium")
print(model.generate("The future of AI is"))
- Fine-tuning a model on custom data:
from r2r import Trainer, DataLoader
trainer = Trainer(model, optimizer="adam", lr=1e-5)
data_loader = DataLoader("custom_dataset.json", batch_size=32)
trainer.train(data_loader, epochs=3)
- Implementing a custom attention mechanism:
from r2r.modules import Attention
class CustomAttention(Attention):
def forward(self, query, key, value):
# Custom attention implementation
attention_scores = torch.matmul(query, key.transpose(-2, -1))
attention_probs = torch.softmax(attention_scores, dim=-1)
return torch.matmul(attention_probs, value)
Getting Started
To get started with R2R, follow these steps:
- Install the library:
pip install r2r
- Import and use R2R components in your project:
from r2r import load_model, Trainer, DataLoader
# Load a pre-trained model
model = load_model("bert-base-uncased")
# Prepare your data
data_loader = DataLoader("your_dataset.json", batch_size=16)
# Create a trainer and fine-tune the model
trainer = Trainer(model, optimizer="adam", lr=2e-5)
trainer.train(data_loader, epochs=5)
# Use the fine-tuned model
result = model.predict("Your input text here")
print(result)
For more detailed information and advanced usage, refer to the official documentation on the R2R GitHub repository.
Competitor Comparisons
🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.
Pros of transformers
- Extensive library with support for numerous pre-trained models
- Well-documented and actively maintained by a large community
- Seamless integration with PyTorch and TensorFlow
Cons of transformers
- Can be complex for beginners due to its extensive features
- Larger library size and potential overhead for simple projects
- May require more computational resources for some models
Code Comparison
R2R:
from r2r import R2R
model = R2R.from_pretrained("r2r-base")
output = model.generate("Translate to French: Hello, world!")
transformers:
from transformers import pipeline
translator = pipeline("translation", model="t5-small")
output = translator("Translate to French: Hello, world!", max_length=40)
Summary
While transformers offers a comprehensive suite of pre-trained models and extensive documentation, R2R provides a more streamlined approach for specific tasks. transformers excels in versatility and community support, but R2R may be more suitable for projects requiring a lighter, more focused solution.
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
Pros of DeepSpeed
- More comprehensive and mature optimization toolkit for deep learning
- Supports a wider range of models and training scenarios
- Offers advanced features like ZeRO optimizer and 3D parallelism
Cons of DeepSpeed
- Steeper learning curve due to its complexity
- May be overkill for smaller projects or simpler models
- Requires more setup and configuration
Code Comparison
R2R example:
from r2r import R2R
model = R2R.from_pretrained("gpt2")
output = model.generate("Hello, how are you?")
print(output)
DeepSpeed example:
import deepspeed
import torch
model, optimizer, _, _ = deepspeed.initialize(
model=torch.nn.Module(),
model_parameters=model.parameters(),
config=ds_config
)
R2R focuses on simplicity and ease of use for retrieval-augmented generation, while DeepSpeed provides a more comprehensive suite of optimization techniques for large-scale deep learning. R2R is better suited for quick prototyping and specific RAG tasks, whereas DeepSpeed excels in optimizing performance for complex, large-scale models across various domains.
Tensors and Dynamic neural networks in Python with strong GPU acceleration
Pros of PyTorch
- Extensive ecosystem with wide industry adoption
- Comprehensive documentation and large community support
- Flexible and dynamic computational graph for easier debugging
Cons of PyTorch
- Steeper learning curve for beginners
- Larger memory footprint compared to some alternatives
- Can be slower for certain operations compared to static graph frameworks
Code Comparison
R2R example:
from r2r import Agent
agent = Agent()
response = agent.chat("Hello, how are you?")
print(response)
PyTorch example:
import torch
x = torch.tensor([1, 2, 3])
y = torch.tensor([4, 5, 6])
z = torch.add(x, y)
print(z)
Summary
R2R is a specialized framework for building AI agents, while PyTorch is a general-purpose deep learning library. R2R focuses on simplifying the process of creating conversational AI, whereas PyTorch provides a comprehensive set of tools for various machine learning tasks. PyTorch offers more flexibility and a larger ecosystem, but may require more expertise to use effectively. R2R, on the other hand, provides a more streamlined approach for specific AI agent development tasks.
TensorFlow code and pre-trained models for BERT
Pros of BERT
- Widely adopted and extensively researched in the NLP community
- Comprehensive documentation and numerous pre-trained models available
- Supports multiple languages and can be fine-tuned for various NLP tasks
Cons of BERT
- Larger model size and higher computational requirements
- May require more extensive training data for optimal performance
- Less focused on specific retrieval-to-retrieval tasks
Code Comparison
BERT example:
from transformers import BertTokenizer, BertModel
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertModel.from_pretrained('bert-base-uncased')
inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
outputs = model(**inputs)
R2R example:
from r2r import R2RModel
model = R2RModel.from_pretrained("sciphi/r2r-base")
query = "What is the capital of France?"
results = model.retrieve(query, top_k=5)
The code snippets demonstrate the different focus areas of the two repositories. BERT is more general-purpose and requires additional steps for specific tasks, while R2R is tailored for retrieval tasks with a simpler API.
An Open Source Machine Learning Framework for Everyone
Pros of TensorFlow
- Extensive ecosystem with robust tools and libraries
- Strong community support and extensive documentation
- Widely adopted in industry and research
Cons of TensorFlow
- Steeper learning curve for beginners
- Can be slower for prototyping compared to more dynamic frameworks
- Large framework size and potential overhead for simpler projects
Code Comparison
TensorFlow example:
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])
R2R example:
from r2r import NeuralNetwork
model = NeuralNetwork([
{'type': 'dense', 'units': 64, 'activation': 'relu'},
{'type': 'dense', 'units': 10, 'activation': 'softmax'}
])
Note: The R2R code example is hypothetical as the actual implementation details of the R2R framework are not publicly available. The comparison aims to illustrate potential differences in API design and usage.
Facebook AI Research Sequence-to-Sequence Toolkit written in Python.
Pros of fairseq
- More comprehensive and feature-rich, supporting a wide range of NLP tasks
- Larger community and more extensive documentation
- Backed by Facebook Research, ensuring regular updates and maintenance
Cons of fairseq
- Steeper learning curve due to its complexity and extensive features
- Heavier and more resource-intensive, potentially overkill for simpler projects
- Less focused on specific tasks compared to R2R's specialized approach
Code Comparison
R2R example:
from r2r import R2RModel
model = R2RModel.from_pretrained("r2r-base")
output = model.generate("Translate to French: Hello, world!")
fairseq example:
from fairseq.models.transformer import TransformerModel
model = TransformerModel.from_pretrained("transformer.wmt19.en-de")
output = model.translate("Hello, world!")
Both repositories provide tools for natural language processing tasks, but fairseq offers a broader range of functionalities while R2R focuses on specific use cases. fairseq's extensive features and community support come at the cost of increased complexity, while R2R provides a more streamlined experience for its targeted applications.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
The most advanced AI retrieval system.
Agentic Retrieval-Augmented Generation (RAG) with a RESTful API.
About
R2R (Reason to Retrieve) is an advanced AI retrieval system supporting Retrieval-Augmented Generation (RAG) with production-ready features. Built around a RESTful API, R2R offers multimodal content ingestion, hybrid search, knowledge graphs, and comprehensive document management.
R2R also includes a Deep Research API, a multi-step reasoning system that fetches relevant data from your knowledgebase and/or the internet to deliver richer, context-aware answers for complex queries.
Usage
# Basic search
results = client.retrieval.search(query="What is DeepSeek R1?")
# RAG with citations
response = client.retrieval.rag(query="What is DeepSeek R1?")
# Deep Research RAG Agent
response = client.retrieval.agent(
message={"role":"user", "content": "What does deepseek r1 imply? Think about market, societal implications, and more."},
rag_generation_config={
"model"="anthropic/claude-3-7-sonnet-20250219",
"extended_thinking": True,
"thinking_budget": 4096,
"temperature": 1,
"top_p": None,
"max_tokens_to_sample": 16000,
},
)
Getting Started
Cloud Option: SciPhi Cloud
Access R2R through SciPhi's managed deployment with a generous free tier. No credit card required.
Self-Hosting Option
# Quick install and run in light mode
pip install r2r
export OPENAI_API_KEY=sk-...
python -m r2r.serve
# Or run in full mode with Docker
# git clone git@github.com:SciPhi-AI/R2R.git && cd R2R
# export R2R_CONFIG_NAME=full OPENAI_API_KEY=sk-...
# docker compose -f compose.full.yaml --profile postgres up -d
For detailed self-hosting instructions, see the self-hosting docs.
Demo
https://github.com/user-attachments/assets/173f7a1f-7c0b-4055-b667-e2cdcf70128b
Using the API
1. Install SDK & Setup
# Install SDK
pip install r2r # Python
# or
npm i r2r-js # JavaScript
# Setup API key
export R2R_API_KEY=pk_..sk_... # Get from SciPhi Cloud dashboard
2. Client Initialization
from r2r import R2RClient
client = R2RClient() # Use base_url=... for self-hosted
const { r2rClient } = require('r2r-js');
const client = new r2rClient(); // Use baseURL=... for self-hosted
3. Document Operations
# Ingest sample or your own document
client.documents.create_sample(hi_res=True)
# client.documents.create(file_path="/path/to/file")
# List documents
client.documents.list()
Key Features
- ð Multimodal Ingestion: Parse
.txt
,.pdf
,.json
,.png
,.mp3
, and more - ð Hybrid Search: Semantic + keyword search with reciprocal rank fusion
- ð Knowledge Graphs: Automatic entity & relationship extraction
- ð¤ Agentic RAG: Reasoning agent integrated with retrieval
- ð User & Access Management: Complete authentication & collection system
Community & Contributing
- Join our Discord for support and discussion
- Submit feature requests or bug reports
- Open PRs for new features, improvements, or documentation
- Book a demo call with the SciPhi founders
Our Contributors
Top Related Projects
🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.
DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.
Tensors and Dynamic neural networks in Python with strong GPU acceleration
TensorFlow code and pre-trained models for BERT
An Open Source Machine Learning Framework for Everyone
Facebook AI Research Sequence-to-Sequence Toolkit written in Python.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot