MedRAG
A RAG study copilot: from lecture PDF to a sourced answer, on your phone
- Flutter
- Dart
- SQLite
- BM25
- Claude API
- Python
- markitdown
- OCR
MedRAG came out of a very concrete need. My girlfriend had a few hours left before her Pathology II exam, and the material was scattered across two PDFs: a summary of the lectures and a 119-page compilation of past exams, with photos, answer keys from different sources and handwritten notes. I took the opportunity to help her and to build, hands-on, an end-to-end RAG (Retrieval-Augmented Generation) system, with no framework hiding the decisions.
I wrote an article walking through each stage: RAG in practice: from lecture PDF to a sourced answer.

The four stages of RAG
- Ingestion:
markitdownconverts the PDF text to Markdown, in two aligned passes to mark the real page numbers, and OCR with a multimodal model reads the exam photos, separating printed text from handwriting. - Indexing: 325 chunks of 700 to 1,300 characters, split along the structure of the text (before headings, at sentence boundaries, with overlap) and with a human-readable source for citation.
- Retrieval: BM25 on the phone itself, with no network, tokenization tuned for medical Portuguese and the content of the open screen added to the query with a lower weight.
- Generation: a prompt with the screen context, retrieved passages and the question in XML tags, a cached system prompt, SSE streaming and answers that cite their sources.
The app
Around the copilot, the app grew into a complete, offline study platform: 18 short chapters with highlights and notes, original teaching figures, 141 questions from 16 past exams with grading and a performance map, 259 flashcards with spaced repetition and a study plan. Everything the user produces stays in the device's SQLite database. No API key is bundled: each person uses their own, stored only on the device.

The medical content comes from the course material and is meant for exam study. It is not clinical guidance.
// screenshots