GRAPE: Let GRPO Supervise Query Rewriting by Ranking for Retrieval
Abstract
The CLIP model has established itself as a cornerstone of large-scale retrieval systems. However, its performance often degrades under distributional shifts such as multilingual, long-form, or multimodal queries. To avoid the prohibitive costs associated with retriever retraining or corpus re-embedding, we propose GRAPE (Grouped Ranking-Aware Policy Optimization Enhancement), a plug-and-play approach that leverages LLM-based query rewriting to bridge these gaps. Unlike existing methods that lack explicit supervision, GRAPE integrates ranking signals into the rewriting LLM via Grouped Relative Policy Optimization (GRPO), ensuring rewritten queries are better aligned with the frozen retriever’s latent distribution. Crucially, we identify a score inflation phenomenon in naive similarity-based finetuning—where irrelevant candidates receive indiscriminately high scores—and mitigate it with a novel corpus-relative ranking-based reward. Extensive experiments across multilingual (Flickr30k-CN, CVLUE, XM3600), long-form (Wikipedia), and multimodal (CIRR) benchmarks demonstrate that GRAPE consistently improves performance, achieving an average gain of 4.9% in Recall@10 without any modification to the underlying retriever.The code is available at https://github.com/mogulzhang/GRAPE.
Lay Summary
Modern image search engines are incredibly powerful, but they often struggle when users type in search queries that are very long, complex, or in languages other than English. Upgrading these massive search systems from scratch to handle every new type of query is extremely expensive and time-consuming.To solve this, we introduce GRAPE, a "plug-and-play" tool that acts as a smart translator between the user and the search engine. Instead of changing the search engine itself, GRAPE uses an AI language model to automatically rewrite the user's complex query into a clear format that the existing search engine can perfectly understand. The key innovation of GRAPE is how we train this rewriting AI. Rather than just teaching the AI to generate words that "look similar" to the target image—which often leads the AI to cheat by using generic buzzwords—we train it by directly evaluating the final search results. We reward the AI only when its rewritten query successfully pushes the correct image to the top of the search ranking. Our experiments show that this approach significantly improves search accuracy across different languages and complex scenarios, all without needing to modify the underlying search system.