RAGPart & RAGMask: Retrieval-Stage Defenses Against Corpus Poisoning in Retrieval-Augmented Generation

Pankayaraj Pathmanathan, Michael-Andrei Panaitescu-Liess, Cho-Yu Jason Chiang, Furong HuangarXiv 2025 · OpenReview

Abstract

Retrieval-Augmented Generation (RAG) has emerged as a promising paradigm to enhance large language models (LLMs) with external knowledge, reducing hallucinations and compensating for outdated information. However, recent studies have exposed a critical vulnerability in RAG pipelines: corpus poisoning, where adversaries inject malicious documents into the retrieval corpus to manipulate model outputs. In this work, we propose two complementary retrieval-stage defenses: RAGPart and RAGMask. Our defenses operate directly on the retriever, making them computationally lightweight and requiring no modification to the generation model. RAGPart leverages the inherent training dynamics of dense retrievers, exploiting document partitioning to mitigate the effect of poisoned points. In contrast, RAGMask identifies suspicious tokens based on significant similarity shifts under targeted token masking. Across two benchmarks, four poisoning strategies, and four state-of-the-art retrievers, our defenses consistently reduce attack success rates while preserving utility under benign conditions. We further introduce an interpretable attack to stress-test our defenses. Our findings highlight the potential and limitations of retrieval-stage defenses, providing practical insights for robust RAG deployments.

Introduction

Retrieval-Augmented Generation (RAG) is the industry standard for grounding Large Language Models (LLMs) in external, up-to-date knowledge. However, RAG has a "garbage in, garbage out" vulnerability known as corpus poisoning. If an adversary injects a maliciously crafted document into the retrieval database, they can trick the retriever into selecting it, subsequently forcing the LLM to generate hallucinations or harmful content.

Current defenses usually occur at the generation stage (e.g., generating multiple responses and voting on them). However, this is often impractical for real-world production: it is computationally expensive and assumes that correct documents are always present in the retrieved set. This paper introduces a shift toward moving the "shield" earlier in the pipeline—to the retrieval stage itself.

Proposed Defenses: RAGPart and RAGMask

The authors introduce two complementary defenses designed to stop malicious data before it reaches the LLM.

RAGPart (Partition & Aggregate)

This method breaks a document into $N$ fragments and embeds them individually. It then creates multiple candidate representations by averaging subsets (size $k$) of these fragment embeddings. Because modern dense retrievers are trained to see document fragments as semantically similar to the whole, RAGPart can "dilute" the influence of a few poisoned fragments through mean pooling and majority voting across different fragment combinations.

Overview of the RAGPart defense pipeline, illustrating the partition, embed, ablate, retrieve, and aggregate steps.

RAGMask (Token-Level Sanitation)

This is a perturbation-based defense that identifies "suspicious" tokens by masking segments of a retrieved document and measuring the resulting shift in similarity to the query. If removing a specific set of tokens causes a massive drop in similarity, those tokens are likely "heavy-hitters" used by an attacker to hijack the retriever. RAGMask suppresses these tokens to sanitize the document.

To stress-test these defenses, the authors also developed AdvRAGgen, a new attack that uses Direct Preference Optimization (DPO) to train a model to generate paraphrases that are highly retrievable but maintain their malicious intent.

Key Insights and Analysis

The "Inductive Bias" Advantage

The way dense retrievers are trained (often using random crops of documents as positive pairs) creates a specific mathematical structure in the embedding space. RAGPart exploits this "inductive bias" to ensure that even if a document is partitioned, its core semantic meaning remains stable while the "noise" of an attack is filtered out.

Comparison of (a) Naive Combination Baseline and (b) RAGPart, demonstrating how RAGPart prevents the retrieval of malicious documents by diluting the poison's impact.

Efficiency and Robustness

Retrievers are much smaller and faster than the LLMs used for generation. By moving the defense to the retrieval stage, the authors achieved a ~6x reduction in dominant computational costs compared to naive fragment-combination baselines. Furthermore, RAGMask reveals that many poisoning attacks rely on a small set of influential tokens; by identifying these "load-bearing" tokens, the system can neutralize threats without needing to understand the actual text content.

Experimental Results

The researchers evaluated their defenses using two standard benchmarks: Natural Questions (NQ) and Financial Opinion Mining and Question Answering (FiQA), against four state-of-the-art dense retrievers: Contriever, ANCE, multilingual e5, and GTE Large.

  • Attack Mitigation: Both RAGPart and RAGMask consistently reduced the Attack Success Rate (ASR) across all tested retrievers and poisoning strategies.
  • Utility Preservation: Under benign conditions, the defenses maintained high Success Rates (SR) for retrieving correct documents, with RAGMask showing a slightly stronger ability to preserve utility.
  • Robustness: While baseline defenses like perplexity filters failed against the new AdvRAGgen attack, RAGPart and RAGMask remained robust, proving they can handle sophisticated, "human-looking" malicious documents.

Conclusion

While effective, these defenses face a fundamental limit: Semantic Poisoning. If an attacker crafts a document that is perfectly relevant to a query but contains a factual lie, retrieval-stage defenses cannot stop it, as retrievers are trained for similarity rather than truth. Future work will explore combining these retrieval-stage defenses with lightweight generation-stage checks for a "defense-in-depth" approach and scaling these methods to billion-scale document corpora.

Summary updated

BibTeX
@misc{pathmanathan2025ragpart,
  author = {Pankayaraj Pathmanathan and Michael-Andrei Panaitescu-Liess and Cho-Yu Jason Chiang and Furong Huang},
  title = {{RAGPart \& RAGMask: Retrieval-Stage Defenses Against Corpus Poisoning in Retrieval-Augmented Generation}},
  year = {2025},
  eprint = {2512.24268},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.24268},
}
Figure