Ask questions about a technical PDF and get answers with page numbers.
I got the idea while using LLMs to pull parameters out of the RISC-V Privileged Spec. Plain embedding search kept missing exact names like stvec or MTVEC_MODE, because to an embedding model those are basically noise. So DocRAG mixes keyword search (BM25) with vector search and shows you the chunks it picked and their scores.
- PyMuPDF pulls the text out page by page.
- Each page gets cut into 900 character chunks with 150 characters of overlap. Chunks never cross pages, so every answer can point to a page.
- Chunks are embedded locally with
all-MiniLM-L6-v2and stored in Chroma. A BM25 index is built over the same chunks. - For a question, both scores get scaled to 0..1 and mixed:
0.6 * vector + 0.4 * bm25. They're on totally different scales otherwise. - The top 5 chunks go to Gemini 3.5 Flash, which answers only from them and cites pages.
pip install -r requirements.txt
export GEMINI_API_KEY=your_key
streamlit run app.pyUpload a PDF, hit index, ask away. Search works without a key, you just won't get the written answer.
pip install pytest
pytestThey build a small RISC-V PDF on the fly, so no key needed.
- rerank the top chunks with a cross-encoder
- OCR for scanned PDFs
- a small labeled question set to measure recall@k