[Paper Review] Learning to Retrieve In-Context Examples for Large Language Models
The paper presents LLM-R, an iterative framework that learns dense retrievers to pick high-quality in-context examples for large language models by distilling from an LLM-informed reward model.
Large language models (LLMs) have demonstrated their ability to learn in-context, allowing them to perform various tasks based on a few input-output examples. However, the effectiveness of in-context learning is heavily reliant on the quality of the selected examples. In this paper, we propose a novel framework to iteratively train dense retrievers that can identify high-quality in-context examples for LLMs. Our framework initially trains a reward model based on LLM feedback to evaluate the quality of candidate examples, followed by knowledge distillation to train a bi-encoder based dense retriever. Our experiments on a suite of $30$ tasks demonstrate that our framework significantly enhances in-context learning performance. Furthermore, we show the generalization ability of our framework to unseen tasks during training. An in-depth analysis reveals that our model improves performance by retrieving examples with similar patterns, and the gains are consistent across LLMs of varying sizes. The code and data are available at https://github.com/microsoft/LMOps/tree/main/llm_retriever .
Motivation & Objective
- Motivate and analyze the sensitivity of LLMs to in-context examples and the need for quality-aware retrieval.
- Propose an iterative framework (LLM-R) that learns a dense retriever using LLM feedback.
- Demonstrate that LLM-R improves in-context learning across diverse tasks and LLM sizes.
- Show that retrieved examples tend to share input patterns or labels with the test case and generalize to unseen tasks.
Proposed method
- Initial candidate retrieval using BM25 from a pool of task mixtures.
- Rank candidates by the LLM's ground-truth log-likelihood given the test input and candidate.
- Train a cross-encoder reward model to score candidate quality using ground-truth labels and hard negatives.
- Use knowledge distillation to train a bi-encoder dense retriever to imitate the reward model via KL-divergence on hard negatives plus an InfoNCE contrastive loss.
- Iteratively retrain the dense retriever with newly retrieved positives/negatives to improve quality.

Experimental results
Research questions
- RQ1Can a learned dense retriever, guided by LLM feedback, outperform heuristic baselines in selecting in-context examples?
- RQ2Does iterative retraining with reward-model supervision improve ICL across multiple tasks and LLM sizes?
- RQ3How well does the approach generalize to unseen tasks and different LLMs?
- RQ4What factors (task type, data patterns, task difficulty) influence the effectiveness of retrieved in-context examples?
Key findings
- LLM-R consistently outperforms baselines (random, k-means, BM25, E5, SBERT, EPR) on 30 tasks, averaging 65.7 after 1 iteration and 66.5 after 2 iterations.
- Iterative training yields diminishing gains after two iterations, suggesting convergence.
- Reward-model-based distillation significantly contributes to performance compared to variants without a reward model.
- LLM-R generalizes to held-out tasks and to different LLMs (GPT-Neo-2.7B, LLaMA-13B, GPT-3.5-turbo), with notable gains especially for smaller LLMs.
- Top retrieved examples tend to share input patterns or same labels as the test, and knowledge-intensive tasks see smaller absolute gains.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.