[ [English](README.md) | [ไธญๆ](README_zh.md)]

### ๐ฅ Rankify: A Comprehensive Python Toolkit for Retrieval, Re-Ranking, and Retrieval-Augmented Generation ๐ฅ
If you like our Framework, **don't hesitate to โญ star this repository โญ**. This helps us to **make the Framework more better and scalable to different models and methods ๐ค**.
_A modular and efficient retrieval, reranking and RAG framework designed to work with state-of-the-art models for retrieval, ranking and rag tasks._
---
## ๐ Demo
To run the demo locally:
```bash
# Make sure Rankify is installed
pip install streamlit
# Then run the demo
streamlit run demo.py
```
https://github.com/user-attachments/assets/13184943-55db-4f0c-b509-fde920b809bc
---
## :link: Navigation
- [Features](#-features)
- [Roadmap](#-roadmap)
- [Installation](#-installation)
- [Quick Start](#rocket-quick-start)
- [Pipeline API](#-one-line-pipeline-api-recommended)
- [RankifyAgent](#-rankifyagent---ai-powered-model-selection)
- [Rankify Server](#-rankify-server---deploy-as-rest-api)
- [Integrations](#-integrations---use-with-your-stack)
- [Web Playground](#-web-playground---interactive-ui)
- [Indexing](#-indexing-via-cli)
- [Retrievers](#2๏ธโฃ-running-retrieval)
- [Re-Rankers](#3๏ธโฃ-running-reranking)
- [Generators](#4๏ธโฃ-using-generator-module)
- [Evaluation](#5๏ธโฃ-evaluating-with-metrics)
- [Documentation](#๐-documentation)
- [Community Contributing](#-Community-Contributions)
- [Contributing](#-contributing)
- [License](#bookmark-license)
- [Acknowledgments](#-acknowledgments)
- [Citation](#star2-citation)
## ๐News
- **[2026-02-16]** Huge thanks to [@JamieHoldcroft](https://github.com/JamieHoldcroft) for integrating **15+** new dense retrievers, including SOTA LLM-based bi-encoders (**SFR**, **E5**, **GritLM**) and reasoning-augmented models (**RaDeR**, **ReasonIR**, **ReasonEmbed**, **BGE-Reasoner**).
- **[2025-10-14]** Updated installation with optional extras: `retriever`, `reranking`, `rag`, and `all`.
- **[2025-10-14]** New **CLI** (`rankify-index`) syntax & examples for **BM25, DPR, ANCE, Contriever, ColBERT, BGE**.
- **[2025-06-11]** Many thanks to [@tobias124](https://github.com/tobias124) for implementing [Indexing](#cli-running-indexing-module) for Custom Dataset.
- **[2025-06-01]** Many thanks to [@aherzinger](https://github.com/aherzinger) for implementing and refactoring the Generator and RAG models.
- **[2025-05-30]** Huge thanks to [@baraayusry](https://github.com/baraayusry) for implementing the Online Retriever using CrawAI and ReACT.
- **[2025-02-10]** Released [reranking-datasets](https://huggingface.co/datasets/abdoelsayed/reranking-datasets) and [reranking-datasets-light](https://huggingface.co/datasets/abdoelsayed/reranking-datasets-light) on Hugging Face.
- **[2025-02-04]** Our [paper](https://arxiv.org/abs/2502.02464) is released on arXiv.
## ๐ง Installation
#### Set up the virtual environment
First, create and activate a conda environment with Python 3.10:
```bash
conda create -n rankify python=3.10
conda activate rankify
```
#### Install PyTorch 2.5.1
we recommend installing Rankify with PyTorch 2.5.1 for Rankify. Refer to the [PyTorch installation page](https://pytorch.org/get-started/previous-versions/) for platform-specific installation commands.
If you have access to GPUs, it's recommended to install the CUDA version 12.4 or 12.6 of PyTorch, as many of the evaluation metrics are optimized for GPU use.
To install Pytorch 2.5.1 you can install it from the following cmd
```bash
pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124
```
#### Basic Installation
To install **Rankify**, simply use **pip** (requires Python 3.10+):
```base
pip install rankify
```
#### Recommended Installation
For full functionality, we **recommend installing Rankify with all dependencies**:
```bash
pip install "rankify[all]"
```
This ensures you have all necessary modules, including retrieval, re-ranking, and RAG support.
#### Optional Dependencies
If you prefer to install only specific components, choose from the following:
```bash
# Retrieval stack (BM25, dense retrievers, web tools)
pip install "rankify[retriever]"
# Install base re-ranking with vLLM support for `FirstModelReranker`, `LiT5ScoreReranker`, `LiT5DistillReranker`, `VicunaReranker`, and `ZephyrReranker'.
pip install "rankify[reranking]"
# RAG endpoints (OpenAI, LiteLLM, vLLM clients)
pip install "rankify[rag]"
```
Or, to install from **GitHub** for the latest development version:
```bash
git clone https://github.com/DataScienceUIBK/rankify.git
cd rankify
pip install -e .
# For full functionality we recommend installing Rankify with all dependencies:
pip install -e ".[all]"
# Install dependencies for retrieval only (BM25, DPR, ANCE, etc.)
pip install -e ".[retriever]"
# Install base re-ranking with vLLM support for `FirstModelReranker`, `LiT5ScoreReranker`, `LiT5DistillReranker`, `VicunaReranker`, and `ZephyrReranker'.
pip install -e ".[reranking]"
# RAG endpoints (OpenAI, LiteLLM, vLLM clients)
pip install -e ".[rag]"
```
#### Using ColBERT Retriever
If you want to use **ColBERT Retriever**, follow these additional setup steps:
```bash
# Install GCC and required libraries
conda install -c conda-forge gcc=9.4.0 gxx=9.4.0
conda install -c conda-forge libstdcxx-ng
```
```bash
# Export necessary environment variables
export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH
export CC=gcc
export CXX=g++
export PATH=$CONDA_PREFIX/bin:$PATH
# Clear cached torch extensions
rm -rf ~/.cache/torch_extensions/*
```
## :rocket: Quick Start
### ๐ **One-Line Pipeline API** (Recommended)
The **simplest way** to use Rankify - HuggingFace-style one-line interface:
```python
from rankify import pipeline
# Create a RAG pipeline with intelligent defaults
rag = pipeline("rag")
answers = rag("What is machine learning?", documents)
# Or customize your configuration
rag = pipeline(
"rag",
retriever="bge", # State-of-the-art dense retriever
reranker="flashrank", # Ultra-fast reranker
generator="basic-rag"
)
```
**Available Pipeline Types:**
- `pipeline("search")` - Document retrieval only
- `pipeline("rerank")` - Retrieve + rerank
- `pipeline("rag")` - Full RAG pipeline (retrieve + rerank + generate)
๐ **[Pipeline API Documentation](https://rankify.readthedocs.io/en/latest/tutorials/pipeline/)**
---
### ๐ค **RankifyAgent** - AI-Powered Model Selection
Let AI help you choose the best models for your use case:
```python
from rankify.agent import RankifyAgent, recommend
# Quick recommendation
result = recommend(task="qa", gpu=True)
print(f"Best Retriever: {result.retriever.name}")
print(f"Best Reranker: {result.reranker.name}")
# Conversational agent
agent = RankifyAgent(backend="azure") # or "openai", "litellm", "local"
response = agent.chat("I need a fast search system for production")
print(response.message)
print(response.code_snippet) # Ready-to-use code
```
๐ **[RankifyAgent Documentation](https://rankify.readthedocs.io/en/latest/tutorials/agent/)**
---
### ๐ **Rankify Server** - Deploy as REST API
Start a production-ready server in one command:
```bash
# CLI
rankify serve --port 8000 --retriever bge --reranker flashrank
# Or in Python
from rankify.server import RankifyServer
server = RankifyServer(retriever="bge", reranker="flashrank")
server.start(port=8000)
```
**API Endpoints:**
- `POST /retrieve` - Document retrieval
- `POST /rerank` - Rerank documents
- `POST /rag` - Full RAG generation
- `GET /health` - Health check
```bash
# Example API call
curl -X POST http://localhost:8000/rag \
-H "Content-Type: application/json" \
-d '{"query": "What is AI?", "n_contexts": 5}'
```
๐ **[Server Documentation](https://rankify.readthedocs.io/en/latest/tutorials/pipeline/server/)**
---
### ๐ **Integrations** - Use with Your Stack
Seamlessly integrate with LangChain, LlamaIndex, and more:
```python
# LangChain
from rankify.integrations import LangChainRetriever
from langchain.chains import RetrievalQA
retriever = LangChainRetriever(method="bge", reranker="flashrank")
chain = RetrievalQA.from_chain_type(llm=your_llm, retriever=retriever)
# LlamaIndex
from rankify.integrations import LlamaIndexRetriever
retriever = LlamaIndexRetriever(method="colbert", reranker="monot5")
```
๐ **[Integrations Documentation](https://rankify.readthedocs.io/en/latest/tutorials/pipeline/integrations/)**
---
### ๐จ **Web Playground** - Interactive UI
Launch an interactive Gradio interface:
```python
from rankify.ui import launch_playground
launch_playground(port=7860)
```
Try models, compare results, and export code - all in your browser!
---
### 1๏ธโฃ **Traditional Workflow** (For Advanced Users)
#### **Pre-retrieved Datasets**
We provide **40+ benchmark datasets** with **1,000 pre-retrieved documents** each:
๐ **[Hugging Face Dataset Repository](https://huggingface.co/datasets/abdoelsayed/reranking-datasets-light)**
#### **Dataset Format**
```json
[
{
"question": "...",
"answers": ["...", "...", ...],
"ctxs": [
{
"id": "...", // Passage ID
"score": "...", // Retriever score
"has_answer": true|false
}
]
}
]
```
#### **List Available Datasets**
```python
from rankify.dataset.dataset import Dataset
Dataset.available_dataset() # Fixed typo: avaiable -> available
```
#### **Download Datasets**
```python
from rankify.dataset.dataset import Dataset
# Download BM25-retrieved documents
dataset = Dataset(retriever="bm25", dataset_name="nq-dev", n_docs=100)
documents = dataset.download(force_download=False)
# Load from file
documents = Dataset.load_dataset('./path/to/dataset.json', n_docs=100)
```
## ๐งฑ Indexing via CLI
The CLI entrypoint is **`rankify-index`** with a subcommand **`index`**.
**Common flags**
- `corpus_path` (positional): path to JSONL corpus.
- `--retriever {bm25,dpr,ance,contriever,colbert,bge}`.
- `--output PATH` (default: `rankify_indices`).
- `--index_type {wiki,msmarco}` (default: `wiki`).
- `--threads INT` (default: `32`, sparse & some dense prep).
- `--device {cpu,cuda}` (default: retrieverโspecific, typically `cuda`).
- `--batch_size INT` (dense encoders / Faiss add batches).
- `--encoder MODEL` (dense encoders only; sensible defaults used if omitted).
> **Index layout**
> - BM25 โ `