Manuscript Offprint
arXiv:2610.05717Retrieval-Based In-Context Learning: A Domain Adaptation Framework
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
In-context retrieval (ICR) is a retrieval-based form of in-context learning (ICL) in which demonstrations are retrieved from a source database based on similarity to the query, rather than sampled independently. In this work, we formulate ICR as a type of domain adaptation problem, where the source distribution P of the database may differ from the target distribution Q of the test query-label pair. We investigate the performance of ICR under a flexible class of distributional shifts that substantially extends prior work [Li et al., 2024b, Guo et al., 2025], and establish theoretical guarantees that quantify the benefits and pitfalls of this learning paradigm. Our theory is verified by experiments on synthetic and language tasks.
1 Introduction
In-context learning (ICL) is the ability of a pretrained model to predict the label of a query point using input-output demonstrations provided in its context, without updating the model's parameters. In most theoretical models of ICL, these demonstrations are modeled as i.i.d. draws from the same distribution that governs the query-label pair [Garg et al., 2022, Guo et al., 2024]. Throughout this paper, ICL refers to this standard setting with i.i.d. demonstrations.
In this work, we consider retrieval-based ICL, in which the input-output demonstrations are selected as a function of the query point. In particular, given access to a large database of demonstrations, a retrieval algorithm selects examples whose feature representations are similar to that of the query point. It has been observed empirically that such retrieved demonstrations can substantially improve performance over randomly sampled demonstrations [Liu et al., 2022, Rubin et al., 2022, Izacard et al., 2023, Huang et al., 2024]. Following recent work, we refer to this setting as in-context retrieval (ICR) [Luo et al., 2024, Guo et al., 2025].
Prior work has begun to explain the benefits of ICR theoretically, but several important regimes remain unexplored. In particular, existing statistical models [Li et al., 2024b, Guo et al., 2025] are restricted to linear-Gaussian settings. Moreover, while these models allow the retrieved demonstrations and the query-label pair to be governed by different marginal distributions, the regression function remains the same: in other words, they model covariate shift, but not a posterior drift that changes the optimal predictor.
We introduce a nonparametric statistical framework for binary classification that casts ICR as a domain adaptation problem admitting both covariate shift and posterior drift. The source domain governs the corpus of demonstrations, the target domain governs the query-label pair, and the predictor operates on a query-dependent subset of retrieved source examples. Throughout, we treat the pretrained model as frozen and study the statistical effect of the demonstrations selected for its context, abstracting away from transformer-level mechanisms for implementing in-context learning.
Within this framework, we characterize the performance of ICR in terms of four key quantities: the context size n, the corpus size m, the degree of posterior drift, and distributional properties of the domains (in particular, the smoothness of the class posterior). Under a nearest-neighbor model of retrieval and prediction,
*University of Michigan. allanzhu@umich.edu
University of Michigan. dnaihao@umich.edu
New Jersey Institute of Technology. yingcong.li@njit.edu
Northwestern University. naichen.shi@northwestern.edu
University of Michigan. clayscot@umich.edu we establish a finite- excess risk bound for ICR. This bound yields two main conclusions. First, the benefit of retrieval: given a sufficiently large corpus size , the ICR bound decays faster in than the ICL rate. Second, the price of posterior drift: when the source and target posteriors disagree, the ICR excess risk contains an irreducible bias that no learning rule with access only to the source corpus can avoid. Consequently, ICR can be asymptotically inconsistent, whereas ICL remains consistent.
Thus, ICR is preferable under a few-shot regime (small n) with a sufficiently large corpus and limited posterior drift; otherwise, using i.i.d. target demonstrations is the safer choice. We support these findings with experiments on synthetic data and a sentiment-analysis task with annotator disagreement.
Retrieval-augmented generation. Retrieval-augmented generation (RAG) has become a central paradigm for enriching language models with external knowledge by conditioning generation on retrieved text [Lewis et al., 2020, Izacard and Grave, 2021, Borgeaud et al., 2022, Es et al., 2024, Gupta et al., 2024], and has seen a wide range of applications beyond language-specific tasks [Chen et al., 2025]. Recent work has improved many components of RAG systems [Chen et al., 2024, Liu et al., 2024, Xu et al., 2024, Asai et al., 2024, Li et al., 2024a, Xiang et al., 2026]. Most of the literature on RAG is empirical and method-driven. In this work, we provide theoretical insight into RAG by analyzing ICR, where query-dependent in-context demonstrations are retrieved.
In-context retrieval. The basic motivation for in-context retrieval (ICR) is that the empirical performance of ICL depends heavily on the choice of in-context examples [Liu et al., 2022]. In particular, retrieval-based prompt selection has been shown to outperform randomly sampled demonstrations [Rubin et al., 2022]. This idea has been broadly validated across a range of settings [Luo et al., 2024], including in-domain labeled data [Izacard et al., 2023, Huang et al., 2024, Ye et al., 2023], cross-domain or cross-lingual retrieval [Cheng et al., 2023, Shi et al., 2022], and LLM-generated demonstrations [Zhang et al., 2023, Li and Qiu, 2023].
Most prior work on ICR is empirical, with limited theoretical understanding of when and why retrieval helps. Two recent works begin to fill this gap: Li et al. [2024b] model demonstrations whose features are -correlated with the query and show that higher correlation yields improved ICR performance, while Guo et al. [2025] analyze the covariate shift between i.i.d. training-time demonstrations and retrieved test-time demonstrations. Both works study linear-regression settings where source and target share the same regression function. In this work, in contrast, we develop a nonparametric framework for binary classification that admits general domain shift and characterizes when retrieval helps versus hurts.
Additional connections to the literature are made below, including to domain adaptation theory.
3 A statistical framework for in-context retrieval
This section develops the statistical models underlying our analysis. We cast standard in-context learning as conventional classification, and in-context retrieval as domain adaptation with a retrieval-based learner. We then revisit the two closest prior theory works [Li et al., 2024b, Guo et al., 2025] within this general framework.
3.1 ICL as conventional classification
We begin by recalling the standard statistical learning setup for binary classification, with feature space and label space . Let be a probability distribution on , referred to as a domain. The -marginal is denoted by and the class posterior distribution is fully characterized by the posterior probability function (or posterior)
A classifier is a function , whose risk (with respect to ) is
A Bayes classifier is one that minimizes , and the canonical Bayes classifier is
The excess risk of is , where is the Bayes risk.
A learner is a function that takes as input a query point and labeled training data and outputs a label. For fixed , the map is a conventional classifier: the classifier induced by . The performance of the learner is measured by the expected excess risk
where indicates that .
Assuming a frozen, pretrained model, we view standard ICL as conventional classification where the learner is the frozen model and the training data are the in-context demonstrations. Throughout, the domain governing the query and the ICL demonstrations is called the target domain and denoted Q, and we denote the test query-label pair by ; the data-generation process of ICL is:
Demonstrations: , ,
Query-label: , independent of .
In particular, the performance of is measured by Equation (1) with , and we write for the expected excess risk of ICL.
3.2 ICR as retrieval-based domain adaptation
Domain adaptation is a variation on standard classification in which there are two probability distributions and on , referred to as the source and target domains. In domain adaptation, the training data come from , but the test points follow . A learner is still a function , but now its performance is measured with respect to
In our setting, the target domain Q governs the test query-label pair , while P governs the source corpus from which demonstrations are retrieved.
A domain shift occurs when . We focus on two particular types of domain shift, which can be expressed in terms of the feature marginals and and class posterior distributions and of the source and target. In covariate shift, [Sugiyama et al., 2007], while in posterior drift, [Scott, 2019, Cai and Wei, 2021, Maity et al., 2024, Zhu et al., 2024, Kirev et al., 2025]. These two types of domain shift may co-occur.
Note that posterior drift is similar to the notion of concept drift, although a concept typically connotes a deterministic classifier. The term conditional shift has also been applied, although we find posterior drift more descriptive.
We view ICR as domain adaptation with a retrieval-based learner. Given , an -retriever is a function that takes as input a query point and a source corpus of demonstrations , and selects the demonstrations in whose feature vectors are most similar to (e.g., in distance). A retrieval-based learner is then a function of the form
where is any conventional learner as described above. Note that for a fixed corpus , the map is the classifier induced by the corpus, analogous to above. Although the corpus has size , this classifier uses only demonstrations as context for any given query. In summary, the data-generation process of ICR is:
Source corpus: , ,
Query-label: , independent of ,
Retrieve: .
A retrieval-based learner is itself a learner, but its “training data” is the source corpus rather than . Its expected excess risk therefore integrates out :
In summary, ICL and ICR differ in where the demonstrations come from (Q versus P) and how they are selected (i.i.d. sampling versus retrieval). Figure 1 contrasts the two learning paradigms of ICL and ICR.
ICL
randomly sample
&
draw query
predict
ICR
draw query
retrieve
predict
Figure 1: Standard ICL vs ICR.
3.3 Connections to prior ICR and domain adaptation theory
The two prior theoretical works on ICR most closely related to ours are Li et al. [2024b] and Guo et al. [2025]. However, both consider Gaussian linear regression ( ) as their data model, whereas our analysis targets binary classification ( ). Despite the difference in statistical model, each can be situated within our framework.
Li et al. [2024b]. Their data model is Gaussian linear regression with a single latent weight vector w shared between the query and all demonstrations:
where controls retrieval similarity and 's are random noise. In our language: (i.e. and ). Marginalizing over gives , and the posterior is the same: . Thus ; so their model captures the effect of retrieval, but not a domain shift.
Guo et al. [2025]. They also use a Gaussian linear model with a shared latent weight vector, but focus on the covariate shift induced by retrieval offsets:
where is the retrieval residual and 's are random noise. In our language: , while the marginal of is shifted by , so in general. Nevertheless, the regression function is again shared, under both and ; the retrieved labels may carry a different noise variance, which leaves the optimal predictor unchanged. The effect they study is therefore covariate shift ( ) together with label noise, not a change in the optimal predictor.
Limitations of prior ICR theory. Although both papers study ICR, they focus primarily on the relevance between the features and , and assume that demonstrations and query share the same regression function. In domain adaptation terms, there is no posterior drift between and that alters the optimal predictor. In practice, however, the source corpus may come from a different distribution with (where ). In addition, both papers adopt isotropic Gaussian models for and , whereas our focus is on more general nonparametric classification setting.
Relation to existing domain adaptation theory. The primary technical tool we use to model domain adaptation is the notion of relative signal strength (RSS) introduced by Zhu et al. [2024]. RSS extends the prior model of Cai and Wei [2021] by allowing the source and target Bayes classifiers to differ on a set of positive measure. Similarly, Fan et al. [2025] quantify source unreliability through an ambiguity level that weights the target mass of unreliable regions by the target margin. As seen below in Lemma 1, integrating the pointwise risk inequality implied by RSS gives a risk-level inequality in the spirit of the transfer exponent of Hanneke and Kpotufe [2019] and the modulus of transfer of Hanneke and Kpotufe [2025]. The RSS-based framework differs substantially from discrepancy-based approaches to domain adaptation [Ben-David et al., 2006, Mansour et al., 2009], which characterize domain relatedness through global distributional discrepancies rather than pointwise relationships between the source and target posteriors. Finally, none of the aforementioned works consider retrieval-based learners, the defining feature of ICR.
4 Performance guarantee for in-context retrieval
Our analysis proceeds in two steps. First, we convert the target-domain excess risk to a source-domain excess risk and establish a lower bound showing that the bias induced by posterior drift is unavoidable; these results are independent of any particular learning algorithm. Second, we derive rates of convergence for a nearest-neighbor type retrieval-based learner for ICR, and contrast with the rates of a comparable nearest-neighbor learner for ICL.
4.1 Relative signal strength and CSPD
The central challenge of ICR is that retrieved demonstrations come from P, whose posterior may differ from the target . We quantify this mismatch via the concept of relative signal strength of Zhu et al. [2024].
Definition 1 (Relative Signal Strength (RSS)) For domains P and Q, define the relative signal strength at as
On , we use the convention whenever .
For , define the high-RSS region .
is a subset of the feature space where source data is reliable for predicting target labels; larger means greater reliability. If , i.e., source and target favor opposite labels, then , so for every . Outside the support of , the RSS is defined to be zero. This is a natural convention in the context of ICR, where a large, diverse source database may cover regions beyond the target domain.
We combine RSS with a covariate shift assumption:
for some . A sufficient condition for this to hold is that both P and Q have Lebesgue densities that are bounded above and below, and the support of the source distribution covers that of the target.
Definition 2 (CSPD distribution class) For , , and , let
We refer to as the Covariate Shift with Posterior Drift (CSPD) distribution class.
Here upper-bounds the target mass of the low-RSS region (where source labels may be unreliable); is the RSS threshold; bounds the covariate shift between and . In particular, implies .
The following lemma relates the target excess risk to the source excess risk.
Lemma 1 (Risk transfer) If , then for any classifier ,
The full proof is in Appendix B.1. Lemma 1 shows that the target excess risk is controlled by the source excess risk, up to a factor and an additive error . This fundamental reduction allows us to bound the expected risk of ICR in terms of the P-excess risk of the learner:
We next show that an error proportional to is unavoidable under posterior drift.
Proposition 1 (Lower bound for ICR) For any , , , and any learning rule that observes a corpus and produces a classifier ,
Full proof in Appendix B.5. Proposition 1 establishes the cost of posterior drift: the additive bias cannot be removed by any learning rule operating on the source corpus. The next subsection turns to the benefit of retrieval, showing that it allows the source-side excess risk to decay faster with respect to the context size n.
4.2 Finite sample analysis of ICR
The results of the previous subsection are learner-agnostic: Lemma 1 holds for any classifier, and Proposition 1 for any learner. To get a precise finite-sample analysis, we must further specify (1) distributional assumptions on and (2) the functional form of the in-context learner. For the latter, we adopt a nearest-neighbor majority-vote model, for two reasons. First, predictions are formed directly from the demonstrations in the context without parameter updates, and transformer architectures are sufficiently expressive to emulate nearest-neighbor prediction [Li et al., 2024c, Agarwal et al., 2024]. Second, nearest-neighbor prediction mirrors the structure of ICR itself: it is precisely a “retrieve-then-vote” procedure, making it a natural theoretical model for retrieval-based prediction.
Let denote the label of the -th nearest neighbor of in dataset , where distances are measured by the metric on . Recall that for ICL, contains i.i.d. demonstrations from the target; and for ICR, is retrieved from a source corpus . We define the corresponding learners as follows.
ICL learner:
ICR learner:
Specifically, the ICL learner applies a k-nearest-neighbor majority vote among , with the rate-optimal choice [Chaudhuri and Dasgupta, 2014]. The ICR learner instead averages over all n demonstrations: the retriever has already selected the n corpus examples closest to .
We now bound the excess risks of both learners under distributional assumptions on P and Q, and combine with Lemma 1 to obtain the ICL and ICR rates.
Assumptions on the target Q. We impose the following conditions on Q.
• -smoothness: for some ,
for all and , where , and and are the closed and open balls of radius around point .
• -margin condition: for some and ,
The -smoothness condition [Chaudhuri and Dasgupta, 2014] characterizes how fast varies over local neighborhoods, with the variation controlled by the probability mass . The larger the , the smoother. It generalizes the Hölder smoothness condition: if is -Hölder continuous and has a density bounded below on a bounded support with regular boundary (e.g., a cube), then is -smooth for some constant [Chaudhuri and Dasgupta, 2014]. The -margin condition [Audibert and Tsybakov, 2007] controls how much probability mass lies near the decision boundary , with larger implying a smaller ambiguous region and hence an easier classification problem.
Assumption on the source P. For the finite-corpus analysis, we further assume is -smooth.
The following lemma derives the margin condition on source distribution P from the RSS condition.
Lemma 2 (Margin transfer via RSS) If and satisfies the -margin condition with constant , then
where is the high-RSS region.
The full proof is in Appendix B.2. We now state the main result: excess risk bounds of ICL and ICR.
Theorem 1 (Excess risks of ICL and ICR) Suppose satisfies -smoothness and the -margin condition with constant . Then ,
(i) The ICL excess risk satisfies
(ii) If additionally and satisfies -smoothness, then and ,
In particular, in the large-corpus regime where
then
Here , , , and .
This is the main result of the paper; full proofs are deferred to Appendices B.3 and B.4. It shows a fundamental bias-variance trade-off: provided the source corpus is sufficiently large, the ICR bound decays strictly faster in n than the ICL bound, but under posterior drift ICR suffers an irreducible bias ; ICL is consistent but converges at a slower rate.
Comparison of ICL and ICR rates. The two rates in Theorem 1 reflect a trade-off between sample efficiency and label correctness. In ICL, the labels are drawn from the correct posterior , but only demonstrations near the query are informative, so the vote uses just the nearest ones. In ICR, the retriever selects from a corpus of size , so all demonstrations in the context are close to the query and all labels are used in the vote, yielding the faster rate. The price is that these labels are drawn from the source posterior rather than , and the irreducible bias quantifies how wrong that posterior may be. The following special cases make the effect of domain shift transparent; throughout, suppose and .
• No shift , hence , ):
This isolates the statistical benefit of retrieval: ICR converges faster than the ICL rate for every . The advantage is most pronounced for non-smooth : the ICL exponent approaches zero as , whereas the ICR exponent is independent of .
• Covariate shift only :
Here, ICR is consistent and converges faster than ICL; covariate shift only inflates the constant.
• Posterior drift only :
The -related term retains the faster decay, but posterior drift introduces an additive error and a factor in the constant.
5 Experiments
Our synthetic experiments validate each component of the theory: (i) with no domain shift, ICR converges faster in than ICL (ii) under posterior drift, ICR incurs a bias growing with (iii) ICL degrades as the target posterior becomes rougher, as quantified by , while ICR is insensitive to (iv) the ICR error saturates once the corpus size exceeds .
We then test the effect of posterior drift on a real-world, sentiment classification task with annotator disagreement. Full setups and detailed results are in Appendix C.
5.1 Synthetic experiments
Setup. Our experiments use the one-dimensional Weierstrass family (see Appendix C.2): and , where is a truncated Weierstrass series whose roughness is controlled by ( represents the Hölder exponent as the truncation level ). This construction varies the smoothness while holding the margin exponent, the Bayes risk ( ), and the Bayes classifier fixed. Unless stated otherwise, , the retrieval corpus has points, and each point on the figure is the mean over 5 seeds. Posterior drift is induced by flipping the source posterior, , on a region with .
We compare two learners: TabPFN [Hollmann et al., 2025], a tabular foundation model that predicts from in-context demonstrations, and the k-NN style learners for ICL/ICR defined in Section 4.2.
Experiment 1: convergence in n (Figure 2). With P = Q and a large corpus, ICR outperforms ICL at every n, and on log-log axes the ICR curves decay visibly faster, consistent with the rate comparison of Theorem 1. TabPFN and k-NN track each other closely, supporting nearest-neighbor estimators as a reasonable model of the actual ICL/ICR learner.

