用分层图结构总结代码,让系统更懂函数间关系,提升检索准确率。
Code-Craft: Hierarchical Graph-Based Code Summarization for Enhanced Context Retrieval
- 从代码图出发,自底向上生成多层摘要,构建上下文感知的代码表示。
- 在7531个函数上测试,大代码库检索精度提升82%(最高+27.15个百分点)。
- 适合大型项目开发人员,尤其对理解复杂函数依赖关系有帮助。
理解与导航大规模代码库仍是软件工程中的重大挑战。现有方法通常将代码视为扁平文本或仅关注局部结构关系,限制了其提供整体、上下文感知信息检索的能力。我们提出分层代码图摘要(HCGS),通过自底向上的方式,从代码图生成多层级的结构化摘要,构建代码库的多层次表征。HCGS利用语言服务器协议实现语言无关的代码分析,并采用并行分层算法高效生成摘要。在包含5个不同代码库共7,531个函数的广泛评估中,HCGS在代码检索准确性方面表现出显著提升:对于大型代码库libsignal,top-1检索精度相对提升高达82%(绝对提升27.15个百分点),小型仓库达到完美Pass@3分数。其分层方法在所有指标上均优于传统纯代码检索,尤其在大型复杂代码库中优势明显,能更好捕捉函数间关系。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。