RL based Query Rewriting

Final results

Training beats prompting everywhere. Beating the original query depends on the retriever.

All numbers are on the test questions. ↑ and ↓ mark a significant difference from the original query (95% paired bootstrap, 1,000 resamples).

Dataset, retrieverOriginal queryPrompted 3BTrained for that retrieverCombined reward
CoSQA, BM250.3390.302 ↓0.358 ↑0.365 ↑
CSN, BM250.4030.387 0.440 ↑0.451 ↑
CoSQA, UniXcoder0.4540.388 ↓0.481 ↑0.468
CSN, UniXcoder0.5150.416 ↓0.503 0.498 ↓

MRR@10. “Trained for that retriever” is seed 1 of the BM25 or UniXcoder reward model, matching the row's retriever.

Explore every method

Pick a setting. Bars are test scores, whiskers 95% intervals, the line the original query.

Dataset
Retriever
Metric
Show data

Reward choice matters across retrievers

Change in test MRR@10 vs the original query. Rows are the reward used in training, columns where the model was tested.

Show data

Why the combined reward

The BM25 model learned to write short keywords that look like function names. They suit keyword matching, but a model that reads meaning loses context, and the BM25 model falls far below the original query under UniXcoder.

Averaging the two rewards gave one model that performs about as well as each specialist on that specialist's own retriever (no significant MRR@10 difference) and avoids the big drop.

A simple baseline we kept honest about

Joining the original query with the untrained rewrite needs no training at all. On CoSQA with BM25 it ties with our trained model. The trained model is clearly better on CodeSearchNet with BM25 and on CoSQA with UniXcoder. Find it as “Original + rewrite joined” in the explorer.

Did we confirm our hypothesis?

The success criteria were written down before any training.

CriterionResult
A trained model beats the original query on CoSQA, on both Hit@10 and MRR@10, significantlyPartly MRR@10 yes with BM25 (both seeds and combined), and with UniXcoder for one seed only. Hit@10 not significant for any model.
It beats the same model before trainingMet With the retriever it was trained for, every setting.
It does not hurt CodeSearchNet compared with the original querySplit BM25 improves. UniXcoder shows small drops, some significant.