Skip to main content
QUICK REVIEW

[Paper Review] ReACC: A Retrieval-Augmented Code Completion Framework

Shuai Lu, Nan Duan|arXiv (Cornell University)|Mar 15, 2022
Software Engineering ResearchComputer Science8 citations
TL;DR

ReACC is a retrieval-augmented code completion framework that enhances code completion by retrieving semantically and lexically similar code snippets from a large codebase. It combines a hybrid retriever (dense + sparse) with a fine-tuned CodeGPT-based generator, achieving state-of-the-art performance on CodeXGLUE benchmarks in Python and Java.

ABSTRACT

Code completion, which aims to predict the following code token(s) according to the code context, can improve the productivity of software development. Recent work has proved that statistical language modeling with transformers can greatly improve the performance in the code completion task via learning from large-scale source code datasets. However, current approaches focus only on code context within the file or project, i.e. internal context. Our distinction is utilizing "external" context, inspired by human behaviors of copying from the related code snippets when writing code. Specifically, we propose a retrieval-augmented code completion framework, leveraging both lexical copying and referring to code with similar semantics by retrieval. We adopt a stage-wise training approach that combines a source code retriever and an auto-regressive language model for programming language. We evaluate our approach in the code completion task in Python and Java programming languages, achieving a state-of-the-art performance on CodeXGLUE benchmark.

Motivation & Objective

  • To improve code completion by leveraging external codebase context beyond the current file.
  • To investigate whether retrieving semantically and lexically similar code snippets enhances code completion performance.
  • To design a stage-wise training framework integrating retrieval and generation for code completion.
  • To evaluate the effectiveness of hybrid retrieval (dense + sparse) and data augmentation in improving code completion accuracy.

Proposed method

  • Uses a dual-encoder dense retriever initialized with GraphCodeBERT and fine-tuned via contrastive learning on synthetic code pairs.
  • Employs a sparse retriever (BM25) for lexical similarity, combined with the dense retriever via a hybrid retrieval strategy.
  • Applies data augmentation via semantic-preserving transformations (e.g., identifier renaming, dead code insertion) to generate positive training pairs for the retriever.
  • Concatenates the input code snippet with retrieved similar code as context for the generator.
  • Uses a decoder-only transformer (CodeGPT-adapted) as the code completion generator, fine-tuned on the augmented context.
  • Employs a stage-wise training strategy: first pre-train the retriever, then fine-tune the generator using retrieved context.

Experimental results

Research questions

  • RQ1Can retrieving external code snippets with similar semantics improve code completion accuracy compared to relying only on internal context?
  • RQ2How does combining dense (semantic) and sparse (lexical) retrieval impact code completion performance?
  • RQ3What is the contribution of different data augmentation techniques to the retriever's generalization and performance?
  • RQ4Does the retrieval-augmented framework outperform strong baselines like CodeGPT and GitHub Copilot in code completion tasks?
  • RQ5How does the performance of ReACC vary across different code domains, such as general-purpose vs. algorithmic code?

Key findings

  • ReACC achieves state-of-the-art performance on the CodeXGLUE benchmark, with a 64.74% exact match score on the PY150 dataset using the hybrid retriever.
  • The hybrid retriever outperforms both dense and sparse baselines, demonstrating the complementary benefits of semantic and lexical similarity.
  • On the CodeNet algorithmic dataset, ReACC improves edit similarity by 18% and exact match by 10% over CodeGPT-adapted, indicating strong effectiveness in specific domains.
  • Ablation studies show that query truncation and identifier renaming are the most impactful data augmentation techniques for the retriever.
  • The generator’s performance degrades slightly when using raw retrieved snippets instead of aligned fragments, indicating the value of context alignment.
  • Even with a smaller retrieval database, ReACC outperforms GitHub Copilot in some cases, and Copilot itself benefits when augmented with ReACC’s retriever.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.