Standard domain fine-tuning often gets worse when you plug it into a retriever at test time: on Gorilla HuggingFace Hub, adding RAG to a domain-finetuned Llama-2-7B drops accuracy from 61.06% to 42.59%. Tianjun Zhang, Shishir Patil, Matei Zaharia, Ion Stoica, Joseph Gonzalez, and colleagues at UC Berkeley introduced RAFT (Retrieval Augmented Fine Tuning) to fix that failure by training the model inside noisy retrieved contexts, lifting HuggingFace Hub accuracy to 74.00% (+31.41 points over DSF + RAG) and HotpotQA from 4.41% to 35.28%.

  • 74.00% on Gorilla HuggingFace Hub with RAFT (Llama-2-7B), beating DSF + RAG (42.59%) by 31.41 points and GPT-3.5 + RAG (29.08%) by 44.92 points.
  • 35.28% on HotpotQA, gaining 35.25 points over base Llama-2-7B + RAG (0.03%) and 30.87 points over DSF + RAG (4.41%).
  • 84.95% on Torch Hub and 86.86% on TensorFlow Hub, beating GPT-3.5 + RAG by 24.74 and 21.27 points while outperforming PubMedQA baselines at 73.30%.
  • Up to 14.93-point drop without reasoning: removing Chain-of-Thought citations cuts HuggingFace from 74.00% to 59.07% and HotpotQA from 35.28% to 25.62%.
  • 100% golden context during training is suboptimal: dropping the answer passage from a fraction (1 - P)% of training rows improves robustness to imperfect retrieval.
Accuracy across in-domain RAG benchmarks with Llama-2-7B vs. GPT-3.5 (higher is better)
Gorilla HuggingFace Hub (API generation)
RAFT (Llama-2-7B)74.00%
DSF (0-shot, no RAG)61.06%
DSF + RAG42.59%
GPT-3.5 + RAG29.08%
Llama-2-7B + RAG26.43%
HotpotQA (multi-hop Wikipedia QA)
GPT-3.5 + RAG41.50%
RAFT (Llama-2-7B)35.28%
DSF (0-shot, no RAG)6.38%
DSF + RAG4.41%

Source: Zhang et al. (2024), Table 1. PubMedQA and Gorilla Torch/TensorFlow Hub show the same pattern, with RAFT reaching 73.30%, 84.95%, and 86.86%.

How RAFT prepares for an open-book exam

The authors frame specialized deployment as a domain-specific open-book exam: you already know the enterprise repo, legal corpus, or medical archive the model will be tested on, and at inference time a retriever passes top-k chunks into the prompt. Standard RAG takes the exam without studying the domain’s structure or style. Standard domain-specific fine-tuning (DSF) studies closed-book (Q -> A without retrieved context), so when top-k chunks arrive at test time, the fine-tuned model gets distracted by irrelevant passages, a weakness well documented in long-context distraction studies.

RAFT constructs supervised training rows that mimic messy retrieval directly. Each training example pairs question Q with a set of documents (one golden document D* plus four distractors D1..D4 in the main experiments) and trains the model to emit a structured Chain-of-Thought answer A* generated by GPT-4-1106. Crucially, A* wraps exact verbatim spans from D* inside ##begin_quote## and ##end_quote## markers under ##Reason: before stating ##Answer:.

Two design levers govern how the recipe generalizes:

RAFT training mixture vs. standard SFT
Standard DSF
100% Q -> A

Learns domain style, but breaks when noisy top-k documents appear at inference.

RAFT golden mix (P%)
Q + D* + D_k-1 -> A*

Teaches the model to spot the gold doc among distractors and quote verbatim evidence.

RAFT fallback (1 - P)%
Q + D_k -> A* (no D*)

Forces memorization of core domain facts so missed retrieval does not derail the answer.

Source: Zhang et al. (2024), Section 3.

Key findings and ablations

Across all five datasets in Table 1, RAFT matches or exceeds both DSF and RAG baselines on Llama-2-7B. On Torch Hub and TensorFlow Hub, DSF alone reaches 84.94% and 86.56%, yet pairing DSF with RAG drops accuracy to 82.80% and 60.29% because naive fine-tuning treats distractors as authoritative context. RAFT absorbs the context without degrading, reaching 84.95% and 86.86%, and on multi-hop HotpotQA it bridges the gap between DSF + RAG (4.41%) and RAFT (35.28%).

Ablations explain which pieces carry the gain:

  • Verbatim Chain-of-Thought stops shortcut overfitting: Training on direct answers without reasoning (RAFT w.o CoT) drops HotpotQA by 9.66 points (35.28% to 25.62%), HuggingFace by 14.93 points (74.00% to 59.07%), PubMedQA from 73.30% to 68.30%, and TensorFlow from 86.86% to 83.21%, with only Torch Hub ticking slightly higher without CoT (86.56% vs. 84.95%).
  • Mixing in distractor-only rows (P < 100%) helps: Sweeping P from 0% to 100% across Natural Questions, TriviaQA, and HotpotQA shows optimal P ranges across 40%, 60%, and 100%, with P = 80% often outperforming always supplying the golden passage.
  • Training with distractors generalizes across test-time k: When sweeping top-k test documents from 2 to 10, models trained only on D* degrade quickly, whereas training with 2 to 4 total documents (D* + 1D on HotpotQA, 3 docs on TriviaQA, D* + 3D on NQ) keeps accuracy stable across varying k.

Caveats and builder takeaway

  • Built for fixed, known corpora: RAFT assumes the test documents come from the same domain seen during fine-tuning. It is not a zero-shot recipe for arbitrary unseen corpora, and fine-tuned models can still overfit to dataset formatting quirks.
  • Synthetic teacher cost and dataset ceiling: Generating ##Reason: traces with verbatim quotes required calling GPT-4-1106 over the training set (outside Gorilla APIBench, which already included reasoning). Even after fine-tuning, RAFT-7B trails GPT-3.5 + RAG on general-knowledge multi-hop HotpotQA (35.28% vs. 41.5%) and yields small gains on binary yes/no tasks like PubMedQA (73.30% vs. 71.6% for DSF + RAG).

If your RAG system serves a stable, specialized corpus (internal APIs, developer docs, compliance rules) and a stronger retriever like ColBERTv2 still sends noisy top-k chunks, RAFT turns a 7B model into a grounded reader. Just audit retrieval and generation separately with tools like Ragas and citation checks whenever the document collection or retriever changes.