Abstract
In this work, we propose DOUBLEDIPPER, a novel In-Context-Learning method that automatically generates few-shot examples for several QA tasks by recycling contexts. Specifically, given an input context (1-3k tokens) and a query, we generate additional query-output pairs from the given context as few-shot examples, while introducing the context only once. This ensures that the demonstrations are leveraging the same context as the target query while only adding a small number of tokens to the prompt. We further enhance each demonstration by instructing the model to explicitly identify the relevant paragraphs before the answer, which improves performance while providing fine-grained attribution to the answer source. We apply our method on multiple LLMs and obtain substantial improvements (+16 absolute points on average across models) on various QA datasets. Surprisingly, despite introducing only single-hop ICL examples, LLMs successfully generalize to multi-hop QA using our approach.
Introduction
Large Language Models (LLMs) are increasingly capable of handling massive context windows, yet they still suffer from the "lost-in-the-middle" phenomenon—the tendency to ignore information buried in the center of a long document. While In-Context Learning (ICL) with few-shot examples can help, it faces two major hurdles in production:
- Token Overhead: Traditional ICL requires prepending several example pairs, each with its own context. In long-context scenarios, this can double or triple the prompt size, leading to massive latency and cost.
- Data Scarcity: Finding high-quality, semantically similar demonstrations for every possible user query is a complex retrieval challenge.
The authors of DoubleDipper set out to solve these issues by making the input context work twice: once as the source of truth and once as the source of its own demonstrations.
Methodology
The DoubleDipper workflow consists of three main steps:
- Recycling: Instead of fetching external examples, the system randomly selects a few paragraphs (usually $k=3$) from the provided input context.
- Self-Generation: A small, efficient LLM (like Gemma 2B) is prompted to generate a simple question-answer pair for each selected paragraph.
- Structured Prompting: These generated pairs are inserted into the prompt as few-shot demonstrations. Crucially, they follow a specific format: Question → Evidence (Paragraph ID) → Answer.
Because the demonstrations use the same context already present in the prompt, the system only needs to add the questions and answers, resulting in a tiny token overhead (~5%) compared to traditional ICL. The "Evidence" step acts as a structured Chain-of-Thought, forcing the model to "lookup" the information before reasoning.
Experimental Evaluation
The researchers evaluated DoubleDipper across 12 different LLMs (including Gemini 1.5 Pro/Flash, GPT-4o-mini, Llama 3.1, and Mistral) using several challenging benchmarks:
- Lost-in-the-middle: Specifically designed to test positional bias in long documents.
- FLenQA: A benchmark for long-context reasoning involving transitive relations and logical rules.
- Multi-hop QA: Including HotpotQA, 2Wiki, and MuSiQue, which require connecting information across multiple different passages.
Results and Key Insights
DoubleDipper provided a substantial +16 absolute point improvement on average across all models and datasets compared to a vanilla zero-shot baseline. It consistently beat traditional ICL (using external examples) by an average of 9.5 points, proving that "recycled" context is more effective than "retrieved" context.
Key insights from the study include:
- In-Domain Advantage: The most relevant demonstrations for a specific document are found within that document itself. Recycling ensures the demonstrations perfectly match the style, vocabulary, and domain of the target task.
- Attribution as a Reasoning Bridge: Identifying relevant paragraphs is a major bottleneck for LLMs. By "teaching" the model to cite its sources through few-shot examples, the method effectively fixes the model's internal retrieval mechanism.
- Simple Examples, Complex Gains: Surprisingly, even though the self-generated demonstrations are simple, single-paragraph lookups, they successfully "prime" the model to perform much more complex multi-hop reasoning tasks.
- Flattening the U-Curve: As shown in the performance metrics, DoubleDipper significantly mitigates positional bias, making the model much more robust at finding information regardless of its location in the text.
Conclusion
While DoubleDipper shows impressive gains, there are areas for future exploration. The evaluation was limited to English and context lengths up to 4,000 tokens; future work is needed to see if the benefits hold for "ultra-long" contexts (100k+ tokens) or multilingual settings. Additionally, while token-efficient, the method requires an initial generation pass to create the demonstrations, which adds a small amount of "time-to-first-token" latency compared to a pure zero-shot approach. Nonetheless, DoubleDipper represents a significant step toward more efficient and reliable long-context LLM applications.
Summary updated