Figure 2: Target excess risk vs. context size ( , , ).

Figure 3: Target excess risk vs. posterior drift ( , , ). ICL (blue) is flat; the ICR error (orange) grows almost linearly in .
Experiment 2: posterior drift (Figure 3). Fixing and sweeping , the ICR excess risk grows almost linearly in , matching the irreducible-bias term of Lemma 1 and Proposition 1, while ICL is unaffected by the drift. In this few-shot regime, ICR remains preferable up to ; after which the drift bias outweighs ICR's variance reduction. At larger context size the crossover occurs much earlier (Appendix C.2.2).
Experiment 3: smoothness (Figure 4). Sweeping at , both ICL curves deteriorate as becomes rougher, whereas ICR is essentially flat in . This confirms the rate comparison of ICL and ICR in Theorem 1: the ICL rate is -dependent while ICR is insensitive to smoothness .
Experiment 4: corpus size (Figure 5). Fixing and sweeping the corpus size , the ICR error drops sharply and then plateaus near the predicted saturation scale of Equation (6) (here ; the dashed vertical line marks the reference scale ).
5.2 Language task
Setup. We use the sentiment analysis dataset of Díaz et al. [2018], in which each sentence is rated by several annotators with 40% label disagreement (training: 59,235 annotated examples / 1,481 annotators; test: 1,419 annotated examples / 878 annotators). Each test annotator defines a target distribution Q. The in-context learner is Qwen3.5-4B [Qwen Team, 2026]; sentences are embedded with BAAI/bge-base-en-v1.5 [Xiao

Figure 4: Target excess risk vs. smoothness ( , , ). ICL (blue) deteriorates as decreases; ICR (orange) is flat.

Figure 5: Target excess risk of ICR vs. corpus size ( , , ). The dashed line marks the reference scale . ICL does not depend on and is omitted for clarity.
et al., 2023] and retrieved by Euclidean distance. ICL draws n demonstrations from the annotator's own training data. We sweep four source-corpus designs with increasing level of posterior drift: no drift ( ), mild ( other annotators), severe (all 1,481 annotators), and extreme (others only). Full details are in Appendix C.
Results (Figure 6). ICR strongly outperforms ICL when P = Q and remains preferable under mild drift for ; as the amount of posterior drift increases, ICR's performance degrades monotonically, and ICL eventually becomes preferable. In Appendix C we repeat the experiment with the stronger Qwen3.5-27B model (Figure 14), where we see model capacity does not remove the bias, consistent with Proposition 1.

