SEVA
Lightweight · LLM-free · on-device

SEVA

Detection of templated corpus poisoning in Retrieval-Augmented Generation — one geometric signal, operated as a hard gate.
V. Varadharajan · Abishek V. P. T. · IEEE TDSC
Read the docs The paper ↗ Repository ↗
Templated poison-evasion
0%
95% Wilson ≤ 0.0154%
Document FPR
0.58%
frozen, non-oracle
Contamination density
1–10%
field standard ≈0.001%
Per-query cost
13–38 ms
no model call
Overview What’s new Signal Hard gate Calibration Detection Alternatives Invariance Deployment Boundary Reproduce Cite
01Overview

Retrieval-Augmented Generation relocates a system's factual authority into a corpus an adversary may be able to write to. SEVA closes the dominant published attack — templated, multi-passage injection — with one cached geometric statistic and a threshold comparison.

No LLM in the loop
No decoder access, no external API, no registration authority. The generator is never asked to adjudicate its own context.
Corpus-level, not per-window
Coherence is computed over the corpus and cached offline, so retrieval-time contamination cannot move a document's score.
Runs where the corpus lives
Desktop GPU, laptop GPU and Apple Silicon reproduce identical detection; retrieval-plus-gate stays sub-millisecond at 10⁶ documents.
02What’s new
01
Corpus-level detection that deploys offline
No LLM call, no decoder access, no registration authority, no API — 13–38 ms per query across three machines.
02
An evaluation with the shortcut removed
Clean and poison drawn from the same security domain. Most evaluations inject security- or instruction-style poison into general-domain prose, inflating linguistic separation. Remove the confound and the soft signals collapse while the geometric gap survives.
03
Density three orders of magnitude past the field
1–10% contamination, against a comparable literature that evaluates at ≈0.001%.
04
Lexical duplicate filtering is corpus-fragile
PoisonedRAG dismissed duplicate filtering in a line; we show why it fails. Effectiveness is a property of the corpus, not the attack: 98% where benign duplication is 0.24%, 0% at 1.15% and 9.06%.
05
Encoder-invariance, first for an LLM-free geometric detector
bge (BAAI), e5 (Microsoft), gte (Alibaba) — zero evasion across all 27 cells.
06
Frozen, non-oracle calibration
Threshold fit on clean coherence alone, frozen, deployed unchanged on held-out poison. Nothing tuned per corpus, density or encoder.
07
Reproducibility that fails closed
Order-sensitive SHA-256 gating on corpora and poison, recorded in every result file: a reproduction that doesn't match fails instead of diverging silently. Two accelerator backends agree on the coherence gap to within 5×10⁻⁷.
What's improved — protocol, against field practice
Dimension
Field standard
SEVA
Contamination density
≈0.001%
1–10%
FPR reporting
single headline rate
per-seed, all nine conditions
Baseline comparison
lifted published numbers
re-run on a shared corpus at matched FPR
Calibration
tuned on the test attack
frozen before, non-oracle
Platforms
one
three machines, two backends
Corpus integrity
none
hash-gated, fails closed
Query cost
5× LLM overhead / decoder access
no model call
Table S5, S12 detail follows in §07.
03The signal — cluster_coh

For a document d, let NK(d) be its K nearest corpus neighbours under cosine similarity. Cluster coherence is the mean pairwise similarity among those neighbours — a k-NN cohesion statistic in the lineage of local-outlier detection, inverted: templated poison is anomalous because it is more locally cohesive than organic text.

cluster_coh(d) = 2 / K(K−1) · Σi<j cos( f(di), f(dj) )
di, dj ∈ NK(d) · K = 5 · ℓ₂-normalized, so each cosine is an inner product

Because K = 5 is tiny against a 100,000-document corpus, the nearest neighbours of a templated passage are almost exclusively its own injected siblings — whatever fraction of the corpus is poisoned.

Embedding space, schematic. Grey: benign documents. Bright cluster: five passages generated from a shared recipe, each one's neighbourhood its own siblings.
The geometry does not move with density

