Skip to content

Latest commit

Β 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Medical RAG Assistant

RAG-based medical Q&A over the Merck Manual (19th ed.) β€” ChromaDB, GTE-large embeddings, Mistral 7B (GGUF). Local, privacy-first, GPU-accelerated.


⚑ Quick Start

git clone https://github.com/ananttripathi/Medical-RAG-System.git
cd Medical-RAG-System
pip install -r requirements.txt
# Place Merck Manual PDF; update path in notebook. See [Installation](#-installation--setup).
jupyter notebook RAG_medical_assistant.ipynb

πŸ“‹ Table of Contents

  1. Project Overview
  2. Business Context
  3. System Architecture
  4. Installation & Setup
  5. Data Processing Pipeline
  6. Model Configuration
  7. Question Answering Without RAG
  8. Prompt Engineering Optimization
  9. RAG Implementation
  10. Evaluation Framework
  11. Experimental Results
  12. Performance Metrics
  13. Business Insights & Recommendations
  14. Limitations & Considerations
  15. Code Examples
  16. References

πŸ“‹ Project Overview

Problem Statement

Business Context:

The healthcare industry is rapidly evolving, with professionals facing increasing challenges in managing vast volumes of medical data while delivering accurate and timely diagnoses. The need for quick access to comprehensive, reliable, and up-to-date medical knowledge is critical for improving patient outcomes and ensuring informed decision-making in a fast-paced environment.

Healthcare professionals often encounter information overload, struggling to sift through extensive research and data to create accurate diagnoses and treatment plans. This challenge is amplified by the need for efficiency, particularly in emergencies, where time-sensitive decisions are vital. Furthermore, access to trusted, current medical information from renowned manuals and research papers is essential for maintaining high standards of care.

Solution:

This project implements a Retrieval-Augmented Generation (RAG) system that:

  • Provides instant access to medical knowledge from the Merck Manual (19th Edition)
  • Delivers contextually accurate responses to medical queries
  • Reduces information overload through intelligent retrieval
  • Supports healthcare professionals in clinical decision-making

Key Features

  • πŸ” Semantic Search: Advanced document retrieval using 1024-dimensional vector embeddings
  • πŸ€– LLM Integration: Mistral 7B Instruct v0.2 model for natural language generation
  • πŸ“š Comprehensive Knowledge Base: 4,114 pages from Merck Manual
  • βœ… Quality Assurance: Automated evaluation of response quality (groundedness & relevance)
  • 🎯 Medical Focus: Optimized for healthcare professional use cases
  • πŸ”’ Privacy-First: Local execution, no external API calls for sensitive medical queries
  • ⚑ GPU Acceleration: Optimized for CUDA-enabled GPUs (38 layers)

πŸ₯ Business Context

Healthcare Industry Challenges

Healthcare professionals encounter several critical challenges:

  1. Information Overload: Exponential growth in medical literature and research publications
  2. Time-Sensitive Decisions: Emergency situations requiring immediate access to accurate information
  3. Accuracy Requirements: High stakes of medical decision-making demand reliable sources
  4. Continuous Learning: Need to stay updated with latest medical protocols and treatments
  5. Resource Constraints: Limited time for extensive research during patient care
  6. Knowledge Accessibility: Difficulty accessing comprehensive medical references quickly

Common Medical Questions Addressed

The system is designed to answer questions like:

1. Diagnostic Assistance

"What are the common symptoms and treatments for pulmonary embolism?"

2. Drug Information

"Can you provide the trade names of medications used for treating hypertension?"

3. Treatment Plans

"What are the first-line options and alternatives for managing rheumatoid arthritis?"

4. Specialty Knowledge

"What are the diagnostic steps for suspected endocrine disorders?"

5. Critical Care Protocols

"What is the protocol for managing sepsis in a critical care unit?"

Project Objective

As an AI specialist, the task is to develop a RAG-based AI solution using renowned medical manuals to address healthcare challenges. The objective is to:

  • Understand issues like information overload
  • Apply AI techniques to streamline decision-making
  • Analyze its impact on diagnostics and patient outcomes
  • Evaluate its potential to standardize care practices
  • Create a functional prototype demonstrating its feasibility and effectiveness

