IN THIS BREAKDOWN · 10 SECTIONS
You can read 23% of this breakdown.
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.
Research notes: the problem, approach and results
HuggingFace API accuracy, RAFT against domain-specific fine-tuning without retrieval
RAFT's margin over domain-specific fine-tuning on Torch Hub (84.95 against 84.94)
HotpotQA, RAFT 7B against GPT-3.5 with retrieval
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.
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.
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).
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.
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
- ◇1 architecture diagram
- </>1 runnable code experiment
- ▦1 results table
- ?5 interview questions with answers
- 03Key takeaways
The recipe's parameters, the main table, the ablations and the misreadings to avoid
Free account - 04How it works
Building the training rows, generating answers, the P and k choices, and test-time use
Premium - 05The numbers that matter
Gains by dataset and baseline, the chain-of-thought ablation, and the P and k studies
Premium - 06Try it yourself
Difference the paper's tables, then build RAFT rows and check which quotes the model can see
Premium - 07Where it breaks
Thin margins, format effects, the quote problem, missing details and inconsistencies
Premium - 08Using it on a deployment
Deciding whether to fine-tune for RAG, and building the data safely
Premium - 09Interview angles
Five questions this paper prepares you for, with answer hints
Premium - 10Read next
Where to go from here on this site
Premium
