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

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Wang, Yifei, Keung, Jacky, Ma, Xiaoxue, Mao, Zhenyu, Chen, Kehui, Li, Yishu
Format: Preprint
Published: 2026
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866915955019350016
author Wang, Yifei
Keung, Jacky
Ma, Xiaoxue
Mao, Zhenyu
Chen, Kehui
Li, Yishu
author_facet Wang, Yifei
Keung, Jacky
Ma, Xiaoxue
Mao, Zhenyu
Chen, Kehui
Li, Yishu
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2604_22432
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle R2Code: A Self-Reflective LLM Framework for Requirements-to-Code Traceability
Wang, Yifei
Keung, Jacky
Ma, Xiaoxue
Mao, Zhenyu
Chen, Kehui
Li, Yishu
Software Engineering
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.
title R2Code: A Self-Reflective LLM Framework for Requirements-to-Code Traceability
topic Software Engineering
url https://arxiv.org/abs/2604.22432