Figure 6: Test error vs. context size n on the sentiment dataset (Qwen3.5-4B; 878 test annotators, mean over 5 seeds). Blue: ICL with i.i.d. demonstrations from the annotator's own data. Yellow → red: ICR under four corpus designs with increasing posterior drift.
6 Conclusions & Limitations
We cast in-context retrieval as domain adaptation with a retrieval-based learner and derive finite-sample excess-risk bounds for both ICL and ICR. The bounds identify when ICR strictly outperforms ICL, and an irreducible bias that prevents ICR from being asymptotically consistent under posterior drift.
Synthetic and sentiment-classification experiments confirm these predictions and carry a practical takeaway: ICR is not always preferable, naively pooling all available source data into the retrieval corpus is not a safe default, and a smaller, well-aligned corpus can be better than a larger one.
The limitation of our work lies in that our analysis is specialized to binary classification and treats the in-context learners (induced by LLMs) as nearest-neighbor-style estimators.
Acknowledgements
The authors thank Aditya Gangrade for helpful discussions and feedback.
References
Rishabh Agarwal, Avi Singh, Lei Zhang, Bernd Bohnet, Luis Rosias, Stephanie Chan, Biao Zhang, Ankesh Anand, Zaheer Abbas, Azade Nova, et al. Many-shot in-context learning. Advances in Neural Information Processing Systems, 37:76930–76966, 2024.
Kwangjun Ahn, Xiang Cheng, Hadi Daneshmand, and Suvrit Sra. Transformers learn to implement preconditioned gradient descent for in-context learning. Advances in Neural Information Processing Systems, 36:45614–45650, 2023.
Akari Asai, Zeqiu Wu, Yizhong Wang, Avirup Sil, and Hannaneh Hajishirzi. Self-RAG: Learning to retrieve, generate, and critique through self-reflection. In The Twelfth International Conference on Learning Representations, 2024.
Jean-Yves Audibert and Alexandre B. Tsybakov. Fast learning rates for plug-in classifiers. The Annals of Statistics, 35(2):608–633, 2007.
Yu Bai, Fan Chen, Huan Wang, Caiming Xiong, and Song Mei. Transformers as statisticians: Provable in-context learning with in-context algorithm selection. Advances in neural information processing systems, 36:57125–57211, 2023.
Shai Ben-David, John Blitzer, Koby Crammer, and Fernando Pereira. Analysis of representations for domain adaptation. Advances in neural information processing systems, 19, 2006.
Sebastian Borgeaud, Arthur Mensch, Jordan Hoffmann, Trevor Cai, Eliza Rutherford, Katie Millican, George Bm Van Den Driessche, Jean-Baptiste Lespiau, Bogdan Damoc, Aidan Clark, Diego De Las Casas, Aurelia Guy, Jacob Menick, Roman Ring, Tom Hennigan, Saffron Huang, Loren Maggiore, Chris Jones, Albin Cassirer, Andy Brock, Michela Paganini, Geoffrey Irving, Oriol Vinyals, Simon Osindero, Karen Simonyan, Jack Rae, Erich Elsen, and Laurent Sifre. Improving language models by retrieving from trillions of tokens. In Kamalika Chaudhuri, Stefanie Jegelka, Le Song, Csaba Szepesvari, Gang Niu, and Sivan Sabato, editors, Proceedings of the 39th International Conference on Machine Learning, volume 162 of Proceedings of Machine Learning Research, pages 2206–2240. PMLR, 17–23 Jul 2022. URL https://proceedings.mlr.press/v162/borgeaud22a.html.
Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, et al. Language models are few-shot learners. Advances in neural information processing systems, 33:1877–1901, 2020.
T Tony Cai and Hongji Wei. Transfer learning for nonparametric classification: Minimax rate and adaptive classifier. The Annals of Statistics, 49(1):100–128, 2021.
Kamalika Chaudhuri and Sanjoy Dasgupta. Rates of convergence for nearest neighbor classification. Advances in Neural Information Processing Systems, 27, 2014.
Jianlyu Chen, Shitao Xiao, Peitian Zhang, Kun Luo, Defu Lian, and Zheng Liu. M3-embedding: Multilinguality, multi-functionality, multi-granularity text embeddings through self-knowledge distillation. In Lun-Wei Ku, Andre Martins, and Vivek Srikumar, editors, Findings of the Association for Computational Linguistics: ACL 2024, pages 2318–2335, Bangkok, Thailand, August 2024. Association for Computational Linguistics. doi: 10.18653/v1/2024.findings-acl.137. URL https://aclanthology.org/2024.findings-acl.137/.
Yiheng Chen, Lingyao Li, Zihui Ma, Qikai Hu, Yilun Zhu, Min Deng, and Runlong Yu. Empowering LLM agents with geospatial awareness: Toward grounded reasoning for wildfire response. arXiv preprint arXiv:2510.12061, 2025.
Chen Cheng, Xinzhi Yu, Haodong Wen, Jingsong Sun, Guanzhang Yue, Yihao Zhang, and Zeming Wei. Exploring the robustness of in-context learning with noisy labels. In ICASSP 2025-2025 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), pages 1–5. IEEE, 2025.
Daixuan Cheng, Shaohan Huang, Junyu Bi, Yuefeng Zhan, Jianfeng Liu, Yujing Wang, Hao Sun, Furu Wei, Weiwei Deng, and Qi Zhang. Uprise: Universal prompt retrieval for improving zero-shot evaluation. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, pages 12318–12337, Singapore, 2023. Association for Computational Linguistics. doi: 10.18653/v1/2023.emnlp-main.758. URL https://aclanthology.org/2023.emnlp-main.758/.
Mark Díaz, Isaac Johnson, Amanda Lazar, Anne Marie Piper, and Darren Gergle. Addressing age-related bias in sentiment analysis. In Proceedings of the 2018 chi conference on human factors in computing systems, pages 1–14, 2018.
Qingxiu Dong, Lei Li, Damai Dai, Ce Zheng, Jingyuan Ma, Rui Li, Heming Xia, Jingjing Xu, Zhiyong Wu, Baobao Chang, Xu Sun, Lei Li, and Zhifang Sui. A survey on in-context learning. In Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing, pages 1107–1128, Miami, Florida, USA, November 2024. Association for Computational Linguistics.
Shahul Es, Jithin James, Luis Espinosa Anke, and Steven Schockaert. RAGAs: Automated evaluation of retrieval augmented generation. In Nikolaos Aletras and Orphee De Clercq, editors, Proceedings of the 18th Conference of the European Chapter of the Association for Computational Linguistics: System Demonstrations, pages 150–158, St. Julians, Malta, March 2024. Association for Computational Linguistics. doi: 10.18653/v1/2024.eacl-demo.16. URL https://aclanthology.org/2024.eacl-demo.16/.
Jianqing Fan, Cheng Gao, and Jason M Klusowski. Robust transfer learning with unreliable source data. The Annals of Statistics, 53(4):1728–1752, 2025.
Shivam Garg, Dimitris Tsipras, Percy S Liang, and Gregory Valiant. What can transformers learn in-context? a case study of simple function classes. Advances in neural information processing systems, 35:30583–30598, 2022.
Halil Alperen Gozeten, Muhammed Emrullah Ildiz, Xuechen Zhang, Mahdi Soltanolkotabi, Marco Mondelli, and Samet Oymak. Test-time training provably improves transformers as in-context learners. In Proceedings of the 42nd International Conference on Machine Learning, pages 20266–20295. PMLR, 2025. URL https://proceedings.mlr.press/v267/gozeten25a.html.
Tianyu Guo, Wei Hu, Song Mei, Huan Wang, Caiming Xiong, Silvio Savarese, and Yu Bai. How do transformers learn in-context beyond simple functions? a case study on learning with representations. In The Twelfth International Conference on Learning Representations, 2024. URL https://openreview.net/forum?id=ikwEDva1JZ.
Yang Guo, Yutian Tao, Yifei Ming, Robert D Nowak, and Yingyu Liang. Retrieval-augmented generation as noisy in-context learning: A unified theory and risk bounds. arXiv preprint arXiv:2506.03100, 2025.
Shailja Gupta, Rajesh Ranjan, and Surya Narayan Singh. A comprehensive survey of retrieval-augmented generation (RAG): Evolution, current landscape and future directions. arXiv preprint arXiv:2410.12837, 2024.
Steve Hanneke and Samory Kpotufe. On the value of target data in transfer learning. Advances in Neural Information Processing Systems, 32, 2019.
Steve Hanneke and Samory Kpotufe. Adaptive sample aggregation in transfer learning, 2025. URL https://arxiv.org/abs/2408.16189.
Noah Hollmann, Samuel Müller, Katharina Eggensperger, and Frank Hutter. TabPFN: A transformer that solves small tabular classification problems in a second. arXiv preprint arXiv:2207.01848, 2022.
Noah Hollmann, Samuel Müller, Lennart Purucker, Arjun Krishnakumar, Max Körfer, Shi Bin Hoo, Robin Tibor Schirrmeister, and Frank Hutter. Accurate predictions on small data with a tabular foundation model. Nature, 637(8045):319–326, 2025.
Jie Huang, Wei Ping, Peng Xu, Mohammad Shoeybi, Kevin Chen-Chuan Chang, and Bryan Catanzaro. Raven: In-context learning with retrieval-augmented encoder-decoder language models. In Conference on Language Modeling, 2024. URL https://openreview.net/forum?id=GMalvQu0XL.
Gautier Izacard and Edouard Grave. Leveraging passage retrieval with generative models for open domain question answering. In Paola Merlo, Jorg Tiedemann, and Reut Tsarfaty, editors, Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics: Main Volume, pages 874–880, Online, April 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021.eacl-main.74. URL https://aclanthology.org/2021.eacl-main.74/.
Gautier Izacard, Patrick Lewis, Maria Lomeli, Lucas Hosseini, Fabio Petroni, Timo Schick, Jane Dwivedi-Yu, Armand Joulin, Sebastian Riedel, and Edouard Grave. Atlas: Few-shot learning with retrieval augmented language models. Journal of Machine Learning Research, 24(251):1–43, 2023. URL https://jmlr.org/papers/v24/23-0037.html.
Ivan Kirev, Lyuben Baltadzhiev, and Nikola Konstantinov. Pac learnability in the presence of performativity. arXiv preprint arXiv:2510.08335, 2025.
Soo Min Kwon, Alec S Xu, Can Yaras, Laura Balzano, and Qing Qu. Out-of-distribution generalization of in-context learning: A low-dimensional subspace perspective. arXiv preprint arXiv:2505.14808, 2025.
Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, Sebastian Riedel, and Douwe Kiela. Retrieval-augmented generation for knowledge-intensive nlp tasks. In H. Larochelle, M. Ranzato, R. Hadsell, M.F. Balcan, and H. Lin, editors, Advances in Neural Information Processing Systems, volume 33, pages 9459–9474. Curran Associates, Inc., 2020. URL https://proceedings.neurips.cc/paper_files/paper/2020/file/6b493230205f780e1bc26945df7481e5-Paper.pdf.
Xiaonan Li and Xipeng Qiu. MoT: Memory-of-thought enables ChatGPT to self-improve. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, pages 6354–6374, 2023.
Xingxuan Li, Ruochen Zhao, Yew Ken Chia, Bosheng Ding, Shafiq Joty, Soujanya Poria, and Lidong Bing. Chain-of-knowledge: Grounding large language models via dynamic knowledge adapting over heterogeneous sources. In The Twelfth International Conference on Learning Representations, 2024a. URL https://openreview.net/forum?id=cPgh4gWZlz.
Yingcong Li, Muhammed Emrullah Ildiz, Dimitris Papailiopoulos, and Samet Oymak. Transformers as algorithms: Generalization and stability in in-context learning. In International conference on machine learning, pages 19565–19594. PMLR, 2023.
Yingcong Li, Ankit S Rawat, and Samet Oymak. Fine-grained analysis of in-context linear estimation: Data, architecture, and beyond. Advances in Neural Information Processing Systems, 37:138324–138364, 2024b.
Zihao Li, Yuan Cao, Cheng Gao, Yihan He, Han Liu, Jason M Klusowski, Jianqing Fan, and Mengdi Wang. One-layer transformer provably learns one-nearest neighbor in context. Advances in Neural Information Processing Systems, 37:82166–82204, 2024c.
Jiachang Liu, Dinghan Shen, Yizhe Zhang, William B Dolan, Lawrence Carin, and Weizhu Chen. What makes good in-context examples for GPT-3? In Proceedings of Deep Learning Inside Out (DeeLIO 2022): The 3rd workshop on knowledge extraction and integration for deep learning architectures, pages 100–114, 2022.
Zheng Liu, Chaofan Li, Shitao Xiao, Yingxia Shao, and Defu Lian. Llama2Vec: Unsupervised adaptation of large language models for dense retrieval. In Lun-Wei Ku, Andre Martins, and Vivek Srikumar, editors, Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 3490–3500, Bangkok, Thailand, August 2024. Association for Computational Linguistics. doi: 10.18653/v1/2024.acl-long.191. URL https://aclanthology.org/2024.acl-long.191/.
Man Luo, Xin Xu, Yue Liu, Panupong Pasupat, and Mehran Kazemi. In-context learning with retrieved demonstrations for language models: A survey. Transactions on Machine Learning Research, 2024. URL https://openreview.net/forum?id=NQPo8ZhQPa.
Junwei Ma, Valentin Thomas, Rasa Hosseinzadeh, Alex Labach, Jesse C Cresswell, Keyvan Golestan, Guangwei Yu, Anthony L Caterini, and Maksims Volkovs. TabDPT: Scaling tabular foundation models on real data. In The Thirty-ninth Annual Conference on Neural Information Processing Systems, 2025.
Subha Maity, Diptavo Dutta, Jonathan Terhorst, Yuekai Sun, and Moulinath Banerjee. A linear adjustment based approach to posterior drift in transfer learning. Biometrika, 2024. URL https://doi.org/10.1093/biomet/asad029.
Yishay Mansour, Mehryar Mohri, and Afshin Rostamizadeh. Domain adaptation: Learning bounds and algorithms. In Proceedings of The 22nd Annual Conference on Learning Theory (COLT 2009), Montréal, Canada, 2009. URL http://www.cs.nyu.edu/~mohri/postscript/nadap.pdf.
Jingang Qu, David Holzmüller, Gaël Varoquaux, and Marine Le Morvan. TabICL: A tabular foundation model for in-context learning on large data. arXiv preprint arXiv:2502.05564, 2025.
Qwen Team. Qwen3.5: Towards native multimodal agents, February 2026. URL https://qwen.ai/blog?id=qwen3.5.
Ohad Rubin, Jonathan Herzig, and Jonathan Berant. Learning to retrieve prompts for in-context learning. In Proceedings of the 2022 conference of the North American chapter of the association for computational linguistics: human language technologies, pages 2655–2671, 2022.
Clayton Scott. A generalized Neyman-Pearson criterion for optimal domain adaptation. In Algorithmic Learning Theory, pages 738–761. PMLR, 2019.
Peng Shi, Rui Zhang, He Bai, and Jimmy Lin. Xricl: Cross-lingual retrieval-augmented in-context learning for cross-lingual text-to-sql semantic parsing. In Findings of the Association for Computational Linguistics: EMNLP 2022, pages 5248–5259, Abu Dhabi, United Arab Emirates, 2022. Association for Computational Linguistics. doi: 10.18653/v1/2022.findings-emnlp.384. URL https://aclanthology.org/2022.findings-emnlp.384/.
Masashi Sugiyama, Matthias Krauledat, and Klaus-Robert Müller. Covariate shift adaptation by importance weighted cross validation. Journal of Machine Learning Research, 8(35), 2007.
Chong Xiang, Tong Wu, Zexuan Zhong, David Wagner, Danqi Chen, and Prateek Mittal. Certifiably robust rag against retrieval corruption. In 2026 IEEE Conference on Secure and Trustworthy Machine Learning (SaTML), pages 392–410, 2026. doi: 10.1109/SaTML68715.2026.00029.
Shitao Xiao, Zheng Liu, Peitian Zhang, and Niklas Muennighoff. C-pack: Packaged resources to advance general chinese embedding, 2023.
Sang Michael Xie, Aditi Raghunathan, Percy Liang, and Tengyu Ma. An explanation of in-context learning as implicit bayesian inference. In International Conference on Learning Representations, 2022. URL https://openreview.net/forum?id=RdJVFCHjUMI.
Fangyuan Xu, Weijia Shi, and Eunsol Choi. RECOMP: Improving retrieval-augmented LMs with context compression and selective augmentation. In The Twelfth International Conference on Learning Representations, 2024. URL https://openreview.net/forum?id=mlJLVigNHp.
Tong Yang, Yu Huang, Yingbin Liang, and Yuejie Chi. In-context learning with representations: Contextual generalization of trained transformers. Advances in Neural Information Processing Systems, 37:85867–85898, 2024.
Jiacheng Ye, Zhiyong Wu, Jiangtao Feng, Tao Yu, and Lingpeng Kong. Compositional exemplars for in-context learning. In International Conference on Machine Learning, pages 39818–39833. PMLR, 2023.
Ruiqi Zhang, Spencer Frei, and Peter L Bartlett. Trained transformers learn linear models in-context. Journal of Machine Learning Research, 25(49):1–55, 2024.
Zhuosheng Zhang, Aston Zhang, Mu Li, and Alex Smola. Automatic chain of thought prompting in large language models. In International Conference on Learning Representations, 2023. URL https://openreview.net/forum?id=5NTt8GFjUHkr.
Yilun Zhu, Jianxin Zhang, Aditya Gangrade, and Clay Scott. Label noise: Ignorance is bliss. Advances in Neural Information Processing Systems, 37:116575–116616, 2024.
Appendix
A Rate of convergence for nearest neighbor classification
This appendix reviews the excess-risk bound for the -nearest-neighbor (-NN) majority-vote classifier of Chaudhuri and Dasgupta [2014], restated using our paper's notation for a generic source distribution . The bound is then specialized to the ICL setting (with and training size ) and the ICR setting (with corpus size and neighbor count ) in the proof of Theorem 1.
Setup. Let be a Borel probability distribution on , where is a separable metric space. Let be the class-probability function, the Bayes classifier, the risk and the Bayes risk. Given an i.i.d. sample , the -NN majority-vote classifier is
where is the label of the -th nearest neighbor of in under .
Assumptions on .
- -smoothness: for some and all , ,
where is the average of over a set , is the closed ball, and is the open ball.
- -margin condition: for some and ,
The following lemma is restated from Chaudhuri and Dasgupta [2014], Lemma 20.
Lemma 3 (Pointwise excess risk for -NN) Let , and suppose is -smooth. Set and . If satisfies , the -NN majority-vote classifier on satisfies
The following lemma is an extension of Chaudhuri and Dasgupta [2014], Lemma 21, to a subset of the input space, which is needed for our analysis.
Lemma 4 (Excess risk on a subset) Let be a measurable set, let , and let denote the -NN majority-vote classifier on a corpus . Suppose is -smooth and, for some and , satisfies the following local margin condition on :
Then
Proof. By Fubini and non-negativity, the expectation equals an integral over A of the pointwise expected excess risk:
Set , , and
Writing , decompose A into
Step 1: Near region. On , the trivial pointwise bound together with the local margin condition gives
Step 2: Far region. For , global smoothness and allow us to apply Lemma 3:
Integrating over and using on the exponential term,
Partition into dyadic shells for . Since , on we have . The local margin condition therefore gives
Step 3: Geometric series. Because , the ratio of consecutive summands in the last display is at most . Their sum is therefore at most twice its first term, which is bounded by
Thus the integral over the far region, apart from , is at most .
Step 4: Combine. Adding Steps 1 and 3,
which is the claimed bound.
Theorem 2 (Chaudhuri and Dasgupta 2014, restated in our notation) Suppose is -smooth and satisfies the -margin condition with constant . Then, for every and ,
Consequently, choosing (with integer rounding and truncation to for small ) yields
for an appropriate .
Proof. The finite-sample inequality (7) is Lemma 21 of Chaudhuri and Dasgupta [2014] restated in our notation. With , both arguments of the maximum are , while decays faster than any polynomial in . For all sufficiently large , this choice also satisfies ; enlarging covers the finitely many smaller values of . Absorbing the exponential term into gives (8), which is Theorem 4(b) of Chaudhuri and Dasgupta [2014].
This matches the minimax rate for nonparametric classification under -Hölder smoothness and the -margin condition [Audibert and Tsybakov, 2007], since, by Lemma 2 of Chaudhuri and Dasgupta [2014], -Hölder smoothness of implies -smoothness with when has a density bounded below on a bounded support with regular boundary (e.g., a cube); substituting into (8) recovers the Hölder rate .
B Proofs
This appendix collects the full proofs of the lemmas, theorems, and propositions stated in Sections 4.1 and 4.2. Throughout, we use the pointwise excess risk
which satisfies .
B.1 Proof of Lemma 1 (Risk transfer)
Lemma (Risk transfer; restated from Lemma 1) If , then for any classifier ,
Proof. Write and decompose:
Low-RSS term. Since , the complement of contributes at most its -mass:
High-RSS term. If then and the bound below is trivial. Otherwise, for , by definition and lie on the same side of , so the Bayes classifiers agree, . Any prediction error of at is therefore an error under both and , and the target signal is weaker by at most :
Hence
where the second inequality uses the density ratio . Adding the bounds on and gives the result.
B.2 Proof of Lemma 2 (margin transfer via RSS)
Lemma (Margin transfer via RSS; restated from Lemma 2) If and satisfies the -margin condition with constant , then for the high-RSS region ,
We denote .
Proof. Fix any t > 0.
Step 1: Subset inclusion with RSS. For , by definition, . Therefore, if and , then
This gives the set inclusion
Step 2: Change measure from to . The set on the left lies in by Definition 1, where (3) gives . By monotonicity of probability and this bound,
Step 3: Apply the -margin condition on . By assumption, for all . Setting ,
Chaining the three steps yields the final result (4).
B.3 Proof of Theorem 1 (ICL excess risk)
Theorem (ICL excess risk; restated from Theorem 1) Under -smoothness and -margin with constant on ,
where is the constant of Theorem 2.
Proof. For ICL, the demonstration set consists of i.i.d. samples from , and the induced classifier is the -NN majority vote with the rate-optimal inner tuning parameter . Specializing Theorem 2 to the target distribution ( in place of , demonstration size in place of ), (8) gives
This proves the claim.
B.4 Proof of Theorem 1 (ICR excess risk)
Theorem (ICR excess risk; full version of Theorem 1) Let , suppose satisfies the -margin condition with constant , and satisfies -smoothness. Then there exists a finite such that, for every and ,
Define
If moreover the corpus exceeds the critical size ,
then the maximum in (9) is attained by its second argument, and
Proof. Throughout, write and recall the pointwise excess risk , so that for . For a fixed corpus , let be the induced classifier.
Step 1: A localized risk transfer. Decompose the target excess risk over and its complement, exactly as in the proof of Lemma 1:
Since , the complement term satisfies . On we have (as shown in that proof), and the density ratio converts the expectation from to . Unlike Lemma 1, we now retain the indicator rather than bounding it by 1:
Adding the two bounds and taking expectation over ,
Step 2: Localized k-NN rate on . By construction the ICR classifier is the majority vote over the nearest neighbors of in , i.e. with neighbor count . We apply Lemma 4 with and . Its smoothness assumption holds by the assumed -smoothness of , and ensures that . Its local margin assumption follows from Lemma 2, which gives for all , with . Lemma 4 then yields, with ,
where the last step uses .
Step 3: Combine (finite corpus). Substituting into (12) and using ,
which is the intermediate finite-corpus bound.
Step 4: Dominating the exponential term. Because , there exists a finite such that, for every ,
Multiplying by and combining with (13) increases the coefficient 5/2 to 3, giving (9).
Step 5: Saturated corpus. The localization term is decreasing in m, and solving
for gives exactly with as in (10). Hence for the maximum is attained by its second argument, and
Substituting into (9) gives (11).
B.5 Proof of Proposition 1 (lower bound)
Proposition (Lower bound for ICR; restated from Proposition 1) For any , , , and any learning rule that observes a corpus and produces a classifier ,
Proof. Partition with and . Fix any pair that satisfies the density-ratio condition . For each , define the pair by
The following RSS identities and set inclusions hold -almost surely:
so and , giving . Hence for either .
The key is that does not depend on , so does not depend on . Thus label drawn from does not contain information about .
On , , so contributes zero to the excess risk. On , and , so the contribution from is
Drawing independently of and using ,
Taking the infimum over and the supremum over yields the claim.
C Experimental details
Hardware and runtime. TabPFN inference and the Qwen3.5-4B sentiment experiments were run on NVIDIA A40, A100 or V100 GPUs; the Qwen3.5-27B sentiment experiments were run on the same GPU cluster. Each synthetic configuration and each Qwen3.5-4B configuration takes less than one hour of wall-clock time; the Qwen3.5-27B runs are correspondingly slower.
C.1 Synthetic experiments: linear
Data-generating process. Features are drawn from (integer grid). The target class-probability function is with fixed per trial, so . Posterior drift is induced by a region , with chosen so that ; inside we set (labels flipped), and outside . The parameter is therefore the fraction of -mass on which source and target labels disagree. The ICR corpus has i.i.d. samples from ; the test set has samples from . ICL samples i.i.d. demonstrations from , shared across all test queries; ICR retrieves the nearest corpus neighbors of each query by Euclidean distance.
Models. TabPFN [Hollmann et al., 2025] is a pre-trained tabular in-context learner that takes labeled demonstrations as context. k-NN uses cross-validation on the demonstrations to pick k in the ICL setting; in the ICR setting it takes a full majority vote over the retrieved neighbors (no inner k). All synthetic results are averaged over 5 independent trials with different draws of w and the data.
This subsection collects the full setup and results for the linear target . It contains two experiments: Experiment 1 fixes and varies the number of demonstrations (for ), and Experiment 2 fixes and varies the posterior drift . For each we show the summary figure and report the complete per-cell results (mean±std over 5 trials, test error on the target ; lower is better); the mean of each cell is the value plotted in the corresponding figure, and the std columns quantify the variation across the 5 trials.
The linear target satisfies the margin condition with a hard margin (any ), but it is discontinuous at the decision boundary and hence not -smooth there. We nevertheless retain these experiments: the qualitative ICL-versus-ICR comparison does not depend on the smoothness assumption, and the higher-dimensional setting complements the one-dimensional Weierstrass family of Appendix C.2, which satisfies both assumptions exactly.
C.1.1 Experiment 1: no domain shift , varying n and d
Figure 7 shows that with no distributional shift, ICR outperforms ICL at every n, especially in the few-shot regime. The gap narrows as n grows, which aligns with our finite-sample theory. TabPFN and k-NN track each other closely, supporting k-NN as a good proxy for the in-context learner.


