RL based Query Rewriting

USC Applied NLP course project · 2026

Teaching a small model to rewrite
code search queries

Developers search code in plain English, but code speaks in function names and APIs. We put a 3B language model in front of a frozen search engine and trained it with reinforcement learning, rewarding it only by how high the correct function ranked.

Developer asks“how to check if a path is writeable python”
RewriterQwen2.5 Coder 3B + LoRA
Rewritten querycheck if path is writeable - os.access
Retriever (frozen)BM25 or UniXcoder
Correct functionBM25 rank 77 → 3
CodeSearchNet with BM25, Hit@10
0.607 → 0.676
About 7 more queries in every 100 find the right function in the top ten
Same model, before vs after training
8 of 8
Trained models beat the untrained 3B in every setting they were trained for, all significant
What we trained
1.0%
29,933,568 LoRA weights on a frozen 3.09B model

Test MRR@10, original query vs prompted vs trained

Higher is better. Whiskers show 95% bootstrap intervals. The trained model uses the combined reward.

Show data

Explore

Go deeper