The code for the paper "PathRAG: Pruning Graph-based Retrieval Augmented Generation with Relational Paths".
cd PathRAG
pip install -e . # or pip install -r requirements.txt python -m venv .venv # create virtual environment
.venv\Scripts\activate # activate the virtual environment
python v1_test.py # to run the project
# if it doesn't works properly then try reinstalling the packages using the above installation commandpython3 -m venv .venv # create virtual environment
Source .venv\bin\activate # activate the virtual environment
python3 v1_test.py # to run the project
# if it doesn't works properly then try reinstalling the packages using the above installation command- You can quickly experience this project in the
v1_test.pyfile. - Rename
exampe.envto.env - Set OpenAI API key in
.envfile and the BASE URL. - Prepare your retrieval document
text.txt. You can modify this in the code inv1_test.py. - The
v1_text.pyfile is the entry point to initialize PathRAG and perform queries.
You can adjust the relevant parameters in the base.py and operate.py files.
import os
folder_path = "your_folder_path"
txt_files = [f for f in os.listdir(folder_path) if f.endswith(".txt")]
for file_name in txt_files:
file_path = os.path.join(folder_path, file_name)
with open(file_path, "r", encoding="utf-8") as file:
rag.insert(file.read())Please cite our paper if you use this code in your own work:
@article{chen2025pathrag,
title={PathRAG: Pruning Graph-based Retrieval Augmented Generation with Relational Paths},
author={Chen, Boyu and Guo, Zirui and Yang, Zidan and Chen, Yuluo and Chen, Junze and Liu, Zhenghao and Shi, Chuan and Yang, Cheng},
journal={arXiv preprint arXiv:2502.14902},
year={2025}
}