一句话:提出 GraphCoder,用代码上下文图与粗到细检索增强 LLM 的仓库级代码补全。
仓库级代码补全需要同时利用通用代码知识与仓库特定知识,但现有代码大模型往往缺乏后者。本文提出 GraphCoder,一个检索增强的代码补全框架:它用代码上下文图(CCG)刻画补全目标及其周围语句间的控制流、数据依赖和控制依赖,从而比序列式上下文更准确地表示目标上下文;基于 CCG,GraphCoder 采用粗到细检索,从当前仓库中定位上下文相似的代码片段,并交给 LLM 生成补全。实验表明,与检索增强基线相比,GraphCoder 的平均 exact match 更高,代码匹配提升 +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.CCS Concepts• Software and its engineering → Search-based software engineering; • Information systems → Language models; Query representation; • Mathematics of computing → Graph algorithms.
@inproceedings{LiuYZS00JW24,
title = {GraphCoder: Enhancing Repository-Level Code Completion via Coarse-to-fine Retrieval Based on Code Context Graph},
author = {Wei Liu and Ailun Yu and Daoguang Zan and Bo Shen and Wei Zhang and Haiyan Zhao and Zhi Jin and Qianxiang Wang},
booktitle = {ASE},
year = {2024},
doi = {10.1145/3691620.3695054}
}