Abstract: Large language models (LLMs) often struggle with knowledge intensive NLP tasks, such as answering "Who won the latest World Cup?" because the knowledge they learn during training may be insufficient or outdated. Conditioning generation on retrieved documents -- a technique known as retrieval augmented generation (RAG) -- mitigates these shortcomings by allowing the model to leverage in-context information. Practitioners can improve LLM RAG performance by fine-tuning on retrieval-augmented instructions, but must beware that this can cause undesirable model behaviors like hallucinations. We attribute this degradation to the fact that the training data is likely to be out-of-distribution for the model and may suffer from quality issues, such as misalignment between retrievals and target responses (since retrievals are frequently added post-hoc). We propose a recipe for training RAG-enabled LLMs using self-generated demonstrations, thereby avoiding training on out-of-distribution text and integrating retrievals into the LLM responses. We evaluate our method on knowledge intensive question answering (QA) tasks and show that our method teaches LLMs to properly handle in-context retrievals and abstain from questions it will likely get wrong. Compared to conventional RA-IT methods, our method prevents model degradation in non-RAG settings while exhibiting superior QA performance.
Introduction
Retrieval-Augmented Generation (RAG) has become the industry standard for grounding Large Language Models (LLMs) in up-to-date, external knowledge. However, simply providing a model with context at inference time is often insufficient. To truly excel, models require fine-tuning on retrieval-augmented instructions (RA-IT).
A critical challenge in standard RA-IT is the "distributional mismatch" between the model's internal knowledge and the external "gold" labels used for training. When a training example forces a model to generate a fact it doesn't naturally "know" or in a style it doesn't naturally use, it encourages the model to ignore context or, worse, hallucinate. These gold responses are often out-of-distribution (OOD) for the model, leading to performance degradation in both RAG and non-RAG settings.
Methodology: SD-RA-IT
To address this, we introduce Self-Demo Retrieval-Augmented Instruction Tuning (SD-RA-IT). Instead of training on external labels, we use a "generate-then-filter" recipe to create a training set that is inherently in-distribution for the model.
The process consists of four main stages:
- Automatic Prompt Generation: We utilize an iterative optimizer to discover system prompts that best encourage the model to utilize retrieved context correctly.
- Self-Generation: The model generates multiple candidate responses for a set of instructions and retrieved documents using the optimized prompts.
- Filtering (The "Self-Demo"): An "LLM-as-a-judge" (typically a larger model from the same family) evaluates these candidates against ground-truth answers. If a candidate is both correct and faithful to the context, it is selected as a self-generated demonstration. If the model correctly identifies that the answer is missing from the context, it generates a self-refusal.
- Post-Training: The model is fine-tuned on these self-demos using either Supervised Fine-Tuning (SFT) or Direct Preference Optimization (DPO).
Experimental Setup
We evaluated our method using the Llama-3-8B and Llama-3-70B model families. The training data was a 10/90 mix of dialogue and general tasks (QA, reasoning, summarization) with retrievals sourced from Wikipedia and CommonCrawl. Evaluation spanned a battery of knowledge-intensive benchmarks, including NQ (Natural Questions), TriviaQA, HotPotQA, FEVER, and MMLU.
Key Results and Insights
Superior Precision and Context Integration
SD-RA-IT consistently outperformed standard RA-IT across benchmarks. For the Llama-3-8B model, our method achieved an F1 score of 81.3, compared to 79.6 for the baseline. The models demonstrated a significantly improved ability to extract correct answers from retrieved snippets, even as the number of snippets increased beyond the training distribution.
Robustness to Zero-Shot RAG
A major drawback of standard RA-IT is that it often degrades the model's performance on "normal" tasks where no documents are provided. While standard RA-IT precision plummeted from ~70% to ~44% in zero-shot settings, SD-RA-IT remained stable, preserving the model's original general-purpose capabilities.
The Power of Abstention
By including self-generated refusals in the training set, SD-RA-IT teaches the model when to stay silent. This significantly reduces hallucinations by helping the model identify when the retrieved context is insufficient to answer the prompt.
Conclusion
SD-RA-IT offers a robust recipe for RAG post-training by aligning the training data with the model's natural distribution. By training on its own successful attempts, the model learns to bridge the gap between internal knowledge and external context without falling into the trap of hallucination. Future work will explore the precision-recall trade-off in model "bravery" and extend these methods to more complex RAG tasks like long-form synthesis and multi-step reasoning.
Summary updated