This repository contains the official implementation of our paper:
FedMosaic: Federated Retrieval-Augmented Generation via Parametric Adapters Accepted at SIGIR 2026.
Retrieval-Augmented Generation (RAG) grounds LLMs in external knowledge, but typically assumes a centralized corpus, which is infeasible when data is siloed across privacy-aware domains. This motivates federated RAG (FedRAG). FedMosaic is, to our knowledge, the first FedRAG framework built on parametric adapters, following the parametric RAG paradigm of PRAG in which each document is encoded into a lightweight adapter that merges with a frozen LLM at inference, so raw text never leaves its owner. Transplanting this to the federated setting raises new challenges: per-document adapters incur heavy storage and communication, and naive merging causes destructive interference. FedMosaic addresses them with two key components:
-
Multi-Document Parametric Adapters. To reduce storage and communication overhead, FedMosaic shares one adapter across a cluster of semantically coherent documents.
-
Selective adapter aggregation. To mitigate inter-silo adapter interference during adapter averaging, FedMosaic aggregates only adapters associated with the most relevant documents and least conflicting parameters.
FedMosaic/
βββ main.py # Unified entry point (prep_dataset / offline / online)
βββ config.yaml # Hyper-parameters and paths
βββ requirements.txt
βββ src/
β βββ prep_dataset.py # Dataset download, retrieval, augmentation, silo split
β βββ cluster.py # Document clustering inside each silo
β βββ train.py # LoRA adapter training + document-specific mask training
β βββ offline.py # Offline stage: clustering -> LoRA -> masks
β βββ online.py # Online stage: retrieve -> rank -> masked inference
β βββ rag.py # RAG-related utilities (ranking, inference)
β βββ silo.py # Silo abstraction and per-silo retrieval
β βββ utils.py # Models, evaluation, I/O helpers
βββ retriever_elasticsearch/ # BM25 retrieval over Wikipedia (Elasticsearch)
β βββ prep_elastic.py
β βββ retriever/
βββ dataset/ # Prepared datasets (or extract from dataset.tar.gz)
We recommend Python 3.10.4 with CUDA-enabled PyTorch.
cd FedMosaic
conda create -n fedmosaic python=3.10.4
pip install -r requirements.txtBefore running, edit config.yaml to set the following paths to match your environment:
| Field | Meaning |
|---|---|
prep_dataset.split.split_model_path |
Local path to the all-MiniLM-L6-v2 sentence embedding model. |
train.save_dir |
Directory used to save trained LoRA adapters and masks. |
rank.rank_model_path |
Local path to the bge-reranker-v2-m3 reranker. |
Additional paths for base LLM checkpoints (e.g. llama3.2-1b-instruct,
llama3-8b-instruct) are read inside src/utils.py; update
them to point at your local model files.
FedMosaic is evaluated on four open-domain QA benchmarks: HotpotQA, 2WikiMultiHopQA, PopQA, and ComplexWebQuestions. You have two options.
tar -xzvf dataset.tar.gzThis produces a dataset/ directory with the pre-retrieved, augmented, and
silo-split data used in our experiments.
-
Set up BM25 retrieval over the DPR Wikipedia dump with Elasticsearch. Follow the instructions in retriever_elasticsearch/README.md to download
psgs_w100.tsv, install Elasticsearch 8.15.0, and build thewikiindex. -
Run the preparation pipeline. This downloads the raw QA datasets, performs BM25 retrieval, generates rewrites / pseudo-QA augmentations, and splits passages into non-IID silos via topic-conditioned Dirichlet sampling:
python main.py \ --mode prep_dataset \ --dataset hotpotqa \ --type bridge \ --augment_model llama3.2-1b-instructReplace
--datasetwith one ofhotpotqa,2wikimultihopqa,popqa, orcomplexwebquestions, and--typewith the corresponding question type (e.g.bridge/comparisonfor HotpotQA).
FedMosaic follows a two-stage pipeline.
Within each silo, documents are clustered by semantic similarity. A shared LoRA adapter is trained per cluster, after which document-specific binary masks are learned on top of the frozen cluster LoRA.
python main.py \
--mode offline \
--dataset hotpotqa \
--type bridge \
--model_name llama3.2-1b-instruct \
--augment_model llama3.2-1b-instructOutputs (cluster LoRAs and masks) are written to train.save_dir as
configured in config.yaml.
For each question, every silo retrieves its top-k passages; the reranker
then selects relevance-aligned, non-conflicting documents, whose corresponding
cluster LoRAs are merged into the frozen LLM together with the document-specific
masks for final generation.
python main.py \
--mode online \
--dataset hotpotqa \
--type bridge \
--model_name llama3.2-1b-instruct \
--augment_model llama3.2-1b-instruct \
--k 5Predictions and evaluation metrics are written to
output/fedmosaic/<dataset>/<type>/<model>/....
| Flag | Values |
|---|---|
--model_name |
llama3.2-1b-instruct, llama3-8b-instruct |
--augment_model |
llama3.2-1b-instruct (default) |
--dataset |
hotpotqa, popqa, 2wikimultihopqa, complexwebquestions |
--type |
dataset-specific question type (e.g. bridge, comparison, total) |
--mode |
prep_dataset, offline, online |
--k |
retrieval top-k per silo (online stage) |
Our retrieval pipeline builds on PRAG and the DPR Wikipedia dump. We thank the authors of these projects for releasing their code and data.