A pairwise deduplicator's behaviour changes as the poison fraction grows; a K = 5 neighbourhood does not. Across 1–10% contamination the gap holds at +0.235 to +0.247 with SNR ≈6.0 — against ≈4.7 for the same signal on a general-domain corpus. The gap reads template homogeneity, not domain contrast.

Density
Clean
Poison
Gap
SNR
1%
0.7518
0.9871
+0.2353
5.99
5%
0.7526
0.9909
+0.2384
6.00
10%
0.7466
0.9939
+0.2474
5.78
Why one signal, not ten

SEVA began as a ten-signal detector fusing coherence with linguistic and structural statistics. The highest-SNR signal in that inventory is also the one an adversary can normalise away — and the one the domain confound inflated, from 38.4 against general-domain prose to 8.1 in-domain. That is the argument for deploying the geometric signal alone.

Signal
Type
SNR
Status
cluster_coh
geometric
5.99
deployed
kw_density
keyword
8.10
confounded 38.4→8.1, normalizable
sent_unif
structural
1.40
ablated
topic_drift
semantic
1.18
ablated
04The hard gate
query q
retrieve top-K_FETCH
gate: drop C[d] > τ
generator

SEVA flags a document when its coherence exceeds a calibrated τ, and flags a query when at least k = 2 of its retrieved documents are flagged. Operating the signal as a hard gate — rather than one term in a weighted score — is what gives SEVA its adaptive robustness: an adversary who normalises soft linguistic statistics changes nothing about the embedding geometry the gate reads.

R     ← rerank top-K of Retrieve_K_FETCH(q, D)
flags ← |{ d ∈ R : C[d] > τ }|
if flags ≥ k:  return Flag   # query poisoned
else:          return Pass
Aggregation exploits the attack's own structure
Rule
Query-FPR
Poison catch
≥1 flagged
3.06%
98.0%
≥2 flagged
0.97%
98.0%
PoisonedRAG injects five passages per target, so a real attack lights up several retrieved documents while benign false positives are isolated — 3.2× fewer false positives at zero cost to catch rate.
Encoder {{ encNote }}
τ
{{ tauLabel }}
Poison caught
{{ caughtLabel }}
Clean flagged
{{ fprLabel }}
Clones caught
{{ cloneLabel }}
Drag τ across the in-domain distributions, and switch encoders to see the same gate re-calibrate. {{ encTauNote }} Curves are normals at the published means, with clean SD inferred from the reported gap and SNR.
05Density-agnostic, non-oracle calibration

τ is the (1 − FPRtarget) quantile of the benign coherence distribution, found by 50-iteration binary search — no labelled poison, no poison scores, no density estimate. The operator sets a false-positive target, not a guess at how poisoned the corpus is. Evaluation then scores held-out benign and all adversarial queries against the frozen τ, with calibration documents excluded from false-positive accounting.

The estimator holds as the corpus grows: 0.7653% at 10k, 0.6741% at 100k and 0.7008% at 1M against the 0.69% pre-registered target — a deviation that does not grow with N.

Density invariance, however, is a large-corpus property. At 10k the gap curve is not flat — it collapses to 0.141 at 1% density, and result_scale10k.json records gap_density_invariant: false and templated_asr_zero: false accordingly. The chart marks where the property fails rather than cropping it out.

Grand-mean document FPR at the non-oracle operating point, three corpus sizes, against the dashed 0.69% target. The 10k bar is marked: calibration tracks the target there, but density invariance does not hold. Source: result_scale10k.json, result_scale100k.json, result_1M.json.
Constant
Value
Meaning
K
5
nearest corpus neighbours for cluster_coh
K_FETCH
20
HNSW over-fetch, reranked to top-K
EMB_DIM
1024
bge-large-en-v1.5, ℓ₂-normalized
INDEX_M / efC
32 / 200
FAISS HNSW parameters
FPR_TARGET
0.0069
universal non-oracle false-positive target
k
2
flag a query when ≥ 2 retrieved docs are flagged
seeds
42, 7, 123
three calibration-partition seeds
τ (frozen)
0.8423
2000 benign queries, 60/40 cal/eval split
Encoder: BAAI/bge-large-en-v1.5 @ d4aa6901d3a41ba39fb536a557fa166f842b0e09 · additionally validated on e5-large-v2 and gte-large.
06Detection, in-domain

Primary corpus: an in-domain Security Stack Exchange Q&A corpus of 100,000 deduplicated documents — a domain-confound control, so clean and poison share a domain and no detector can lean on topic contrast. Three densities × three seeds, complete per-seed accounting.

Tier
Density
Evasion
Doc-FPR
L1 (naive)
1%
0.0 ± 0.0%
0.54 ± 0.17%
5%
0.0 ± 0.0%
0.63 ± 0.18%
10%
0.0 ± 0.0%
0.52 ± 0.15%
Zero is a measurement, not a rounding

Zero evasions in 25,000 high-encounter trials puts the 95% Wilson upper bound at 0.0154%. The margin is wide, not marginal: the least-cohesive poison document scores 0.8905 against a clean mean of 0.7510, with τ frozen at 0.8423. Re-deriving τ on the poisoned corpus would inflate it to 0.9767 — a threshold the gate deliberately does not use.

Every poison document sits above the frozen gate. Source: result_hienc_ci.json.
The geometric core beats the composite it replaced
Attack
Hard gate
10-signal composite
Templated (held-out)
0%
0%
Real PoisonedRAG
2%
28%
Adaptive (keyword-drop)
0%
49–57%
Poison-evasion; lower is better. The composite collapses under an adversary that normalises the features it reads. The gate, reading only geometry, does not move.
07Against the alternatives
Reproduced head-to-head vs the per-query state of the art
Defense
Catch @ matched ~0.8% FPR
Native benign doc-FPR
SEVA
100%
≈0.6%
RAGDefender
≈89%
50.4%
The setup favours the baseline: RAGDefender runs on SEVA's own encoder to isolate the algorithm, at a looser operating point than SEVA's, with a best-case idealised threshold in its favour. It still loses — and reaches 89% only by discarding half the clean corpus.
Matched-FPR sweep — coherence vs lexical vs embedding dedup
Corpus
FPR
cluster_coh
MinHash
s_nd
Natural Questions
0.5%
70%
0%
30%
0.69%
82%
0%
52%
1%
92%
0%
74%
2%
98%
100%
95%
HotpotQA
0.5%
95%
0%
97%
0.69%
97%
0%
98%
1%
100%
0%
99%
2%
100%
0%
100%
Lexical filtering catches nothing at any deployable false-positive rate below 2%.
Corpus-fragility, in one column
Corpus
Benign dup.
cluster_coh
MinHash
s_nd
Security SE
0.24%
98%
98%
98%
Natural Questions
1.15%
82%
0%
52%
HotpotQA
9.06%
97%
0%
98%
MinHash goes 98% → 0% → 0% as benign duplication rises 0.24% → 1.15% → 9.06%. Semantic cohesion holds across all three.
Deployment capability
Defense
LLM-free
No decoder
No pre-reg.
Corpus-level
Density
RobustRAG
✕ (5×)
≈0.001%
AV Filter
≈0.001%
RAGShield
≈0.001%
RAGDefender
≈1%
SEVA (ours)
1–10%
The only row scoring all four capability columns — and the only one evaluated three orders of magnitude past the field's density.
08Encoder-invariance

Three embedding models of independent lineages, each in its correct symmetric convention, all at the non-oracle operating point: zero evasion across all 27 cells. What generalises is that the gate works — not the size of the margin. Absolute separation is encoder-dependent, and the honest reading is that a deployment should calibrate on its own encoder rather than inherit a published gap.

