Research map / Large language models / Retrieval and knowledge
Repoformer: Selective Retrieval for Repository-Level Code Completion
Read the paperCheck your idea against 108,967 papers
AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.
Proposes Repoformer, a StarCoderBase-based code LM fine-tuned with a self-supervised multi-task objective to self-decide whether cross-file retrieval is worth triggering for repository-level code completion, improving accuracy and cutting latency.
Problem
Always-on retrieval augmentation for repository-level code completion is often unhelpful or harmful to code LMs and adds substantial inference latency.
Approach
A code LM is trained to emit a special <cc> token to self-trigger retrieval, with labels mined from public repositories by contrasting generation quality with and without retrieved context; a joint loss trains both the self-assessment and robust RAG generation, so the same model acts as selective policy and generator in a single forward pass.
Key results
- Repoformer-3B with threshold selection matches or beats the 16B StarCoder always-retrieving baseline on several RepoEval tasks in ES and outperforms same-sized StarCoderBase-3B always retrieving by over 3 ES points.
- Repoformer-16B achieves state-of-the-art results across tasks, outperforming the strongest StarCoder baseline by about 3% on average.
- Selective retrieval yields up to 70% inference speedup in online serving with no accuracy loss; Repoformer-1B as a plug-and-play policy reduces latency of larger LMs by about 25% while improving accuracy.
Measured effects reported in the paper
| What was changed | Where | Measured | Effect |
|---|---|---|---|
| use Repoformer threshold-selective retrieval instead of always retrieving | StarCoderBase-16B · RepoEval API | ES: 74.50 -> 77.93 | Helped |
| use Repoformer threshold-selective retrieval instead of always retrieving | StarCoderBase-16B · CrossCodeLongEval Chunk | ES: 71.90 -> 75.50 | Helped |
| use threshold selection instead of greedy selection | Repoformer-1B · RepoEval API | ES: 71.00 -> 72.70 | Helped |
| use greedy selection instead of always retrieval | Repoformer-1B · RepoEval API | ES: 72.02 -> 71.04 | Hurt |
| use threshold selection instead of always retrieval | Repoformer-1B · RepoEval API | speedup: 0% -> 28% | Helped |
| use Repoformer-1B as a selective retrieval policy for the larger generation model | StarCoderBase-7B · RepoEval API | ES: 73.65 -> 74.10 | Helped |
| remove self-evaluation loss (ablation) | Repoformer-1B · CrossCodeLongEval Chunk | ES: 69.97 -> 70.45 | Helped |
| remove self-evaluation loss (ablation) | Repoformer-1B · CrossCodeLongEval Function | ES: 53.71 -> 53.90 | Helped |
| add retrieved contexts to training (ablation) | A2 (without self-evaluation loss) · CrossCodeLongEval Chunk | ES: 68.85 -> 70.45 | Helped |
| add retrieved contexts to training (ablation) | A2 (without self-evaluation loss) · CrossCodeLongEval Function | ES: 52.12 -> 53.90 | Helped |
| place retrieved contexts in the input context rather than after fim_middle (ablation) | A4 · CrossCodeLongEval Function | ES: 26.35 -> 53.56 | Helped |
| combine self-evaluation and generation losses as a single cross-entropy loss (ablation) | Repoformer-1B · CrossCodeLongEval Chunk | ES: 69.97 -> 70.21 | Helped |
Surprising findings
- Retrieval improves performance on only about 20% of instances for four code LMs on RepoEval function completion; around 20% of retrievals actually harm performance.
- Trial-retrieval and uncertainty-based selective RAG heuristics fail to generalize well across tasks and incur retrieval latency.
Limitations
- Function completion labeling relies on edit similarity, leading to poorly calibrated retrieval decisions for function completion under unit-test metric.
- Uniform selective policy across repositories; no personalization to repository duplication levels.
- Speedup gains depend on retrieval being a large share of latency; gains are smaller with sparse retrieval on small repositories.
Experimental setup
Datasets: The Stack RepoEval CrossCodeEval
Benchmarks: RepoEval CrossCodeLongEval CrossCodeEval
Metrics: exact match edit similarity unit test pass rate identifier F1 speedup retrieval ratio
Baselines: StarCoderBase always retrieving StarCoder always retrieving No retrieval CodeGen-Mono Code Llama CodeGen25 ChatGPT
Builds on: StarCoder ContraCLM fill-in-the-middle RG-1
Closest papers by meaning
- Hierarchical Context Pruning: Optimizing Real-World Code Completion with Repository-Level Pretrained Code LLMs (AAAI 2025 · similarity 0.89)
- RepoBench: Benchmarking Repository-Level Code Auto-Completion Systems (ICLR 2024 · similarity 0.89)
- Towards A Generalist Code Embedding Model Based On Massive Data Synthesis (NeurIPS 2025 · similarity 0.89)
- CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking (ICLR 2025 · similarity 0.87)
- PinNet: Pinpoint Instructive Information for Retrieval Augmented Code-to-Text Generation (ICML 2024 · similarity 0.87)
- LiveCodeBench: Holistic and Contamination Free Evaluation of Large Language Models for Code (ICLR 2025 · similarity 0.86)
Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.
