RAG poisoning

Also known as: knowledge base poisoning · retrieval poisoning

On this page 7

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.

StageAttacker actionSystem weakness exploited
Target selectionChooses queries or topics to influencePredictable user questions
Payload craftingWrites text optimized for similarity and persuasionEmbedding similarity as sole relevance signal
InjectionPlaces content in an indexed sourceOpen or weakly governed ingestion
RetrievalWaits for the passage to rank in the top resultsSmall top-k with no source weighting
GenerationModel repeats or obeys the passageRetrieved text treated as trusted
Stages of a typical RAG poisoning attack

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.

ObjectivePayload contentExample impact
Targeted misinformationFalse factual claims for specific queriesWrong policy, price or medical answer
Instruction injectionHidden commands addressed to the modelTool misuse or altered behavior
Data exfiltrationInstructions to embed secrets in links or imagesLeak of conversation or document data
Denial of servicePassages that trigger refusals or blockingSystem refuses legitimate questions
Promotion or biasContent favoring a product or viewpointManipulated recommendations
Backdoor triggerPassages activated only by a rare phraseStealthy, hard-to-detect manipulation
Common RAG poisoning objectives

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.

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.

AttackEntry pointPersistenceRemoval
RAG poisoningRetrieval corpus or indexUntil the document is removedDelete and reindex the source
Training data poisoningPretraining or fine-tuning dataBaked into model weightsRetraining or unlearning
Direct prompt injectionUser inputSingle sessionEnds with the session
Indirect prompt injectionAny external content read at runtimeWhile the content is reachableRemove or isolate the content
Memory poisoningAgent long-term memoryAcross future sessionsPurge memory entries
RAG poisoning compared with neighboring attacks

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.

LayerControlWhat it reduces
IngestionSource allowlists, write permissions, content signingWho can add documents
IngestionScanning for instructions and anomaliesObvious injection payloads
RetrievalSource trust scores and per-user access filteringRanking of untrusted text
RetrievalDiverse top-k and duplicate detectionDominance by clustered fake passages
GenerationSpotlighting and instruction hierarchyObedience to retrieved commands
OutputCitation checks and link or image filteringExfiltration and unsupported claims
Defensive controls by pipeline layer

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.