Figure 7: Test error on Q vs. number of demonstrations n, with P = Q (no domain shift). Color: ICL (blue) vs. ICR (orange). Line style: TabPFN (solid, ●) vs. k-NN (dashed, □). Corpus size m = 20,000, . Results averaged over 5 independent runs.
C.1.2 Experiment 2: posterior drift , varying
Figure 8 shows that, fixing and sweeping , ICR error increases monotonically from at to at , while ICL error does not depend on . The crossover for marks the
Table 1: Experiment 1, : test error on , we report meanstd over 5 trials.
| TabPFN-ICL | TabPFN-ICR | -NN-ICL | -NN-ICR | |
|---|---|---|---|---|
| 4 | ||||
| 16 | ||||
| 32 | ||||
| 128 | ||||
| 256 |
Table 2: Experiment 1, : test error on , we report meanstd over 5 trials.
| TabPFN-ICL | TabPFN-ICR | -NN-ICL | -NN-ICR | |
|---|---|---|---|---|
| 4 | ||||
| 16 | ||||
| 32 | ||||
| 128 | ||||
| 256 |
bias–variance tipping point predicted by the theory: below ICR’s variance reduction outweighs the bias from posterior drift; above , the irreducible error dominates.


Figure 8: Test error on vs. posterior drift parameter , with fixed. Color: ICL (blue) vs. ICR (orange). Line style: TabPFN (solid) vs. -NN (dashed). ICL baselines (horizontal) are the means over 5 runs values (since only affects the ICR corpus; not affecting ICL). ICR mean error grows monotonically with . Results averaged over 5 independent runs.
Table 3: Experiment 2, , : test error on vs. posterior drift , we report meanstd over 5 trials.
| TabPFN-ICL | TabPFN-ICR | -NN-ICL | -NN-ICR | |
|---|---|---|---|---|
| 0.0 | ||||
| 0.1 | ||||
| 0.2 | ||||
| 0.3 | ||||
| 0.4 | ||||
| 0.5 | ||||
| 0.6 | ||||
| 0.7 | ||||
| 0.8 | ||||
| 0.9 | ||||
| 1.0 |
Table 4: Experiment 2, , : test error on vs. posterior drift , we report meanstd over 5 trials.
| TabPFN-ICL | TabPFN-ICR | -NN-ICL | -NN-ICR | |
|---|---|---|---|---|
| 0.0 | ||||
| 0.1 | ||||
| 0.2 | ||||
| 0.3 | ||||
| 0.4 | ||||
| 0.5 | ||||
| 0.6 | ||||
| 0.7 | ||||
| 0.8 | ||||
| 0.9 | ||||
| 1.0 |
C.2 Synthetic experiments: Weierstrass
Overview. All experiments in this subsection replace the linear target with a Weierstrass-type class-probability function of controlled smoothness on , which holds the margin exponent, the Bayes risk, and the Bayes classifier fixed while varies; the full construction is given below. Experiments 1 and 2 sweep the number of demonstrations and the posterior drift at fixed smoothness, while Experiments 3 and 4 sweep the smoothness and the retrieval corpus size .
Data-generating process. We take with , so and, in one dimension, Chaudhuri–Dasgupta's measure-based smoothness exponent coincides with the pointwise Hölder exponent. The class-probability function is
where the smoothness parameter is encoded in the normalized Weierstrass-style odd sine series
The coefficients on frequencies give pointwise Hölder exponent as ; we truncate at and normalize by the supremum so that for every .
We fix A = 0.24, b = 0.85, and f = 2 across ; here f denotes the frequency.
This construction of allows us to control the smoothness easily, see the figure below for examples of for different . The Bayes risk is and the Bayes classifier is , which is independent of .

