RAG-based medical Q&A over the Merck Manual (19th ed.) β ChromaDB, GTE-large embeddings, Mistral 7B (GGUF). Local, privacy-first, GPU-accelerated.
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- Project Overview
- Business Context
- System Architecture
- Installation & Setup
- Data Processing Pipeline
- Model Configuration
- Question Answering Without RAG
- Prompt Engineering Optimization
- RAG Implementation
- Evaluation Framework
- Experimental Results
- Performance Metrics
- Business Insights & Recommendations
- Limitations & Considerations
- Code Examples
- References
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
- π 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)
Healthcare professionals encounter several critical challenges:
- Information Overload: Exponential growth in medical literature and research publications
- Time-Sensitive Decisions: Emergency situations requiring immediate access to accurate information
- Accuracy Requirements: High stakes of medical decision-making demand reliable sources
- Continuous Learning: Need to stay updated with latest medical protocols and treatments
- Resource Constraints: Limited time for extensive research during patient care
- Knowledge Accessibility: Difficulty accessing comprehensive medical references quickly
The system is designed to answer questions like:
"What are the common symptoms and treatments for pulmonary embolism?"
"Can you provide the trade names of medications used for treating hypertension?"
"What are the first-line options and alternatives for managing rheumatoid arthritis?"
"What are the diagnostic steps for suspected endocrine disorders?"
"What is the protocol for managing sepsis in a critical care unit?"
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
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
- Library: PyMuPDFLoader (langchain_community)
- Input: Medical diagnosis manual PDF (4,114 pages)
- Output: Structured document objects with metadata
- Method: RecursiveCharacterTextSplitter
- Tokenizer: tiktoken (cl100k_base encoding)
- Chunk Size: 512 tokens
- Overlap: 20 tokens (configurable)
- Total Chunks: 8,497 document chunks
- Model: thenlper/gte-large
- Architecture: BERT-based transformer
- Dimensions: 1024
- Max Sequence Length: 512 tokens
- Pooling: Mean tokens pooling
- Normalization: L2 normalization
- Database: ChromaDB
- Storage: Persistent on-disk storage
- Search Algorithm: Cosine similarity
- Indexing: Automatic HNSW indexing
- Directory:
merck_db/
- 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
- Input: User submits medical query
- Embedding: Query converted to 1024-dim vector
- Retrieval: Top-3 similar chunks retrieved from ChromaDB
- Context Building: Chunks combined into context string
- Prompt Formation: System message + context + question
- Generation: Mistral 7B generates response
- Output: Medical answer delivered to user
- 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_pathin the notebook to your local path. The notebook also supports loading from Google Drive (see notebook).
pip install -r requirements.txtFor 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- Open
RAG_medical_assistant.ipynbin Jupyter. - Set
merck_pdf_pathto your Merck Manual PDF path (or use the Google Drive setup in the notebook). - 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.
Co-author: ananttripathiak
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
Open a GitHub Issue for questions or suggestions.