silent-rag 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- silent_rag-0.2.0/PKG-INFO +437 -0
- silent_rag-0.2.0/README.md +411 -0
- silent_rag-0.2.0/pyproject.toml +44 -0
- silent_rag-0.2.0/setup.cfg +4 -0
- silent_rag-0.2.0/src/silent_rag/__init__.py +12 -0
- silent_rag-0.2.0/src/silent_rag/analyze_benchmark_results.py +210 -0
- silent_rag-0.2.0/src/silent_rag/data.py +245 -0
- silent_rag-0.2.0/src/silent_rag/detect/__init__.py +0 -0
- silent_rag-0.2.0/src/silent_rag/detect/base.py +56 -0
- silent_rag-0.2.0/src/silent_rag/detect/canary.py +118 -0
- silent_rag-0.2.0/src/silent_rag/detect/combined.py +78 -0
- silent_rag-0.2.0/src/silent_rag/detect/domain_classifier.py +143 -0
- silent_rag-0.2.0/src/silent_rag/detect/features.py +179 -0
- silent_rag-0.2.0/src/silent_rag/detect/ks.py +49 -0
- silent_rag-0.2.0/src/silent_rag/detect/llm_judge.py +99 -0
- silent_rag-0.2.0/src/silent_rag/detect/mmd.py +85 -0
- silent_rag-0.2.0/src/silent_rag/detect/psi.py +78 -0
- silent_rag-0.2.0/src/silent_rag/detect/qpp.py +89 -0
- silent_rag-0.2.0/src/silent_rag/detect/re_embed.py +102 -0
- silent_rag-0.2.0/src/silent_rag/detect/two_stage.py +80 -0
- silent_rag-0.2.0/src/silent_rag/eval/__init__.py +0 -0
- silent_rag-0.2.0/src/silent_rag/eval/all_test_questions.py +168 -0
- silent_rag-0.2.0/src/silent_rag/eval/combine.py +167 -0
- silent_rag-0.2.0/src/silent_rag/eval/detector_scoring.py +239 -0
- silent_rag-0.2.0/src/silent_rag/eval/f1_partial_upgrade.py +93 -0
- silent_rag-0.2.0/src/silent_rag/eval/figures.py +210 -0
- silent_rag-0.2.0/src/silent_rag/eval/ground_truth.py +64 -0
- silent_rag-0.2.0/src/silent_rag/eval/permutation.py +125 -0
- silent_rag-0.2.0/src/silent_rag/eval/question_vulnerability.py +120 -0
- silent_rag-0.2.0/src/silent_rag/eval/report.py +237 -0
- silent_rag-0.2.0/src/silent_rag/eval/results.py +33 -0
- silent_rag-0.2.0/src/silent_rag/eval/severity_analysis.py +410 -0
- silent_rag-0.2.0/src/silent_rag/eval/thresholds.py +184 -0
- silent_rag-0.2.0/src/silent_rag/eval/two_stage.py +152 -0
- silent_rag-0.2.0/src/silent_rag/eval/window.py +66 -0
- silent_rag-0.2.0/src/silent_rag/eval/window_analyses.py +257 -0
- silent_rag-0.2.0/src/silent_rag/eval/window_questions.py +103 -0
- silent_rag-0.2.0/src/silent_rag/inject/__init__.py +0 -0
- silent_rag-0.2.0/src/silent_rag/inject/base.py +73 -0
- silent_rag-0.2.0/src/silent_rag/inject/controls.py +226 -0
- silent_rag-0.2.0/src/silent_rag/inject/f1_partial_upgrade.py +134 -0
- silent_rag-0.2.0/src/silent_rag/inject/f2_distractors.py +91 -0
- silent_rag-0.2.0/src/silent_rag/inject/f2_stale_twins.py +134 -0
- silent_rag-0.2.0/src/silent_rag/inject/f3_chunk_fallback.py +74 -0
- silent_rag-0.2.0/src/silent_rag/inject/f5_config_mismatch.py +63 -0
- silent_rag-0.2.0/src/silent_rag/inject/f5_query_pooling.py +62 -0
- silent_rag-0.2.0/src/silent_rag/inject/model_check.py +99 -0
- silent_rag-0.2.0/src/silent_rag/judge.py +331 -0
- silent_rag-0.2.0/src/silent_rag/manifest.py +140 -0
- silent_rag-0.2.0/src/silent_rag/monitor.py +427 -0
- silent_rag-0.2.0/src/silent_rag/monitor_demo.py +120 -0
- silent_rag-0.2.0/src/silent_rag/pipeline.py +257 -0
- silent_rag-0.2.0/src/silent_rag/plots/__init__.py +1 -0
- silent_rag-0.2.0/src/silent_rag/plots/_common.py +234 -0
- silent_rag-0.2.0/src/silent_rag/plots/figures_models.py +217 -0
- silent_rag-0.2.0/src/silent_rag/plots/figures_statistics.py +376 -0
- silent_rag-0.2.0/src/silent_rag/plots/style.py +257 -0
- silent_rag-0.2.0/src/silent_rag/run.py +711 -0
- silent_rag-0.2.0/src/silent_rag/types.py +69 -0
- silent_rag-0.2.0/src/silent_rag.egg-info/PKG-INFO +437 -0
- silent_rag-0.2.0/src/silent_rag.egg-info/SOURCES.txt +115 -0
- silent_rag-0.2.0/src/silent_rag.egg-info/dependency_links.txt +1 -0
- silent_rag-0.2.0/src/silent_rag.egg-info/entry_points.txt +2 -0
- silent_rag-0.2.0/src/silent_rag.egg-info/requires.txt +22 -0
- silent_rag-0.2.0/src/silent_rag.egg-info/top_level.txt +1 -0
- silent_rag-0.2.0/tests/test_all_test_questions.py +273 -0
- silent_rag-0.2.0/tests/test_analyze_benchmark_results.py +145 -0
- silent_rag-0.2.0/tests/test_audit_fixes.py +618 -0
- silent_rag-0.2.0/tests/test_basics.py +49 -0
- silent_rag-0.2.0/tests/test_bootstrap_ci.py +59 -0
- silent_rag-0.2.0/tests/test_canary.py +114 -0
- silent_rag-0.2.0/tests/test_combine.py +124 -0
- silent_rag-0.2.0/tests/test_configs.py +99 -0
- silent_rag-0.2.0/tests/test_controls.py +233 -0
- silent_rag-0.2.0/tests/test_data.py +89 -0
- silent_rag-0.2.0/tests/test_data_extra.py +61 -0
- silent_rag-0.2.0/tests/test_detector_scoring.py +323 -0
- silent_rag-0.2.0/tests/test_domain_classifier.py +197 -0
- silent_rag-0.2.0/tests/test_eval_f1_partial_upgrade.py +113 -0
- silent_rag-0.2.0/tests/test_f2_distractors.py +152 -0
- silent_rag-0.2.0/tests/test_f2_stale_twins.py +151 -0
- silent_rag-0.2.0/tests/test_f3_chunk_fallback.py +225 -0
- silent_rag-0.2.0/tests/test_features.py +65 -0
- silent_rag-0.2.0/tests/test_figures.py +43 -0
- silent_rag-0.2.0/tests/test_final_freeze.py +187 -0
- silent_rag-0.2.0/tests/test_inject_f1.py +333 -0
- silent_rag-0.2.0/tests/test_inject_f5.py +143 -0
- silent_rag-0.2.0/tests/test_inject_f5_query_pooling.py +109 -0
- silent_rag-0.2.0/tests/test_ks.py +84 -0
- silent_rag-0.2.0/tests/test_llm_judge.py +245 -0
- silent_rag-0.2.0/tests/test_macos_openmp.py +27 -0
- silent_rag-0.2.0/tests/test_manifest.py +139 -0
- silent_rag-0.2.0/tests/test_mmd.py +87 -0
- silent_rag-0.2.0/tests/test_model_check.py +152 -0
- silent_rag-0.2.0/tests/test_monitor.py +169 -0
- silent_rag-0.2.0/tests/test_permutation.py +333 -0
- silent_rag-0.2.0/tests/test_pipeline.py +283 -0
- silent_rag-0.2.0/tests/test_plots_common.py +354 -0
- silent_rag-0.2.0/tests/test_plots_models.py +338 -0
- silent_rag-0.2.0/tests/test_plots_statistics.py +460 -0
- silent_rag-0.2.0/tests/test_plots_style.py +265 -0
- silent_rag-0.2.0/tests/test_psi.py +99 -0
- silent_rag-0.2.0/tests/test_qpp.py +134 -0
- silent_rag-0.2.0/tests/test_query_shift.py +176 -0
- silent_rag-0.2.0/tests/test_question_vulnerability.py +126 -0
- silent_rag-0.2.0/tests/test_re_embed.py +103 -0
- silent_rag-0.2.0/tests/test_report.py +154 -0
- silent_rag-0.2.0/tests/test_score_depth.py +69 -0
- silent_rag-0.2.0/tests/test_seeds_and_chunks.py +93 -0
- silent_rag-0.2.0/tests/test_severity_analysis.py +290 -0
- silent_rag-0.2.0/tests/test_smoke_analysis_f1.py +137 -0
- silent_rag-0.2.0/tests/test_thresholds.py +130 -0
- silent_rag-0.2.0/tests/test_two_stage.py +157 -0
- silent_rag-0.2.0/tests/test_two_stage_detector.py +115 -0
- silent_rag-0.2.0/tests/test_window.py +59 -0
- silent_rag-0.2.0/tests/test_window_analyses.py +256 -0
- silent_rag-0.2.0/tests/test_window_questions.py +106 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: silent-rag
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Label-free monitoring of retrieval quality in RAG, and the benchmark behind it
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: numpy
|
|
8
|
+
Requires-Dist: pandas
|
|
9
|
+
Requires-Dist: scipy
|
|
10
|
+
Requires-Dist: pyarrow
|
|
11
|
+
Provides-Extra: bench
|
|
12
|
+
Requires-Dist: datasets; extra == "bench"
|
|
13
|
+
Requires-Dist: sentence-transformers; extra == "bench"
|
|
14
|
+
Requires-Dist: faiss-cpu; extra == "bench"
|
|
15
|
+
Requires-Dist: scikit-learn; extra == "bench"
|
|
16
|
+
Requires-Dist: duckdb; extra == "bench"
|
|
17
|
+
Requires-Dist: matplotlib; extra == "bench"
|
|
18
|
+
Requires-Dist: pyyaml; extra == "bench"
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: silent-rag[bench]; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest; extra == "dev"
|
|
22
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
23
|
+
Requires-Dist: nbstripout; extra == "dev"
|
|
24
|
+
Provides-Extra: judge
|
|
25
|
+
Requires-Dist: anthropic; extra == "judge"
|
|
26
|
+
|
|
27
|
+
<div align="center">
|
|
28
|
+
|
|
29
|
+
# Silent Failures
|
|
30
|
+
|
|
31
|
+
**Detecting retrieval degradation in RAG systems without relevance labels**
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+

