[Paper Review] RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generation
RepoCoder introduces an iterative retrieval-generation framework for repository-level code completion, leveraging repository context and iterative prompts to improve completion accuracy over In-File baselines across multiple models. It also presents RepoEval, a benchmark with line, API invocation, and function body completion using unit tests.
The task of repository-level code completion is to continue writing the unfinished code based on a broader context of the repository. While for automated code completion tools, it is difficult to utilize the useful information scattered in different files. We propose RepoCoder, a simple, generic, and effective framework to address the challenge. It streamlines the repository-level code completion process by incorporating a similarity-based retriever and a pre-trained code language model in an iterative retrieval-generation pipeline. RepoCoder makes effective utilization of repository-level information for code completion and has the ability to generate code at various levels of granularity. Moreover, we propose a new benchmark RepoEval, which consists of the latest and high-quality real-world repositories covering line, API invocation, and function body completion scenarios. Experimental results indicate that RepoCoder significantly improves the In-File completion baseline by over 10% in all settings and consistently outperforms the vanilla retrieval-augmented code completion approach. Furthermore, we validate the effectiveness of RepoCoder through comprehensive analysis, providing valuable insights for future research. Our source code and benchmark are publicly available: https://github.com/microsoft/CodeT/tree/main/RepoCoder
Motivation & Objective
- Motivate repository-level code completion to utilize cross-file context within a codebase.
- Propose a generic retrieval-augmented generation framework to incorporate repository-level information.
- Demonstrate iterative retrieval to bridge the gap between retrieval context and target completion.
- Introduce RepoEval to evaluate line, API invocation, and function body completion with unit tests.
Proposed method
- Construct a repository code corpus by sliding window over files to build a retrieval collection.
- Use a retriever to fetch relevant snippets from the repo based on unfinished code X as query (C_repo, X).
- Apply an iterative scheme where each generation Y^{i-1} is used to refine the retrieval for Y^{i}, without changing model parameters.
- Prompt design combines retrieved snippets C_ret with unfinished code X to guide generation by a pre-trained language model.
- Utilize both sparse (Jaccard-based) and dense (UniXcoder-based) retrievers, and multiple generation models (GPT-3.5-Turbo, CodeGen variants).
- Benchmark with RepoEval: three granularities (line, API invocation, function body) and unit-test-based evaluation.
Experimental results
Research questions
- RQ1Can repository-level context improve code completion beyond in-file context?
- RQ2Does iterative retrieval-generation (RepoCoder) outperform single-pass RAG and In-File baselines across different models?
- RQ3How does retrieval quality affect completion performance in repository-level code completion?
- RQ4What is the impact of iteration count on performance and when to stop iterating?
- RQ5How does RepoEval capture real-world repository-level completion scenarios including unit tests?
Key findings
- RepoCoder consistently improves In-File completion by over 10% in EM and ES across datasets and models.
- Two or more iterations in RepoCoder reliably outperform vanilla RAG across line and API completion tasks.
- CodeGen models with 350M parameters achieve comparable performance to GPT-3.5-Turbo in RepoCoder settings.
- Dense retrievers yield similar performance to sparse retrievers in RepoCoder’s framework, suggesting robustness across retrieval choices.
- RepoCoder with two iterations shows higher recall for ground-truth API invocations, indicating better retrieval guidance for generation.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.