verifiable-rag
Document-grounded Q&A with sentence-level citations, NLI verification, and calibrated refusal.
Status: pre-alpha · v0.5 launch sprint · interfaces are still subject to change
📚 Full documentation at firish.github.io/rag-rack — quickstart, concept guides, how-to recipes, API reference, benchmark reports.
What this is
A Python library for building RAG pipelines that:
- Produce sentence-level citations — every generated sentence traces back to exact source spans
(doc_id, page, char_start, char_end). - Verify every claim via NLI against its cited span before returning it.
- Refuse when uncertain — calibrated abstention with a user-tunable strictness slider, not a "say I don't know" prompt.
- Are fully auditable — inspect retrieval scores, reranker decisions, per-claim NLI results, and a self-contained HTML report per query.
One benchmark result that drives the design: on RAGTruth (the canonical 2,700-example RAG hallucination benchmark), a dual NLI ensemble of two small open-source models (HHEM-2.1-open + MiniCheck-Flan-T5-Large) matches Claude Sonnet 4.6 as a judge — AUROC 0.844 vs 0.846 — at ~250× lower per-call cost. Full result in benchmarks/PUBLISHED_ragtruth.md.
Quickstart
The bundled demo document ships with the package. No setup required beyond an LLM API key:
import verifiable_rag
from verifiable_rag.demo import sample_paper_path
answer = verifiable_rag.ask(
"What is the mechanism of action of penicillin?",
docs=sample_paper_path(),
)
print(answer.text)
export ANTHROPIC_API_KEY=...
python -c "import verifiable_rag; from verifiable_rag.demo import sample_paper_path; \
print(verifiable_rag.ask('Who discovered penicillin?', docs=sample_paper_path()).text)"
For an actual production setup, point docs= at your own PDFs and pick a preset:
import verifiable_rag
answer = verifiable_rag.ask(
"What did the authors find?",
docs=["paper1.pdf", "paper2.pdf"],
preset="hybrid_balanced", # RECOMMENDED — Cohere + Dual NLI + Haiku
output_html="audit.html", # optional — write the HTML audit report
)
print(answer.text)
# Programmatic access to the audit trail:
for sentence in answer.unsupported_sentences: # sentences the verifier flagged
print(f"⚠ unsupported: {sentence.text}")
# Or emit a structured audit dump for logging / metrics:
metrics_client.emit(answer.audit_trail())
See examples/ for runnable demos covering the headline UX patterns. The full quickstart walks through each step in detail.
Presets
Five named presets cover most use cases. Switch via preset="..." or call the factories directly:
| Preset | Components | Required keys | When to use |
|---|---|---|---|
local_minimal |
BGE + PyMuPDF + Haiku, no verifier | ANTHROPIC_API_KEY |
Hobbyist / quickest start |
local_verified |
+ BGE rerank + HHEM NLI | ANTHROPIC_API_KEY |
Local with verification |
hybrid_balanced |
Docling + Cohere + Dual NLI + constrained Haiku | ANTHROPIC_API_KEY + COHERE_API_KEY |
Default — the published baseline |
hybrid_strict |
Same as balanced, refuse below faithfulness 0.7 | same | Higher-trust use cases |
hybrid_paranoid |
Sonnet generator, refuse below faithfulness 0.9 | same | Compliance / high-trust |
For mix-and-match outside the presets, use verifiable_rag.build_pipeline(...) or load a YAML config (see examples/pipeline.yaml, Pipeline.from_yaml(), and the YAML config guide).
Architecture
PDF/DOCX → Parser → Document model → Chunker → Indexer
↓
Answer ← Abstention ← Verifier ← Generator ← Retriever + Reranker
Every step preserves character-level spans. Every generated sentence carries (supporting_sentence_ids, confidence) linked to exact source locations. Citation granularity is decoupled from chunk granularity by design.
Audit trail
Every Answer exposes its full audit trail:
answer = verifiable_rag.ask(question, docs=...)
answer.text # final answer string
answer.sentences # list of CitedSentence with supporting_sentence_ids
answer.verification_results # per-sentence NLI checks
answer.retrieved_chunks # the reranked passages the generator saw
# Convenience accessors:
answer.supported_sentences # list[CitedSentence] (passed verification)
answer.unsupported_sentences # list[CitedSentence] (verifier flagged)
answer.verification_for(idx) # VerificationResult | None for a sentence index
answer.cited_sentence_ids # frozenset of all source IDs cited
answer.min_nli_score # worst-case sentence — the bottleneck
answer.audit_trail() # JSON-serializable dict for logging / metrics
# Or render the full audit as a self-contained HTML page:
answer.to_html() # returns HTML string
# or pass output_html="report.html" to verifiable_rag.ask()
The HTML report includes the query, the answer with per-sentence verification color coding, the faithfulness components, per-sentence NLI scores, and every reranked passage with its retrieval score — citations are anchored links into the passage list.
Installation
pip install verifiable-rag # core, no heavy deps
pip install "verifiable-rag[docling,bge,lancedb]" # parser + embedder + index
pip install "verifiable-rag[hhem,minicheck]" # NLI verifiers (adds torch + transformers)
pip install "verifiable-rag[litellm]" # LLM-judge verifier
pip install "verifiable-rag[yaml]" # YAML config loader
pip install "verifiable-rag[all]" # everything
First-run model downloads
Verifier model weights are not bundled in the wheel — they're downloaded lazily from HuggingFace Hub on first use and cached forever in ~/.cache/huggingface/hub/.
| Verifier | Model | Size |
|---|---|---|
HHEMVerifier |
vectara/hallucination_evaluation_model |
~600 MB |
MiniCheckVerifier |
lytang/MiniCheck-Flan-T5-Large |
~770 MB |
LLMJudgeVerifier |
(hosted API, no local model) | 0 |
Published benchmark results
| Benchmark | Headline | Report | Blog post |
|---|---|---|---|
| ALCE (Princeton citation quality) | Constrained decoding beats prompted by +4–7 F1 under dual-LLM-judge cross-validation | report | post |
| RAGTruth (hallucination detection) | Dual NLI ensemble = Sonnet judge at 1/250× the cost (AUROC 0.844 vs 0.846) | report | post |
| LitQA2 (biomedical scientific Q&A) | Constrained decoding lifts MC; contextual retrieval is a null result on saturated retrieval | report | post |
Roadmap
| Phase | Milestone | Status |
|---|---|---|
| 0–1 | Repo skeleton, data model, baseline pipeline | ✅ done |
| 2 | Eval harness + BENCHMARKS.md | ✅ done |
| 3 | Sentence-level citations (prompted / constrained / SAFE) | ✅ done |
| 4 | Faithfulness verification + calibrated refusal (v0.4) | ✅ done |
| 5 | Hardening, mkdocs docs, Gradio demo on HF Spaces (v0.5) | in progress |
| 6 | Launch — PyPI release + Show HN | pending |
Contributing
See CLAUDE.md for architecture decisions, hard rules, and contribution conventions. Methodology critiques on the published benchmarks are especially welcome — eval rigor is the whole moat, and the only way to find the holes is to invite people to look for them.
License
MIT
Metadata
Release files for verifiable-rag 0.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| verifiable_rag-0.5.2.tar.gz | 149.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| verifiable_rag-0.5.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 329.9 kB
Release files / verifiable_rag-0.5.2.tar.gz
| Download URL | verifiable_rag-0.5.2.tar.gz |
|---|---|
| Size | 149.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29cdaad18ff1aa361bbf439c38a751dd03ae120f46fcc22d23543d2a7bdaedda
|
|
BLAKE2b-256 checksum How to use checksums |
46702e7ea0a78b88345e74d97382f913c1d58999951962ac7e80bdcd66c28344
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 31, 2026.
Transparency logRelease files / verifiable_rag-0.5.2-py3-none-any.whl
| Download URL | verifiable_rag-0.5.2-py3-none-any.whl |
|---|---|
| Size | 180.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2575a7a48622ddb6fba28c08fbdcd953c010559d03a67bf118eaeabf4bc42f28
|
|
BLAKE2b-256 checksum How to use checksums |
ed491a9b6208386b3c0869658df6286831dc6528f0c6d1987068fd4edb5c4f6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 31, 2026.
Transparency logSecurity for verifiable-rag 0.5.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for verifiable_rag-0.5.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 31, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.