In-Context Optimization for Retrieval-Augmented Generation: A Gradient-Descent Perspective

Mingchen Li, Jiatan Huang, Chuxu Zhang, Liang Zhao, Hong Yu
5/25/2026
cs.CL
transformer-attentionrag

No confident code implementation found for this paper.

Abstract

In-context learning has recently been linked to implicit gradient descent in linear self-attention models, suggesting that context can induce a forward-pass update. Retrieval-augmented generation (RAG) also relies on context, but retrieved documents are usually treated as static evidence rather than signals for adaptation.

Show full abstract

We study RAG as an in-context optimization process. First, we show that one linear self-attention layer can implement one gradient-descent step on a unified linearized RAG objective covering both projection-based and dot-product retrieval interfaces. This gives an exact regime where retrieval-augmented prediction and in-context optimization coincide. We use this result not as a literal model of LLM computation, but as a guide for adapting the interaction between queries and retrieved evidence. We then test the boundary of this correspondence: it remains stable under controlled linear extensions, but becomes feature-distribution dependent under nonlinear architectures. Finally, we turn this view into a lightweight method for frozen RAG LLMs. The method keeps the retriever and backbone fixed, and predicts a context-conditioned update to a generator-side evidence-use interface. Across seven QA benchmarks, two retrievers, and two frozen LLM backbones, this forward-only update improves a shared-interface baseline, transfers to held-out tasks, and approaches test-time gradient adaptation at much lower per-query cost.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{li2026incontext,
  title  = {In-Context Optimization for Retrieval-Augmented Generation: A Gradient-Descent Perspective},
  author = {Mingchen Li and Jiatan Huang and Chuxu Zhang and Liang Zhao and Hong Yu},
  year   = {2026},
  eprint = {2605.26356},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2605.26356v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2605.26356.svg)](https://codeofpaper.com/paper/2605.26356)

Discussion