How asanmateu/medgraph-ai works
Purpose and Deployment
A containerized healthcare RAG system that answers natural-language questions over a Neo4j healthcare graph using LangChain and OpenAI models. Docker Compose coordinates three application concerns: API, Streamlit client, and graph-data loading. Core deployment files: docker-compose.yml, Makefile, chatbot_api/Dockerfile.
User and API Entry Points
The Streamlit application is the user-facing entry point; it submits questions to the configured backend URL. The FastAPI service exposes the hospital RAG endpoint and API documentation. Paths: chatbot_frontend/src/main.py, chatbot_api/src/main.py, chatbot_api/src/models/hospital_rag_query.py.
Agent Orchestration
The hospital RAG agent is the central request coordinator. It receives a validated query, invokes graph-oriented and review-oriented chains/tools as appropriate, and produces the response returned by FastAPI. Async support allows non-blocking agent requests. Paths: chatbot_api/src/agents/hospital_rag_agent.py, chatbot_api/src/utils/async_utils.py, chatbot_api/src/main.py.
Structured Graph Retrieval
A Cypher chain translates healthcare questions into graph queries, executes them against Neo4j, and uses an LLM to formulate an answer from retrieved relationships. Neo4j connection credentials and separate Cypher/QA model choices are supplied through environment variables. Paths: chatbot_api/src/chains/hospital_cypher_chain.py, chatbot_api/src/agents/hospital_rag_agent.py.
Review and Operational Context
A distinct review chain handles hospital-review retrieval/answering, while a wait-time tool supplies operational wait-time information to the agent. This separates graph reasoning from specialized contextual capabilities. Paths: chatbot_api/src/chains/hospital_review_chain.py, chatbot_api/src/tools/wait_times.py, chatbot_api/src/agents/hospital_rag_agent.py.
Graph Data Ingestion Boundary
The ETL container bulk-loads hospital-domain CSV datasets into Neo4j. Local data/ files and/or environment-configured CSV URLs are the source boundary; Neo4j/AuraDB is the durable knowledge-graph boundary. Paths: hospital_neo4j_etl/src/hospital_bulk_csv_write.py, hospital_neo4j_etl/src/entrypoint.sh, data/hospitals.csv.
Runtime and External Dependencies
Python services run in separate API, frontend, and ETL containers, each with its own package definition and startup script. Required external services are OpenAI’s API for GPT models and a Neo4j 5+/AuraDB instance for graph persistence and retrieval. Paths: chatbot_api/pyproject.toml, chatbot_frontend/pyproject.toml, hospital_neo4j_etl/pyproject.toml.
Main entry points: hospital_rag_agent.py Hospital RAG Agent · main.py FastAPI Service · docker-compose.yml Docker Compose · hospital_cypher_chain.py Cypher Retrieval Chain
Components 14
Container Deployment
Docker Compose coordinates the application concerns.
- Docker Compose · Coordinates API, frontend, and ETL containers.
docker-compose.yml - Streamlit Client · Submits user questions to the configured backend.
chatbot_frontend/src/main.py
API and RAG
- FastAPI Service · Exposes the hospital RAG endpoint and API documentation.
chatbot_api/src/main.py - Hospital Query Model
chatbot_api/src/models/hospital_rag_query.py - Hospital RAG Agent · Coordinates retrieval and specialized capabilities asynchronously.
chatbot_api/src/agents/hospital_rag_agent.py - Async Support
chatbot_api/src/utils/async_utils.py - Cypher Retrieval Chain · Generates Cypher, queries the graph, and formulates answers.
chatbot_api/src/chains/hospital_cypher_chain.py - Hospital Review Chain · Retrieves and answers hospital-review questions.
chatbot_api/src/chains/hospital_review_chain.py - Wait-Time Tool · Supplies operational wait-time context.
chatbot_api/src/tools/wait_times.py
Graph Ingestion
- ETL Entrypoint · Starts the bulk graph-loading process.
hospital_neo4j_etl/src/entrypoint.sh - Hospital CSV Bulk Loader · Loads hospital-domain CSV data into Neo4j.
hospital_neo4j_etl/src/hospital_bulk_csv_write.py - Hospital CSV Data · Local files or configured CSV URLs are ingestion sources.
data/hospitals.csv
Other components
- OpenAI API · Provides Cypher and QA model inference.
- Neo4j / AuraDB · Durable healthcare graph used for ingestion and retrieval.
Connections 16
- Docker Compose → Streamlit Client: runs
- Docker Compose → FastAPI Service: runs
- Docker Compose → ETL Entrypoint: runs
- Streamlit Client → FastAPI Service: submits questions
- FastAPI Service → Hospital Query Model: validates request
- FastAPI Service → Hospital RAG Agent: dispatches query
- Hospital RAG Agent → Async Support: uses
- Hospital RAG Agent → Cypher Retrieval Chain: invokes
- Hospital RAG Agent → Hospital Review Chain: invokes
- Hospital RAG Agent → Wait-Time Tool: queries
- Cypher Retrieval Chain → Neo4j / AuraDB: executes Cypher
- Cypher Retrieval Chain → OpenAI API: uses LLMs
- Hospital Review Chain → OpenAI API: uses LLM
- ETL Entrypoint → Hospital CSV Bulk Loader: starts
- Hospital CSV Data → Hospital CSV Bulk Loader: source data
- Hospital CSV Bulk Loader → Neo4j / AuraDB: bulk loads