MCPcopy Index your code
hub / github.com/chenyiqun/MMOA-RAG

github.com/chenyiqun/MMOA-RAG @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
762 symbols 4,159 edges 158 files 231 documented · 30%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

MMOA-RAG

This repository contains the code for MMOA-RAG, a system for multi-modules optimization involving Query Rewriter, Retriever, Selector and Generator. The code is organized into several components that facilitate the deployment, training, and evaluation of the RAG system.

Paper: Improving Retrieval-Augmented Generation through Multi-Agent Reinforcement Learning

Table of Contents

Computational Resource Requirements

We used two servers, each equipped with 8 A800 GPUs (each with 80GB of memory), for training MMOA-RAG. One server was dedicated to deploying the retrieval model, while the other was used for training MARL.

Why is a separate machine needed to deploy the retrieval model? During the MARL training process, updates to the Query Rewriter are involved, and it is necessary to obtain Top-k documents in real-time during Rollout. This requires high real-time performance from the retrieval model. Therefore, we deployed the retrieval model on a separate machine using Faiss and leveraged GPU acceleration to ensure fast retrieval results.

Deploying the Retrieval Model

The retrieval models are deployed using a specialized machine due to the multi-modules optimization that involves the training of the Query Rewriter.

To deploy the retrieval model, execute the following:

  1. Ensure the code in ./flask_server.py is properly configured.
  2. Start the retrieval model API by running in one server: bash bash run_server.sh

Getting the SFT and MAPPO Training Data

To generate the training data for SFT and MAPPO processes, follow these steps:

Run the following script to obtain the SFT training data: bash python qr_s_g_sft_data_alpaca.py

Run the following script to get the MAPPO training data for each dataset: bash python get_ppo_data_alpaca.py

We developed the code of MAPPO to joint optimizing multiple modules in RAG system based on LLaMA-Factory, and the core code can be seen at: bash ./LLaMA-Factory/src/llamafactory/train/ppo/trainer_qr_s_g.py

Warm Start for RAG System

To warm start multiple modules in the RAG system using SFT, execute: bash bash LLaMA-Factory/run_sft.sh

Multi-Agent Optimization for RAG System

To perform joint learning of the multiple modules in the RAG system using MAPPO, run the following command in another server: bash bash LLaMA-Factory/run_mappo.sh

Evaluation

Evaluate the performance of the RAG system by executing: bash CUDA_VISIBLE_DEVICES=0 python evaluate_qr_s_g.py

Others

Create necessary directories: 1. ./data for storing data sets. For example, ./data/ambigqa is used to save the AmbigQA dataset.

  1. ./models for saving checkpoints of the retrieval model and LLMs.

Core symbols most depended-on inside this repo

append
called by 210
LLaMA-Factory/src/llamafactory/webui/chatter.py
register_model_group
called by 66
LLaMA-Factory/src/llamafactory/extras/constants.py
_register_template
called by 64
LLaMA-Factory/src/llamafactory/data/template.py
update
called by 44
LLaMA-Factory/src/llamafactory/extras/misc.py
get_logger
called by 38
LLaMA-Factory/src/llamafactory/extras/logging.py
get_elem_by_id
called by 33
LLaMA-Factory/src/llamafactory/webui/manager.py
apply
called by 22
LLaMA-Factory/src/llamafactory/data/formatter.py
get_mm_plugin
called by 21
LLaMA-Factory/src/llamafactory/data/mm_plugin.py

Shape

Function 406
Method 250
Class 101
Route 5

Languages

Python100%

Modules by API surface

LLaMA-Factory/src/llamafactory/train/ppo/trainer_qr_s_g.py39 symbols
LLaMA-Factory/src/llamafactory/data/mm_plugin.py35 symbols
LLaMA-Factory/src/llamafactory/train/callbacks.py27 symbols
LLaMA-Factory/src/llamafactory/api/protocol.py20 symbols
LLaMA-Factory/src/llamafactory/webui/runner.py18 symbols
LLaMA-Factory/src/llamafactory/extras/misc.py18 symbols
LLaMA-Factory/src/llamafactory/train/trainer_utils.py17 symbols
LLaMA-Factory/src/llamafactory/webui/utils.py16 symbols
LLaMA-Factory/src/llamafactory/data/formatter.py16 symbols
evaluate_qr_s_g.py14 symbols
LLaMA-Factory/src/llamafactory/extras/packages.py14 symbols
LLaMA-Factory/src/llamafactory/data/template.py14 symbols

For agents

$ claude mcp add MMOA-RAG \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact