What it is
A deterministic linter for RAG corpora and retrievers. One call returns one report. chaffer inspects the corpus offline: no embedding, no LLM calls, no vector-DB hits. Sub-second on 50,000 chunks, pure Python stdlib.
Why it's needed
The bugs that wreck production RAG are corpus-hygiene bugs that pass code review, not retriever bugs. The same boilerplate header is copy-pasted into every doc, so top-5 retrieval returns four duplicates. A chunker emits oversized chunks and the embed model silently truncates the tail. Eval queries were written by reading the source docs, so reported recall is partly a string-match exercise. An empty chunk slips in and pollutes top-k with a zero-vector. The configured embed model produces 1536-dim vectors but the index expects 768.
What it does
chaffer flags exact and near-duplicate chunks, oversized chunks for the named embed model, embed-model vs index dim mismatch, eval queries leaking verbatim into the corpus, empty/whitespace chunks, PII in chunks, and BM25-vs-semantic top-k disagreement. A second mode, check_retriever, audits actual retrieval behaviour against eval queries. Every finding lists chunk indices, severity, and a fix - and report.ok() returns False when anything critical fires.
How to use it
Install it:
pip install chafferThen call it:
import chaffer
report = chaffer.check_corpus(
chunks,
embed_model_name="text-embedding-3-small",
eval_queries=["What is X?", "How does Y work?"],
)
print(report)
if not report.ok():
raise SystemExit("Fix the critical corpus issues before indexing.")Links
- PyPI: pypi.org/project/chaffer/
- GitHub: github.com/asmitdash/chaffer