AI
Training LLMs to rewrite documents boosts retrieval performance while cutting inference costs
A new method shifts computational burden offline by optimizing how documents are represented, helping retrieval systems find more relevant results faster.
Embedding language models into retrieval pipelines for query rewriting and document ranking has become commonplace, but this approach comes with a steep price: it adds expensive computation directly to the latency-critical retrieval path. Researchers are now exploring a different strategy—optimizing the documents themselves rather than the queries, moving heavy lifting offline.
The Challenge of Effective Document Rewriting#
Simply rewriting documents to be more general or informative doesn't guarantee better retrieval. The core problem is that retrieval systems operate discriminatively—they rank documents based on similarity to queries in the retriever's learned vector space. An effective rewrite must therefore make a document appear more similar to relevant queries than to competing documents, all while respecting the specific notion of similarity that the retriever uses.
DocOpt: Optimization via Reinforcement Learning#
Researchers have developed DocOpt, a method that treats document rewriting as an explicit optimization problem. The approach uses group relative policy optimization (GRPO) with retriever ranking improvements as rewards, requiring only black-box access to retrieval rankings. Importantly, it generalizes across different retriever architectures—single-vector embeddings, multi-vector systems, and lexical (keyword-based) search.
Results Across Retrieval Tasks#
Testing on code and visual retrieval tasks reveals measurable gains at each stage. Starting from OpenAI's text-embedding-3-small baseline (58.35 nDCG@5), zero-shot rewriting with various LLMs improved results to between 60.83 and 64.23. Applying the optimized DocOpt approach pushed performance further to 67.94 nDCG@5—surpassing a 6.5 times more expensive retriever (text-embedding-3-large at 66.15) while keeping computation offline.
Why This Matters#
The work highlights a fundamental shift in how to architect retrieval systems. By moving LLM work to document preparation rather than query time, teams can achieve better search quality without adding latency to user-facing queries. This approach also maintains compatibility with existing retriever infrastructure, making it practical for real-world deployment.