Figure 9: Examples of the Weierstrass class-probability function for different values of the smoothness parameter .
Models. TabPFN takes the labeled demonstrations in context; k-NN uses Euclidean distance with the theory-inspired neighborhood size
which balances the bias/variance terms of Theorem 2. The retrieval corpus has i.i.d. samples from . The population excess risk over is approximated by evaluating on a deterministic grid of equally spaced points on , averaged over 5 seeds.
C.2.1 Experiment 1: no domain shift , large , varying
This experiment sweeps the number of demonstrations with no domain shift , at two smoothness levels (smooth) and (rougher); all remaining parameters follow the common setup above (, , , oracle , 5 seeds 42–46). Figure 10 shows that ICR outperforms ICL at every and both smoothness levels, and Tables 5 and 6 report the per-cell values.

(demonstrations)

(demonstrations)
| TabPFN-ICL | TabPFN-ICR |
Figure 10: Target excess risk vs. number of demonstrations on the 1-D Weierstrass family (; ; oracle ). Color: ICL (blue) vs. ICR (orange). Line style: TabPFN (solid, ) vs. -NN (dashed, ). Both axes are log-scaled. Corpus size , ; each curve is the mean over 5 seeds (42–46).
Table 5: Weierstrass sample-size sweep, : target excess risk, meanstd over 5 seeds.
| TabPFN-ICL | TabPFN-ICR | -NN-ICL | -NN-ICR | |
|---|---|---|---|---|
| 4 | ||||
| 16 | ||||
| 32 | ||||
| 64 | ||||
| 128 | ||||
| 256 | ||||
| 512 | ||||
| 1024 |
C.2.2 Experiment 2: posterior drift , varying
This experiment fixes the smoothness at and sweeps the posterior drift at two context sizes, (few-shot) and (variance-limited). The drift region is a union of periodic sub-brackets, each covering the leftmost -fraction of one width-2/N interval of , so that holds exactly and samples every macro-cycle of uniformly; on the source posterior is flipped, . ICL uses -labels and is therefore -independent. Figure 11 shows the resulting bias–variance crossover, and Tables 7 and 8 report the per-cell values.
C.2.3 Experiment 3: varying smoothness (via the Weierstrass function)
Motivation. Theorem 1 predict that ICL pays a smoothness penalty at rate , while ICR attains the -independent rate in the large-corpus limit. To isolate this effect, we vary while
Table 6: Weierstrass sample-size sweep, : target excess risk, meanstd over 5 seeds.
| TabPFN-ICL | TabPFN-ICR | -NN-ICL | -NN-ICR | |
|---|---|---|---|---|
| 4 | ||||
| 16 | ||||
| 32 | ||||
| 64 | ||||
| 128 | ||||
| 256 | ||||
| 512 | ||||
| 1024 |


