RAG-Retrieval

NovaSearch-TeamMIT活跃维护

统一 RAG 检索环节的微调工具,覆盖 Embedding、ColBERT 和 ReRanker 三类模型,省去分别搭训练流程的麻烦。

Unify Efficient Fine-tuning of RAG Retrieval, including Embedding, ColBERT, ReRanker.

rag_retrieval_only_train发布于 2024-05-04 10:03 UTC1,137star88fork同步于 2026-11-07 07:29 UTC

怎么上手

由 README 提炼,执行前请确认
conda create -n rag-retrieval python=3.8 && conda activate rag-retrieval
pip install -r requirements.txt
pip install rag-retrieval
硬件要求按 README 说明

README 未说明具体显存要求;训练支持 deepspeed、fsdp 多卡策略,并建议手动安装与本地 CUDA 兼容的 torch 版本。

支持 Apple Silicon多卡 / 张量并行
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

统一 RAG 检索模型的训练、推理与蒸馏,覆盖 Embedding、ColBERT 和 Reranker

统一 RAG 检索环节的微调工具,覆盖 Embedding、ColBERT 和 ReRanker 三类模型,省去分别搭训练流程的麻烦。

核心能力

  • 端到端微调 Embedding、ColBERT 与 Reranker 模型
  • 兼容 bge、bce、gte 等主流开源检索模型
  • 支持将大模型蒸馏到 0.5B LLM 或 BERT-base
  • Embedding 支持 MRL 降维与 Stella 蒸馏方法
  • 提供 rag-retrieval 库统一调用各类 Reranker

容易踩的坑

自动安装的 torch 可能与本地 CUDA 不兼容,建议先手动装匹配版本;训练需进入对应模型子目录(如 rag_retrieval/train/embedding)再运行脚本;推理库仅覆盖 Reranker,训练与推理依赖分开安装。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

1 个版本rag_retrieval_only_train
  1. rag_retrieval_only_trainRAG-Retrieval v0.1 pre-release最新正式版2024-05-04 · 2024-05-04 10:03 UTC

    Unify Efficient Fine-tuning of RAG Retrieval, including Embedding, ColBERT,Cross Encoder

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    English | 中文

    The RAG-Retrieval offers end-to-end code for training, inference, and distillation of the RAG retrieval model.

    • For training, RAG-Retrieval supports fine-tuning of any open-source RAG retrieval models, including embedding models (figure a,bert-based, llm-based), late interactive models (figure d,colbert), and reranker models (figure c,bert-based, llm-based).
    • For inference, RAG-Retrieval focuses reranker and has developed a lightweight Python library rag-retrieval, which provides a unified way to call any different RAG ranking models.
    • For distillation, Distillation of support embedding models and reranker models, support distill from a larger model to a smaller model (0.5b llm or bert-base).

    ColBERT

    Communication between communities

    Join our WeChat group chat

    News

    Features

    • Simple yet Elegant: Rejects complex, with a simple and understandable code structure for easy modifications.
    • Supports end-to-end fine-tuning of RAG retrieval models: Embedding (bert-based, llm-based), late interaction models (colbert), and reranker models (bert-based, llm-based).
    • Supports fine-tuning of any open-source RAG retrieval models: Compatible with most open-source embedding and reranker models, such as: bge (bge-embedding, bge-m3, bge-reranker), bce (bce-embedding, bce-reranker), gte (gte-embedding, gte-multilingual-reranker-base).
    • Supports distillation of larger models into smaller models: Enables the distillation of larger LLM-based reranker or embedding models into smaller ones (e.g., a 0.5B-parameter LLM or BERT-base).
    • Advanced Algorithms: For embedding models, supports the MRL algorithm to reduce the dimensionality of output vectors and Stella distillation method.
    • Multi-gpu training strategy: Includes deepspeed, fsdp.

    Quick Start

    Installation

    For training (all):

    conda create -n rag-retrieval python=3.8 && conda activate rag-retrieval
    # To avoid incompatibility between the automatically installed torch and the local cuda, it is recommended to manually install the compatible version of torch before proceeding to the next step.
    pip install -r requirements.txt 
    

    For prediction (reranker):

    # To avoid incompatibility between the automatically installed torch and the local cuda, it is recommended to manually install the compatible version of torch before proceeding to the next step.
    pip install rag-retrieval
    

    Training

    For different model types, please go into different subdirectories. For example: For embedding, and similarly for others. Detailed procedures can be found in the README file in each subdirectories.

    cd ./rag_retrieval/train/embedding
    bash train_embedding.sh
    

    inference

    RAG-Retrieval has developed a lightweight Python library, rag-retrieval, which provides a unified interface for calling various RAG reranker models with the following features:

    • Supports multiple ranking models: Compatible with common open-source ranking models (Cross Encoder Reranker, Decoder-Only LLM Reranker).

    • Long document friendly: Supports two different handling logics for long documents (maximum length truncation and splitting to take the maximum score).

    • Easy to Extend: If there is a new ranking model, users only need to inherit from BaseReranker and implement the rank and compute_score functions.

    For detailed usage and considerations of the rag-retrieval package, please refer to the Tutorial

    Experimental Results

    Results of the reranker model on the MTEB Reranking task

    ModelModel Size(GB)T2RerankingMMarcoRerankingCMedQAv1CMedQAv2Avg
    bge-reranker-base1.1167.2835.4681.2784.1067.03
    bce-reranker-base_v11.1170.2534.1379.6481.3166.33
    rag-retrieval-reranker0.4167.3331.5783.5486.0367.12

    Among them, rag-retrieval-reranker is the result of training on the hfl/chinese-roberta-wwm-ext model using the RAG-Retrieval code, and the training data uses the training data of the bge-rerank model.

    Results of the Colbert model in the MTEB Reranking task

    ModelModel Size(GB)DimT2RerankingMMarcoRerankingCMedQAv1CMedQAv2Avg
    bge-m3-colbert2.24102466.8226.7175.8876.8361.56
    rag-retrieval-colbert0.41102466.8531.4681.0584.2265.90

    Among them, rag-retrieval-colbert is the result of training on the hfl/chinese-roberta-wwm-ext model using the RAG-Retrieval code, and the training data uses the training data of the bge-rerank model.

    Fine-tune the open source BGE series models with domain data

    ModelT2ranking
    bge-v1.5-embedding66.49
    bge-v1.5-embedding finetune67.15+0.66
    bge-m3-colbert66.82
    bge-m3-colbert finetune67.22+0.40
    bge-reranker-base67.28
    bge-reranker-base finetune67.57+0.29

    The number with finetune at the end means that we used RAG-Retrieval to fine-tune the corresponding open source model, and the training data used the training set of T2-Reranking.

    It is worth noting that the training set of the three open source models of bge already includes T2-Reranking, and the data is relatively general, so the performance improvement of fine-tuning using this data is not significant. However, if the open source model is fine-tuned using a vertical field data set, the performance improvement will be greater.

    Citation

    If you find this repository helpful, please cite our work:

    @misc{zhang2025jasperstelladistillationsota,
          title={Jasper and Stella: distillation of SOTA embedding models}, 
          author={Dun Zhang and Jiacheng Li and Ziyang Zeng and Fulong Wang},
          year={2025},
          eprint={2412.19048},
          archivePrefix={arXiv},
          primaryClass={cs.IR},
          url={https://arxiv.org/abs/2412.19048}, 
    }
    

    Acknowledge

    During the development process, we borrowed or based on the implementation of the following projects. We sincerely appreciate the efforts of these teams for their contributions to open-source research and development.

    Star History

    Star History Chart

    License

    RAG-Retrieval is licensed under the MIT License.