Seedlabs
Source research

vul-rag : Enhancing LLM-based Vulnerability Detection via Knowledge-level RAG

Xueying Du, Geng Zheng, Kaixin Wang, Yi Zou, Yujia Wang, Wentai Deng et al. · 2026 · 229 citationsRead the paper

Although LLMs have shown promising potential in vulnerability detection, this study reveals their limitations in distinguishing between vulnerable and similar-but-benign patched code (only 0.06–0.14 accuracy). It shows that LLMs struggle to capture the root causes of vulnerabilities during vulnerability detection. To address this challenge, we propose enhancing LLMs with multi-dimensional vulnerability knowledge distilled from historical vulnerabilities and fixes. We design a novel knowledge-level Retrieval-Augmented Generation framework Vul-RAG , which improves LLMs with an accuracy increase of 16–24% in identifying vulnerable and patched code. Additionally, vulnerability knowledge generated by Vul-RAG can further (1) serve as high-quality explanations to improve manual detection accuracy (from 60% to 77%), and (2) detect 10 previously-unknown bugs in the recent Linux kernel release with six assigned CVEs.

What the full text shows

Working prototype
  • VUL-RAG increased the pairwise accuracy of LLMs in identifying vulnerable and patched code compared to baselines. — 16% - 24% increase (Evaluated on the PairVul benchmark using GPT-4o, Claude Sonnet 3.5, Qwen2.5-Coder-32B-Instruct, and DeepSeek-R1)
  • VUL-RAG improved balanced precision and recall over baselines. — 9%-14% (precision) and 7%-11% (recall) (Evaluated on the PairVul benchmark)
  • VUL-RAG generated knowledge improved manual vulnerability detection accuracy. — from 60% to 77% (User study on manual vulnerability comprehension)
  • VUL-RAG detected previously-unknown bugs in a recent Linux kernel release. — 10 bugs detected, 6 assigned CVEs (Real-world Linux kernel release)
  • Baseline LLMs using basic prompts showed very low ability to distinguish between vulnerable and patched code pairs. — 0.06 - 0.14 accuracy (PairVul benchmark)
Setup
PairVul benchmark consisting of 586 pairs across 420 CVEs (Top-10 CWEs) from the Linux kernel; training set for knowledge base included 2,317 pairs across 1,154 CVEs.
How
The authors developed VUL-RAG, a knowledge-level RAG framework that distills multi-dimensional vulnerability knowledge (functional semantics, root causes, and fixes) from historical CVEs. It uses BM25 for retrieval and Reciprocal Rank Fusion (RRF) for re-ranking to augment LLM prompts with high-level vulnerability knowledge rather than raw code snippets.
Limitations
Benchmark construction excluded code exceeding 16,384 tokens · Knowledge base construction relied on GPT-3.5-turbo for distillation

Summarized by Gemma 4 from the open-access full text · 22 Nov 2026. Read it