Figure 11: Target excess risk vs. posterior drift on the Weierstrass family at (smooth ), for over 5 seeds. is a union of periodic sub-brackets, each covering the leftmost -fraction of one width-2/N interval of , so samples every macro-cycle of uniformly and holds exactly. Color: ICL (blue) vs. ICR (orange). Line style: TabPFN (solid, ) vs. -NN (dashed, ). ICL curves are exactly flat because ICL uses labels and does not see the drift; ICR curves rise almost linearly in across the whole range, saturating near at . At small (left, ) ICR beats ICL up to ; at large (right, ) ICR is roughly an order of magnitude below ICL at (variance-limited regime), but ICL overtakes it already by . In both regimes the ICR bias tracks almost linearly, matching the reduction in Lemma 1.
Table 7: Experiment 2, , : target excess risk vs. posterior drift , meanstd over 5 seeds (Weierstrass family, , , , ; oracle ; ; ). Region is the leftmost -fraction of each of equal-width periodic brackets partitioning , so exactly and samples every macro-cycle of uniformly; on ; ICL uses labels (so ICL columns are -constant).
| TabPFN-ICL | TabPFN-ICR | -NN-ICL | -NN-ICR | |
|---|---|---|---|---|
| 0.0 | ||||
| 0.1 | ||||
| 0.2 | ||||
| 0.3 | ||||
| 0.4 | ||||
| 0.5 | ||||
| 0.6 | ||||
| 0.7 | ||||
| 0.8 | ||||
| 0.9 | ||||
| 1.0 |
Table 8: Experiment 2, , : target excess risk vs. posterior drift , meanstd over 5 seeds (same setup as Table 7).
| TabPFN-ICL | TabPFN-ICR | -NN-ICL | -NN-ICR | |
|---|---|---|---|---|
| 0.0 | ||||
| 0.1 | ||||
| 0.2 | ||||
| 0.3 | ||||
| 0.4 | ||||
| 0.5 | ||||
| 0.6 | ||||
| 0.7 | ||||
| 0.8 | ||||
| 0.9 | ||||
| 1.0 |
holding the margin exponent , the Bayes risk , and the Bayes classifier fixed by construction.

