Skip to main content
QUICK REVIEW

[论文解读] An Empirical Evaluation of LLM-Based Approaches for Code Vulnerability Detection: RAG, SFT, and Dual-Agent Systems

Md Hasan Saju, Maher Muhtadi|arXiv (Cornell University)|Jan 1, 2026
Software Engineering ResearchComputer Science被引用 0
一句话总结

该论文将 RAG、SFT(QLoRA 适配器)和双代理 LLM 系统与基线 LLM 在五个 CWE 下的代码漏洞检测进行比较,结果显示 RAG 获得总体最高性能。

ABSTRACT

The rapid advancement of Large Language Models (LLMs) presents new opportunities for automated software vulnerability detection, a crucial task in securing modern codebases. This paper presents a comparative study on the effectiveness of LLM-based techniques for detecting software vulnerabilities. The study evaluates three approaches, Retrieval-Augmented Generation (RAG), Supervised Fine-Tuning (SFT), and a Dual-Agent LLM framework, against a baseline LLM model. A curated dataset was compiled from Big-Vul and real-world code repositories from GitHub, focusing on five critical Common Weakness Enumeration (CWE) categories: CWE-119, CWE-399, CWE-264, CWE-20, and CWE-200. Our RAG approach, which integrated external domain knowledge from the internet and the MITRE CWE database, achieved the highest overall accuracy (0.86) and F1 score (0.85), highlighting the value of contextual augmentation. Our SFT approach, implemented using parameter-efficient QLoRA adapters, also demonstrated strong performance. Our Dual-Agent system, an architecture in which a secondary agent audits and refines the output of the first, showed promise in improving reasoning transparency and error mitigation, with reduced resource overhead. These results emphasize that incorporating a domain expertise mechanism significantly strengthens the practical applicability of LLMs in real-world vulnerability detection tasks.

研究动机与目标

  • 通过基于 LLM 的方法提升代码漏洞检测能力的动机。
  • 从 BigVul 与企业仓库中 curate 一个平衡的漏洞数据集,以实现稳健评估。
  • 将 RAG、SFT(QLoRA 适配器)与双代理架构与基础模型进行比较。
  • 分析性能及统计显著性,为实际漏洞检测的方法选择提供依据。

提出的方法

  • 使用来自 BigVul 与 GlassHouse 仓库的五个 CWE 类别组成的、训练集 5000 条、测试集 1000 条的平衡数据集。
  • 评估三种基于 LLM 的方法:检索增强生成(RAG)、带 QLoRA 适配器的有监督微调(SFT),以及具有检测代理和验证代理的双代理 LLM 系统。
  • 将基础 LLM 模型(LLaMA 3.2-3B)作为对比基线。
  • 在 RAG 中,利用 MITRE CWE 数据的领域知识对 LLM 进行增强,并进行分块文本处理,嵌入存储于 Chroma。
  • 在 SFT 中,使用指令-输入-输出格式进行微调,设置等效 3 万步并使用 8 位 AdamW 优化。
  • 在双代理中,由检测代理给出初步的漏洞判断,由验证代理复核并修正推理。
Figure 2: Retrieval-Augmentation Generation Process
Figure 2: Retrieval-Augmentation Generation Process

实验结果

研究问题

  • RQ1RAG、SFT 和双代理 LLM 方法与基线 LLM 在多类 CWE 的代码漏洞检测上有何比较?
  • RQ2领域知识增强与参数高效微调对检测性能有何影响?
  • RQ3双代理架构是否能提升推理透明度并在不过度增加资源开销的情况下减少错误?

主要发现

  • RAG 以平均 F1 为 0.85、全 CWE 的准确率为 0.86,取得最高总体性能。
  • RAG 在各 CWE 的表现包括:CWE-119(F1 0.80)、CWE-399(F1 0.89)、CWE-264(F1 0.84)、CWE-20(F1 0.86)、CWE-200(F1 0.89)。
  • SFT 的平均 F1 为 0.80,准确率为 0.81,CWE 逐项 F1 范围为 0.73~0.84。
  • 双代理 LLM 的平均 F1 为 0.77,准确率为 0.78,CWE 逐项 F1 范围为 0.73~0.86。
  • 基础模型(无增强)平均 F1 为 0.67,准确率为 0.65。
  • 统计检验(配对 t 检验)显示三种技术均显著优于基线模型,RAG: t(4)=5.97, p=0.0042;SFT: t(4)=3.75, p=0.0195;双代理: t(4)=2.89, p=0.0440。
Figure 3: Supervised Fine-Tuning Process
Figure 3: Supervised Fine-Tuning Process

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。