Encoder
Lineage
Clean
Poison
Gap
SNR
Evasion
bge-large
BAAI
0.751
0.990
+0.236–0.245
5.9–6.1
0%
e5-large-v2
Microsoft
0.866
0.990
+0.122–0.127
6.4–6.7
0%
gte-large
Alibaba
0.881
0.996
+0.113–0.117
5.2–5.3
0%
Coherence gap (bars, left) against minimum SNR (markers, right) per encoder. Source: result_encoder_bge.json, result_encoder_e5.json, result_encoder_gte.json.
09Deployment — platforms and scale

A hash-verified, byte-identical corpus was re-embedded independently on CUDA and on Apple Silicon. The coherence gap agrees to within 5×10⁻⁷ and the detection decision is identical; only latency differs. The decision is a property of the geometry, not of the accelerator.

Platform
Gap (1–10%)
SNR
Evasion
Mean / p95
RTX 5080 (CUDA)
+0.236–0.245
5.9–6.1
0%
13.4–15.7 / ≤18.8 ms
RTX 4060 (CUDA)
+0.236–0.245
5.9–6.1
0%
38.1 / 43.6 ms
Apple M4 (MPS)
+0.236–0.245
5.9–6.1
0%
28.1 / 37.3 ms
Per-query latency differs; the decision does not. Solid: mean. Hatched: p95. Source: result_4060.json, result_M4.json.
Million-document scale
Density
n_poison
Gap
SNR
Evasion
Doc-FPR
1%
10,000
+0.245
5.63
0%
0.68%
5%
50,000
+0.249
5.57
0%
0.72%
15.0 ms mean / 18.2 ms p95 at 10⁶ documents, of which retrieval and gate are ≈0.4 ms — sub-millisecond at 10× scale.
10The boundary of the assumption

Host-anchored cloning evades the deployed gate on every target while remaining retrievable — and the bypass is not expensive.

Why it evades
Each injected passage mimics a distinct benign host, so its neighbourhood is that host's neighbourhood. Coherence lands at 0.751 — inside the clean distribution, not near it. No threshold on this statistic separates them without discarding the corpus.
No complementary signal closes it
The natural geometric complements we tested do not recover the gap, and reproducing CleanBase at a matched operating point yields the same pattern.
Scope of the finding
The boundary follows from the mutual-similarity assumption the cohesion family shares — CleanBase, SeCon-RAG, GRADA, TopoGuard — rather than from SEVA's statistic. It delimits the family, not one detector.
Also out of scope: single-injection attacks that forgo the cluster (CorruptRAG, PoisonCraft) and availability attacks such as MutedRAG's guardrail-tripping denial of service.
11Reproduce in one command
Environment
git clone https://github.com/varadharajanv0310/SEVA-IEEE.git
cd SEVA-RAG
conda env create -f environment.yml
conda activate seva
Headline in-domain run
cd reproduction
python hardgate_xrun.py --label local
# rebuilds the 100k corpus from pinned HF revisions and
# STOPS unless it matches SHA-256 28ec3811…; regenerates
# the exact 10k poison (4f7ee3f3…); embeds once with
# bge-large; emits result_local.json
Figures
python reproduction/make_figures.py
Repository map
reproduction/frozen detector, deterministic corpus + poison builders, turnkey runners, MANIFEST.json, committed result JSONs
results/in-domain grid (3 densities × 3 seeds) and the general-domain contrast
whitebox_attack_results/headline attack experiments behind the head-to-head, cross-domain and ROC tables
adaptive_attack_results/diversity-injection adaptive attack — the gate holds 0%
poison_corpus_diverse.jsondeterministic templated poison, 10k documents
SEVA_tdsc.tex · SEVA_arxiv.texTDSC submission with supplement, and the self-contained extended version
12Cite
@misc{seva2026,
  title  = {SEVA: Lightweight, LLM-Free Detection of Templated
            Corpus Poisoning in Retrieval-Augmented Generation},
  author = {V. Varadharajan},
  year   = {2026},
  url    = {https://github.com/varadharajanv0310/SEVA-IEEE}
}