A community-driven registry for Claude, Cursor, Windsurf, Cline & more. Not affiliated with Anthropic.
Are you the author? Sign in to claim
AMG-RAG (Agentic Medical Graph-RAG) is a comprehensive framework that automates the construction and continuous updating
AMG-RAG (Agentic Medical Graph-RAG) is a comprehensive framework that automates the construction and continuous updating of Medical Knowledge Graphs (MKGs), integrates reasoning, and retrieves current external evidence for medical Question Answering (QA). Our approach addresses the challenge of rapidly evolving medical knowledge by dynamically linking new findings and complex medical concepts.

Our evaluations on standard medical QA benchmarks demonstrate superior performance:
| Dataset | Score | Metric |
|---|---|---|
| MEDQA | 74.1% | F1 Score |
| MEDMCQA | 66.34% | Accuracy |
AMG-RAG surpasses both comparable models and those 10 to 100 times larger, while enhancing interpretability for medical queries.
The enhanced AMG-RAG system consists of six key components:
# Clone the repository
git clone https://github.com/MrRezaeiUofT/AMG-RAG.git
cd AMG-RAG
# Install core dependencies
pip install langchain langchain-community langchain-openai
pip install transformers langgraph pandas numpy requests wikipedia networkx python-decouple
# Optional: Install additional packages
pip install langchain-huggingface langchain-chroma langchain-ollama
Create a .env file in the root directory:
OPENAI_API_KEY=your_openai_api_key_here
pubmed_api=your_pubmed_api_key_here
from AMG_with_KG import AMG_RAG_System
# Initialize the system
system = AMG_RAG_System(use_openai=True, openai_key="your-api-key")
# Sample medical question
question_data = {
"question": "A 45-year-old man presents with severe chest pain...",
"options": {
"A": "Unstable angina",
"B": "Acute inferior wall myocardial infarction",
"C": "Acute anterior wall myocardial infarction",
"D": "Aortic dissection",
"E": "Pulmonary embolism"
},
"answer": "B"
}
# Get answer with reasoning
result = system.answer_question(question_data)
print(f"Answer: {result['answer']}")
print(f"Confidence: {result['confidence']:.2f}")
print(f"Explanation: {result['explanation']}")
# Access the knowledge graph
kg = system.kg
# Explore entities
for entity_name, entity in kg.entities.items():
print(f"Entity: {entity_name}")
print(f"Type: {entity.entity_type}")
print(f"Confidence: {entity.confidence:.2f}")
print(f"Description: {entity.description[:100]}...")
# Explore relationships
for relation in kg.relations:
print(f"{relation.source} --[{relation.relation_type}]--> {relation.target}")
print(f"Confidence: {relation.confidence:.2f}")
The system expects input data in JSONL format:
{
"question": "Medical question text",
"options": {
"A": "Option A text",
"B": "Option B text",
"C": "Option C text",
"D": "Option D text"
},
"answer": "B",
"answer_idx": 1,
"meta_info": "Additional metadata"
}
# OpenAI (recommended)
system = AMG_RAG_System(use_openai=True, openai_key="your-api-key")
# Local Ollama
system = AMG_RAG_System(use_openai=False)
# Entity extraction settings
max_entities = 8 # Maximum entities per question
relevance_threshold = 5 # Minimum relevance score (1-10)
# Relationship analysis settings
confidence_threshold = 0.3 # Minimum confidence for relationships
max_relationship_depth = 2 # Maximum exploration depth
# Search parameters
pubmed_max_results = 3 # Max PubMed articles
wikipedia_sentences = 3 # Wikipedia summary length
AMG-RAG/
├── AMG-with-KG.py # Main AMG-RAG system
├── Simple_AMG_RAG.py # Simplified version
├── create_VDB.py # Vector database utilities
├── dataset/ # Input datasets
│ ├── MEDQA/ # MEDQA dataset
│ ├── MedMCQA/ # MedMCQA dataset
│ └── PubMedQA/ # PubMedQA dataset
├── results/ # Output results
├── new_VDB/ # Vector database storage
├── requirements.txt # Dependencies
├── .env # Environment variables
└── README.md # This file
If you use AMG-RAG in your research, please cite our paper:
@inproceedings{rezaei-etal-2025-agentic,
title = "Agentic Medical Knowledge Graphs Enhance Medical Question Answering: Bridging the Gap Between {LLM}s and Evolving Medical Knowledge",
author = "Rezaei, Mohammad Reza and
Fard, Reza Saadati and
Parker, Jayson Lee and
Krishnan, Rahul G and
Lankarany, Milad",
editor = "Christodoulopoulos, Christos and
Chakraborty, Tanmoy and
Rose, Carolyn and
Peng, Violet",
booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2025",
month = nov,
year = "2025",
address = "Suzhou, China",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2025.findings-emnlp.679/",
doi = "10.18653/v1/2025.findings-emnlp.679",
pages = "12682--12701",
ISBN = "979-8-89176-335-7",
abstract = "Large Language Models (LLMs) have greatly advanced medical Question Answering (QA) by leveraging vast clinical data and medical literature. However, the rapid evolution of medical knowledge and the labor-intensive process of manually updating domain-specific resources can undermine the reliability of these systems. We address this challenge with Agentic Medical Graph-RAG (AMG-RAG), a comprehensive framework that automates the construction and continuous updating of Medical Knowledge Graph (MKG), integrates reasoning, and retrieves current external evidence from the MKG for medical QA.Evaluations on the MEDQA and MEDMCQA benchmarks demonstrate the effectiveness of AMG-RAG, achieving an F1 score of 74.1{\%} on MEDQA and an accuracy of 66.34{\%} on MEDMCQA{---}surpassing both comparable models and those 10 to 100 times larger. By dynamically linking new findings and complex medical concepts, AMG-RAG not only boosts accuracy but also enhances interpretability for medical queries, which has a critical impact on delivering up-to-date, trustworthy medical insights."
}
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
npx CLI installing 100+ agents, commands, hooks, and integrations in one command
干净、强大、属于你的 AI Agent 平台 --AI agents, without the clutter.
An AI-powered custom node for ComfyUI designed to enhance workflow automation and provide intelligent assistance
Native macOS app to monitor Claude AI usage limits and watch your coding sessions live