GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
arXiv preprint

RAFT: Adapting Language Model to Domain Specific RAG

Fine-tune on questions paired with the right document plus distractors, with answers that quote the right one, so the model learns to read past bad retrieval. Strong on APIs; read the tables closely.

Breakdown by FDE Interviews · 10 min read · Updated

About the original · 2024
AUTHORS
Zhang, Patil, Jain, Shen, Zaharia, Stoica, Gonzalez
FROM
UC Berkeley
PUBLISHED
Mar 2024 · arXiv preprint
CITED BY
414Semantic Scholar · Oct 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 23% of this breakdown.

01

The paper in one minute

When a model will answer questions about a known set of documents (a company's manuals, an API's docs, a medical corpus), there are two usual choices. Retrieval-augmented generation leaves the model as it is and pastes retrieved passages into the prompt. Fine-tuning teaches the model the domain but usually trains on questions and answers without documents. Tianjun Zhang, Shishir Patil, Joseph Gonzalez and colleagues at UC Berkeley framed it as exam preparation: RAG is an open-book exam without studying, fine-tuning is studying for a closed-book exam. RAFT (Retrieval-Augmented Fine-Tuning) studies for the open-book exam.

Each training row has a question, a set of documents and an answer. Documents are either golden (the answer can be deduced from them) or distractors (they cannot). For a fraction P of questions, the context contains the golden document and k distractors (four in most experiments). For the remaining 1 − P, it contains only distractors. The target answer is the same in both cases: a chain-of-thought explanation, written by GPT-4, that quotes the golden document between ##begin_quote## and ##end_quote## markers and ends with the answer. Llama 2 7B is fine-tuned on these rows. At test time, it gets a question and retrieved documents, like any RAG system.

The authors give two reasons. Distractors teach the model to ignore irrelevant retrieved text, and rows without the golden document push it to learn domain knowledge rather than only reading. They evaluated on PubMedQA, HotpotQA and three API-call benchmarks from Gorilla (HuggingFace, Torch Hub, TensorFlow Hub), against the base Llama 2 chat model with and without retrieval, domain-specific fine-tuning (DSF) with and without retrieval, and GPT-3.5 with retrieval.

THE IDEA, VISUALLY
TRAINING ROWS P of rows question + golden doc + 4 distractors → quoted reasoning + answer 1 − P question + distractors only → the same quoted reasoning + answer Same target either way, so in the 1 − P rows the model learns to quote a document it cannot see. P was best at 40% to 100% depending on the dataset. A TARGET ANSWER (FIGURE 3, GPT-4 WRITTEN) Q: The Oberoi family is part of a hotel company that has a head office in what city? ##Reason: ... ##begin_quote## The Oberoi Group is a hotel company with its head office in Delhi. ##end_quote## establishes the head office ... ##Answer: Delhi Fine-tune Llama 2 7B on the rows. At test time: question plus retrieved documents, as in ordinary RAG. TABLE 1 PubMed HotPot HF Torch TF Llama2 7B + RAG 58.80 0.03 26.43 8.60 43.06 DSF 59.70 6.38 61.06 84.94 86.56 DSF + RAG 71.60 4.41 42.59 82.80 60.29 GPT-3.5 + RAG 71.60 41.50 29.08 60.21 65.59 RAFT 7B 73.30 35.28 74.00 84.95 86.86 RAFT − DSF: +13.6, +28.9, +12.9, +0.01, +0.30 RAFT − GPT-3.5 on HotPot: −6.2 CHAIN-OF-THOUGHT ABLATION (TABLE 2) PubMed 68.3 73.3 HotPot 25.62 35.28 HuggingFace 59.07 74.0 Torch Hub 86.56 84.95 TensorFlow 83.21 86.86 grey: without CoT; blue: with CoT Gains over the base model are mostly answer format: Llama 2 with RAG scored 0.03 on HotPot.
RAFT trains on the golden document mixed with distractors, and sometimes on distractors alone, with GPT-4-written answers that quote the golden text. It beat plain domain fine-tuning by wide margins on HotPot and HuggingFace, by 0.01 on Torch Hub, and trailed GPT-3.5 on HotPot. Chain-of-thought hurt on Torch Hub.
Research notes: the problem, approach and results
74.00 vs 61.06

HuggingFace API accuracy, RAFT against domain-specific fine-tuning without retrieval

+0.01

RAFT's margin over domain-specific fine-tuning on Torch Hub (84.95 against 84.94)

35.28 vs 41.5

HotpotQA, RAFT 7B against GPT-3.5 with retrieval

THE PROBLEM

To answer questions over a fixed set of documents, you can retrieve at test time (RAG) or fine-tune on the domain. RAG alone does not use the chance to study the domain; fine-tuning without documents does not prepare the model to read retrieved text, which is often wrong.

THE IDEA

Build fine-tuning rows from question, document and answer triples. For a fraction P of questions the context holds the golden document plus distractors; for the rest only distractors. The target is a chain-of-thought answer that quotes the golden document verbatim. Fine-tune Llama 2 7B; at test time, use normal retrieval.

THE RESULT

RAFT 7B scored 73.30 on PubMedQA, 35.28 on HotpotQA and 74.00, 84.95 and 86.86 on the Gorilla API benchmarks, above domain fine-tuning with or without retrieval on all five. The margins over domain fine-tuning ranged from 28.9 points (HotPot) to 0.01 (Torch Hub).

02

Why it matters to an FDE

Customers with a fixed corpus and a narrow task regularly ask whether to fine-tune or use RAG. RAFT is the most cited argument for doing both, and its recipe is easy to reproduce.

Train with the noise you will see. If production retrieval returns one useful passage among several useless ones, training examples should look like that. Models trained only on clean context learn to trust whatever is in front of them.

Answer format is half the win. The base Llama 2 scored 0.03 on HotpotQA with retrieval; fine-tuning on the domain's answer style alone took it to 6.38. Much of what any fine-tune buys is the right output format, which a good prompt or a stronger model can also buy.

Check that quotes are real. RAFT's targets quote the golden document. In rows where that document is absent, the target still quotes it, which teaches the model to produce quotations it cannot see. In production, verify every quotation against the retrieved text.

A strong general model may be enough. GPT-3.5 with retrieval beat RAFT 7B on HotpotQA. For general-knowledge questions the case for fine-tuning a small model is weaker than for specialized API documentation, where RAFT's margins were largest.

THE FULL BREAKDOWN

Understand the mechanism. Try it on a real problem.

Unlock this breakdown and 99 more papers.

Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.

6 months · One payment · No auto-renewal

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦1 results table
  • ?5 interview questions with answers
  1. 03Key takeaways

    The recipe's parameters, the main table, the ablations and the misreadings to avoid

    Free account
  2. 04How it works

    Building the training rows, generating answers, the P and k choices, and test-time use

    Premium
  3. 05The numbers that matter

    Gains by dataset and baseline, the chain-of-thought ablation, and the P and k studies

    Premium
  4. 06Try it yourself

    Difference the paper's tables, then build RAFT rows and check which quotes the model can see

    Premium
  5. 07Where it breaks

    Thin margins, format effects, the quote problem, missing details and inconsistencies

    Premium
  6. 08Using it on a deployment

    Deciding whether to fine-tune for RAG, and building the data safely

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →