RAG Custom Engine
~20% precision gain over dense baselines
A complete Retrieval-Augmented Generation pipeline built entirely from scratch — no LangChain, no vector database. Custom HNSW vector store, Okapi BM25 and Reciprocal Rank Fusion, a 3-stage Self-RAG gate (retrieval decision, relevance grading, hallucination check) and contextual compression, all in pure Python. ~20% precision gain over dense-vector baselines.
Problem
Understand retrieval-augmented generation end to end by building it without a framework or a vector database.
Approach
- Custom HNSW vector store and Okapi BM25 keyword index in pure Python
- Hybrid retrieval with Reciprocal Rank Fusion
- 3-stage Self-RAG gate: retrieval decision, relevance grading and hallucination check
- Contextual compression and a dual-layer memory system
- GPT-4o-mini for generation
Screens








Results
- ~20% precision gain over dense-vector baselines
Stack
- Python
- HNSW
- BM25
- Self-RAG
- FastAPI
- GPT-4o-mini
By Muzammil Nawaz Khan, AI Engineer.