Level 4 · advanced · ~35 h
Build a RAG system with retrieval evaluation
Implement a retrieval-augmented generation system over a Wikipedia subset with hybrid BM25 and dense retrieval, reranking, and a full retrieval-plus-generation evaluation using NDCG, recall and answer correctness.
Prerequisites
Problem statement
- 01Implement a retrieval-augmented generation system over a Wikipedia subset with hybrid BM25 and dense retrieval, reranking, and a full retrieval-plus-generation evaluation using NDCG, recall and answer correctness.
Real-world motivation
- 01RAG failures are often retrieval failures; evaluating only final answers hides where the pipeline broke.
Learning objectives
- 01Build hybrid retrieval with reranking
- 02Implement retrieval metrics from scratch
- 03Attribute answer errors to retrieval or generation
Technical architecture
- 01BM25 and dense embedding indices
- 02reciprocal-rank fusion
- 03cross-encoder reranker and answer synthesis
Mathematical foundations
- 01BM25 score $\sum_i \mathrm{IDF}(q_i)\frac{f(q_i,d)(k_1+1)}{f(q_i,d)+k_1(1-b+b|d|/avgdl)}$
- 02NDCG and Recall@k for retrieval
Dataset and sources
- 01SQuAD open-domain setting
- 02Wikipedia passage subset
- 03BEIR-style query set
Step-by-step tasks
- 01Chunk and index the corpus with both retrievers
- 02Implement fusion and reranking
- 03Implement NDCG, MAP and Recall@k and verify against pytrec_eval
- 04Build the generation prompt with retrieved passages
- 05Evaluate retrieval and generation separately
- 06Ablate top-k and reranker usage
Implementation requirements
- 01Use rank_bm25 and sentence-transformers
- 02Cache embeddings
- 03Log retrieved passages for every answer
Testing requirements
- 01Check metrics against pytrec_eval
- 02Verify no answer passage leaks into query text
Evaluation metrics
- 01NDCG@10
- 02Recall@20
- 03answer F1
- 04faithfulness to retrieved passages
Expected outputs
- 01RAG pipeline code
- 02retrieval and generation eval tables
- 03error attribution analysis
- 04demo interface
Common failure modes
- 01chunking splits the answer passage
- 02retriever returns topically similar but wrong passages
- 03generator ignores retrieved evidence
Stretch goals
- 01add query rewriting
- 02implement self-reflection on low-confidence retrievals
Research extensions
- 01derive the effect of retrieval recall on answer accuracy
- 02study reranker cost-quality tradeoffs
GitHub submission requirements
- 01Pipeline code and indices
- 02Metric implementation with reference checks
- 03Evaluation tables
- 04Error attribution report
Completion rubric
- 01retrieval metrics correct
- 02hybrid retrieval implemented
- 03error attribution performed
- 04ablations reported
- 05no test leakage
Submit when every rubric item is satisfied and your repository contains runnable code plus a reproduction command.