Manuscript Offprint

arXiv:2608.23965

RAGSentinel: Certifiable Geometric Consensus for Robust Retrieval-Augmented Generation

Yueyang Quan, Anjun Gao, Yufei Xia, Minghong Fang, Zhuqing Liu

Abstract

Retrieval-augmented generation (RAG) improves the factuality of large language models by grounding responses in external documents, but it also exposes a critical security vulnerability: adversarial documents injected into the knowledge database can enter the context window and steer the model toward targeted incorrect answers. Existing post-retrieval defenses rely on instruction following, parametric knowledge, or text-level consistency, all of which can be imitated or optimized against by adaptive attackers. We propose RAGSentinel, a training-free, label-free defense for black-box RAG systems. RAGSentinel uses a surrogate encoder to measure query-conditioned hidden-state shifts induced by retrieved documents, removes shared topic directions, and filters poisoned documents as geometric outliers from a robust majority consensus. We prove that, under an honest-majority assumption and a representation-level separation condition, RAGSentinel exactly recovers a poison-free majority-sized context. Experiments across three question-answering datasets, three LLM families, and multiple poisoning attacks show that RAGSentinel consistently achieves low attack success rates while preserving competitive accuracy and remaining effective against adaptive attacks with full pipeline knowledge.

1 Introduction

Large language models (LLMs) (Brown et al., 2020; Achiam et al., 2023) have demonstrated remarkable capabilities across a wide range of knowledge-intensive tasks, yet their reliance on static parametric knowledge limits their ability to stay current and factually grounded (Lewis et al., 2020). Retrieval-augmented generation (RAG) (Karpukhin et al., 2020; Chen et al., 2024b) addresses this by coupling LLMs with an external knowledge database at inference time, enabling factually accurate responses without retraining. In a typical RAG pipeline, a retriever selects the top-k documents from the knowledge database, which are concatenated with the user query and passed to the LLM as context.

Recent studies have demonstrated that RAG systems are susceptible to knowledge poisoning attacks. In this threat model, an adversary inserts malicious documents into the knowledge database prior to inference. These documents are carefully constructed so that they achieve high retrieval ranking for a specific target query while embedding an incorrect answer (Zou et al., 2025; Zhong et al., 2023; Zhang et al., 2026a, 2025b). The attack requires no access to the deployed LLM, no query modification, and no inference-time intervention, only the ability to write to the database. Because adversarial documents are optimized to be retrieval-relevant and factually plausible, they are indistinguishable from benign documents in query logs and model outputs, leaving existing pipelines with no natural point of interception (Zhang et al., 2026c; Greshake et al., 2023).

Existing post-retrieval defenses fall into three families, each undermined by a structural limitation. Instruction-based methods prompt the LLM to resist suspicious context (Xiang et al., 2024; Wei et al., 2025; Asai et al., 2024; Gao et al., 2023), but rely on the model's own judgment to detect contradictions, precisely the capability that plausible adversarial documents are designed to defeat. Knowledge integration techniques aim to resolve discrepancies between retrieved evidence and the LLM's stored parametric knowledge (Wang et al., 2025; Zhou et al., 2025; Wang et al., 2023b; Jeong et al., 2024). However, their effectiveness depends on the model possessing reliable domain-specific knowledge, making them less applicable when such knowledge is limited or unavailable. In contrast, consistency-based approaches assess the

*Yufei Xia performed this research when he was under the supervision of Minghong Fang.

agreement among retrieved documents (Deng et al., 2025; Jiang et al., 2023b; Cheng et al., 2025). Yet, this assumption can be exploited by sophisticated adversaries, who may generate mutually consistent poisoned documents that closely resemble the benign corpus while collectively promoting an incorrect answer. All three families share a common blind spot: each operates on signals that an attacker can directly optimize against, token outputs, parametric knowledge conflicts, or cross-document text overlap. What an attacker cannot easily control, however, is the hidden-state shift that a document induces in an encoder when it asserts a false claim: asserting a factually wrong answer leaves a geometric trace in representation space that text-level optimization cannot erase, because the encoder's semantic geometry lies outside the attacker's control. This signal is one that all three families leave entirely untapped.

We make the following observation: when each retrieved document is appended to the query and passed through a surrogate encoder, the resulting hidden-state shift encodes that document's factual stance. After removing the shared query-topic component, benign documents induce residual shifts that cluster near a common direction, while poisoned documents are geometric outliers in this same space. This structure holds even under retrieval-optimized adversarial documents: asserting a false factual claim leaves a geometric trace in representation space that text-level optimization cannot erase. This signal requires no interaction with the deployed LLM, no labeled poison examples, and no model retraining.

We propose RAGSentinel, a training-free, label-free post-retrieval defense that exploits this geometric structure to identify and remove poisoned documents before the deployed LLM is invoked. The defender has text-in, text-out access to the deployed LLM and a separately chosen surrogate encoder for hidden-state extraction, with no knowledge of which documents are poisoned or what the correct answer is. RAGSentinel scores documents by their deviation from a robust majority consensus via the geometric median, and selects a trusted context using a query-adaptive filtering radius, passing it to the LLM in a single zero-shot call with exactly k+1k + 1 surrogate forward passes.

Theoretically, we prove that under an honest-majority assumption and a geometric separation condition, RAGSentinel exactly recovers a poison-free majority-sized context (Theorem 1). Empirically, we evaluate on Natural Questions, HotpotQA, and MS-MARCO, across three LLM families and three poisoning attacks. RAGSentinel consistently achieves low attack success rates while maintaining accuracy comparable to Vanilla RAG, incurring negligible computational overhead, and retaining its defensive advantage under three adaptive attacks with full pipeline knowledge.

Our contributions are as follows:

• We identify poisoned documents as geometric outliers in a surrogate encoder’s residual space, persistent even under retrieval-optimized adversarial construction.

• We propose RAGSentinel, a training-free, black-box-compatible defense that filters poisoned documents by their geometric deviation from the benign majority consensus.

• We prove a certifiable filtering guarantee (Theorem 1) and corroborate it with extensive experiments across datasets, models, attacks, and adaptive adversaries.

References (42)