TLDR: DeRAG is a novel black-box adversarial attack framework that uses Differential Evolution to create short prompt suffixes. These suffixes can effectively manipulate Retrieval-Augmented Generation (RAG) systems, forcing them to retrieve incorrect documents. The method is gradient-free, achieves high success rates with minimal tokens, evades detection, and significantly degrades the quality of AI-generated answers, exposing critical vulnerabilities in RAG.
Retrieval-Augmented Generation (RAG) systems have become crucial for making large language models (LLMs) more accurate and less prone to generating false information. RAG works by combining LLMs with external information retrieval, allowing the models to pull relevant facts from a vast corpus of documents to inform their responses. This grounding in external data is meant to improve factual accuracy and reduce ‘hallucinations’ where LLMs invent information.
However, recent research has shown that RAG systems are not immune to manipulation. Just like other AI systems, they can be vulnerable to adversarial attacks, particularly through a technique called prompt injection. This involves carefully crafted inputs that can subtly alter the system’s behavior, leading it to produce incorrect or unintended outputs.
Introducing DeRAG: A Black-Box Attack on RAG
A new research paper, DeRAG: Black-box Adversarial Attacks on Multiple Retrieval-Augmented Generation Applications via Prompt Injection, introduces a novel method to exploit these vulnerabilities. Authored by Jerry Wang and Fang Yu from National ChengChi University, DeRAG (Differential Evolution Prompt Optimization) is a gradient-free approach that treats the RAG pipeline as a ‘black box.’ This means it doesn’t need access to the internal workings or gradients of the RAG model, making it highly applicable to real-world scenarios where models are often proprietary or accessed via APIs.
DeRAG’s core innovation lies in its use of Differential Evolution (DE), a population-based evolutionary optimization algorithm. Instead of relying on complex internal model information, DE evolves a population of short, adversarial prompt suffixes. The goal is to optimize these suffixes so that when appended to a user’s query, they force the RAG system to retrieve a specific, incorrect document, pushing it to the top of the retrieval results.
How DeRAG Achieves Its Goal
The process involves encoding candidate suffixes, performing arithmetic operations on their continuous representations (mutation), and then combining them with original suffixes (crossover). The ‘fitness’ of each new suffix is evaluated by how effectively it re-ranks a chosen incorrect document to a high position in the retrieval list. The system then selects the best-performing suffixes, iterating until a desired outcome is achieved or a stopping criterion is met.
DeRAG was tested on various datasets, including MS MARCO, SciFact, FiQA, and FEVER, and evaluated against both sparse and dense retrievers. For sparse retrievers, DeRAG’s sequential variant (DE_seq_stop) achieved high success rates (e.g., 97% Top-20 success on SciFact) while using an average of only 2-3 tokens in the adversarial suffix. It matched or outperformed PRADA, a state-of-the-art black-box method for sparse retrieval.
Against dense retrievers, which are generally considered more robust, DeRAG also showed strong performance. It achieved success rates comparable to or even surpassing GGPP, a gradient-guided white-box attack, but with the significant advantage of being a black-box method. DeRAG consistently used fewer tokens (often 2-3 tokens) and induced smaller semantic shifts in the query, making the attacks more subtle and harder to detect.
Efficiency and Stealth
The research highlights a trade-off between the length of the adversarial suffix and the number of optimization iterations. DeRAG’s sequential variant finds very compact suffixes at the cost of more iterations, while its fixed-length variant uses a slightly larger token budget but converges faster. The paper also demonstrates that an early-stopping strategy significantly improves success rates and identifies the minimal suffix length needed, saving computational resources.
A critical aspect of DeRAG is its ability to evade detection. Experiments against a BERT-based adversarial suffix detector showed that DeRAG-generated suffixes were nearly indistinguishable from benign inputs, achieving near-chance detection accuracy. This stealthiness is attributed to the minimal number of tokens used in the attack. Furthermore, the authors introduced a readability-aware suffix construction strategy, which helps maintain the fluency of the generated suffixes without compromising attack success.
Also Read:
- Large Language Models: A New Frontier in Cybersecurity
- Enhancing Drug Side Effect Detection with AI: A Look at RAG and GraphRAG Architectures
Impact on AI-Generated Answers
The study also investigated the downstream impact of these attacks on the quality of answers generated by RAG systems. By forcing an irrelevant target document into the top retrieval results, even if not at rank 1, DeRAG significantly degraded the factual accuracy and overall quality of the LLM’s answers. This underscores that protecting only the very top retrieval rank is insufficient; limiting adversarial influence at any position within the retrieval window is crucial for maintaining trustworthy AI outputs.
In conclusion, DeRAG reveals critical vulnerabilities in RAG systems, demonstrating that effective black-box adversarial attacks are feasible with minimal perturbations. This research not only highlights potential security risks but also provides valuable insights for developing more robust and trustworthy AI defenses in the future, such as improved prompt precision, embedding regularization, and anomaly detection mechanisms.