Data Description

Merck Manual of Diagnosis and Therapy (19th Edition)

The Merck Manuals are medical references published by the American pharmaceutical company Merck & Co., that cover a wide range of medical topics, including disorders, tests, diagnoses, and drugs. The manuals have been published since 1899, when Merck & Co. was still a subsidiary of the German company Merck.

Key Statistics:

  • Total Pages: 4,114
  • Sections: 23 major medical sections
  • Format: PDF document
  • Content: Comprehensive medical reference covering diagnosis and therapy
  • Authority: Industry-standard medical reference since 1899

πŸ—οΈ System Architecture

Technology Stack

1. Document Processing

  • Library: PyMuPDFLoader (langchain_community)
  • Input: Medical diagnosis manual PDF (4,114 pages)
  • Output: Structured document objects with metadata

2. Text Chunking

  • Method: RecursiveCharacterTextSplitter
  • Tokenizer: tiktoken (cl100k_base encoding)
  • Chunk Size: 512 tokens
  • Overlap: 20 tokens (configurable)
  • Total Chunks: 8,497 document chunks

3. Embedding Model

  • Model: thenlper/gte-large
  • Architecture: BERT-based transformer
  • Dimensions: 1024
  • Max Sequence Length: 512 tokens
  • Pooling: Mean tokens pooling
  • Normalization: L2 normalization

4. Vector Database

  • Database: ChromaDB
  • Storage: Persistent on-disk storage
  • Search Algorithm: Cosine similarity
  • Indexing: Automatic HNSW indexing
  • Directory: merck_db/

5. Language Model

  • Model: Mistral 7B Instruct v0.2
  • Format: GGUF (Quantized)
  • Quantization: Q6_K (6-bit)
  • Parameters: 7 billion
  • Context Window: 2,300 tokens
  • GPU Layers: 38 (CUDA acceleration)
  • Batch Size: 512 tokens

Data Flow

  1. Input: User submits medical query
  2. Embedding: Query converted to 1024-dim vector
  3. Retrieval: Top-3 similar chunks retrieved from ChromaDB
  4. Context Building: Chunks combined into context string
  5. Prompt Formation: System message + context + question
  6. Generation: Mistral 7B generates response
  7. Output: Medical answer delivered to user

πŸš€ Installation & Setup

Prerequisites

  • Python 3.10 or 3.11
  • GPU (optional): CUDA-capable GPU recommended for Mistral 7B; CPU possible but slower
  • Merck Manual: PDF of Merck Manual of Diagnosis and Therapy (19th Edition). Update merck_pdf_path in the notebook to your local path. The notebook also supports loading from Google Drive (see notebook).

Install Dependencies

pip install -r requirements.txt

For llama-cpp-python with GPU support (Mistral 7B):

# CUDA
CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python --force-reinstall --no-cache-dir

# CPU only
CMAKE_ARGS="-DLLAMA_CUBLAS=off" pip install llama-cpp-python --force-reinstall --no-cache-dir

Run

  1. Open RAG_medical_assistant.ipynb in Jupyter.
  2. Set merck_pdf_path to your Merck Manual PDF path (or use the Google Drive setup in the notebook).
  3. Run cells in order. The first run downloads the Mistral 7B GGUF model and builds the ChromaDB index.

Data Processing Pipeline, Model Configuration, RAG Implementation, Evaluation Framework, Results, and Code Examples are fully documented in the notebook.


πŸ‘€ Author

Co-author: ananttripathiak


πŸ“„ License

This project is licensed under the MIT License.

Suggested GitHub topics: rag medical-ai healthcare merck-manual chromadb mistral langchain llm sentence-transformers vector-database


πŸ“¬ Contact

Open a GitHub Issue for questions or suggestions.

About

Retrieval-augmented generation (RAG) system for medical Q&A using the Merck Manual of Diagnosis and Therapy (19th Edition). Semantic search via ChromaDB and GTE-large embeddings; answer generation with Mistral 7B (GGUF). Runs fully locally for privacy, with optional GPU acceleration.

Topics

Resources

Contributing

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages