增强基于LLM的故障定位:一种功能感知的检索增强生成框架
Enhancing LLM-based Fault Localization with a Functionality-Aware Retrieval-Augmented Generation Framework
AI总结:
提出FaR-Loc框架,结合LLM与检索增强生成,通过功能提取、语义检索和重排序提升方法级故障定位,在Defects4J上显著优于现有基线。
摘要:
故障定位(FL)是软件调试中一项关键但耗时的任务,旨在识别有缺陷的代码元素。尽管大型语言模型(LLM)的最新进展在故障定位方面显示出潜力,但由于缺乏项目特定知识以及难以导航大型项目,它们往往在处理复杂系统时遇到困难。为解决这些局限性,我们提出了FaR-Loc,一种新颖的框架,通过将LLM与检索增强生成(RAG)相结合来增强方法级故障定位。FaR-Loc由三个关键组件组成:LLM功能提取、语义密集检索和LLM重排序。首先,给定一个失败的测试及其相关的堆栈跟踪,LLM功能提取模块生成一个简洁的自然语言描述,捕获失败行为。接下来,语义密集检索组件利用预训练的代码理解编码器,将功能描述(自然语言)和覆盖的方法(代码)嵌入到共享语义空间中,从而能够检索具有相似功能行为的方法。最后,LLM重排序模块根据检索方法的上下文相关性对其进行重新排序。我们在广泛使用的Defects4J基准上的实验表明,FaR-Loc在Top-1准确率上分别优于最先进的基于LLM的基线SoapFL和AutoFL 14.6%和9.1%,在Top-5准确率上分别优于19.2%和22.1%。它还在所有Top-N指标上超越了所有基于学习和基于频谱的基线,且无需重新训练。此外,我们发现,纳入代码结构的预训练代码嵌入模型(如UniXcoder)可以将故障定位性能显著提高,Top-1准确率最高提升49.0%。最后,我们进行了一项案例研究,以说明FaR-Loc的有效性,并为其实际应用提供见解。
英文摘要:
Fault localization (FL) is a critical but time-consuming task in software debugging, aiming to identify faulty code elements. While recent advances in large language models (LLMs) have shown promise for FL, they often struggle with complex systems due to the lack of project-specific knowledge and the difficulty of navigating large projects. To address these limitations, we propose FaR-Loc, a novel framework that enhances method-level FL by integrating LLMs with retrieval-augmented generation (RAG). FaR-Loc consists of three key components: LLM Functionality Extraction, Semantic Dense Retrieval, and LLM Re-ranking. First, given a failed test and its associated stack trace, the LLM Functionality Extraction module generates a concise natural language description that captures the failing behavior. Next, the Semantic Dense Retrieval component leverages a pre-trained code-understanding encoder to embed both the functionality description (natural language) and the covered methods (code) into a shared semantic space, enabling the retrieval of methods with similar functional behavior. Finally, the LLM Re-ranking module reorders the retrieved methods based on their contextual relevance. Our experiments on the widely used Defects4J benchmark show that FaR-Loc outperforms state-of-the-art LLM-based baselines SoapFL and AutoFL, by 14.6% and 9.1% in Top-1 accuracy, by 19.2% and 22.1% in Top-5 accuracy, respectively. It also surpasses all learning-based and spectrum-based baselines across all Top-N metrics without requiring re-training. Furthermore, we find that pre-trained code embedding models that incorporate code structure, such as UniXcoder, can significantly improve fault localization performance by up to 49.0% in Top-1 accuracy. Finally, we conduct a case study to illustrate the effectiveness of FaR-Loc and to provide insights for its practical application.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。