Evaluation-Driven Local RAG
Retrieval-augmented generation over 5 ML books, built evaluation-first: a fixed, hand-labelled query set decides every change. Embeddings, retrieval, reranking, generation and the judge all run locally on one laptop with a 6 GB GPU. No cloud calls at runtime or in evaluation.
- Reading
- 0.942recall@5n = 43 answerable queries from a 48-query gold set
- Limitation
- Only 5 paraphrase and 2 multi-hop queries; the judge is the same model as the generator; 1 of 5 unanswerable questions is still answered.
Problem
Answer questions over 5 ML books on one laptop with a 6 GB GPU and no cloud calls, and know how often the answers are right.
Approach
Evaluation came first: a hand-labelled gold set of 48 queries, 43 answerable and 5 unanswerable, with retrieval scored by recall@k, MRR and NDCG, and answers judged locally for faithfulness, relevancy and context. Three retrieval configurations ran against the same 1,721 chunks. 41 tests. No LangChain.
Result
Hybrid + rerank ships with recall@5 of 0.942 against 0.884 for dense, and refuses 4 of 5 unanswerable questions against 2 of 5. Context recall rose from 0.556 to 0.716. Dense still ranks best at top-1: R@1 of 0.616 against 0.570.
Limitation
Only 5 paraphrase and 2 multi-hop queries; the judge is the same model as the generator; 1 of 5 unanswerable questions is still answered.
Finding
On the first 25 queries the reranker seemed to win every metric. At 48 queries its top-1 lead vanished. Dense is the best top-1 ranker; hybrid + rerank wins recall@5, which is what feeds the generator.
| Configuration | R@1 | R@3 | R@5 | R@10 | MRR | NDCG@10 |
|---|---|---|---|---|---|---|
| Dense | 0.616 | 0.860 | 0.884 | 0.930 | 0.753 | 0.799 |
| Hybrid | 0.407 | 0.791 | 0.860 | 0.919 | 0.620 | 0.687 |
| Hybrid + rerank (shipped) | 0.570 | 0.895 | 0.942 | 0.954 | 0.729 | 0.783 |
| Configuration | Faithfulness | Relevancy | Context precision | Context recall | Refusals |
|---|---|---|---|---|---|
| Dense | 0.665 | 0.874 | 0.686 | 0.556 | 2/5 |
| Hybrid + rerank (shipped) | 0.670 | 0.926 | 0.754 | 0.716 | 4/5 |
Specification
- Corpus
- 5 ML books, 1,721 chunks after 24,286 repeated header and footer lines were stripped
- Gold set
- 48 queries: 36 factoid, 5 paraphrase, 2 multi-hop, 5 unanswerable
- Pipeline
- Token-aware recursive chunker (about 900 tokens, 15% overlap); bge-m3 into pgvector with an HNSW cosine index; dense top-50 and BM25 top-50 fused by RRF (k = 60); cross-encoder rerank to 5; answers cite chunk IDs or refuse
- Evaluation
- Retrieval: recall@k, MRR, NDCG@10. Generation: faithfulness, answer relevancy, context precision and context recall, judged by qwen2.5:7b at temperature 0
- Tests
- 41; ruff and mypy clean
- Hardware
- One laptop, 6 GB GPU, no cloud calls
- Stack
- Python 3.12, PostgreSQL 17 + pgvector, bge-m3 embeddings, bm25s, bge-reranker-v2-m3, qwen2.5:7b via Ollama, FastAPI, React. No LangChain.