RAG from Scratch
- Python
- NumPy
- Gemini
- Question
- Can I build every stage of a RAG pipeline by hand, and measure it?
- Setup
- Chunking, embeddings, cosine retrieval, LLM reranking and a hit@k harness, all written by hand.
- Result
- The reranker was silently doing nothing. Fixing its prompt contract raised hit@1 from 13/17 to 17/17.
- Chunk
- Embed
- Cosine top 5
- LLM rerank
- hit@k
17 questions over 6 chunks: a method check, not a benchmark.
13 → 17/17hit@1 after finding a silent reranker bug
A small set: 17 questions over 6 chunks.
Before fix13/17
After fix17/17
- No framework. Lists, dicts and NumPy, so every intermediate state can be inspected.
- Embedding calls kept apart from the similarity maths, so ranking is testable without the API.
- The metric named honestly: hit@k, not recall@k, since each question has one answer phrase.