Introduction
In-Context Learning (ICL) has emerged as a transformative capability of Large Language Models (LLMs), allowing them to perform complex tasks by simply observing a few examples provided within the prompt. This "few-shot" approach requires no weight updates, making it highly flexible. However, ICL is notoriously brittle; performance often fluctuates significantly based on the specific examples chosen, their ordering, and even their formatting.
Traditionally, researchers relied on a static set of hand-picked or randomly selected demonstrations for every query. This approach is inherently limited, as a single set of examples cannot capture the nuances of every possible input. This survey explores the shift toward Retrieval-based ICL (RetICL), a dynamic paradigm where a specialized retriever model identifies the most relevant demonstrations from a large database for each specific query, significantly enhancing model performance and stability.
The RetICL Framework: Four Design Pillars
The survey provides a comprehensive taxonomy of the RetICL landscape, categorizing the field into four primary design pillars that determine how demonstrations are selected and utilized.
1. Retrieval Objectives
The primary goal of retrieval is to determine what makes an example "good." Most methods focus on similarity, seeking examples that match the query's semantic or structural properties. However, diversity is increasingly recognized as a vital objective. By selecting a diverse set of examples, the model can cover a broader range of the task's output space, preventing it from becoming stuck in repetitive patterns.
2. Inference Strategies
Once the objective is defined, the system must decide how to select the examples:
- One-hoc: The simplest method, retrieving the top-$k$ most similar examples in a single pass.
- Clustering: The database is grouped into clusters, and representatives are picked from different clusters to ensure variety.
- Iterative: Examples are selected sequentially; the second example is chosen based on its relationship to both the query and the first selected example, optimizing the set as a whole.
3. Retriever Models
Retrievers range from simple algorithms to complex neural networks:
- Off-the-shelf: Standard tools like BM25 (keyword matching) or SBERT (dense embeddings) are frequently used. Surprisingly, the survey notes that BM25 remains a remarkably strong baseline, often outperforming neural retrievers in tasks like semantic parsing.
- Fine-tuned: These models are trained specifically to select examples that maximize LLM performance, often using the LLM’s own feedback as a reward signal in a reinforcement learning framework.
4. Retrieval Corpus
The source of demonstrations is equally critical. While many systems use standard in-domain training sets, newer approaches utilize "free-form" corpora like Wikipedia or even synthetically generated examples created by the LLM itself to fill gaps in the available data.
Key Insights and Empirical Results
RetICL consistently outperforms static example selection across a wide array of benchmarks, including Natural Language Understanding (NLU), mathematical reasoning (GSM8K), and code generation (HumanEval).
Performance Gains
In Open-domain Question Answering (QA), using BM25 to retrieve examples can lead to a performance boost of over 10% compared to random selection. In more complex text generation tasks, such as Table-to-Text, retrieved demonstrations have shown improvements of 25-30%. While fine-tuned retrievers (such as the EPR model) represent the current state-of-the-art, they require more computational resources than off-the-shelf alternatives.
Reducing Brittleness
Beyond raw accuracy, one of the most significant advantages of RetICL is stability. By providing contextually relevant examples, the model becomes much less sensitive to the order in which those examples are presented. This mitigates one of the most common headaches in prompt engineering and makes LLM deployments more robust in production environments.
Future Frontiers
Despite the success of RetICL, several challenges remain for future research:
- Scaling to Small LMs: Most ICL research focuses on models with 100B+ parameters. Enhancing the retrieval capabilities of smaller, more efficient models is a priority for edge computing.
- Retrieval from Raw Text: Moving away from labeled input-output pairs toward generating demonstrations from raw, unlabeled text (like Wikipedia) would greatly expand the utility of RetICL.
- Active and Multimodal Retrieval: Developing systems that update their retrieval corpus in real-time and extending these strategies to Vision-Language models are the next logical steps for the field.
Conclusion
Retrieval-based In-Context Learning represents a significant evolution in how we interact with Large Language Models. By moving from static prompts to dynamic, query-aware context, RetICL addresses the inherent brittleness of few-shot learning and unlocks higher levels of performance across diverse and complex reasoning tasks.
Summary updated