How snowteam2023/medrag works
Project Type and Purpose
• MedRAG is a research-driven, full-fledged implementation for a healthcare copilot that integrates knowledge graphs into RAG models.
• Its purpose is to improve diagnostic accuracy through enhanced reasoning and retrieval by leveraging a diagnostic knowledge graph, as described in the README.
Main Components to Highlight
a. Data & Knowledge Ingestion:
• Dataset: Represented by the “dataset” directory which includes the “knowledge graph of DDXPlus.xlsx”. This file is used for building the disease knowledge graph.
• Embeddings: The “Embeddings_saved” directory contains pre-computed embeddings (CP_DC_embeddings and CP_KG_embeddings) that are used to represent either the clinical data or the knowledge graph nodes.
b. Core Processing Units:
• Knowledge Graph Construction Module: This includes hierarchical aggregation logic (referenced in the README figures and images like DDXPlusKG.pdf) that builds and maintains the disease knowledge graph.
• RAG-based Reasoning Module: This module integrates EHR retrieval with the diagnostic knowledge graph for enhanced reasoning. It is central to the MedRAG approach.
• KG Retrieval Module: Indicated by the file “KG_Retrieve.py”, this module likely handles the retrieval of relevant knowledge from the constructed graph given a query.
c. User Interface / Execution Entry Points:
• Main Application Scripts: “main.py” and “main_MedRAG.py” are the primary entry points. They coordinate the processing workflows, invoking data ingestion, retrieval, and diagnostic suggestion generation.
• Authentication & API Integration: “authentication.py” handles token management for third-party services like OpenAI’s API and Hugging Face, ensuring that external model calls are authenticated.
d. Evaluation & Metrics:
• Metrics: The “metrics” directory (e.g., “metrics DDXPlus.py”) is used for evaluation and performance measurement of the model outputs compared to baselines.
e. Supporting Artifacts:
Relationships and Interactions
• Embeddings Flow: The pre-computed embeddings stored under Embeddings_saved are fed into the retrieval modules to facilitate faster, high-quality matching.
• Authentication and External APIs: The authentication module connects to external language model APIs (OpenAI/Hugging Face) with tokens, which are then used by the RAG module for generating diagnostic recommendations.
• Control Flow: The main scripts (main.py and main_MedRAG.py) integrate the above components. They orchestrate the flow from input data, through retrieval and reasoning, to output (diagnostic suggestions along with follow-up questions).
Architectural Patterns & Key Design Principles
• Modularity: Each component (data ingestion, KG construction, retrieval, reasoning, and evaluation) is clearly separated for better maintainability.
• Pipeline Workflow: The architecture is primarily a data processing pipeline where raw clinical data and knowledge graphs are sequentially processed, combined with real-time API calls for augmented generation.
• Extensibility/Plug-in Points: The design should allow easy swapping or enhancement of individual modules (for instance, different backbone LLMs or an updated KG_Retrieve component).
Relevant Technologies & Frameworks
• APIs: Usage of OpenAI and Hugging Face LLM APIs for augmentation.
• Data Processing: Excel-based datasets and pre-saved embeddings.
• Evaluation: Custom metrics scripts for measuring diagnostic accuracy across multiple criteria.