Universal Demonstration Retrieval for In-Context Learning

This direction is no longer present in the current build. Its last version stays readable and citable here.

Version 1 of 126 papers27 conceptsfrozen 2026-10-04

In-context learning (ICL) allows Large Language Models (LLMs) to solve new tasks simply by seeing a few examples (demonstrations) in their prompt. However, the performance of ICL is notoriously sensitive: choosing the "wrong" examples can lead to poor accuracy or even model hallucinations.

Traditionally, researchers used simple semantic similarity—finding examples that look like the input—to build these prompts. A growing body of research now suggests a more powerful approach: training specialized retrievers to identify examples based on the internal preferences of the LLM itself. Crucially, these preferences appear to be universal, meaning a retriever trained on one model's feedback often works perfectly for another.

Moving Beyond Semantic Similarity

The intuition behind early ICL was that similar inputs should yield similar outputs. If you want a model to translate a sentence about a cat, you show it other sentences about cats. However, Nan Yang and colleagues found that "most similar" does not equal "most informative." An example might be semantically related but provide no structural guidance on how the model should format its response.

To solve this, researchers developed LLM-Aware Retrieval. Instead of using a static distance metric, they use the LLM as a judge. In the LLM-R framework, Nan Yang uses the model's own log-probabilities to measure how much a specific example helps it predict the correct answer. Similarly, Ge Li introduced LAIL, which trains a retriever to find "preferred" examples that maximize the model's likelihood of generating correct code.

Learning from Preferences

If we treat example selection as a ranking problem, we can apply the same techniques used to align LLMs with human values. Yuwen Ji introduced SeDPO, which applies Direct Preference Optimization (DPO) to retrieval. Instead of just labeling examples as "good" or "bad," SeDPO teaches the retriever the relative utility of examples—learning that Example A is slightly more helpful than Example B for a specific query.

Other researchers have framed this as a reinforcement learning problem. Haowei Du and Dongyan Zhao developed RLS, using policy-based reinforcement learning to pick examples for utterance rewriting. By receiving direct feedback from the LLM on the quality of the final output, the retriever learns to prioritize "informative" examples over merely "similar" ones.

The Power of Composition and Diversity

Selecting the best individual examples is only half the battle; the set of examples must work together. If you provide three examples that all demonstrate the same edge case, you waste the model's context window.

Jiacheng Ye addressed this with CEIL, which uses Determinantal Point Processes (DPPs). This mathematical framework ensures that the selected examples are not only relevant but also diverse and non-redundant. By selecting a "compositional" set, the prompt covers a broader range of the task's logic. Yang Zhao further optimized this with a two-stage DPP approach that achieves the performance of per-instance retrieval while cutting token costs by 90%, making high-quality ICL viable for high-throughput applications.

The Universal Utility of Demonstrations

Perhaps the most surprising and significant finding across this research is cross-model transferability.

Evidence from Xiaonan Li (UDR) and Zheng Zhang (GENICL) shows that a retriever trained on the feedback of a small, efficient model (like a 7B parameter model) works remarkably well for much larger models (like GPT-4). This suggests that "informativeness" is an inherent property of the data relative to the task, rather than a quirk of a specific model's weights.

This universality has three major implications:

  1. Efficiency: We can train retrievers using cheap, small models and "zero-shot" transfer them to expensive, proprietary ones.
  2. Generalization: A single "Unified Demonstration Retriever" (Xiaonan Li) can be trained once and used across dozens of different NLP tasks and model architectures.
  3. Stability: As shown by Ting-Yun Chang and Robin Jia, high-quality data curation alone can stabilize ICL, making it robust across different prompt formats and model scales.

By shifting the focus from "finding similar text" to "optimizing for model preference," this research direction provides a scalable, principled way to unlock the full potential of few-shot learning.

Papers in this version

History & citationVersion 1 · 2026-10-04

No longer present in the current build · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_universal_demonstration_retrieval_for_in_18e1d1c6,
  title = {Universal Demonstration Retrieval for In-Context Learning},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/universal-demonstration-retrieval-for-in-context-learning/rdr_18e1d1c633284d86aeee1c1bf165d114},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-26},
}

This exact version (version 1, frozen text):

@misc{lacuna_universal_demonstration_retrieval_for_in_18e1d1c6_v1,
  title = {Universal Demonstration Retrieval for In-Context Learning},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/universal-demonstration-retrieval-for-in-context-learning/rdr_18e1d1c633284d86aeee1c1bf165d114/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-26},
}