Code-Craft:基于层次图的代码摘要生成以增强上下文检索
Code-Craft: Hierarchical Graph-Based Code Summarization for Enhanced Context Retrieval
AI总结:
本文提出层次代码图摘要生成方法HCGS,通过自底向上构建代码库多层表示并结合语言服务器协议与并行算法,在大规模代码检索中显著提升精度。
摘要:
理解与导航大规模代码库仍然是软件工程中的重大挑战。现有方法通常将代码视为扁平文本,或主要关注局部结构关系,限制了它们提供整体性、上下文感知信息检索的能力。我们提出层次代码图摘要生成(HCGS),这是一种新颖的方法,通过从代码图以自底向上的方式生成结构化摘要,构建代码库的多层表示。HCGS 利用语言服务器协议(Language Server Protocol)实现语言无关的代码分析,并采用基于层级的并行算法进行高效摘要生成。通过在五个不同代码库(共 7,531 个函数)上的广泛评估,HCGS 在代码检索准确性方面表现出显著提升,在 libsignal 等大型代码库中,top-1 检索精度的相对提升最高达 82 个百分点(绝对提升 27.15 个百分点),在较小仓库中取得了完美的 Pass@3 分数。该系统的层次化方法在所有指标上始终优于传统的仅代码检索,尤其在更大、更复杂的代码库中收益显著,因为在这些代码库中理解函数间关系至关重要。
英文摘要:
Understanding and navigating large-scale codebases remains a significant challenge in software engineering. Existing methods often treat code as flat text or focus primarily on local structural relationships, limiting their ability to provide holistic, context-aware information retrieval. We present Hierarchical Code Graph Summarization (HCGS), a novel approach that constructs a multi-layered representation of a codebase by generating structured summaries in a bottom-up fashion from a code graph. HCGS leverages the Language Server Protocol for language-agnostic code analysis and employs a parallel level-based algorithm for efficient summary generation. Through extensive evaluation on five diverse codebases totaling 7,531 functions, HCGS demonstrates significant improvements in code retrieval accuracy, achieving up to 82 percentage relative improvement in top-1 retrieval precision for large codebases like libsignal (27.15 percentage points), and perfect Pass@3 scores for smaller repositories. The system's hierarchical approach consistently outperforms traditional code-only retrieval across all metrics, with particularly substantial gains in larger, more complex codebases where understanding function relationships is crucial.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。