On The Importance of Reasoning for Context Retrieval in Repository-Level Code Editing

Alexander Kovrigin, Aleksandra Eliseeva, Yaroslav Zharov, Timofey BryksinarXiv 2024 · OpenReview

TL;DR

This paper investigates the crucial but often opaque "context retrieval" step in repository-level code editing tasks performed by LLMs. By decoupling this component and analyzing the impact of reasoning and specialized tools, the authors reveal that reasoning significantly boosts the precision of retrieved code, though it struggles to determine when enough context has been gathered.

What Problem Does This Paper Address?

Large Language Models (LLMs) are increasingly being used for complex software engineering tasks, including editing entire code repositories. A key challenge in these "repository-level code editing" tasks is efficiently finding the relevant pieces of code (context) within a large codebase to fulfill a given request. While many existing approaches tackle this end-to-end, it's unclear how much each sub-component, particularly context retrieval, contributes to the overall success. This paper aims to shed light on this by isolating and analyzing the context retrieval process itself, specifically exploring the roles of reasoning and specialized tools.

Methods

The authors decouple context retrieval from the broader code editing pipeline to study it in isolation. They compare several context retrieval strategies, ranging from a simple baseline using a standard BM25 retriever to more sophisticated approaches employing ReAct-style agents. These agents iteratively reason and act, with variations in the tools they can access (basic BM25 vs. code structure-aware tools from AutoCodeRover) and their stopping criteria (context length, tool calls, or self-reflection). The core idea is to systematically increase the reasoning complexity and evaluate its impact.

Datasets

The study uses two datasets for evaluating repository-level code editing:

  • SWE-bench Lite: A subset of the SWE-bench benchmark, containing 300 issues across 11 Python repositories. This dataset focuses on real-world GitHub issues and their corresponding patches.
  • LCA Code Editing: A newly introduced dataset consisting of 119 data points from 39 GitHub repositories. It features curated commit messages as natural language instructions and their associated code changes. LCA is noted for its larger-scale changes compared to SWE-bench Lite.

Key Insights and Ideas

  • Reasoning is Key for Precision: The most significant finding is that increasing reasoning complexity directly correlates with higher precision in the retrieved context. This means reasoning helps LLMs pinpoint more relevant code snippets.
  • Recall Needs More Than Just Reasoning: While reasoning improves precision, recall (finding all relevant code) is more closely tied to the length of the retrieved context. This suggests that current reasoning mechanisms aren't sufficient to determine when enough context has been gathered to solve a task.
  • Specialized Tools are Game-Changers: Agents equipped with task-specific, code structure-aware tools consistently outperform those relying solely on general search tools, regardless of their reasoning capabilities. This highlights the critical role of domain-specific tooling.
  • Decoupling is Essential: By isolating context retrieval, the paper provides a clearer understanding of its strengths and weaknesses, which is crucial for building more effective repository-level code editing systems.

Key Results

The paper reports quantitative results using precision, recall, and F1 scores at both file and entity levels.

  • Precision Gains: For SWE-bench Lite, the best strategy (ACR with custom tools) achieved a precision of 55.2% at the file level, a significant improvement over the baseline's 9.2%. Similar gains were observed for LCA.
  • Recall Correlation: Recall generally increased with longer context lengths. For instance, the "ReAct + CL" strategy, which aims for longer contexts, often showed higher recall.
  • Tool Impact: Across the board, strategies using AutoCodeRover's custom tools (ACR) significantly outperformed those using only BM25, especially in terms of precision and F1 scores.

Limitations and Future Work

The authors acknowledge several limitations:

  • Proprietary LLM: The study relies on a single proprietary LLM (GPT-3.5 Turbo), which might limit the generalizability of the findings. Future work should explore other LLMs.
  • Limited Approaches: Only a subset of context retrieval approaches was explored. Expanding this range would offer a more comprehensive view.

