Sentiment steering against RAG
A retrieval-augmented system repeats what is in its corpus. So an attacker who can add a handful of documents can change what the model says about a person or a topic without ever touching the question being asked.
What I did
I built the black-box attack simulation and the detector that answers it. The attack poisons a slice of the corpus with sentiment-shifted passages about public officials; the defence inspects retrieved passages before they ever reach the generator, so it does not depend on which model is generating.
Approach
Passages are embedded with a MiniLM sentence encoder and retrieved through a FAISS index, then generated with Llama 3.1. Detection is two independent signals over the retrieved set: cosine similarity, which catches the near-duplicate phrasing that poisoning tends to introduce, and a z-score on the sentiment distribution, which catches passages whose polarity sits outside the corpus baseline. Either signal can flag a passage, which is what keeps recall high.
Why it matters
Retrieval is how most deployed language models get their facts, and a corpus is far easier to edit than a model. The detector works on retrieved passages rather than generations, so it transfers across generators and retrievers instead of being tuned to one stack.
- Poisoned share of corpus needed
- 0.04%
- Attack success rate
- 81.26%
- Polarity flip rate
- 65.21%
- Recall on poisoned passages
- 97.75%
Built with Python, FAISS, Sentence-Transformers (MiniLM-L6-v2), Llama 3.1, scikit-learn, PyTorch
Publication
ICC 2026 — IEEE International Conference on Communications pp. 1–6 May 2026
-
The corpus is the attack surface
Retrieval treats the corpus as ground truth. Nothing in a standard RAG stack asks whether a passage deserves that trust.
-
0.04% is enough
Poisoning a fraction of a percent of the corpus with sentiment-shifted passages produced an 81.26% attack success rate and flipped polarity on 65.21% of queries.
-
Retrieval concentrates the damage
Because poisoned passages are written to match the query closely, top-k retrieval pulls them in preferentially. The attacker never has to touch the query.
-
Two cheap signals catch them
Cosine similarity flags the repetitive phrasing poisoning introduces; a z-score on sentiment flags passages outside the corpus baseline. Together they reach 97.75% recall at about 18.5 seconds per query.
-
The model never sees them
Filtering happens before generation, so the defence is model-agnostic — swap the generator and it still holds.