Skip to content

Healthcare AI / RAG / Full Stack

Medical Chatbot

A retrieval-augmented medical chatbot built as a learning project. Rather than answering from whatever the model happens to remember, it retrieves passages from a curated set of medical articles and answers from those — with authentication and saved conversations around it.

Next.jsNextAuthPythonFlaskMongoDBOpenAIRAG
Medical Chatbot — schematic overview diagram
Schematic overview — a diagram, not a product screenshot

NoteThis is an educational project built to practise retrieval-augmented generation. It is not a medical device, it does not provide diagnosis, and it is not a substitute for advice from a qualified clinician.

01Overview

What it is.

The project was my way into RAG on a domain where being wrong matters. Medical text is a good stress test: the vocabulary is precise, and a plausible-sounding but unsourced answer is worse than no answer at all.

The knowledge base is a curated article set that is chunked and embedded ahead of time. At query time the chatbot retrieves the closest passages and answers strictly from them, so what it says can be traced back to a source.

02 — The problem

General-purpose chat models answer medical questions fluently whether or not they actually know the answer, and there is no way for the reader to see where a claim came from.

03 — The approach

Constrain the model to a fixed, curated corpus. Retrieve first, generate second, and keep the retrieved passage visible so the answer is checkable rather than taken on trust.

04Key features

What it actually does.

Curated knowledge base

A fixed set of medical articles is pre-processed and embedded, so the retrieval scope is known and reviewable.

Retrieval-grounded answers

Every response is generated from retrieved passages rather than from unconstrained model memory.

Authenticated sessions

NextAuth handles sign-in so each user's conversations stay private to them.

Persistent conversations

Chat threads are stored in MongoDB and can be reopened and continued.

Scope guardrails

Questions outside the knowledge base return a clear 'not covered' response instead of an invented answer.

05Architecture

How the pieces fit together.

Medical Chatbot — system architecture diagram
Knowledge base → retrieval → grounded response. Diagram, not a screenshot.
  1. 01

    Next.js client

    Chat interface and NextAuth-backed session management.

  2. 02

    Flask service

    Python service handling embedding, retrieval and the OpenAI call.

  3. 03

    Knowledge base

    Medical articles chunked and embedded ahead of time into a vector index.

  4. 04

    MongoDB

    Users and conversation history.

06Technology

The stack.

Chosen for the problem, not for the resume.

Frontend
Next.jsReactNextAuth
Backend
FlaskPythonREST APIs
AI
OpenAIRAGEmbeddings
Data
MongoDB
07AI & data workflow

From input to output.

The sequence a single request travels through.

  1. 01

    Curate

    Source articles are selected and cleaned before anything is indexed.

  2. 02

    Embed

    Chunks are embedded once, ahead of time, so query latency stays low.

  3. 03

    Retrieve

    The question is embedded and matched against the index by semantic similarity.

  4. 04

    Answer

    The model is prompted to answer only from the retrieved passages, and to say so when they do not cover the question.

08What I learned

The part that stuck.

Student portfolio, so this section is the point — here is what this build actually taught me.

  • 01

    Saying 'I don't have that in my sources' is a feature. Getting the model to do that reliably took more prompt iteration than getting it to answer well.

  • 02

    Pre-computing embeddings for a fixed corpus is dramatically faster at query time than embedding on demand, and it makes the retrieval scope auditable.

  • 03

    Working in a domain with real-world consequences changed how I write disclaimers and scope limits — they belong in the product, not just the README.

Next project

AI-Powered Project Management System

A project and task manager where an admin can assign work and then just ask a chatbot who is doing what.

Work together

Have a project idea?

I'm open to freelance projects, collaborations, internships, and opportunities where I can contribute while continuing to grow.

Usually replies within a day · Lahore, Pakistan · PKT (UTC+5)

Chat on WhatsApp