arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2604.22432cs.SE
收藏

R2Code:一种用于需求到代码追溯的自反思大语言模型框架

R2Code: A Self-Reflective LLM Framework for Requirements-to-Code Traceability

City University of Hong Kong(香港城市大学);Hong Kong Metropolitan University(香港都会大学)

Yifei Wang, Jacky Keung, Xiaoxue Ma, Zhenyu Mao, Kehui Chen, Yishu Li

AI总结:

本文提出R2Code框架,通过分解增强的双向对齐网络、自反思一致性验证模块和动态上下文适应检索机制,提升需求到代码追溯的准确性并降低推理成本。

摘要:

准确的需求到代码追溯对软件维护至关重要。然而,现有的基于信息检索和嵌入的方法严重依赖词汇相似性,往往在不同项目和语言中产生不完整或不一致的链接,并且由于长上下文检索和提示而产生高成本。本文提出了R2Code,一种基于大语言模型的语义追溯框架,旨在提高追溯链接的准确性同时减少推理成本。R2Code集成了三个组件:1)一种分解增强的双向对齐网络(BAN),将四层需求语义与相应代码结构对齐,以支持跨层语义匹配;2)一种自反思一致性验证(SRCV)模块,通过解释引导的一致性检查来校准链接可靠性;3)一种动态上下文适应检索(DCAR)机制,通过语义重叠加权调整检索粒度并过滤上下文以提高上下文利用效率。在五个公共数据集上的实验表明,R2Code在多个领域和两种编程语言中 consistently 超过了最强的基线,实现了平均F1提升7.4%,同时通过自适应上下文控制将token消耗减少了高达41.7%。

英文摘要:

Accurate requirement-to-code traceability is crucial for software maintenance. However, existing IR- and embedding-based methods are heavily dependent on lexical similarity, often yielding incomplete or inconsistent links across projects and languages and incurring high cost from long-context retrieval and prompting. This paper presents R2Code, an LLM-based semantic traceability framework designed to improve trace link accuracy while reducing inference cost. R2Code integrates three components: 1) a decomposition-enhanced Bidirectional Alignment Network (BAN) that aligns four-layer requirement semantics with corresponding code structures to support cross-level semantic matching; 2) a Self-Reflective Consistency Verification (SRCV) module that conducts explanation-guided consistency checking to calibrate link reliability; and 3) a Dynamic Context-Adaptive Retrieval (DCAR) mechanism that adjusts retrieval granularity and filters contexts using semantic-overlap weighting for efficient context utilization. Experiments on five public datasets spanning multiple domains and two programming languages demonstrate that R2Code consistently outperforms the strongest baselines, achieving an average F1 gain of 7.4%, while reducing token consumption by up to 41.7% through adaptive context control.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