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

RepoGenReflex: Enhancing Repository-Level Code Completion with Verbal Reinforcement and Retrieval-Augmented Generation

Jicheng Wang, Yifeng He, Hao ChenarXiv 2024 · DOI

Abstract

Repository-level code completion is a complex task requiring models to understand dependencies across vast codebases. Current approaches using Retrieval-Augmented Generation (RAG) often suffer from static retrieval mechanisms that fail to adapt when initial snippets are insufficient. We introduce RepoGenReflex, a framework that leverages Verbal Reinforcement Learning (VRL) to iteratively refine code generation. By utilizing a "Reflector" component to provide natural language feedback, the system dynamically adjusts its retrieval strategy and improves code quality. Our evaluation on the new RepoGenEval benchmark demonstrates that RepoGenReflex significantly outperforms existing state-of-the-art models.

Introduction

Modern software engineering involves intricate interdependencies across numerous files. While Large Language Models (LLMs) excel at local code completion, repository-level completion presents two primary challenges: limited context windows and the inefficiency of static retrieval. Traditional RAG systems often fail if the initial search does not capture the necessary context. RepoGenReflex addresses these issues by transforming code completion into an adaptive, iterative process guided by linguistic feedback.

The RepoGenReflex Framework

RepoGenReflex operates through a sophisticated feedback loop designed to mimic a developer's iterative debugging process. The framework consists of five core components:

  1. Retriever: Identifies relevant code snippets within the repository based on the current context.
  2. Actor: A generative LLM that produces code completions using the retrieved snippets and the unfinished code.
  3. Evaluator: Assesses the generated code against ground truth using metrics such as Exact Match (EM) and Edit Similarity (ES).
  4. Reflector: Analyzes the Evaluator's output and the generated code to produce verbal reinforcement—natural language critiques that guide the next iteration.
  5. Experience Cache: Stores feedback to inform subsequent retrieval attempts.
Overview of the RepoGenReflex framework, illustrating the iterative loop between the Retriever, Actor, Evaluator, and Reflector.

Verbal Reinforcement Learning

A key innovation of RepoGenReflex is the use of Verbal Reinforcement Learning (VRL). Unlike traditional reinforcement learning, which requires computationally expensive weight updates, VRL uses linguistic feedback to refine model behavior. The Reflector acts as the "brain" of this loop, identifying missing dependencies or logic errors and suggesting specific improvements for the Retriever to target in the next cycle.

Example of verbal reinforcement generated by the Reflector, including evaluation analysis, contextual analysis, and specific code suggestions.

Interestingly, research indicated that general-purpose models, such as Meta-Llama-3-8B, often outperform specialized code models when acting as the Reflector. This suggests that the reasoning and linguistic capabilities of generalist LLMs are better suited for providing nuanced feedback than models optimized purely for code syntax.

Evaluation and Results

To evaluate the framework, the authors introduced RepoGenEval, a benchmark comprising eight high-quality Python repositories created after 2023. This ensures the models are tested on modern codebases not present in their initial training data.

RepoGenReflex demonstrated superior performance across multiple metrics. On the RepoGenEval benchmark, it achieved an Exact Match (EM) score of approximately 0.438 and an Edit Similarity (ES) of 0.735, significantly surpassing state-of-the-art models like CodeGemma and StarCoder. Ablation studies confirmed that the Reflector and Experience Cache are vital to these gains; removing them resulted in a marked decrease in completion accuracy.

Conclusion

RepoGenReflex represents a significant step forward in repository-level code completion by combining the strengths of RAG and VRL. While the iterative nature of the framework introduces some computational overhead, the gains in accuracy and the ability to handle complex cross-file dependencies are substantial. Future work will focus on optimizing the speed of the RAG-VRL loop and expanding the framework's support to other programming languages like C++ and Rust.

Summary updated

BibTeX
@misc{wang2024repogenreflex,
  author = {Jicheng Wang and Yifeng He and Hao Chen},
  title = {{RepoGenReflex: Enhancing Repository-Level Code Completion with Verbal Reinforcement and Retrieval-Augmented Generation}},
  year = {2024},
  eprint = {2409.13122},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2409.13122},
}
Figure