NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Towards A Generalist Code Embedding Model Based On Massive Data Synthesis

Chaofan Li, Jianlyu Chen, Yingxia Shao, Defu Lian, Zheng Liu

TL;DR

Existing code embedding models are severely held back by a lack of diverse, high-quality training data. This paper presents CodeR, a state-of-the-art 1.5B code embedding model trained on CodeR-Pile—a massive 2.9-million-sample synthetic dataset spanning 47 tasks and 20 programming languages—using a 3-stage curriculum learning strategy called Annealing. Despite its compact size, CodeR significantly outperforms both general-purpose and specialized code embedders (including commercial ones like Voyage-Code-003) across in-domain and out-of-domain retrieval benchmarks.

What Problem Does This Paper Address?

Retrieval-Augmented Generation (RAG) is transforming automated software engineering tasks such as code completion, bug fixing, and repo-level Q&A. However, RAG pipelines hinge on dense embedding models that can reliably capture the semantics of source code.

Standard text embedding models perform poorly on code because source code has strict syntax, control flow, and inter-file dependencies that differ fundamentally from natural language. Meanwhile, high-quality code retrieval training data is exceptionally scarce, and existing open datasets cover only a handful of languages or narrow search tasks (such as docstring-to-function matching). Proprietary solutions like Voyage-code-003 perform well, but their training data and weights remain closed, impeding community research.

Methods

To overcome data scarcity without incurring astronomical generation costs, the authors introduce a three-stage data synthesis pipeline adhering to the DRU (Diversity, Reliability, Usability) principle, paired with a curriculum learning strategy:

  1. Collaborative Data Synthesis Pipeline:
  2. Brainstorming: High-capacity proprietary LLMs (DeepSeek-R1, GPT-4o, Claude 3 Opus, Gemini 2.0 Flash) brainstormed 47 diverse code retrieval tasks categorized into four paradigms: Text2Code, Code2Text, Code2Code, and Hybrid.
  3. Instructing: GPT-4o mini created task-specific generation instructions, output schemas, and annotation rubrics, refined by human experts.
  4. Triplets Generation & Verification: A cost-effective open-source model (Qwen2.5-Coder-32B-Instruct) consumed real code from GitHub to generate query-positive pairs, followed by a self-annotation quality check (retaining only label = 1).
  5. Hard Negative Mining: Rather than generating synthetic negatives with LLMs, 15 hard negatives per pair were mined from a real GitHub codebase using FAISS index retrieval (Topk-PercPos).
  6. Annealing (Curriculum Learning):
  7. Stage 1 (Warming-up): Train exclusively on general text-only retrieval data (from the BGE training set) to build basic semantic representation capabilities.
  8. Stage 2 (Intensive Training): Train on a mixture of text and code data (existing + synthetic) to bridge the modal divide and increase entropy.
  9. Stage 3 (Cooling-down): Fine-tune strictly on filtered, high-difficulty code data. Simple pairs (where multilingual-E5 places positives in the top-3) are discarded, and GPT-4o mini categorizes and selects only "medium" and "hard" reasoning pairs.
  10. Model Architecture: Initialized from Qwen-2.5-Coder-1.5B and trained via InfoNCE contrastive loss using LoRA (rank 32, alpha 64) with task-specific instruction prompts.

Datasets

  • CodeR-Pile (New): 2,885,059 training triplets covering 47 tasks, 20 programming languages (e.g., Python, Java, Rust, Go, C++, SQL), and 2 natural languages (English, Chinese).
  • BGE Training Corpus: Text retrieval and semantic textual similarity (STS) datasets used for Stages 1 and 2.
  • CoIR: Standard code retrieval benchmark consisting of 10 datasets across 8 tasks (used for in-domain training/evaluation).
  • CoIR-filter (New): A de-duplicated, cleaned version of the CoIR test sets introduced by the authors to eliminate inflated scores caused by redundant queries/documents.
  • CodeRAG: 6 out-of-domain code retrieval datasets (HumanEval, MBPP, DS-1000, ODEX, RepoEval, SWE-bench-Lite) to test zero-shot generalization.

Key Insights and Ideas

  • Real-World Hard Negatives Beat Synthetic Negatives: When prompting LLMs to synthesize hard negatives, retrieval performance on downstream tasks collapsed (CoIR NDCG@10 dropped from 67.29 to 56.40). Mining real, similar code snippets from actual repositories provides far more realistic contrastive boundaries.
  • Open Lightweight LLMs Suffice for Generation: When seeded with well-crafted instructions, Qwen2.5-Coder-32B-Instruct achieved 93% annotation accuracy on accepted positives and produced synthetic data nearly matching GPT-4o mini's performance (67.29 vs. 68.95), drastically reducing data curation costs.
  • Curriculum "Annealing" Prevents Negative Transfer: Training directly on mixed data or skipping text warm-up resulted in noticeable performance degradation (NDCG@10 fell from 70.12 to 68.49 and 68.89, respectively). Transitioning from broad text to complex, filtered code ensures stable representation learning.
  • Filtering Trivial Data in Final Stages is Crucial: Skipping hardness filtering in Stage 3 caused a ~1.87-point drop in NDCG@10, confirming that dense retrievers benefit most from challenging, high-reasoning pairs once initial convergence is reached.

Key Results

  • CoIR Benchmark: CodeR-1.5B (full data) scored 81.77 NDCG@10, surpassing all open and closed baselines, including Voyage-code-003 (78.53), CodeXEmbed-7B (in-domain: 78.20), and Gemini-embedding (73.90).
  • CoIR-Filter: On the de-duplicated evaluation set, CodeR-1.5B widened its margin, outperforming Voyage-code-003 by 4.27 points (93.00 vs. 88.73 NDCG@10).
  • Out-of-Domain Generalization (CodeRAG): CodeR-1.5B achieved 72.8 NDCG@10 on CodeRAG, outperforming Voyage-code-002 (63.7) and SFR-mistral-7B (67.0), demonstrating strong zero-shot transfer on diverse SWE and repo-level tasks.

Limitations and Future Work

  • Language Coverage: Natural language instructions and queries are currently restricted to English and Chinese.
  • Model Scale: The released model is fixed at 1.5B parameters; scaling up to 7B+ backbones remains open.
  • Re-ranking: The study concentrates strictly on first-stage bi-encoder retrieval; leveraging CodeR-Pile to train cross-encoder re-rankers is left for future exploration.

Summary updated

BibTeX
@inproceedings{li2025towards,
  author = {Chaofan Li and Jianlyu Chen and Yingxia Shao and Defu Lian and Zheng Liu},
  title = {{Towards A Generalist Code Embedding Model Based On Massive Data Synthesis}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=K3S0uNfUsY},
}
Figure