Skip to main content
QUICK REVIEW

[论文解读] RepoHyper: Search-Expand-Refine on Semantic Graphs for Repository-Level Code Completion

Huy N. Phan, Hoang Ngo Phan|arXiv (Cornell University)|Mar 10, 2024
Semantic Web and OntologiesComputer Science被引用 3
一句话总结

RepoHyper 提出了一种新颖的仓库级代码补全框架,通过利用仓库级语义图(RSG)和搜索-扩展-重排序检索流水线,提升了上下文的相关性。通过结合基于图的语义搜索与链接预测进行重排序,其在 RepoBench 上相较于强基线模型,检索准确率平均提升 49%,Exact Match(EM)提升 +4.1。

ABSTRACT

Code Large Language Models (CodeLLMs) have demonstrated impressive proficiency in code completion tasks. However, they often fall short of fully understanding the extensive context of a project repository, such as the intricacies of relevant files and class hierarchies, which can result in less precise completions. To overcome these limitations, we present ool, a multifaceted framework designed to address the complex challenges associated with repository-level code completion. Central to RepoHYPER is the {\em Repo-level Semantic Graph} (RSG), a novel semantic graph structure that encapsulates the vast context of code repositories. Furthermore, RepoHyper leverages Expand and Refine retrieval method, including a graph expansion and a link prediction algorithm applied to the RSG, enabling the effective retrieval and prioritization of relevant code snippets. Our evaluations show that ool markedly outperforms existing techniques in repository-level code completion, showcasing enhanced accuracy across various datasets when compared to several strong baselines. Our implementation of RepoHYPER can be found at https://github.com/FSoft-AI4Code/RepoHyper.

研究动机与目标

  • 为解决现有代码补全工具无法有效利用代码邻近关系之外的全局仓库上下文的问题。
  • 通过不仅引入语法相似性,还融合程序语义关系(如类继承与方法依赖)来提升相关代码片段的检索准确率。
  • 设计一种可扩展且高效的检索机制,避免处理整个代码库,通过结构化知识表示实现。
  • 证明仅通过改进上下文检索(无需修改 LLM 架构)即可显著提升端到端代码补全性能。

提出的方法

  • 构建仓库级语义图(RSG),以编码全局仓库上下文,包括代码元素、依赖关系以及语义关系(如继承与方法调用)。
  • 采用“先搜索后扩展”策略:首先使用密集编码器(如 UniXCoder)检索语义相似的代码片段,随后通过预定义路径类型在 RSG 上进行广度优先搜索(BFS)扩展检索范围。
  • 在 RSG 上训练链接预测模型,用于对扩展后的候选片段进行重排序,基于结构与语义接近度优先选择语义相关性更高的片段。
  • 将检索到的 top-k 片段作为上下文输入代码大语言模型(CodeLLM),实现准确的仓库级代码补全。
  • 通过重排序损失函数优化检索流水线,增强相关与无关上下文之间的决策边界。
  • 实验采用 RepoBench 基准,涵盖上下文检索(CR)与端到端代码补全(EECC)两种评估设置。
Figure 1: Illustration of graph-based semantic search versus similarity-based search. The orange block indicates the ground-truth line that needs to complete to call the function get_similarity_metric . Similarity-based methods mistakenly focus on MultiLabelInversionModel class due to its similarity
Figure 1: Illustration of graph-based semantic search versus similarity-based search. The orange block indicates the ground-truth line that needs to complete to call the function get_similarity_metric . Similarity-based methods mistakenly focus on MultiLabelInversionModel class due to its similarity

实验结果

研究问题

  • RQ1基于图的检索系统是否能通过同时捕捉语义相似性与程序语义关系,在仓库级代码补全任务中超越传统基于相似性的方法?
  • RQ2与仅依赖嵌入相似性相比,引入结构关系(如类继承、方法调用)在多大程度上提升了检索准确率?
  • RQ3在语义图上使用链接预测,在将广泛候选片段精炼为高度相关子集方面有多高效,适用于代码补全任务?
  • RQ4仅通过改进上下文检索,是否能在不修改底层 LLM 的前提下,带来可测量的端到端代码补全性能提升?

主要发现

  • 在上下文检索(CR)任务中,RepoHyper 相较于基于相似性的基线模型,检索准确率平均提升 49%,且使用相同的编码器。
  • 在端到端代码补全(EECC)任务中,RepoHyper 相较于 RepoCoder 及其他 RepoBench 基线模型,Exact Match(EM)提升 +4.1,CodeBLEU 提升 +5.6。
  • 该方法在检索与全局程序语义相关的上下文类型(如类继承与导入关系)方面显著优于基线,准确率极高。
  • 消融实验表明,将模式搜索与链接预测器结合可获得最高性能(在困难子集上 Acc@3 达 69.12%),优于穷举搜索与重排序基线。
  • 链接预测组件至关重要:若移除该模块,性能显著下降;而使用余弦相似度进行重排序则导致过平滑现象,削弱决策边界清晰度。
  • RepoHyper 在多种上下文类型上展现出强大的泛化能力,但针对名称相似的片段,由于 kNN 阶段锚点使用有限,仍存在挑战。
Figure 2: Overall Architecture of RepoHyper. Here we use $K=1$ .
Figure 2: Overall Architecture of RepoHyper. Here we use $K=1$ .

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。