| TabPFN-ICL | TabPFN-ICR |
Figure 12: Target excess risk vs. smoothness exponent on the Weierstrass family at , with (log-spaced, 5 seeds). Color: ICL (blue) vs. ICR (orange). Line style: TabPFN (solid, ) vs. -NN (dashed, ). The horizontal axis is logarithmic; the -axis is reversed so rougher is on the right. Both -NN-ICL and TabPFN-ICL trend upward as decreases, matching the prediction of Theorem 1; the -NN-ICL curve saturates near at the finite- noise floor. ICR sits about an order of magnitude below ICL and is essentially flat in , consistent with the -independent rate of Theorem 1; the ICL/ICR gap widens as .
Table 9: Experiment 3, : target excess risk vs. smoothness , meanstd over 5 seeds (Weierstrass family, , , , ; oracle ; ; ).
| TabPFN-ICL | TabPFN-ICR | -NN-ICL | -NN-ICR | |
|---|---|---|---|---|
C.2.4 Experiment 4: varying corpus size
Prediction from the finite-corpus bound. The ICR bound in (5) is governed by
whose two terms represent localization bias and label variance, respectively. The bound enters its variance-limited regime when
as given exactly in (6). Thus increasing improves the bias-dependent part of the guarantee below this scale, whereas the bound no longer improves with above it. This is a sufficient, order-level saturation condition rather than an exact crossover between ICR and ICL: the multiplicative constant depends on , and the upper bound does not imply that ICL must be better below the threshold.
Setup and results. We use the smooth Weierstrass family from Experiment 3 with no shift , fix , and vary the corpus size over powers of two for . Figure 13 marks the unit-constant reference : 512 for and approximately 1448 for . For both k-NN and TabPFN, ICR improves sharply as the corpus becomes larger than the context and then reaches a low-error plateau, while ICL is unaffected by corpus size. The transition is sharper for k-NN and more gradual for TabPFN; the small nonmonotone fluctuations across adjacent corpus sizes are consistent with finite-trial variation. Table 10 reports all configurations and seeds rather than selecting individual runs.
(5 seeds)
(5 seeds)


