RepoDoc: 基于知识图谱的自动文档生成与增量更新框架
RepoDoc: A Knowledge Graph-Based Framework to Automatic Documentation Generation and Incremental Updates
AI总结:
RepoDoc通过构建仓库知识图谱,实现代码文档的自动化生成与增量更新,提升文档覆盖率和完整性,同时提高生成效率与准确性。
摘要:
维护大型代码库的最新、全面文档是一个持续的挑战。最近自动文档生成的进步从基于模板的规则转向了大型语言模型(LLMs),但现有工具仍将源代码视为扁平片段,生成孤立文档,缺乏语义结构。这种设计也导致了过多的token消耗和缓慢的生成速度,同时无法捕捉代码变更在依赖项中的传播方式。我们提出了RepoDoc,一个使用仓库知识图谱(RepoKG)作为整个文档生命周期的语义基础的系统。我们的框架包括三个阶段:(1)RepoKG构建,提取代码实体及其关系;(2)模块聚类,将代码分为功能紧密、层次化的单元;(3)基于技能代理的生成,查询图谱以创建模块化、交叉引用的文档,并自动生成Mermaid图表。对于增量维护,语义影响传播机制在RepoKG中双向导航以定位所有受影响的部分,允许选择性、针对性的再生。在24个跨8种编程语言的仓库上评估,RepoDoc显著优于现有最先进的替代方案。它提高了API覆盖率32.5%,完整性10.4%,同时生成文档速度提高3倍,token消耗减少85%。对于增量更新,它将更新时间减少73%,token使用减少77%,并实现10.2%更高的更新召回率,更准确地反映在再生文档中的代码变更。源代码和实验成果可在https://github.com/SYSUSELab/RepoDoc获取。
英文摘要:
Maintaining up-to-date, comprehensive documentation for large codebases is a persistent challenge. Recent progress in automated documentation has moved from template-based rules to large language models (LLMs), yet existing tools still process source code as flat fragments, producing isolated documents that lack semantic structure. This design also leads to excessive token consumption and slow generation, while failing to capture how code changes propagate across dependencies. We propose RepoDoc, a system that uses a repository knowledge graph (RepoKG) as the semantic foundation for the entire documentation lifecycle. Our framework consists of three stages: (1) RepoKG construction, which extracts code entities and their relationships; (2) module clustering, which groups code into functionally cohesive, hierarchical units; and (3) skillful agent-based generation, which queries the graph to create modular, cross-referenced documentation with auto-generated Mermaid diagrams. For incremental maintenance, a semantic impact propagation mechanism navigates the RepoKG bidirectionally to pinpoint all affected parts, allowing selective, targeted regeneration. Evaluated on 24 repositories across 8 programming languages, RepoDoc substantially outperforms state-of-the-art alternatives. It improves API coverage by 32.5% and completeness by 10.4%, while generating documentation 3x faster with 85% fewer tokens. For incremental updates, it cuts update time by 73% and token usage by 77%, and achieves 10.2% higher update recall, more accurately reflecting code changes in the regenerated documentation. The source code and experimental artifacts are available at https://github.com/SYSUSELab/RepoDoc.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。