How I built a RAG search engine for Nepal's legal documents
Keyword search fails on legal text because the same concept appears under many phrasings. When I built Kanun AI, a legal-document assistant for Nepal, I needed section-level answers with citations a researcher can actually check, not a list of whole documents.
The pipeline
Documents are parsed with PyMuPDF and pypdf, chunked at section level with metadata, embedded with sentence-transformers, and indexed in Qdrant. At query time, dense vector search is combined with classical TF-IDF, then a reranker reorders the top results for precision.
FastAPI exposes search, summary and evaluation endpoints with OpenAPI docs. The React frontend wraps it in a chat UI with document upload, a file browser and snippet panels.
The part most tutorials skip
Measuring retrieval quality. The service has evaluation endpoints computing MRR and MAP, so retrieval quality is measured instead of assumed. If you change the chunking, the embedding model or the reranker, you can see whether retrieval actually got better.
Corpus coverage is deliberately narrow today: English translations of Nepali Acts. The pipeline is built to widen it.
Stack
- Python and FastAPI for the retrieval service
- Qdrant as the vector store
- sentence-transformers for embeddings
- PyMuPDF and pypdf for parsing
- Docker for deployment
- React for the frontend