|
|
35
|
+

|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
[Project page](https://srikarmk.github.io/Silent-RAG-Failures/) · [Monitoring guide](docs/monitoring_guide.md) · [Results](#held-out-results) · [Screenshots](#screenshots) · [Running it](#running-it) · [Monitoring your own system](#monitoring-your-own-system)
|
|
39
|
+
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
## Motivation
|
|
43
|
+
|
|
44
|
+
A RAG system embeds the user's question, finds the most similar documents in a vector index, and passes them to an LLM along with the question. If the retrieval step gets worse, nothing errors out. The system stays up and latency looks normal, but the answers get worse, and usually nobody notices for a while.
|
|
45
|
+
|
|
46
|
+
A few ways this happens in practice:
|
|
47
|
+
|
|
48
|
+
- an embedding model gets upgraded, but only part of the corpus is re-embedded
|
|
49
|
+
- outdated documents stay in the index next to their replacements
|
|
50
|
+
- chunking or preprocessing settings change partway through the corpus
|
|
51
|
+
- users start asking about things the corpus doesn't cover
|
|
52
|
+
|
|
53
|
+
Production systems don't have relevance labels, so you can't just track nDCG. Teams rely on label-free signals instead, like drift statistics or retrieval scores, and it isn't clear which of these actually catch real damage. That is the question this project tries to answer.
|
|
54
|
+
|
|
55
|
+
**What we released**
|
|
56
|
+
|
|
57
|
+
1. An open-source benchmark (`python -m silent_rag.run`) that injects retrieval failures at controlled severity and scores label-free detectors against the real nDCG@10 damage
|
|
58
|
+
2. Held-out results on SciFact and FiQA, then on four more domains: which check catches which failure, how early, and how often it alarms on harmless changes. They are summarized [below](#held-out-results) and in full in the [monitoring guide](docs/monitoring_guide.md)
|
|
59
|
+
3. [`silent-rag-monitor`](#monitoring-your-own-system), a small CLI that runs the cheap checks on your own retrieval logs
|
|
60
|
+
4. A [project page](https://srikarmk.github.io/Silent-RAG-Failures/) that replays real windows from the held-out run, so you can watch each check react to each failure
|
|
61
|
+
|
|
62
|
+
## Approach
|
|
63
|
+
|
|
64
|
+
We build a standard retrieval pipeline, break it in controlled ways, and check whether each detector notices. The detectors only get what a production system would have: queries, embeddings and similarity scores. The labeled relevance judgments are used for one thing only, measuring how much damage each failure actually caused.
|
|
65
|
+
|
|
66
|
+
```mermaid
|
|
67
|
+
flowchart LR
|
|
68
|
+
A[("Corpus")] --> B["Embed<br/>sentence-transformers"]
|
|
69
|
+
B --> C[("FAISS index")]
|
|
70
|
+
Q["Queries"] --> C
|
|
71
|
+
C --> D["Inject failure<br/>F1–F5, 10%–90% severity"]
|
|
72
|
+
D --> E["Label-free detectors"]
|
|
73
|
+
D --> F["nDCG@10 drop<br/>(uses labels)"]
|
|
74
|
+
E --> G{"Did the detector fire<br/>when the damage was real?"}
|
|
75
|
+
F --> G
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Failure families
|
|
79
|
+
|
|
80
|
+
Each failure is applied at increasing severity, mostly from 10% up to 90% of the corpus or query traffic.
|
|
81
|
+
|
|
82
|
+
| ID | Failure | Injector | How we simulate it | Where it ran |
|
|
83
|
+
|---|---|---|---|---|
|
|
84
|
+
| F1 | Partial embedding upgrade | `F1_partial_upgrade` | Part of the index re-embedded with bge-small or all-MiniLM; queries stay on the old model | NFCorpus, SciFact, FiQA |
|
|
85
|
+
| F2 | Off-topic documents | `F2_distractors` | Unrelated ArguAna passages added to the collection | NFCorpus, SciFact, FiQA |
|
|
86
|
+
| F2 | Stale copies | `F2_stale_twins` | An edited old copy of a relevant document left beside it | NFCorpus |
|
|
87
|
+
| F3 | Chunking change | `F3_chunk_fallback` | Part of the corpus re-indexed as chunks, each document scored by its best chunk | MLDR, NFCorpus |
|
|
88
|
+
| F4 | Questions outside the corpus | none | Not tested: there is no ground truth for them | |
|
|
89
|
+
| F5 | Config mismatch | `F5_index_no_normalize`, `F5_query_cls_pooling` | New documents indexed without normalization; queries encoded with CLS instead of mean pooling | NFCorpus, SciFact, FiQA (index side) |
|
|
90
|
+
|
|
91
|
+
**F1** replaces a random `severity` fraction of index rows with the same documents embedded by `alt_model`. Queries stay on the clean model. `alt_model` and `alt_revision` (a lowercase 40-character commit hash) have no defaults and must be in the config, and each replacement model gets its own label. F1 rejects an `alt_model` that is the clean model (compared ignoring case, whatever the revisions). It also rejects models that need a document prefix F1 doesn't add: `intfloat/e5-*` and `intfloat/multilingual-e5-*`, whose model cards require `passage: `. Limitations: model names are compared as written, so `all-MiniLM-L6-v2` and `sentence-transformers/all-MiniLM-L6-v2` count as different. The prefix list only blocks the models it names, so an unlisted model that needs a prefix, or an e5 copy under another org, gets through. Models are added to the list only with evidence from their card, and every replacement model is pinned in a reviewed config.
|
|
92
|
+
|
|
93
|
+
We also run **negative controls**: changes that move the data around without hurting retrieval. A good detector should stay quiet on these, so they tell us its false-alarm rate. Each is the harmless twin of a failure:
|
|
94
|
+
|
|
95
|
+
| Control | Injector | What changes |
|
|
96
|
+
|---|---|---|
|
|
97
|
+
| Full model switch | `H_full_swap` | Documents and queries both move to bge-small or all-MiniLM; retrieval improves |
|
|
98
|
+
| Mixed truncation | `H_mixed_truncation` | Part of the index re-embedded at 512 tokens instead of 256 |
|
|
99
|
+
| Topic shift | `H_query_topic_shift` | Query traffic moves to one topic cluster; the index is unchanged |
|
|
100
|
+
| Queries without normalization | `H_query_no_normalize` | Each query's scores are rescaled; the ranking is unchanged |
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Detectors
|
|
104
|
+
|
|
105
|
+
`python -m silent_rag.run --list` prints every registered detector. They fall into four groups:
|
|
106
|
+
|
|
107
|
+
| Family | Detectors |
|
|
108
|
+
|---|---|
|
|
109
|
+
| Score statistics (QPP) | `qpp_max` (top-1 score fell), `qpp_gap`, `qpp_nqc`, `combined_scores` |
|
|
110
|
+
| Drift tests on the scores | `ks_*` and `psi_*` on the top-1 score, the mean and spread of the top 10, the gap and the margin |
|
|
111
|
+
| Embedding drift | `mmd_query`, `mmd_retrieved_docs`, `domain_classifier_query`, `domain_classifier_retrieved_docs` |
|
|
112
|
+
| Active checks | `canary` (fixed queries with known answers), `re_embed` (re-encode a sample of the index), `llm_judge`, `two_stage` (a cheap check gates the judge) |
|
|
113
|
+
|
|
114
|
+
Most score detectors also come as `<name>_perm`, the same statistic scored by a per-window permutation p-value.
|
|
115
|
+
|
|
116
|
+
## Evaluation
|
|
117
|
+
|
|
118
|
+
The ground truth is the drop in **nDCG@10** from the clean baseline. Each check runs on a sampled window of queries, repeated over many trials per condition. A condition counts as harmful when its drop is significant under a paired bootstrap test.
|
|
119
|
+
|
|
120
|
+
Each detector is scored on:
|
|
121
|
+
|
|
122
|
+
- **Accuracy**: AUROC for separating harmful conditions from clean and harmless ones
|
|
123
|
+
- **Earliness**: the lowest severity at which it fires, at a 5% false-alarm rate
|
|
124
|
+
- **False alarms**: how often its default threshold fires on the harmless changes
|
|
125
|
+
- **Cost**: compute and API cost per check
|
|
126
|
+
|
|
127
|
+
We'll also report how big an nDCG@10 drop the common "PSI > 0.25" rule of thumb actually corresponds to.
|
|
128
|
+
|
|
129
|
+
### Datasets
|
|
130
|
+
|
|
131
|
+
| Dataset | Size | Used for |
|
|
132
|
+
|---|---:|---|
|
|
133
|
+
| NFCorpus | 3,633 medical documents | Development. All detector tuning happens here |
|
|
134
|
+
| SciFact | 5,183 scientific abstracts | Held-out evaluation |
|
|
135
|
+
| FiQA | 57,638 financial forum posts | Held-out evaluation |
|
|
136
|
+
| ArguAna | 7,376 debate arguments | Extra held-out evaluation |
|
|
137
|
+
| SciDocs | 25,657 scientific papers | Extra held-out evaluation |
|
|
138
|
+
| CQADupStack Android | 22,998 Q&A forum posts | Extra held-out evaluation |
|
|
139
|
+
| CQADupStack Programmers | 32,176 Q&A forum posts | Extra held-out evaluation |
|
|
140
|
+
| MLDR | long documents | Chunking change (F3), development only |
|
|
141
|
+
|
|
142
|
+
The six held-out sets are never used for tuning, so the final numbers show how well the detectors generalize to data they haven't seen. The four extra domains were added after the SciFact and FiQA run, with new data loaders and nothing else changed (tags `final-v2`, `final-v3`). ArguAna's own 1,298 query documents are dropped from its corpus, and its off-topic documents come from NFCorpus instead of ArguAna. These sets have no training split, so 200 test questions are set aside for canaries and never scored.
|
|
143
|
+
|
|
144
|
+
## Held-out results
|
|
145
|
+
|
|
146
|
+
Final run `c287e006fdc2` ([#29](https://github.com/Srikarmk/Silent-RAG-Failures/issues/29)): SciFact and FiQA, 3 seeds × 20 windows of 100 queries per condition, 16 detectors, a window counted as harmful when its nDCG@10 drop is significant and at least 0.02. AUROC of harmful windows against clean and harmless windows, as a range over the two datasets:
|
|
147
|
+
|
|
148
|
+
| Check | F1 upgrade stalls (bge-small) | F1 (all-MiniLM) | F5 index without normalization | Alarms on a finished upgrade to bge-small |
|
|
149
|
+
|---|---|---|---|---|
|
|
150
|
+
| `qpp_max` | 0.92–0.96 | 0.92–0.96 | 0.10–0.14 (backwards) | 0% |
|
|
151
|
+
| `ks_top1` | 0.61–0.64 | 0.61–0.65 | 1.00 | 100% |
|
|
152
|
+
| `re_embed` | 0.87–0.89 | 0.83–0.84 | 0.29 | 100% |
|
|
153
|
+
| `canary` | 0.86–0.90 | 0.83–0.87 | 0.88–0.93 | 100% |
|
|
154
|
+
|
|
155
|
+
So no single check is enough. `qpp_max` is free and catches a stalled upgrade but reads missing normalization backwards, because unnormalized vectors raise scores; a KS test on the same scores catches that one. Off-topic documents (F2) did no measurable harm on the held-out sets, and no score-based check saw them on NFCorpus. Thresholds, false alarms, costs and the reasoning behind each recommendation are in the [monitoring guide](docs/monitoring_guide.md), and the [project page](https://srikarmk.github.io/Silent-RAG-Failures/#replay) replays the windows behind these numbers.
|
|
156
|
+
|
|
157
|
+
### Four more domains
|
|
158
|
+
|
|
159
|
+
The same setup on ArguAna, SciDocs and the Android and Programmers forums of CQADupStack, one frozen run per dataset (`configs/final_<dataset>.yaml`). Range over the four:
|
|
160
|
+
|
|
161
|
+
| Check | F1 upgrade stalls (bge-small) | F1 (all-MiniLM) | F5 index without normalization | Alarms on a finished upgrade to bge-small |
|
|
162
|
+
|---|---|---|---|---|
|
|
163
|
+
| `qpp_max` | 0.91–0.95 | 0.92–0.97 | 0.02–0.13 (backwards) | 0% |
|
|
164
|
+
| `combined_scores` | 0.90–0.96 | 0.87–0.96 | 0.07–0.17 (backwards) | 0% |
|
|
165
|
+
| `ks_top1` | 0.60–0.69 | 0.62–0.70 | 1.00 | 100% |
|
|
166
|
+
| `re_embed` | 0.88–0.91 | 0.83–0.86 | 0.29–0.31 | 100% |
|
|
167
|
+
| `canary` | 0.87–0.93 | 0.86–0.90 | 0.93–0.96 | 100% |
|
|
168
|
+
|
|
169
|
+
The pattern held on all four. Two things did not. The finished upgrade to bge-small, which improved retrieval everywhere else, made both forums worse (mean nDCG@10 drop 0.034 on Android and 0.012 on Programmers, harmful in 22 and 6 of 60 windows), so a model that is better on average can still be worse for a given collection. And calibration was uneven: `qpp_max` raised false alarms on 7–10% of clean windows on ArguAna and the two forums but 32% on SciDocs. F2 again did no measurable harm.
|
|
170
|
+
|
|
171
|
+
### Baseline and window size
|
|
172
|
+
|
|
173
|
+
Our first pass over SciFact is in [`notebooks/scifact_eda.ipynb`](notebooks/scifact_eda.ipynb), using `multi-qa-MiniLM-L6-cos-v1`.
|
|
174
|
+
|
|
175
|
+
| | Queries | Documents |
|
|
176
|
+
|---|---:|---:|
|
|
177
|
+
| Median length (tokens) | 21 | 316 |
|
|
178
|
+
| Max length (tokens) | 79 | 1,939 |
|
|
179
|
+
| Longer than 512 tokens (the model's hard limit) | 0 | 455 (8.8%) |
|
|
180
|
+
| Longer than ~250 tokens (what the model was trained on) | 0 | 3,793 (73.2%) |
|
|
181
|
+
|
|
182
|
+
Query length is not a concern. Document length is: most abstracts are longer than the inputs this model was trained on.
|
|
183
|
+
|
|
184
|
+
**Baseline.** We kept `multi-qa-MiniLM-L6-cos-v1` and embed title + text truncated at 256 tokens, with no chunking ([#5](https://github.com/Srikarmk/Silent-RAG-Failures/issues/5)). The goal is to evaluate detectors, not to get the best retriever. Clean nDCG@10 with exact cosine search in FAISS:
|
|
185
|
+
|
|
186
|
+
| Dataset | Test queries | nDCG@10 | 95% bootstrap CI |
|
|
187
|
+
|---|---:|---:|---|
|
|
188
|
+
| NFCorpus | 323 | 0.292 | 0.259–0.325 |
|
|
189
|
+
| SciFact | 300 | 0.546 | 0.496–0.595 |
|
|
190
|
+
| FiQA | 648 | 0.360 | 0.332–0.387 |
|
|
191
|
+
|
|
192
|
+
Truncating at 256 instead of 512 tokens made no significant difference on any of the three.
|
|
193
|
+
|
|
194
|
+
**Window size.** Each check scores a window of **100 queries** ([#4](https://github.com/Srikarmk/Silent-RAG-Failures/issues/4)). On NFCorpus, that's enough for the paired bootstrap to catch an nDCG@10 drop of about 0.06 in 80% of windows while staying under a 5% false-alarm rate. Windows of 25 or 50 queries only reliably catch drops of 0.10–0.13, and alarm more often than 5%. Both analyses are in [`experiments/baseline/window_size.py`](experiments/baseline/window_size.py).
|
|
195
|
+
|
|
196
|
+
## Timeline
|
|
197
|
+
|
|
198
|
+
All six milestones are done. Each has its issues on the [project board](https://github.com/users/Srikarmk/projects/2).
|
|
199
|
+
|
|
200
|
+
| Due | Milestone | Done when | Status |
|
|
201
|
+
|---|---|---|---|
|
|
202
|
+
| Oct 18 | [Baseline](https://github.com/Srikarmk/Silent-RAG-Failures/milestone/1) | Model and chunking fixed; clean nDCG@10 with CIs on SciFact, FiQA, NFCorpus | Done |
|
|
203
|
+
| Oct 31 | [Failure injection](https://github.com/Srikarmk/Silent-RAG-Failures/milestone/2) | F1–F5 plus negative controls; nDCG@10 drops steadily with severity, negative controls don't | Done (F4 not tested) |
|
|
204
|
+
| Nov 11 | [Drift + QPP detectors](https://github.com/Srikarmk/Silent-RAG-Failures/milestone/3) | Implemented and tuned on NFCorpus | Done |
|
|
205
|
+
| Nov 18 | [Canary, re-embed, LLM judge](https://github.com/Srikarmk/Silent-RAG-Failures/milestone/4) | Implemented, with cost per check recorded for every detector | Done |
|
|
206
|
+
| Nov 24 | [Held-out evaluation](https://github.com/Srikarmk/Silent-RAG-Failures/milestone/5) | AUROC, earliness and false alarms on SciFact and FiQA; heatmap; PSI analysis | Done |
|
|
207
|
+
| Dec 1 | [Release](https://github.com/Srikarmk/Silent-RAG-Failures/milestone/6) | Benchmark, monitoring guide, final report | Done (the agentic extension was not attempted) |
|
|
208
|
+
|
|
209
|
+
## Screenshots
|
|
210
|
+
|
|
211
|
+
Real output from a fresh clone on 2026-12-05 (macOS, Python 3.14, empty caches). The terminal images are drawn from the captured text by [`docs/screenshots/render_terminal.py`](docs/screenshots/render_terminal.py); the page images are screenshots of the project page.
|
|
212
|
+
|
|
213
|
+
**Install and test.** The full suite passes from a clean checkout.
|
|
214
|
+
|
|
215
|
+

|
|
216
|
+
|
|
217
|
+
**End-to-end smoke run** (`configs/smoke.yaml`) and its report.
|
|
218
|
+
|
|
219
|
+

|
|
220
|
+
|
|
221
|
+
**The monitor demo** on NFCorpus: clean windows stay quiet, the partial upgrade and the missing normalization alarm, and one window after a harmless full model switch raises a false alarm.
|
|
222
|
+
|
|
223
|
+

|
|
224
|
+
|
|
225
|
+
**The replay on the project page.** Twenty clean windows, then twenty after half the SciFact index is re-embedded with bge-small. Every check catches it (19 or 20 of 20 windows), and the KS and PSI tests also alarm on 6 of the 20 clean windows. Red bars are alarms on harmful windows, amber bars alarms on harmless ones.
|
|
226
|
+
|
|
227
|
+

|
|
228
|
+
|
|
229
|
+
The same deployment after a finished upgrade, which improves retrieval. KS, PSI, the re-embedding check and the canaries alarm on all 20 windows after it; `qpp_max` stays quiet.
|
|
230
|
+
|
|
231
|
+

|
|
232
|
+
|
|
233
|
+
The results table on the page:
|
|
234
|
+
|
|
235
|
+

|
|
236
|
+
|
|
237
|
+
## Running it
|
|
238
|
+
|
|
239
|
+
**Setup** (Python 3.10 or newer; we've run it on 3.14 and 3.15)
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
git clone https://github.com/Srikarmk/Silent-RAG-Failures.git
|
|
243
|
+
cd Silent-RAG-Failures
|
|
244
|
+
python -m venv .venv && source .venv/bin/activate
|
|
245
|
+
pip install -e ".[dev]"
|
|
246
|
+
pytest
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
`pip install -e ".[dev]"` takes the newest releases. For the exact versions we tested with, install `requirements-lock.txt` first (`pip install -r requirements-lock.txt && pip install -e . --no-deps`). A fresh install a day newer than our dev environment (torch 2.15 vs 2.14, newer transformers, pandas and datasets) gave identical nDCG drops and p-values on `configs/dev.yaml`.
|
|
250
|
+
|
|
251
|
+
On Windows (PowerShell), activate with `.venv\Scripts\Activate.ps1` instead of `source .venv/bin/activate`. If PowerShell refuses to run the script, allow it for the current session first with `Set-ExecutionPolicy -Scope Process RemoteSigned`.
|
|
252
|
+
|
|
253
|
+
On a Mac, faiss and torch together segfault (exit 139, no error message) unless OpenMP runs one thread. `import silent_rag` sets `OMP_NUM_THREADS=1` and `KMP_DUPLICATE_LIB_OK=TRUE` for you on macOS, unless you've set them yourself. That also limits torch to one thread, so the first embedding of a corpus is slower than it could be; it's how every run so far was made. A script or notebook that imports faiss or torch *before* `silent_rag` still needs them set first.
|
|
254
|
+
|
|
255
|
+
**Run**
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
python -m silent_rag.run --list # registered failures and detectors
|
|
259
|
+
python -m silent_rag.run --config configs/smoke.yaml # end-to-end check, a few minutes on a laptop CPU, plus first-time downloads
|
|
260
|
+
python -m silent_rag.run --config configs/dev.yaml # development run, NFCorpus only
|
|
261
|
+
python -m silent_rag.run --config configs/final.yaml --final # held-out run, SciFact + FiQA
|
|
262
|
+
python -m silent_rag.run --config configs/final_scidocs.yaml --final # one extra domain; also arguana, cqadupstack_android, cqadupstack_programmers
|
|
263
|
+
python -m silent_rag.eval.report results/dev.parquet # the tables, as Markdown
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
`configs/dev.yaml` took 26 minutes from a fresh clone with empty caches (M5 Pro, CPU), downloads included. The report prints, for each `min_drop` (0, 0.02 and 0.06 by default, recomputed from the table): how often each condition is harmful, AUROC for every detector and failure with 95% seed CIs, and each detector's false alarms on clean windows and the negative controls, with the earliest detected severity, at a threshold set for 5% false alarms on clean windows. That threshold is set leave-one-seed-out, so each seed is scored against the other seeds' clean windows; the table gives the mean over seeds and the worst seed. `--out report.md` writes it to a file. CI runs `configs/smoke.yaml` and the report on every pull request, on a fresh Ubuntu machine; on a pull request a failure there (usually a Hub download) is a warning, on main it fails.
|
|
267
|
+
|
|
268
|
+
Datasets (`nfcorpus`, `scifact`, `fiqa`, `arguana`, `scidocs`, `cqadupstack_android`, `cqadupstack_programmers`) download from the Hugging Face Hub at pinned revisions. Corpus embeddings are cached under `cache/embeddings/` (or `$SILENT_RAG_CACHE/embeddings/`), keyed on the model, its revision, the settings that change the vectors and the corpus text itself, so only the first run of a setup embeds the corpus. The runner refuses every held-out set unless `--final` is passed.
|
|
269
|
+
|
|
270
|
+
**Output.** One parquet file, `results/<config name>.parquet` (or `--out`), with one row per dataset × failure × severity × trial × detector:
|
|
271
|
+
|
|
272
|
+
| Column | Meaning |
|
|
273
|
+
|---|---|
|
|
274
|
+
| `run_id` | hash of the config, so rows from different setups never mix |
|
|
275
|
+
| `dataset`, `model`, `model_revision` | what was run |
|
|
276
|
+
| `failure`, `severity`, `expected_harmful` | the condition; `clean` has severity 0, negative controls have `expected_harmful = False` |
|
|
277
|
+
| `seed`, `trial`, `window_size` | which query window was scored |
|
|
278
|
+
| `detector`, `score` | the detector's output, higher = more likely broken |
|
|
279
|
+
| `ndcg_drop`, `p_value`, `harmful` | ground truth: mean nDCG@k drop on the window, the one-sided paired bootstrap p-value, and `harmful = p_value < alpha and ndcg_drop >= min_drop` |
|
|
280
|
+
| `cost_s`, `cost_usd` | time per check, and API cost for the LLM judge |
|
|
281
|
+
|
|
282
|
+
**Config**
|
|
283
|
+
|
|
284
|
+
```yaml
|
|
285
|
+
datasets: [nfcorpus]
|
|
286
|
+
model: sentence-transformers/multi-qa-MiniLM-L6-cos-v1
|
|
287
|
+
retriever: {revision: <hub commit>} # any Retriever argument: normalize, query_prefix, max_seq_length...
|
|
288
|
+
failures: # at least one entry
|
|
289
|
+
F1_partial_upgrade_minilm: # label: the `failure` value in the results table
|
|
290
|
+
injector: F1_partial_upgrade # registered injector that runs
|
|
291
|
+
severities: [0.1, 0.5, 0.9] # fraction affected, in (0, 1]
|
|
292
|
+
alt_model: sentence-transformers/all-MiniLM-L6-v2 # other keys go to the constructor
|
|
293
|
+
alt_revision: 1110a243fdf4706b3f48f1d95db1a4f5529b4d41
|
|
294
|
+
# shorthand for an injector without params: F9_my_failure: [0.1, 0.5] (label = injector name)
|
|
295
|
+
detectors: [ks_top1, re_embed]
|
|
296
|
+
window_size: 100
|
|
297
|
+
trials: 20
|
|
298
|
+
seeds: [0, 1, 2] # repeats the whole run (windows, reference window, damage) under one run_id
|
|
299
|
+
# optional, with defaults: k: 10, alpha: 0.05, min_drop: 0.0
|
|
300
|
+
# score_depth: 100 also logs each query's top 100 scores as Observation.deep_scores (ground truth stays at k)
|
|
301
|
+
# seed: 0 instead of seeds runs once
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Labels must be unique (ignoring case and spaces), and can't be `clean` or another injector's registered name. Each label's params are checked against its injector's constructor before anything loads or is embedded.
|
|
305
|
+
|
|
306
|
+
Detectors that take parameters are listed as `{name: {param: value}}`, e.g. `- re_embed: {sample: 50, metric: l2}`. `re_embed` treats per-doc distances below a noise floor as 0 (`floor`, default 1e-5 for cosine and 5e-3 for l2), so a clean index scores exactly 0 and thresholds should be above 0. One setting per detector per run; use two runs to compare settings.
|
|
307
|
+
|
|
308
|
+
**Adding a failure.** Put a module in `src/silent_rag/inject/`, subclass `Injector` and register it. The `name` is what `injector:` refers to in the config. The results table records the config label instead.
|
|
309
|
+
|
|
310
|
+
```python
|
|
311
|
+
import dataclasses
|
|
312
|
+
from silent_rag.inject.base import Injector, register
|
|
313
|
+
|
|
314
|
+
@register
|
|
315
|
+
class MyFailure(Injector):
|
|
316
|
+
name = "F9_my_failure"
|
|
317
|
+
harmful = True # False for a negative control
|
|
318
|
+
|
|
319
|
+
def apply(self, state, severity, seed):
|
|
320
|
+
emb = state.doc_embeddings.copy() # never modify state in place
|
|
321
|
+
... # damage a `severity` fraction, deterministically from `seed`
|
|
322
|
+
return dataclasses.replace(state, doc_embeddings=emb)
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Config keys other than `injector` and `severities` are passed to the constructor. Don't give a default to anything that changes the damage, so every setting that matters is written in the config. For checks specific to your injector, override the classmethod `check_config(params, run_cfg)` and raise `ValueError`. It runs before any data loads, with the label's params and the clean `model` and `revision`, and the runner reports the error under the label.
|
|
326
|
+
|
|
327
|
+
Keep query positions fixed. If the failure changes `query_texts`, set `query_embeddings=None` so the runner re-embeds them with the clean model; if it changes how queries are encoded, edit `query_embeddings` yourself (`state.config` is descriptive, nothing reads it to re-encode). The index and query arrays are read-only during a run, so copy before changing them. With chunking, set `parent_ids` and keep `doc_ids`, `doc_texts` and `doc_embeddings` row-aligned.
|
|
328
|
+
|
|
329
|
+
For each dataset and seed, the runner makes one injector per failure and calls `attach(retriever, state)` on it once, before any `apply`. `state` is the clean, read-only `RetrievalState`, the same object `apply` later receives, so `attach` can read `state.doc_ids` and `state.doc_texts`. The instance is then reused for every severity and trial. Put expensive setup in `attach` (a second model's embeddings for the whole corpus, a re-chunked corpus), keep the result on `self`, and pick rows per trial in `apply`, rather than re-embedding inside every trial. Encode through `Retriever.embed_texts` so the vectors are cached on disk and later seeds reuse them.
|
|
330
|
+
|
|
331
|
+
**Adding a detector.** Same pattern in `src/silent_rag/detect/`:
|
|
332
|
+
|
|
333
|
+
```python
|
|
334
|
+
from silent_rag.detect.base import Detector, register
|
|
335
|
+
|
|
336
|
+
@register
|
|
337
|
+
class MyDetector(Detector):
|
|
338
|
+
name = "my_detector"
|
|
339
|
+
|
|
340
|
+
def fit(self, reference): # Observation from the clean system
|
|
341
|
+
self.ref = reference.topk_scores[:, 0].mean()
|
|
342
|
+
|
|
343
|
+
def score(self, window): # Observation that may be damaged; higher = more likely broken
|
|
344
|
+
return float(self.ref - window.topk_scores[:, 0].mean())
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
An `Observation` holds what a production system could log (query ids, texts and embeddings, top-k ids and scores, the index rows with their ids and texts, and with `score_depth` set, each query's deeper score list in `deep_scores`) and deliberately no qrels. Treat it as read-only. A detector that needs to re-embed overrides `attach(retriever)`, which gets the clean retriever. The runner makes a fresh detector for each dataset and seed and calls `attach` once, just before `fit()`. New modules in `inject/` and `detect/` are picked up automatically.
|
|
348
|
+
|
|
349
|
+
## Monitoring your own system
|
|
350
|
+
|
|
351
|
+
`silent-rag-monitor` runs the benchmark's cheap checks on your own retrieval logs. It needs no relevance labels, no model and no API key. All it reads is the similarity scores of each query's top 10 results.
|
|
352
|
+
|
|
353
|
+
**Try it first.** The demo builds logs from NFCorpus, breaks part of them on purpose, and prints what the monitor says next to what really happened to nDCG@10. It downloads about 180 MB the first time.
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
silent-rag-monitor demo
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
On our machine both clean windows stayed quiet, all four harmful windows alarmed (two with half the index on another model, two with 10% of documents indexed without normalization), and one of the two windows after a harmless full model switch raised a false alarm.
|
|
360
|
+
|
|
361
|
+
**On your logs.** Write one JSON line per query, in the order they arrived:
|
|
362
|
+
|
|
363
|
+
```json
|
|
364
|
+
{"query_id": "q1", "scores": [0.71, 0.69, 0.66, 0.65, 0.64, 0.62, 0.61, 0.61, 0.60, 0.58]}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Scores are similarities, sorted high to low, at least 10 per query. An optional `time` field labels the windows, and other fields are ignored. Parquet or CSV with `query_id` and `scores` columns work too. If your vector store returns distances, add `--distances`.
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
silent-rag-monitor fit --log last_week.jsonl --out baseline.json # from a period you trust
|
|
371
|
+
silent-rag-monitor check --log today.jsonl --baseline baseline.json # exits 1 if anything alarms
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
`fit` uses half the baseline as the reference and the other half to set each alarm threshold, so that 5% of clean windows of 100 queries alarm. Give it at least 1,000 queries. `check` cuts the new log into consecutive windows of 100 and reports which checks alarm, how far the mean top-1 score moved, and what the benchmark saw behind that pattern. `--json` gives the same as JSON, and the exit code (0 quiet, 1 alarm, 2 bad input) lets you run it from cron or CI.
|
|
375
|
+
|
|
376
|
+
The default checks are `qpp_max`, `ks_top1` and `psi_mean10`. `qpp_max` caught partial model upgrades best (AUROC 0.91 to 0.97 on six held-out sets) but only sees scores falling. The other two caught every harmful window of missing normalization, which raises scores. `--checks` picks others, and `silent-rag-monitor checks` lists them.
|
|
377
|
+
|
|
378
|
+
An alarm means the scores look different from your baseline, not that answers got worse. A full, intended model switch and a change in what users ask set the checks off too. Treat an alarm as the cue to look at a sample of queries or run a quality check, and refit the baseline after any intended change to the model, the index or k.
|
|
379
|
+
|
|
380
|
+
From Python:
|
|
381
|
+
|
|
382
|
+
```python
|
|
383
|
+
from silent_rag.monitor import Monitor, make_log
|
|
384
|
+
|
|
385
|
+
monitor = Monitor.fit(make_log(baseline_scores)) # array of shape (n_queries, 10)
|
|
386
|
+
for window in monitor.check(make_log(today_scores)):
|
|
387
|
+
print(window.alarm, window.reading())
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
**Install.** The monitor only needs numpy, pandas, SciPy and pyarrow, so a plain install is small:
|
|
391
|
+
|
|
392
|
+
```bash
|
|
393
|
+
pip install "silent-rag @ git+https://github.com/Srikarmk/Silent-RAG-Failures.git"
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
`demo` uses the benchmark's pipeline, so it needs the `bench` extra (PyTorch, sentence-transformers, FAISS and the datasets library): `pip install "silent-rag[bench] @ git+https://github.com/Srikarmk/Silent-RAG-Failures.git"`.
|
|
397
|
+
|
|
398
|
+
## Repository
|
|
399
|
+
|
|
400
|
+
```text
|
|
401
|
+
src/silent_rag/
|
|
402
|
+
types.py Dataset, RetrievalState, Observation (no labels)
|
|
403
|
+
data.py BEIR loaders, pinned revisions
|
|
404
|
+
pipeline.py embed, cache, index, search
|
|
405
|
+
inject/ failure injectors (F1, F2, F3, F5) and the harmless controls (H_*)
|
|
406
|
+
detect/ label-free detectors
|
|
407
|
+
eval/ ground truth (nDCG drop, bootstrap), window-size analysis, results table
|
|
408
|
+
run.py experiment runner
|
|
409
|
+
monitor.py silent-rag-monitor: the cheap checks on your own logs
|
|
410
|
+
monitor_demo.py its NFCorpus demo
|
|
411
|
+
configs/ dev.yaml (NFCorpus), final.yaml (held-out), final_<dataset>.yaml (extra domains)
|
|
412
|
+
experiments/ one-off analyses (baseline CIs, window size, truncation)
|
|
413
|
+
notebooks/ exploration only
|
|
414
|
+
site/ project page (Next.js static export), deployed to GitHub Pages on push to main
|
|
415
|
+
docs/ monitoring guide, screenshots
|
|
416
|
+
tests/
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for how we're working.
|
|
420
|
+
|
|
421
|
+
**Stack:** sentence-transformers, FAISS, scikit-learn, SciPy, DuckDB, matplotlib
|
|
422
|
+
|
|
423
|
+
## Team
|
|
424
|
+
|
|
425
|
+
Kameswara Sai Srikar Manda, Alekhya Bulusu, Shane Hussey, Ying-Jen Chiang
|
|
426
|
+
|
|
427
|
+
DS5500 Capstone, Fall 2026, Northeastern University
|
|
428
|
+
|
|
429
|
+
## References
|
|
430
|
+
|
|
431
|
+
1. Lewis et al. [Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks](https://arxiv.org/abs/2005.11401). 2020.
|
|
432
|
+
2. Thakur et al. [BEIR: A Heterogeneous Benchmark for Zero-shot Evaluation of Information Retrieval Models](https://arxiv.org/abs/2104.08663). 2021.
|
|
433
|
+
3. Chen et al. [M3-Embedding](https://arxiv.org/abs/2402.03216) (source of MLDR). 2024.
|
|
434
|
+
4. Ouyang et al. [HoH: A Dynamic Benchmark for Evaluating the Impact of Outdated Information on RAG](https://arxiv.org/abs/2503.04800). 2025.
|
|
435
|
+
5. Zheng et al. [Revisiting RAG Retrievers: An Information Theoretic Benchmark](https://arxiv.org/abs/2602.21553). 2026.
|
|
436
|
+
6. Garani. [A Systematic Taxonomy of Failure Modes in Retrieval-Augmented Generation Systems](https://aclanthology.org/2026.trustnlp-main.27/). TrustNLP 2026.
|
|
437
|
+
7. Reimers and Gurevych. [Sentence-BERT](https://arxiv.org/abs/1908.10084). EMNLP 2019.
|