Retrieval-Augmented Few-Shot Prompting Versus Fine-Tuning for Code Vulnerability Detection
Fouad Trad, Ali Chehab

TL;DR
This paper demonstrates that retrieval-augmented few-shot prompting significantly improves code vulnerability detection performance over standard prompting and fine-tuning, especially with large language models, while reducing training costs.
Contribution
It introduces retrieval-augmented prompting as an effective strategy for code vulnerability detection, outperforming traditional prompting and fine-tuning methods in accuracy and efficiency.
Findings
Retrieval-augmented prompting achieves 74.05% F1 score at 20 shots.
It outperforms zero-shot and fine-tuned prompting in accuracy.
Fine-tuning CodeBERT yields higher performance but at higher resource costs.
Abstract
Few-shot prompting has emerged as a practical alternative to fine-tuning for leveraging the capabilities of large language models (LLMs) in specialized tasks. However, its effectiveness depends heavily on the selection and quality of in-context examples, particularly in complex domains. In this work, we examine retrieval-augmented prompting as a strategy to improve few-shot performance in code vulnerability detection, where the goal is to identify one or more security-relevant weaknesses present in a given code snippet from a predefined set of vulnerability categories. We perform a systematic evaluation using the Gemini-1.5-Flash model across three approaches: (1) standard few-shot prompting with randomly selected examples, (2) retrieval-augmented prompting using semantically similar examples, and (3) retrieval-based labeling, which assigns labels based on retrieved examples without…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Engineering Research · Software Testing and Debugging Techniques · Web Application Security Vulnerabilities
