arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~

超越向量相似度:分层上下文感知图RAG与标准RAG在企业代码迁移中的对比

Beyond Vector Similarity: Hierarchical Context-Aware Graph RAG vs Standard RAG in Enterprise Code Migration

Nilesh Jaiswal, Aniket Agrawal, Arjit Shukla, Divya Malhotra, Saurabh Garg, Suchit Puri, Suddhasatwa Bhaumik

arXiv 2609.12464首次发表:更新:

发表机构

Google Cloud(谷歌云)

机构由 AI 辅助整理,请以论文原文为准。

AI 中文总结

针对企业代码迁移中标准RAG无法捕获拓扑关系导致编译失败的问题,提出分层上下文驻留图(HCRG)方法,利用AST、属性图和上下文缓存实现父级优先翻译,显著降低API幻觉率并提升依赖解析质量,为代码库现代化提供更优路径。

AI 中文摘要

随着企业将遗留单体系统现代化改造为微服务,大型语言模型(LLMs)被广泛用于自动化代码翻译。然而,传统的基于向量的检索增强生成(标准RAG)难以捕获拓扑关系。它检索孤立的代码块,切断了继承链,导致编译失败率较高。本文引入一种分层上下文驻留图(HCRG)方法来解决这些局限。我们的流程使用tree-sitter进行抽象语法树(AST)提取,将架构边映射到Google Cloud Spanner属性图,并将该结构序列化到Gemini上下文缓存中,以实现拓扑优先、父级优先的代码翻译。我们将评估从朴素的文本重叠转向自定义的7指标软件工程框架。传统指标如CodeBLEU(两种方法均得分91%)实际上掩盖了标准RAG的结构性失败,因为其生成了语法上看似合理但实际有缺陷的代码。实验表明,图RAG显著缓解了依赖丢失:API幻觉率从56.4%降至16.2%,依赖解析质量从34.8%提升至65.9%,父子一致性从26.7%上升至45.5%。然而,图RAG引入了特定的权衡。密集的全局上下文导致LLM防御性过度工程,使圈复杂度一致性从71.6%降至46.7%,并略微降低了文档字符串保留率(从67.0%降至61.0%)。最终,虽然以代码复杂度换取幻觉减少,图RAG为自动化企业代码库现代化提供了一条更可行、架构更健全的路径。

英文摘要

As enterprises modernize legacy monolithic systems to microservices, Large Language Models (LLMs) are heavily utilized for automated code translation. However, traditional vector-based Retrieval-Augmented Generation (Standard RAG) struggles to capture topological relationships. It fetches isolated chunks that sever inheritance chains, leading to high compilation failure rates. This paper introduces a Hierarchical Context-Resident Graph (HCRG) methodology to resolve these limitations. Our pipeline uses tree-sitter for Abstract Syntax Tree (AST) extraction, maps architectural edges into a Google Cloud Spanner Property Graph, and serializes this structure into a Gemini Context Cache for topological, parent-first code translation. We shift evaluation from naive text-overlap to a custom 7-metric Software Engineering framework. Traditional metrics like CodeBLEU (which scored 91% for both methods) effectively masked Standard RAG's structural failures behind syntactically plausible but broken code. Empirically, Graph RAG decisively mitigates dependency loss: API hallucination rates dropped from 56.4% to 16.2%, Dependency Resolution Quality improved from 34.8% to 65.9%, and Parent-Child Consistency rose from 26.7% to 45.5%. However, Graph RAG introduces specific trade-offs. The dense global context causes defensive over-engineering by the LLM, reducing Cyclomatic Complexity Consistency from 71.6% to 46.7%, and slightly degrades Docstring Preservation (67.0% to 61.0%). Ultimately, while trading code complexity for reduced hallucinations, Graph RAG provides a substantially more viable, architecturally sound path for automated enterprise codebase modernization.

Comments11 pages, 2 images, 3 tables

论文原文

arXiv 摘要页 · PDF 原文 · HTML 原文

↑