当上下文咬人:通过文档级注意力崩溃检测RAG投毒
研究论文 · 2026/08/18
检索增强生成(RAG)对于增强大型语言模型至关重要,但容易受到投毒攻击。现有检测方法依赖输出端信号(如困惑度和一致性),但研究发现故意攻击常引发虚假自信,使中毒输出困惑度更低,导致基于不确定性的检测失效。为此,我们探索生成器内部动态,发现一种称为注意力崩溃的独特特征:与良性生成中分散的注意力不同,受攻击生成的注意力集中于中毒文档,熵降低。基于此,我们提出D-SCAN(文档级信号崩溃分析),一种轻量级检测框架,通过监控注意力动态识别受攻击生成。在多个攻击基准上的广泛实验证明了其有效性,且D-SCAN能在攻击未改变最终答案时也能检测到攻击。代码已公开。
该论文针对RAG投毒检测的现有局限,提出基于内部注意力动态的新方法,具有创新性和实用性,且代码开源,值得关注。
Retrieval-augmented generation (RAG) is indispensable for enhancing large language models. However, RAGs are increasingly susceptible to poisoning attacks, in which adversarial documents are injected to manipulate generator outputs. Previous methods rely on output-side signals such as perplexity and consistency checks to detect such attacks. Nevertheless, our analysis reveals that deliberate attacks often induce false confidence, where poisoned outputs exhibit even lower perplexity than benign ones, rendering uncertainty-based detection ineffective. To address this challenge, we explore the internal dynamics of the generator and identify a distinctive signature termed Attention Collapse. Unlike the dispersed attention in benign generations, attacked generations exhibit a decrease in entropy as attention concentrates on poisoned documents. Building on these findings, we propose D-SCAN (Document-level Signal Collapse Analysis), a lightweight detection framework that monitors attention dynamics to identify attacked generations. Extensive experiments on multiple attack benchmarks demonstrate the effectiveness of our method. Moreover, D-SCAN can detect attacks even when they fail to alter the final answer. Code is available at https://github.com/yingtaoren/D-Scan.git.