mlsanityData to 7 Oct 2026

Retrieval-Augmented Few-Shot Prompting Versus Fine-Tuning for Code Vulnerability Detection

arXiv 2512.04106 ↗First posted 28 Nov 2025cs.SE cs.AI cs.CLcited by 0

On the map: Retrieval-augmented generation → Privacy and security of RAG

Abstract (arXiv)

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 model inference. Our results show that retrieval-augmented prompting consistently outperforms the other prompting strategies. At 20 shots, it achieves an F1 score of 74.05% and a partial match accuracy of 83.90%. We further compare this approach against zero-shot prompting and several fine-tuned models, including Gemini-1.5-Flash and smaller open-source models such as DistilBERT, DistilGPT2, and CodeBERT. Retrieval-augmented prompting outperforms both zero-shot (F1 score: 36.35%, partial match accuracy: 20.30%) and fine-tuned Gemini (F1 score: 59.31%, partial match accuracy: 53.10%), while avoiding the training time and cost associated with model fine-tuning. On the other hand, fine-tuning CodeBERT yields higher performance (F1 score: 91.22%, partial match accuracy: 91.30%) but requires additional training, maintenance effort, and resources.

Key facts. No citing papers in the map yet (data through 7 Oct 2026). Placed in Privacy and security of RAG, one of 15 directions in Retrieval-augmented generation. Builds on 11 of its 18 references that are in the map. First posted on arXiv 28 Nov 2025.

Builds on

11 of 18 references.

References · 11

  1. 2019DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lightercited by 4,243
  2. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
  3. 2020Deep Learning based Vulnerability Detection: Are We There Yet?cited by 142
  4. 2021Cutting Down on Prompts and Parameters: Simple Few-Shot Learning with Language Modelscited by 139
  5. 2022Improving the Domain Adaptation of Retrieval Augmented Generation (RAG) Models for Open Domain Question Answeringcited by 126
  6. 2018Automated Vulnerability Detection in Source Code Using Deep Representation Learningcited by 114
  7. 2023Fairness-guided Few-shot Prompting for Large Language Modelscited by 53
  8. 2018Automated software vulnerability detection with machine learningcited by 34
  9. 2024To Ensemble or Not: Assessing Majority Voting Strategies for Phishing Detection with Large Language Modelscited by 12
  10. 2024Large Multimodal Agents for Accurate Phishing Detection with Enhanced Token Optimization and Cost Reductioncited by 4
  11. 2024Evaluating the Efficacy of Prompt-Engineered Large Multimodal Models Versus Fine-Tuned Vision Transformers in Image-Based Security Applicationscited by 3

Built on by

Not cited yet.

Similar, not cited

Close in wording, no citation either way

  1. 2026PromptAudit: Auditing Prompt Sensitivity in LLM-Based Vulnerability Detection
  2. 2024Can LLM Prompting Serve as a Proxy for Static Analysis in Vulnerability Detection
  3. 2026An Empirical Evaluation of LLM-Generated Code Security Across Prompting Methods
  4. 2026ConceptCoder: Improve Code Reasoning via Concept Learning
  5. 2026VulTriage: Triple-Path Context Augmentation for LLM-Based Vulnerability Detection
  6. 2026Revisiting Vul-RAG: Reproducibility and Replicability of RAG-based Vulnerability Detection with Open-Weight Models
  7. 2025ReVul-CoT: Towards Effective Software Vulnerability Assessment with Retrieval-Augmented Generation and Chain-of-Thought Prompting
  8. 2025Reasoning with LLMs for Zero-Shot Vulnerability Detection