Introduction
In-Context Learning (ICL) has become a cornerstone of Large Language Model (LLM) utility, allowing models to adapt to new tasks via a few-shot prompt. However, the effectiveness of ICL is highly sensitive to the specific demonstrations selected. Current retrieval strategies generally fall into two categories: similarity-based methods (e.g., BM25, TopK), which are computationally efficient but "model-blind," and uncertainty-based methods (e.g., ConE), which are "model-aware" but require expensive inference passes for every candidate example. Both approaches frequently suffer from informational redundancy, failing to address the specific knowledge gaps of the model.
The TopicK Framework
To address these limitations, we introduce TopicK, a framework that shifts the retrieval focus toward topic-level informational demands. TopicK identifies the specific topics required by a test input that the LLM likely lacks knowledge in, then retrieves demonstrations to fill those specific gaps.
Methodology
The TopicK process consists of three primary stages:
- Topical Knowledge Assessment: A global set of topics is mined from the candidate pool. A lightweight Topic Predictor (MLP) is trained to map text embeddings to topic distributions. Simultaneously, the LLM's inherent "Topical Knowledge" is estimated by measuring its zero-shot accuracy across these topics.
- Topic Coverage-based Retrieval: Demonstrations are selected iteratively based on a relevance score that prioritizes topics required by the test input, covered by the candidate, and currently "unknown" to the model (based on low zero-shot accuracy).
- Cumulative Coverage: The system tracks topics already covered by previously selected examples to ensure the next demonstration provides novel, non-redundant information.
Experimental Results
TopicK was evaluated across six diverse datasets, including general domains (CommonsenseQA, SciQ), natural language inference (QNLI, MNLI), and specialized domains (MedMCQA, Law), using Llama-3.2 and Qwen-2.5 model families.
Performance and Efficiency
TopicK consistently outperformed both similarity-based and uncertainty-based baselines across all benchmarks. A key advantage is its efficiency; by using a lightweight predictor instead of full LLM inference at retrieval time, TopicK achieves "model-awareness" with minimal overhead. For example, on the QNLI dataset, TopicK was 37x faster than the leading uncertainty-based method, ConE, while delivering higher accuracy.
Specialized Domains and Closed-Source Models
The framework showed particularly strong gains in specialized medical and legal domains (up to 6.38% improvement), where model knowledge gaps are more pronounced. Furthermore, TopicK remains effective for closed-source models (e.g., GPT-4o-mini) by using zero-shot accuracy as a proxy for internal knowledge states.
Conclusion and Future Work
TopicK demonstrates that the most effective demonstrations are those that provide information the model lacks, rather than those that are simply similar to the input. While currently utilizing a flat topic structure, future iterations may explore hierarchical taxonomies to further refine knowledge assessment. TopicK provides a scalable, efficient path toward optimizing ICL for both open and closed-source LLMs.
Summary updated