Future work should focus on developing reasoning approaches that can effectively determine the sufficiency of gathered context. Additionally, further research into "Agent-Computer Interfaces" is suggested to optimize the interaction between LLMs and external environments, maximizing reasoning potential and improving performance. The authors emphasize that reasoning for retrieval is a vital area for continued research.

Summary updated

Abstract

Recent advancements in code-fluent Large Language Models (LLMs) enabled the research on repository-level code editing. In such tasks, the model navigates and modifies the entire codebase of a project according to request. Hence, such tasks require efficient context retrieval, i.e., navigating vast codebases to gather relevant context. Despite the recognized importance of context retrieval, existing studies tend to approach repository-level coding tasks in an end-to-end manner, rendering the impact of individual components within these complicated systems unclear. In this work, we decouple the task of context retrieval from the other components of the repository-level code editing pipelines. We lay the groundwork to define the strengths and weaknesses of this component and the role that reasoning plays in it by conducting experiments that focus solely on context retrieval. We conclude that while the reasoning helps to improve the precision of the gathered context, it still lacks the ability to identify its sufficiency. We also outline the ultimate role of the specialized tools in the process of context gathering. The code supplementing this paper is available at https://github.com/JetBrains-Research/ai-agents-code-editing.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
SWE-bench LiteReAct + SR (BM25)File-level Precision (P)25.6+16.4 vs baselineretrieval-tool=BM25 · reasoning-method=ReAct + SR
Source quote
L139: ReAct + SR │ \textbf{\pbar{25.6}} │ \rbar{40.3} │ \textbf{\fbar{29.6}} │ \textbf{\pbar{14.2}} │ \rbar{18.6} │ \textbf{\fbar{14.3}} │ 246
SWE-bench LiteReAct + SR (ACR Tools)File-level Precision (P)42.0+32.8 vs baselineretrieval-tool=ACR · reasoning-method=ReAct + SR
Source quote
L143: ReAct + SR │ \pbar{42.0} │ \rbar{50.6} │ \fbar{44.4} │ \pbar{25.8} │ \rbar{30.6} │ \fbar{25.4} │ 306
LCAReAct + SR (BM25)File-level Precision (P)30.4+11.6 vs baselineretrieval-tool=BM25 · reasoning-method=ReAct + SR
Source quote
L150: ReAct + SR │ \textbf{\pbar{30.4}} │ \rbar{21.2} │ \fbar{21.7} │ \pbar{20.7} │ \rbar{7.8} │ \fbar{9.4} │ 198
LCAReAct + SR (ACR Tools)File-level Precision (P)49.6+30.8 vs baselineretrieval-tool=ACR · reasoning-method=ReAct + SR
Source quote
L154: ReAct + SR │ \pbar{49.6} │ \rbar{31.4} │ \fbar{34.5} │ \pbar{36.3} │ \rbar{12.6} │ \fbar{15.2} │ 568
Reported baseline / comparator measurements (2)
BenchmarkMethodMetricScoreProtocol / Evidence
SWE-bench LiteBaseline (BM25) baselineFile-level Precision (P)9.2retrieval-tool=BM25
Source quote
L136: Baseline │ \pbar{9.2} │ \rbar{29.6} │ \fbar{13.5} │ \pbar{4.8} │ \rbar{17.6} │ \fbar{7.2} │ 493
LCABaseline (BM25) baselineFile-level Precision (P)18.8retrieval-tool=BM25
Source quote
L147: Baseline │ \pbar{18.8} │ \rbar{25.3} │ \fbar{18.9} │ \pbar{12.7} │ \rbar{9.6} │ \fbar{9.4} │ 487
BibTeX
@misc{kovrigin2024importance,
  author = {Alexander Kovrigin and Aleksandra Eliseeva and Yaroslav Zharov and Timofey Bryksin},
  title = {{On The Importance of Reasoning for Context Retrieval in Repository-Level Code Editing}},
  year = {2024},
  eprint = {2406.04464},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.04464},
}
Figure