Skip to content

🩺 RAGnosis β€” An AI-powered clinical reasoning assistant that retrieves real diagnostic notes (from MIMIC-IV-Ext-DiReCT) and generates explainable medical insights using Mistral-7B & FAISS, wrapped in a clean Gradio UI. ⚑ GPU-ready, explainable, and open-source.

Notifications You must be signed in to change notification settings

asadsandhu/RAG-Diagnostic-Assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🩺 RAGnosis – Clinical Reasoning via Retrieval-Augmented Generation

License: MIT Python Hugging Face GitHub Repo

βš•οΈ A lightweight Retrieval-Augmented Generation (RAG) assistant for clinical diagnosis, trained on annotated medical notes from MIMIC-IV-Ext-DiReCT, and deployable both on GPU (fast) and CPU (slow) modes.


πŸ–ΌοΈ Demo

🎯 Try the model live (CPU deployment):
πŸ”— RAGnosis – Hugging Face Spaces

Demo


βš™οΈ Tech Stack

Layer Details
🧠 Model Nous-Hermes-2-Mistral-7B-DPO (GPU) / BioMistral-7B (CPU)
πŸ₯ Dataset MIMIC-IV-Ext-DiReCT
πŸ” Retriever FAISS + SentenceTransformers (all-MiniLM-L6-v2)
πŸ’» Frontend Gradio (via Hugging Face Spaces)
🧠 Backend PyTorch + Transformers + BitsAndBytes

πŸš€ Features

  • πŸ”Ž Top-k retrieval from real, annotated clinical notes
  • 🧠 Explainable diagnosis using structured logic and LLMs
  • πŸ“‹ Based on real diagnostic chains from MIMIC-IV-Ext-DiReCT
  • πŸ’¬ Clean Gradio UI for free-text medical queries
  • βœ… Supports GPU for fast inference or CPU fallback

πŸ§ͺ Pipeline Overview

βœ… Step 1: Preprocessing

  • Parse annotated .json samples and knowledge graphs
  • Chunk clinical facts into retrieval_corpus.csv
  • Embed chunks using Sentence-BERT
  • Save embeddings into faiss_index.bin

βœ… Step 2: Retrieval (FAISS)

  • Query is embedded using MiniLM
  • Top-k chunks are returned using FAISS index

βœ… Step 3: Generation

  • Query and context are merged into a prompt
  • Model (Mistral-7B) generates the diagnosis
  • Output is parsed and shown in Gradio UI

⚠️ Deployment Modes (CPU vs GPU)

Feature Hugging Face (CPU) Local/Colab (GPU)
Model Used BioMistral/BioMistral-7B Nous-Hermes-2-Mistral-7B-DPO
Speed 🐒 ~500 seconds per query ⚑ <10 seconds per query
Accuracy βœ… Good βœ… Great (instruction-tuned)
Setup Ready-to-use (slow) Requires CUDA but runs super fast
Hosting Free (Hugging Face Spaces) Free (Colab, Kaggle, local CUDA)

πŸ’‘ For real-time use, prefer running the CUDA version via GitHub clone. Hugging Face version is for preview/demo only.


πŸ›  Run Locally with GPU (Recommended)

πŸ” 1. Clone the Repository

git clone https://github.com/asadsandhu/RAG-Diagnostic-Assistant.git
cd RAG-Diagnostic-Assistant

πŸ“¦ 2. Install Dependencies

pip install -r requirements.txt

πŸš€ 3. Run the App (CUDA Required)

python app.py

βœ”οΈ Required files are included:

  • retrieval_corpus.csv
  • faiss_index.bin

πŸ“ Folder Structure

RAG-Diagnostic-Assistant/
β”œβ”€β”€ app.py                  # Deployable backend using Gradio
β”œβ”€β”€ RAGnosis.ipynb          # Notebook version of the pipeline
β”œβ”€β”€ faiss_index.bin         # FAISS vector index
β”œβ”€β”€ retrieval_corpus.csv    # Processed clinical chunks
β”œβ”€β”€ requirements.txt        # Dependencies
β”œβ”€β”€ assets/
β”‚   └── demo.png            # Sample UI screenshot
└── README.md

πŸ“š Dataset: MIMIC-IV-Ext-DiReCT

  • Combines annotated diagnostic chains (in samples/) and structured graphs (in diagnostic_kg/)
  • Captures how clinicians move from symptom β†’ rationale β†’ diagnosis
  • Original repo: DiReCT GitHub

⚑ Sample Prompt

Query: "patient is experiencing shortness of breath"

πŸ’¬ LLM Output:

"Shortness of breath is a common symptom that can be caused by a variety of respiratory conditions. The differential diagnosis for shortness of breath includes asthma, chronic obstructive pulmonary disease (COPD), congestive heart failure, pneumonia, and pneumothorax. In order to determine the cause of the shortness of breath, it is important to consider the patient's medical history, physical examination findings, and diagnostic testing results. For example, if the patient has a history of asthma and is experiencing wheezing and a prolonged expiratory phase on examination, this would suggest asthma as the cause of the shortness of breath. On the other hand, if the patient has a history of congestive heart failure and is experiencing orthopnea, crackles on auscultation, and a history of edema, this would suggest congestive heart failure as the cause of the shortness of breath."


πŸ“£ Medium Blog

πŸ“– Read the full blog explaining RAGnosis, dataset structure, pipeline design, and tradeoffs:

πŸ‘‰ Read on Medium


πŸ‘€ Author & Links

Built by Asad Ali AI Developer & NLP Researcher


πŸ“„ License

MIT License. See LICENSE for details.


πŸ™ Acknowledgments

  • πŸ₯ MIT-LCP for MIMIC-IV dataset
  • πŸ§ͺ DiReCT team for annotated clinical reasoning data
  • πŸ€— Hugging Face Transformers & Gradio
  • πŸ” Facebook Research for FAISS
  • 🧠 Nous Research for Mistral models

⚠️ Disclaimer: This tool is for academic and demo purposes only. Not intended for clinical use.

About

🩺 RAGnosis β€” An AI-powered clinical reasoning assistant that retrieves real diagnostic notes (from MIMIC-IV-Ext-DiReCT) and generates explainable medical insights using Mistral-7B & FAISS, wrapped in a clean Gradio UI. ⚑ GPU-ready, explainable, and open-source.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages