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

Efficient Code Embeddings from Code Generation Models

Daria Kryvosheieva, Saba Sturua, Michael Günther, Scott Martens, Han Xiao

TL;DR

Jina AI introduces jina-code-embeddings (0.5B and 1.5B), a pair of compact code retrieval models fine-tuned from pre-trained autoregressive code generation LLMs. By combining task-specific instruction prefixes, Matryoshka representation learning, and simple last-token pooling, these lightweight models outperform much larger generalist embedding models and rival proprietary state-of-the-art alternatives on comprehensive code retrieval benchmarks.

What Problem Does This Paper Address?

Developer tools like Cursor and Claude Code depend heavily on retrieval-augmented generation (RAG) to pull relevant context, API documentation, and code snippets into an LLM's prompt window. However, building effective code embedding models is challenging:

  1. Data limitations: Supervised embedding models historically rely on aligned docstrings, comments, and pedagogical snippets, which fail to capture complex, real-world development scenarios.
  2. Model trade-offs: Traditional BERT-based code embedders (e.g., CodeBERT) struggle to scale. Conversely, massive general-purpose embedding models (like Gemini Embedding or Qwen3 Embedding) perform well on code but are computationally expensive to host, train, and run in latency-sensitive IDEs.

The authors address this gap by exploring whether small, pre-trained code generation models can be efficiently converted into high-performance, specialized code embedding models.

Methods

The authors build their suite—jina-code-embeddings-0.5b (494M parameters) and 1.5b (1.54B parameters)—on top of the Qwen2.5-Coder backbones using the following design choices:

  • Decoder-Only Backbone with Last-Token Pooling: Rather than using mean pooling or complex attention pooling, the authors extract the final hidden state of the last token to form the representation.
  • Task-Specific Instruction Prefixes: Downstream code retrieval is divided into five task categories: Natural Language to Code (NL2Code), Technical QA (TechQA), Code-to-Code (Code2Code), Code to Natural Language (Code2NL), and Code to Completion (Code2Completion). Each category uses fixed, hand-crafted prompt prefixes tailored separately for queries and candidate documents (e.g., "Find the most relevant code snippet given the following query:\n" vs. "Candidate code snippet:\n").
  • Contrastive Fine-Tuning & MRL: Models are trained using an InfoNCE loss ($\tau = 0.05$) across in-batch negatives. They also integrate Matryoshka Representation Learning (MRL), enabling users to truncate vector dimensions to trade off small amounts of accuracy for lower memory and storage costs.
  • Training Setup: Trained for 1,500 steps on 4× 80GB A100 GPUs (taking ~8.3 hours for the 0.5B model and ~12 hours for the 1.5B model) with a sequence length of 512.

Datasets

The training corpus includes a mix of open datasets, adapted non-retrieval corpora, and synthetically generated data:

  • Public & Adapted Data: Training splits from MTEB Code benchmarks (AppsRetrieval, CodeSearchNet, StackOverflowQA, SyntheticText2SQL, CoSQA), CoSQA+, and adapted code problem sets (LeetCode, MBPP, Spider, SWE-Bench, WikiSQL, StackExchange).
  • Synthetic Datasets (via GPT-4o):
  • SyntheticDLTrans: Cross-framework deep learning code translations (e.g., PyTorch to TensorFlow) covering architectures, training loops, and tensor operations.
  • Multilingual CodeChef extensions: GPT-4o expanded C++ and Python competitive programming solutions into eight additional languages (C, C#, Go, Java, JavaScript, Ruby, Rust, TypeScript) to support cross-lingual code-to-code retrieval (CodeChefXLang).
  • Evaluation: Evaluated across 25 code-related retrieval benchmarks, including the MTEB-CoIR benchmark, HumanEval, MBPP, DS-1000, and several in-house tasks.

Key Insights and Ideas

  • Code generation models are natural embedding backbones: An autoregressive model pre-trained to synthesize code has already acquired rich semantic representations of code structure and syntax. Fine-tuning it with a contrastive objective successfully unlocks these representations for retrieval.
  • Simpler pooling wins: While recent literature advocates for trainable latent-attention pooling in decoder-based embedders, the authors' ablation study revealed that standard last-token pooling consistently yielded superior average accuracy over mean and latent-attention pooling.
  • Fixed task prefixes reduce ambiguity: Rather than allowing open-ended user instruction-tuning (which can cause unpredictable embedding behavior), strictly categorizing code tasks into 5 explicit asymmetric query/document prefix formats optimized retrieval behavior.

Key Results

Across the 25 evaluation benchmarks (including MTEB Code tasks):

  • Overall Performance:
  • jina-code-embeddings-0.5b: 78.41% overall average (78.72% on MTEB Code).
  • jina-code-embeddings-1.5b: 79.04% overall average (78.94% on MTEB Code).
  • Comparison Against Larger Models:
  • Both models significantly outperform the similarly sized Qwen3-Embedding-0.6B (73.49% overall) as well as larger models like jina-embeddings-v4 (74.11%) and Google's gemini-embedding-001 (77.38%).
  • The 1.5B model performs competitively with the proprietary voyage-code-3 (79.23% overall / 79.84% MTEB Code).

Limitations and Future Work

  • Training vs. Evaluation Length Discrepancy: The models were trained on relatively short sequences (512 tokens), yet evaluated on lengths up to 8,192 tokens. Extending training sequence lengths could improve performance on large files or full repository retrieval.
  • CLS Pooling Omitted: The authors did not test [CLS] token pooling (noting it is typically disfavored in decoder architectures).
  • Reliance on Synthetic Data: While GPT-4o generation effectively filled data gaps for tasks like cross-framework translation, real-world validation of these translations was limited to manual spot-checking.

Summary updated

BibTeX
@inproceedings{kryvosheieva2025efficient,
  author = {Daria Kryvosheieva and Saba Sturua and Michael Günther and Scott Martens and Han Xiao},
  title = {{Efficient Code Embeddings from Code Generation Models}},
  booktitle = {DL4C @ NeurIPS},
  year = {2025},
  url = {https://openreview.net/forum?id=smR7RPdWZs},
}
Figure