RAG poisoning is an attack on retrieval-augmented generation (RAG) systems in which an adversary inserts or modifies documents in the knowledge source so that the retriever selects them for targeted queries and the language model then repeats false information, follows hidden instructions or leaks data. In AI security, it is treated as a form of data poisoning that targets the retrieval corpus at inference time rather than the training data of the model.
The attack is also called knowledge base poisoning or retrieval poisoning. It matters because many RAG deployments index content that outsiders can influence, such as public web pages, wikis, support tickets, shared drives or email, and because the model usually treats retrieved text as trusted context.
How RAG poisoning works
A successful RAG poisoning attack must satisfy two conditions at once: the malicious passage must be retrieved for the target query, and once retrieved it must steer the generated answer. Research attacks such as PoisonedRAG formalize these as a retrieval condition and a generation condition and show that a handful of crafted passages can dominate the answers to selected questions even in corpora with millions of documents.
To meet the retrieval condition, the attacker writes text that is semantically close to the anticipated query in embedding space, often by repeating the question itself or its key phrases. To meet the generation condition, the passage states the desired false answer with apparent authority or embeds an indirect prompt injection that instructs the model directly.
| Stage | Attacker action | System weakness exploited |
|---|---|---|
| Target selection | Chooses queries or topics to influence | Predictable user questions |
| Payload crafting | Writes text optimized for similarity and persuasion | Embedding similarity as sole relevance signal |
| Injection | Places content in an indexed source | Open or weakly governed ingestion |
| Retrieval | Waits for the passage to rank in the top results | Small top-k with no source weighting |
| Generation | Model repeats or obeys the passage | Retrieved text treated as trusted |
The attacker does not need access to the model or the vector database. Write access to any indexed source is sufficient, which includes editing a public page that a crawler collects, opening a support ticket, sharing a document into a synchronized folder or sending an email to a mailbox that an assistant reads. In black-box settings, attackers infer likely queries from product documentation and test their passages against public embedding models, since similar embedding models tend to rank the same text highly.
Attack goals and payload types
RAG poisoning serves several distinct attacker goals, and the defenses that matter depend on which one applies. Misinformation is the most studied, but instruction payloads that hijack agentic systems carry the highest operational risk.
| Objective | Payload content | Example impact |
|---|---|---|
| Targeted misinformation | False factual claims for specific queries | Wrong policy, price or medical answer |
| Instruction injection | Hidden commands addressed to the model | Tool misuse or altered behavior |
| Data exfiltration | Instructions to embed secrets in links or images | Leak of conversation or document data |
| Denial of service | Passages that trigger refusals or blocking | System refuses legitimate questions |
| Promotion or bias | Content favoring a product or viewpoint | Manipulated recommendations |
| Backdoor trigger | Passages activated only by a rare phrase | Stealthy, hard-to-detect manipulation |
Some attacks target the retriever itself rather than the corpus, for example by poisoning the data used to fine-tune the embedding model so that a trigger word maps to attacker documents. This variant overlaps with classic model poisoning and requires access to the training pipeline.
How it differs from related attacks
RAG poisoning sits between training data poisoning and prompt injection, and practitioners often confuse the three. The distinction lies in where the malicious content enters and how long it persists.
| Attack | Entry point | Persistence | Removal |
|---|---|---|---|
| RAG poisoning | Retrieval corpus or index | Until the document is removed | Delete and reindex the source |
| Training data poisoning | Pretraining or fine-tuning data | Baked into model weights | Retraining or unlearning |
| Direct prompt injection | User input | Single session | Ends with the session |
| Indirect prompt injection | Any external content read at runtime | While the content is reachable | Remove or isolate the content |
| Memory poisoning | Agent long-term memory | Across future sessions | Purge memory entries |
Because the poisoned content lives in an index, remediation is cheaper than for weight poisoning, but detection is harder: the malicious passage looks like an ordinary document until a specific query retrieves it.
Defenses and mitigations
No single control prevents RAG poisoning, so mature deployments apply defense in depth across ingestion, retrieval and generation. Frameworks such as the OWASP Top 10 for LLM Applications, MITRE ATLAS and NIST AI 100-2 describe the threat and the corresponding control families.
| Layer | Control | What it reduces |
|---|---|---|
| Ingestion | Source allowlists, write permissions, content signing | Who can add documents |
| Ingestion | Scanning for instructions and anomalies | Obvious injection payloads |
| Retrieval | Source trust scores and per-user access filtering | Ranking of untrusted text |
| Retrieval | Diverse top-k and duplicate detection | Dominance by clustered fake passages |
| Generation | Spotlighting and instruction hierarchy | Obedience to retrieved commands |
| Output | Citation checks and link or image filtering | Exfiltration and unsupported claims |
The most effective single principle is to treat retrieved content as untrusted data, never as instructions. Architectures such as the dual LLM pattern and CaMeL separate a privileged planner from a model that reads untrusted text, which limits damage when an agent combines private data, external content and the ability to act.
Monitoring completes the picture. Logging which documents supported each answer allows teams to trace a harmful output back to its source passage, remove it and search the index for near-duplicates planted alongside it.
Limitations of current defenses
Detection of poisoned passages remains an open research problem, and several common assumptions do not hold in practice.
- Perplexity filters are weak: fluent, model-written payloads look statistically normal.
- Larger corpora do not dilute the attack: retrieval is query-specific, so a few targeted passages can still rank first.
- Access control is not integrity: an insider or compromised account can poison an internal wiki.
- Citations do not prove truth: a model can cite the poisoned document faithfully.
- Red teaming must include the corpus: tools such as garak and PyRIT test prompts, but corpus-level tests need planted canary documents.
The simple explanation
Many AI assistants look things up before they answer. They search a library of documents and then summarize what they find. RAG poisoning means sneaking a fake page into that library.
The fake page is written to match a likely question. When someone asks that question, the assistant finds the fake page and trusts it. It then repeats the lie or follows hidden orders in the text. The assistant is only as trustworthy as the library it reads.
How it is used in practice
A software company runs a support chatbot that retrieves answers from its public community forum and product documentation. An attacker posts three forum replies that closely paraphrase the question about resetting two-factor authentication. Each reply states that users should send their recovery codes to a lookalike support address.
Within days, the chatbot begins quoting this advice for that exact question. The security team discovers the problem when a customer reports the suspicious address. Answer logs show which forum posts supported each response, so the team removes the posts and excludes unmoderated forum content from the index. It also adds an output filter that blocks unknown email domains. Subsequent red-team tests with planted canary posts confirm that only moderated content now reaches the retriever, and the incident is contained within one day of detection.