Repoformer: Selective Retrieval for Repository-Level Code Completion

Di Wu, W. Ahmad, Dejiao Zhang, M. K. Ramanathan, Xiaofei Ma
2/12/2026

No official code found. Best implementation: amazon-science/Repoformer (67 stars, Apache-2.0, last commit 2025-06-17).

Abstract

Recent advances in retrieval-augmented generation (RAG) have initiated a new era in repository-level code completion. However, the invariable use of retrieval in existing methods exposes issues in both efficiency and robustness, with a large proportion of the retrieved contexts proving unhelpful or harmful to code language models (code LMs). In this paper, we propose a selective RAG framework to avoid retrieval when unnecessary. To power this framework, we design a self-supervised learning approach to enable a code LM to accurately self-evaluate whether retrieval can improve its output quality and robustly leverage the potentially noisy retrieved contexts. Using this LM as both the selective RAG policy and the generation model, our framework achieves state-of-the-art repository-level code completion performance on diverse benchmarks including RepoEval, CrossCodeEval, and CrossCodeLongEval, a new long-form code completion benchmark. Meanwhile, our analyses show that selectively retrieving brings as much as 70% inference speedup in the online serving setting without harming the performance. We further demonstrate that our framework is able to accommodate different generation models, retrievers, and programming languages. These advancements position our framework as an important step towards more accurate and efficient repository-level code completion.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Repoformer: Selective Retrieval for Repository-Level Code Completion (ICML 2024)

6711Shell, PythonMay 21, 20241 years agoApache-2.0

Similar Papers

Cite this paper

@article{wu2026repoformer,
  title  = {Repoformer: Selective Retrieval for Repository-Level Code Completion},
  author = {Di Wu and W. Ahmad and Dejiao Zhang and M. K. Ramanathan and Xiaofei Ma},
  year   = {2026},
  eprint = {2403.10059},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2403.10059},
  journal = {ICML 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2403.10059.svg)](https://codeofpaper.com/paper/2403.10059)

Discussion