A Retrieval-Augmented Generation (RAG) agent designed for healthcare information querying, built with LangChain and Neo4j knowledge graphs.
- Overview
- Key Features
- Architecture
- Prerequisites
- Quick Start
- Example Queries
- Database Design
- Technical Stack
- Acknowledgments
This project implements a healthcare-focused RAG chatbot that leverages LangChain's capabilities for natural language processing and Neo4j's graph database for structured healthcare data storage. The application provides an intuitive interface for querying complex healthcare relationships and information.
- Knowledge Graph Integration - Neo4j for healthcare data relationships
- RESTful API - FastAPI-powered scalable backend
- Interactive UI - Intuitive Streamlit interface
- Containerized - Docker-based deployment
- Multi-Model Support - Configurable OpenAI models
graph LR
A[User] --> B[Streamlit UI]
B --> C[FastAPI Backend]
C --> D[LangChain Agent]
D --> E[Neo4j Database]
D --> F[OpenAI API]
- Docker and Docker Compose
- OpenAI API access
- Neo4j AuraDB instance
- Python 3.8+
git clone https://github.com/asanmateu/medgraph-ai
cd medgraph-aiCreate a .env file in the project root with the variables:
# OpenAI Configuration
OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
# Neo4j Database Configuration
NEO4J_URI=<YOUR_NEO4J_URI>
NEO4J_USERNAME=<YOUR_NEO4J_USERNAME>
NEO4J_PASSWORD=<YOUR_NEO4J_PASSWORD>
# Data Source URLs
HOSPITALS_CSV_PATH=https://raw.githubusercontent.com/hfhoffman1144/langchain_neo4j_rag_app/main/data/hospitals.csv
PAYERS_CSV_PATH=https://raw.githubusercontent.com/hfhoffman1144/langchain_neo4j_rag_app/main/data/payers.csv
PHYSICIANS_CSV_PATH=https://raw.githubusercontent.com/hfhoffman1144/langchain_neo4j_rag_app/main/data/physicians.csv
PATIENTS_CSV_PATH=https://raw.githubusercontent.com/hfhoffman1144/langchain_neo4j_rag_app/main/data/patients.csv
VISITS_CSV_PATH=https://raw.githubusercontent.com/hfhoffman1144/langchain_neo4j_rag_app/main/data/visits.csv
REVIEWS_CSV_PATH=https://raw.githubusercontent.com/hfhoffman1144/langchain_neo4j_rag_app/main/data/reviews.csv
# Model Configuration
HOSPITAL_AGENT_MODEL=gpt-3.5-turbo-1106
HOSPITAL_CYPHER_MODEL=gpt-3.5-turbo-1106
HOSPITAL_QA_MODEL=gpt-3.5-turbo-0125
# Service Configuration
CHATBOT_URL=http://host.docker.internal:8000/hospital-rag-agentEnsure your Neo4j AuraDB instance is running, then execute:
make build && make startmake stop- API Documentation:
http://localhost:8000/docs - User Interface:
http://localhost:8501
Try asking the agent:
- "Which hospitals have the highest patient satisfaction?"
- "Show me physicians specializing in cardiology"
- "What's the average wait time for emergency visits?"
The application utilizes a graph database structure optimized for healthcare data relationships. Understanding this schema will help formulate effective queries.
The following node types and their properties are available for querying:
Relationships between nodes contain additional contextual information:
- LangChain: Orchestration framework for LLM applications
- Neo4j: Graph database for healthcare data storage
- FastAPI: High-performance API framework
- Streamlit: Interactive web application framework
- Docker: Containerization platform
- OpenAI GPT-3.5: Language model for natural language understanding
This project builds upon the excellent foundation provided by Real Python's LLM RAG Chatbot tutorial.