Skip to content
~/rafael-ferreira

MedRAG

A RAG study copilot: from lecture PDF to a sourced answer, on your phone

  • Flutter
  • Dart
  • SQLite
  • BM25
  • Claude API
  • Python
  • markitdown
  • OCR
Cover of the MedRAG project

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.

Architecture: ingestion and curation on the computer; SQLite, BM25, prompt assembly and the Claude API on the phone

The four stages of RAG

  • Ingestion: markitdown converts 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.

Teaching figure from the app comparing reactive follicular hyperplasia and follicular lymphoma

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

Gallery

Other projects

Cover of the Markmedi project
markmedi.com · private ★ featured

Markmedi

My main project: scheduling, medical records, telemedicine, finance, CRM and marketing for clinics, in a modular Laravel and Vue monolith with queues, real-time updates and per-clinic encryption.

  • Laravel
  • Vue 3
  • Inertia.js
  • TypeScript
  • Tailwind CSS
Cover of the B2B platform for ticket and course sales project
b2b-ticketing-and-courses-platform · private ★ featured

B2B platform for ticket and course sales

A B2B platform that sells tickets and courses, validates event entry with signed QR codes and offline check-in, and lets companies buy licenses and track each employee's progress.

  • Laravel
  • Vue 3
  • Inertia.js
  • TypeScript
  • Tailwind CSS