# FlashRAG

> A Python toolkit for reproducible RAG research with 23 built-in algorithms and 36 benchmark datasets

- Category: Retrieval & Knowledge (RAG) / RAG Frameworks & Platforms
- Language: Python
- Licence: MIT
- Repository: https://github.com/RUC-NLPIR/FlashRAG
- Website: https://arxiv.org/abs/2405.13576
- Canonical page: https://ai-tldr.dev/tools/flashrag/

## In short

FlashRAG is a Python toolkit for reproducing and developing Retrieval-Augmented Generation (RAG) research. 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 FlashRAG.

## Overview

FlashRAG is a Python toolkit for reproducing and developing Retrieval-Augmented Generation (RAG) research. It bundles 36 pre-processed benchmark datasets and 23 published RAG algorithms behind one consistent interface, so you can re-run reported results or build your own pipeline without re-implementing each method from scratch.

It is aimed at researchers and engineers who compare RAG methods and need numbers they can trust. Because every method shares the same components for retrieval, reranking, generation, and compression, results across algorithms stay comparable and experiments are easier to reproduce.

As a RAG framework, FlashRAG focuses on the experiment loop rather than production serving. It includes preprocessing scripts for corpus handling and index building, and it uses tools like Faiss for vector search and vLLM for faster LLM inference.

## What it does

- 23 pre-implemented RAG algorithms with reported results, including 7 reasoning-based methods for multi-hop tasks
- 36 pre-processed benchmark RAG datasets for testing and validating model performance
- Modular components for RAG pipelines: retrievers, rerankers, generators, and compressors
- Preprocessing scripts for corpus processing, retrieval index building, and document pre-retrieval
- Faster execution with vLLM and FastChat for LLM inference and Faiss for vector index management
- A built-in UI to configure RAG baselines and run evaluation scripts visually

## Getting started

Install the package, then assemble a RAG pipeline from FlashRAG's config and pipeline classes.

1. Install FlashRAG

   Install the pre-release package from PyPI. You can also clone the repo and install from source.

```bash
pip install flashrag-dev --pre
```

2. Add optional acceleration

   For vLLM-accelerated inference and vector indexing, install the full extras and Faiss.

```bash
pip install flashrag-dev[full]
pip install vllm>=0.4.1
conda install -c pytorch faiss-cpu=1.8.0
```

3. Run a sequential pipeline

   Load a config and dataset, then run a SequentialPipeline with evaluation enabled.

```python
from flashrag.config import Config
from flashrag.utils import get_dataset
from flashrag.pipeline import SequentialPipeline

config_dict = {'data_dir': 'dataset/'}
my_config = Config(
    config_file_path='my_config.yaml',
    config_dict=config_dict
)

all_split = get_dataset(my_config)
test_data = all_split['test']

pipeline = SequentialPipeline(my_config)
output_dataset = pipeline.run(test_data, do_eval=True)
```

## When to use it

- Reproduce reported results for published RAG methods using the same datasets and settings
- Benchmark several retrieval and generation strategies side by side on standard datasets
- Prototype a custom RAG pipeline by mixing retrievers, rerankers, generators, and compressors
- Study reasoning-based RAG methods on complex multi-hop question answering tasks
