TL;DR
Current code retrieval benchmarks are fundamentally flawed because they treat valid alternative code implementations as "negatives," penalizing models for being correct. This paper introduces MegaCode, a massive, semantically curated dataset of 193M pairs, and demonstrates that rigorous data filtering allows a 0.5B parameter model to outperform 8B parameter giants.
What Problem Does This Paper Address?
In the world of code search (finding code snippets using natural language), we rely on benchmarks to tell us which models are best. However, these benchmarks typically assume a one-to-one relationship: one query equals one "ground truth" snippet.
The authors argue this is a "systemic problem." If a model retrieves a perfectly functional piece of code that wasn't the specific one chosen by the benchmark creators, it receives zero credit. These "hidden positives" make evaluation unstable and underestimate model quality. Furthermore, the training data used for these models is often "noisy," relying on simple heuristics (like pairing a function with its docstring) that are frequently outdated or irrelevant.
Methods
The researchers attacked this problem from two angles: evaluation and training.
- Unified LLM-as-a-Judge Evaluation: Instead of trusting old, incomplete labels, they used a high-capacity LLM (Claude-Opus-4.6) to re-annotate the top 10 results from every model. This creates a consistent "semantic standard" across different benchmarks, rewarding models for finding any relevant code, not just the "official" snippet.
- The MegaCode Pipeline: To improve training, they built a multi-stage pipeline:
- Heuristic Pairing: Initial extraction of 300M (comment, code) pairs using Tree-sitter.
- Semantic Filtering: They trained a 1.5B "reranker" model (supervised by an LLM) to score the relevance of these pairs, discarding the noise. This resulted in the MegaCode dataset (193M high-quality pairs).
- Contrastive Pre-training: Training a family of embedding models (0.5B to 7B) using a symmetric cross-entropy loss.
- Hard Negative Mining: A final fine-tuning stage where the model is forced to distinguish between the correct code and "near-miss" negatives.
Datasets
- MegaCode (New): The largest semantically curated dataset for code search to date, featuring 193M positive pairs across 14 programming languages (Python, Java, C++, Rust, etc.).
- Evaluation Benchmarks: The authors re-evaluated six major benchmarks: CoSQA, CoSQA+, CSN-Orig, CSN-Adv, CSN-Query, and RepoQA.
Key Insights and Ideas
- The "Hidden Positive" Magnitude: The scale of the labeling problem is massive. Depending on the dataset, 44% to 87% of relevant code snippets were missing from the original benchmark labels.
- Curation Trumps Scaling: The most significant finding is that data quality matters more than model size. Their 0.5B parameter model—trained on clean, curated data—matched or beat existing 8B parameter models.
- Heuristics are a Bottleneck: Traditional methods of scraping (comment, function) pairs are too noisy. Docstrings often describe what a function used to do or are too generic to be useful for training.
- Hard Negatives are Essential: Pre-training on millions of positives isn't enough. Models need "hard negatives" (code that looks similar but doesn't solve the query) to develop sharp decision boundaries.
Key Results
- State-of-the-Art Performance: The MegaCode-emb-7B model improved the average Mean Reciprocal Rank (MRR@10) by 3.5 points over the strongest existing baselines.
- Efficiency: Their 0.5B model outperformed the Qwen3-Embedding-8B on several benchmarks, proving that smart data curation can reduce the need for massive compute.
- Judge Validation: The authors validated their LLM judge against human experts, finding an 87.3% agreement rate, suggesting that LLMs are now reliable enough to replace brittle heuristic benchmarks.
Limitations and Future Work
- The "User Query" Gap: While models are getting very good at docstring-based benchmarks (scoring >0.90 MRR), they still struggle with natural, messy user queries (like those in CoSQA). These remain the "frontier" for code search.
- LLM Bias: While the LLM judge is more consistent than heuristics, it is not a perfect "gold standard" and may have its own inherent biases in how it interprets code relevance.
- Future Directions: The authors suggest that future gains will likely come from even better supervision and more complex, multi-file query distributions rather than simply increasing parameter counts.
Summary updated