GitHunt
DI

Dinesh-Sharma2004/Medical_chatbot

This project implements a Retrieval-Augmented Generation (RAG) chatbot that can answer medical questions—especially focused on Anatomy and Forensics—based on uploaded PDF documents. It uses Hugging Face models for embedding and language generation, FAISS for vector storage, and a simple Streamlit frontend for an interactive chat interface.

Medical Chatbot (FastAPI + React + RAG)

Medical Chatbot is a full-stack app that lets users upload PDF documents, build a FAISS vector index, and ask medical questions with Groq-powered responses.

Stack

  • Backend: FastAPI, LangChain, FAISS
  • Frontend: React + Vite
  • Embeddings: FastEmbed (BAAI/bge-small-en-v1.5)
  • LLM: Groq API
  • Deployment: Railway (single Docker service)

Project Structure

  • backend/ FastAPI app, ingestion, RAG chain
  • frontend/ React app
  • Dockerfile builds frontend and serves with backend
  • docker-compose.yml local container orchestration

Local Run

  1. Create backend environment file at backend/.env.
  2. Install backend dependencies:
pip install -r backend/requirements.txt
  1. Install frontend dependencies:
cd frontend
npm install
npm run build
cd ..
  1. Start API:
uvicorn backend.main:app --host 0.0.0.0 --port 8000
  1. Open:
  • http://localhost:8000/
  • Health: http://localhost:8000/api/health

Docker

docker build -t medical-chatbot .
docker run --env-file backend/.env -p 8000:8000 medical-chatbot

Railway Deployment

  1. Login and initialize:
npx @railway/cli login
npx @railway/cli init --name Medical_chatbot
  1. Create/link service and deploy:
npx @railway/cli service link backend
npx @railway/cli up --service backend
  1. Set required variables:
  • GROQ_API_KEYS (required, comma-separated keys supported)
  • GROQ_MODEL (default: llama-3.1-8b-instant)
  • DB_FAISS_BASE (recommended with volume: /data/vectorstore)
  • EMBED_MODEL (default: BAAI/bge-small-en-v1.5)
  • EMBED_BATCH_SIZE (recommended: 4 on small Railway plans)
  • RAG_MAX_PDF_PAGES (recommended: 80 on small Railway plans)
  1. Add persistent volume for vectorstore:
npx @railway/cli volume add

Mount path:

  • /data

Then set:

npx @railway/cli variable set --service backend --environment production DB_FAISS_BASE=/data/vectorstore

Redeploy:

npx @railway/cli up --service backend

API Endpoints

  • GET /api/health
  • POST /api/upload
  • GET /api/upload/status/{job_id}
  • POST /api/ask
  • POST /api/ask/stream
  • GET /api/source/{doc_id}

Troubleshooting

  • {"detail":"Not Found"} for /app/health:

    • Use /api/health instead.
  • RAG not ready:

    • Upload at least one PDF first.
    • Ensure vectorstore exists in DB_FAISS_BASE.
  • Frontend loads but blank/errors:

    • Ensure static assets are served from /assets.
    • Hard refresh browser after deploy.
  • Railway OOM during ingest:

    • Reduce EMBED_BATCH_SIZE (e.g. 4).
    • Reduce RAG_MAX_PDF_PAGES (e.g. 80).
    • Upload smaller PDFs first.

Security

  • Never commit real API keys.
  • Rotate keys immediately if leaked.

Languages

JavaScript60.7%Python35.9%HTML1.4%CSS1.4%Dockerfile0.5%Shell0.1%

Contributors

Created March 19, 2025
Updated March 2, 2026