Figure 13: Excess error on Q versus corpus size m, with n fixed and . Color: ICL (blue) versus ICR (orange). Line style: TabPFN (solid, ●) vs. k-NN (dashed, □). Per (n, seed) we draw one corpus of size and use nested prefixes ; the ICL demo set is drawn once per n from that corpus and reused across every m. Consequently ICL is exactly constant along the m axis for each seed, and the horizontal ICL baselines are the across-seed means of those per-seed constants. Both ICR curves collapse sharply around the reference scale and remain near their asymptotic value thereafter. The dotted grey line marks the unit-constant reference (512 for , for ); the actual saturation threshold is for some unknown constant. All 5 seeds (42–46). Setup: 1-D Weierstrass -family with , , , , oracle , linspace , and joint demonstrations.
Table 10: Corpus-size sweep: excess error on , mean sample standard deviation over five seeds. ICL entries are constant along the axis by construction (see Fig. 13 caption) and are shown once per ; ICR entries vary per .
| n | m | TabPFN-ICL | TabPFN-ICR | k-NN-ICL | k-NN-ICR |
|---|---|---|---|---|---|
| 64 | 64 | 0.133 ± 0.019 | 0.145 ± 0.042 | ||
| 128 | 0.073 ± 0.022 | 0.140 ± 0.028 | |||
| 256 | 0.038 ± 0.011 | 0.109 ± 0.032 | |||
| 512 | 0.020 ± 0.005 | 0.019 ± 0.009 | |||
| 1024 | 0.097 ± 0.033 | 0.021 ± 0.006 | 0.079 ± 0.016 | 0.009 ± 0.003 | |
| 2048 | 0.021 ± 0.006 | 0.008 ± 0.004 | |||
| 4096 | 0.017 ± 0.005 | 0.008 ± 0.003 | |||
| 8192 | 0.016 ± 0.002 | 0.007 ± 0.001 | |||
| 16384 | 0.018 ± 0.003 | 0.008 ± 0.002 | |||
| 128 | 128 | 0.075 ± 0.026 | 0.130 ± 0.034 | ||
| 256 | 0.047 ± 0.008 | 0.144 ± 0.047 | |||
| 512 | 0.026 ± 0.012 | 0.107 ± 0.016 | |||
| 1024 | 0.013 ± 0.004 | 0.008 ± 0.004 | |||
| 2048 | 0.091 ± 0.025 | 0.012 ± 0.005 | 0.065 ± 0.022 | 0.005 ± 0.005 | |
| 4096 | 0.011 ± 0.003 | 0.004 ± 0.001 | |||
| 8192 | 0.011 ± 0.001 | 0.004 ± 0.001 | |||
| 16384 | 0.011 ± 0.002 | 0.005 ± 0.001 | |||
| 32768 | 0.011 ± 0.001 | 0.004 ± 0.001 |
C.3 Sentiment classification: full setup
We use the sentiment classification dataset of Díaz et al. [2018], a language benchmark with substantial annotator-induced posterior drift: each sentence is labeled by 4–5 individuals with label disagreement. The training split has 59,235 annotated examples from 1,481 annotators (up to 40 per annotator); the test split has 1,419 annotated examples from 878 annotators. This five-class classification () experiment qualitatively tests the implications of our binary classification theory. Each test annotator is treated as a target distribution . Sentences are encoded with BAAI/bge-base-en-v1.5 [Xiao et al., 2023] and retrieved by Euclidean distance; the in-context learner is Qwen3.5-4B [Qwen Team, 2026]. ICL demonstrations are sampled uniformly without replacement from the annotator's own training data. Errors are averaged over test annotators and over 5 independent retrieval/sampling runs.
Posterior drift depends on the choice of source corpus. The same dataset can yield very different source distributions depending on how the retrieval corpus is assembled, and this choice directly controls the drift relative to each test annotator's : (1) self — only the test annotator's own training data (, no drift, but the corpus is small, examples); (2) self + 100 random others — mild drift, moderately larger corpus; (3) all 1,481 annotators — the entire training set, severe drift but the largest corpus; (4) others only — the test annotator deliberately excluded, extreme drift. This sweep makes explicit a tradeoff that practitioners face whenever labels come from heterogeneous sources: a tightly curated corpus minimizes posterior drift at the cost of size, while pooling all available data maximizes corpus size at the cost of drift. Notably, much of the existing ICR literature treats the entire training set as the retrieval corpus by default, with no explicit accounting for posterior drift—which, as our results show, is exactly the regime where ICR can fail catastrophically.
Results. ICR strongly outperforms ICL when and remains preferable under mild posterior drift for . Under severe drift the ICR error stays near while ICL keeps improving with ; under extreme drift, ICR error rises to , well above the ICL baseline. This finding not only verifies our theory, but also has a practical takeaway: naively pooling all available data is not a safe default—a smaller, well-aligned corpus can dominate a larger, drifted one.
Effect of model scale. Figure 14 repeats the experiment with the stronger Qwen3.5-27B model alongside Qwen3.5-4B. The 27B model is markedly better in the few-shot regime where the corpus is aligned with the target (e.g., 0.12 vs. 0.26 at under ), yet its error under severe and extreme drift is essentially unchanged from the 4B model: model capacity does not remove the irreducible drift-induced bias, consistent with Proposition 1.
Qwen3.5-4B
Qwen3.5-27B

n (demonstrations)
ICL
ICR, no drift (P = Q)
ICR, severe drift
ICR, extreme drift
ICR, mild drift

n (demonstrations)
Figure 14: Test error vs. number of demonstrations n on the age-biased sentiment dataset (878 test annotators, mean over 5 seeds), for Qwen3.5-4B (left) and Qwen3.5-27B (right). Blue: ICL with demonstrations sampled uniformly without replacement from the annotator's own data. Yellow → red: ICR under four corpus designs with increasing posterior drift. The stronger model improves ICR only where the corpus is aligned with the target; under severe and extreme drift its error is essentially unchanged—the drift-induced bias is irreducible. Per-cell mean values are in Tables 11 and 12.
Reproducibility. Data. We use the age-biased sentiment re-annotation of Sentiment140 by Díaz et al. [2018]: 59,235 training rows (1,481 annotators, ≤ 40 each) and 1,419 test rows (878 annotators, 1–4 each). Each rating is an ordinal label in , verbalized as Very negative, Somewhat negative, Neutral, Somewhat positive, Very positive; test error is 1 – accuracy (exact match). Every test annotator with at least 5 of their own training examples defines a target Q; results are averaged over all 878 test annotators and 5 seeds (42–46).
In-context learner. Qwen3.5-4B and Qwen3.5-27B with greedy decoding (do_sample=False), max_new_tokens = 10, and thinking disabled (enable_thinking=False), using the system prompt: “You are a sentiment classifier. Output only the label (Very negative, Somewhat negative, Neutral, Somewhat positive, Very positive) and nothing else. Do not explain, do not add punctuation, do not repeat the input.” Each demonstration is formatted as Input: {sentence} \n Output: {label}; demonstrations are concatenated, followed by the query Input: {sentence} \n Output:. The completion is mapped to a rating by case-insensitive substring matching, longest label first.
Retrieval. Sentences are embedded with BAAI/bge-base-en-v1.5 [Xiao et al., 2023] (unit-normalized); the n nearest neighbors are retrieved by Euclidean distance (equivalently, cosine distance on unit vectors). ICL samples n demonstrations uniformly without replacement from the annotator's own training data, fixed across that annotator's queries; ICR retrieves n per-query nearest neighbors from the source corpus.
Per-cell mean (sentiment). We report means (averaged across 878 test annotators and 5 independent runs):

Figure 15: Test error vs. number of demonstrations on the age-biased sentiment dataset (878 test annotators, Qwen3.5-4B). Each point is the mean over 5 independent runs (seeds 42–46). Blue: Qwen-ICL with demonstrations sampled uniformly without replacement from the annotator's own training data. Yellow red: Qwen-ICR under four levels of posterior drift, as a result of expanding the source corpus: no drift (, self only), mild (self + 100 random others), severe (all 1,481 annotators), and extreme (all other annotators, self excluded). ICR sharply outperforms ICL when the source corpus is well-aligned with the target distribution and degrades as posterior drift increases. Uncertainty estimates are reported in Table 11.
Table 11: Sentiment classification with Qwen3.5-4B: test error (mean std over 5 seeds, 878 test annotators) vs. number of demonstrations across the four corpus designs.
| Qwen-ICL | ICR () | ICR (mild) | ICR (severe) | ICR (extreme) | |
|---|---|---|---|---|---|
| 4 | |||||
| 8 | |||||
| 16 | |||||
| 32 |
Table 12: Sentiment classification with Qwen3.5-27B: test error (mean std over 5 seeds, 878 test annotators) vs. number of demonstrations across the four corpus designs.
| Qwen-ICL | ICR () | ICR (mild) | ICR (severe) | ICR (extreme) | |
|---|---|---|---|---|---|
| 4 | |||||
| 8 | |||||
| 16 | |||||
| 32 |

Figure 16: Test error vs. number of demonstrations n on the age-biased sentiment dataset (878 test annotators, Qwen3.5-27B). Each point is the mean over 5 independent runs (seeds 42–46). Blue: Qwen-ICL with demonstrations sampled uniformly without replacement from the annotator's own training data. Yellow → red: Qwen-ICR under four levels of posterior drift, as a result of expanding the source corpus: no drift (P = Q, self only), mild (self + 100 random others), severe (all 1,481 annotators), and extreme (all other annotators, self excluded). Compared to Qwen3.5-4B (Figure 15), the stronger model lowers the ICR error under no/mild drift but does not remove the irreducible bias under severe or extreme drift, matching the theory. Uncertainty estimates are reported in Table 12.