Source code for "TeaRAG: A Token-Efficient Agentic Retrieval-Augmented Generation Framework"
July 2, 2026 ยท View on GitHub
Source code for "TeaRAG: A Token-Efficient Agentic Retrieval-Augmented Generation Framework"
๐ News: Our paper has been accepted by ACM TOIS (Transactions on Information Systems)!
๐ Overview
TeaRAG is a tokenโefficient, agentic RetrievalโAugmented Generation framework that solves complex queries with fewer tokens and faster reasoning. By compressing both retrieval content and reasoning steps, TeaRAG delivers +4% / +2% EM gains on Llama3โ8BโInstruct and Qwen2.5โ14BโInstruct while cutting token usage by ~60%. Built on FlashRAG, it integrates graphโbased knowledge retrieval and a novel Iterative Processโaware DPO to achieve better results and higher efficiency in agentic RAG.
๐ Model & Dataset
Our models and the Wiki corpusโbased knowledge graph are available on Hugging Face: ๐ค zclfe/tearag
โ๏ธ Installation
# Clone TeaRAG (built on top of FlashRAG)
git clone https://github.com/Applied-Machine-Learning-Lab/TeaRAG.git
cd TeaRAG
pip install -e .
# FlashRAG dependencies
pip install vllm>=0.4.1
conda install -c pytorch -c nvidia faiss-gpu=1.8.0
# Training dependencies
pip3 install flash-attn --no-build-isolation
pip install accelerate==0.34.2
pip install trl==0.17.0
pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 \
--index-url https://download.pytorch.org/whl/cu126
# Redis setup
pip install redis
sudo apt install redis-server -y
redis-server --dir path/redis \
--appendonly yes \
--appendfilename appendonly.aof \
--daemonize yes \
--port 6379
# Test Redis (note: dataset loading may take some time)
redis-cli GET t:77899428
๐ Repository Structure
TeaRAG's file organization should be constructed as follows, to minimize modifications to the code.
โโโ Root Path
โโโ TeaRAG # Source code for TeaRAG
โโโ model # Saved pre-trained models
โโโ data # Datasets and corpora
โโโ train_log # Intermediate outputs and trained models
โโโ log # Inference logs (config, intermediate results, final results)
โโโ redis # Redis-based knowledge graph storage
โโโ index # Pre-built retrieval indexes
This repository builds on FlashRAG and uses a similar structure except for the alg directory, which contains our customized scripts:
โโโ alg
โโโ config # Fixed inference hyper-parameter configs
โโโ data # Dataset preparation scripts
โโโ download # Model + dataset download scripts
โโโ ds_config # DeepSpeed config
โโโ index # Index construction scripts
โโโ infer_script # Inference scripts
โโโ method # Method entry points
โโโ train # Training code
โโโ train_script # Training scripts
โโโ prepare.sh # Full preparation pipeline
โโโ run_pipeline_medium.sh # Full pipeline for Llama3-8B-Instruct
โโโ run_pipeline_qwen.sh # Full pipeline for Qwen2.5-14B-Instruct
โถ๏ธ Quick Start
Prepare (download data, build KG + index, prepare training set)
cd alg
bash prepare.sh
Train & Evaluate (Llama-3-8B-Instruct)
cd alg
bash run_pipeline_medium.sh
Train & Evaluate (Qwen2.5-14B-Instruct)
cd alg
bash run_pipeline_qwen.sh
Run inference for all datasets/models/baselines
cd alg/infer_script
bash run_all.sh
๐ฌ Contact
For questions, suggestions, or bug reports, please reach out:
๐ง zclfe00@gmail.com
We welcome contributions and feedback to make TeaRAG even better!
๐ Acknowledgements
- FlashRAG โ TeaRAG is built upon the overall framework of FlashRAG.
- Xiaohongshu โ This research was supported by computational resources from Xiaohongshuโs Search group, which greatly facilitated this research.
Citation
If TeaRAG is helpful in your research or applications, please consider citing our work:
@article{zhang2025tearag,
title={TeaRAG: A Token-Efficient Agentic Retrieval-Augmented Generation Framework},
author={Zhang, Chao and Wang, Yuhao and Xu, Derong and Zhang, Haoxin and Lyu, Yuanjie and Chen, Yuhao and Liu, Shuochen and Xu, Tong and Zhao, Xiangyu and Gao, Yan and others},
journal={ACM Transactions on Information Systems},
year={2025},
publisher={ACM New York, NY}
}