arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.07003cs.SE
收藏

GraphCoder:通过基于代码上下文图的检索与语言模型增强仓库级代码补全

GraphCoder: Enhancing Repository-Level Code Completion via Code Context Graph-based Retrieval and Language Model

Wei Liu, Ailun Yu, Daoguang Zan, Bo Shen, Wei Zhang, Haiyan Zhao, Zhi Jin, Qianxiang Wang

AI总结:

针对代码大语言模型缺乏仓库特定知识导致仓库级代码补全性能不佳的问题,提出基于代码上下文图的检索增强框架GraphCoder,通过结构化上下文捕捉与粗到细检索提升补全精度与效率。

摘要:

仓库级代码补全的性能取决于对通用知识与仓库特定知识的有效利用。尽管代码大语言模型(code LLM)在通用代码补全任务中表现出色,但由于缺乏仓库特定知识,它们在仓库级补全任务上的性能往往不尽如人意。为解决这一问题,我们提出GraphCoder,这是一种检索增强型代码补全框架,通过基于图的检索-生成流程结合大语言模型的通用代码知识与仓库特定知识。具体而言,GraphCoder通过代码上下文图(CCG)更准确地捕捉补全目标的上下文,该图包含代码语句间的控制流、数据依赖与控制依赖,相比现有检索增强方法中使用的基于序列的上下文,是一种更结构化的补全目标上下文捕捉方式;基于CCG,GraphCoder进一步采用从粗到细的检索流程,从当前仓库中定位与补全目标上下文相似的代码片段。实验结果证明了GraphCoder的有效性与效率:与基线检索增强方法相比,GraphCoder的平均精确匹配(EM)更高,代码匹配提升+6.06,标识符匹配提升+6.23,同时占用更少的时间与空间。

英文摘要:

The performance of repository-level code completion depends upon the effective leverage of both general and repository-specific knowledge. Despite the impressive capability of code LLMs in general code completion tasks, they often exhibit less satisfactory performance on repository-level completion due to the lack of repository-specific knowledge in these LLMs. To address this problem, we propose GraphCoder, a retrieval-augmented code completion framework that leverages LLMs' general code knowledge and the repository-specific knowledge via a graph-based retrieval-generation process. In particular, GraphCoder captures the context of completion target more accurately through code context graph (CCG) that consists of control-flow, data- and control-dependence between code statements, a more structured way to capture the completion target context than the sequence-based context used in existing retrieval-augmented approaches; based on CCG, GraphCoder further employs a coarse-to-fine retrieval process to locate context-similar code snippets with the completion target from the current repository. Experimental results demonstrate both the effectiveness and efficiency of GraphCoder: Compared to baseline retrieval-augmented methods, GraphCoder achieves higher exact match (EM) on average, with increases of +6.06 in code match and +6.23 in identifier match, while using less time and space.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