Visit https://huggingface.co/spaces/umerkk164/alia-health
This medical health chatbot uses an intelligent multi-agent architecture to provide comprehensive answers about patients by accessing and analyzing different data sources. Here's how it works:
The system has access to four key types of patient data:
- π Assessments: Measurement-based care assessments taken by patients that provide objective and self-reported insights into their mental health state
- π₯ EHR (Electronic Health Records): Complete medical history including diagnoses, medications, and family medical history
- π Intake Forms: Patient responses to clinician-designed intake assessments (customizable per clinician)
- π¬ Session Transcripts: Detailed transcripts from therapy sessions showing therapeutic progress and interactions
The system uses a hierarchical agent structure with specialized agents for different data types:
- Acts as the central coordinator that receives clinician queries
- Intelligently routes questions to appropriate specialized agents
- Has access to all tools and can call multiple agents in a single response
- Provides comprehensive, structured final answers
-
π Assessment Agent
- Specializes in analyzing measurement-based care assessments
- Interprets scores, trends, and clinical significance
- Tracks patient progress over time
- Provides context about assessment tools and clinical thresholds
-
π Transcript Agent
- Focuses on therapy session analysis
- Retrieves and analyzes session content
- Provides insights into therapeutic progress
- Cites specific sessions and interactions
-
π₯ EHR Agent (Graph RAG)
- Uses advanced graph database technology for structured medical data
- Handles three specific data types:
diagnoses: Patient conditions and diseasesmedications: Current and past medications with dosagesfamily_history: Relevant family medical history
The system uses two advanced retrieval methods:
-
Vector Search (Semantic RAG): For unstructured text data like transcripts, assessments, and intake forms
- Uses Google's Generative AI embeddings for semantic understanding
- Finds contextually relevant information even when exact keywords don't match
-
Graph RAG: For structured EHR data
- Uses Neo4j graph database for complex medical relationships
- Enables precise queries about diagnoses, medications, and family history
- Maintains relationships between different medical entities
- Query Reception: Clinician asks a question about a patient
- Intelligent Routing: Main agent analyzes the query and determines which data sources are needed
- Parallel Processing: Multiple specialized agents can be called simultaneously
- Data Retrieval: Each agent uses its specialized retrieval tool to find relevant information
- Integration: Main agent synthesizes all retrieved information
- Clinical Response: Provides a comprehensive, structured answer with proper medical context
- Context-Aware: Maintains conversation history for follow-up questions
- Patient-Specific: All queries are filtered by patient ID for data security
- Multi-Modal: Can handle both structured (EHR) and unstructured (transcripts, assessments) data
- Real-Time: Provides streaming responses with tool execution visibility
- Safety-First: Only uses factual data, never hallucinates information
- Framework: LangChain + LangGraph for agent orchestration
- LLM: Google Gemini 2.0 Flash for natural language processing
- Vector Database: ChromaDB for semantic search
- Graph Database: Neo4j for EHR relationship mapping
- Embeddings: Google Generative AI embeddings for semantic understanding
This architecture ensures that clinicians receive accurate, comprehensive, and contextually relevant information about their patients while maintaining strict data security and medical accuracy standards.
Before you begin, ensure you have the following installed:
- Python 3.8+: Download from https://www.python.org/downloads/
- pip: Python's package installer (usually included with Python).
-
Clone the repository:
git clone https://github.com/umerkayvyro/alia-bot/ cd alia-bot -
Create a conda environment (recommended):
conda create --name langchain python=3.9 # or your desired Python version conda activate langchain -
Install dependencies:
pip install -r requirements.txt
-
Configure Environment Variables:
-
Create a
.envfile in the root directory of the project:cp .env.example .env
-
Edit the
.envfile and add your configuration:GOOGLE_API_KEY=<Your_Google_API_Key> GOOGLE_MODEL=gemini-2.0-flash TEMPERATURE=0.5 # Path Configuration (customize as needed) CHROMA_DB_PATH=shared_chroma_db SHARED_DOCS_PATH=shared_docs BM25_INDEX_PATH=bm25_index.pkl- Replace
<Your_Google_API_Key>with your actual Google API key. You'll need to obtain this from the Google Cloud Console. GOOGLE_MODEL: Specifies the Gemini model to use (default:gemini-2.0-flash).- See
ENVIRONMENT_VARIABLES.mdfor a complete list of available configuration options. TEMPERATURE: Controls the randomness of the model's output (default:0.5). Lower values make the output more predictable, higher values make it more creative.
- Replace
Important: Never commit your
.envfile to version control. Add it to your.gitignorefile. -
Absolutely β hereβs a clean, GitHub-friendly Markdown version of your project structure for your README.md:
alia-chatbot/
βββ app/ # Main application directory
β βββ **pycache**/ # Python cache files (ignored)
β βββ models/ # Data models (e.g., for chat messages)
β β βββ chat\_models.py
β βββ public/ # Static files (e.g., HTML, CSS, JavaScript)
β β βββ index.html
β βββ routes/ # API route definitions
β β βββ **pycache**/
β β βββ chat.py # Chat-related API endpoints
β β βββ home.py # Home/index route
β βββ services/ # Business logic and external service integrations
β β βββ **pycache**/
β β βββ chat\_service.py # Logic for interacting with the Gemini model
β βββ utils/ # Utility functions and helpers
β βββ config.py # Configuration settings
β βββ dependencies.py # Dependency injection setup
β βββ main.py # FastAPI application entry point
βββ .env # Environment variables (API keys, settings)
βββ README.md # Project documentation
βββ requirements.txt # Python dependencies
-
Navigate to the project root directory in your terminal.
-
Run the application using Uvicorn:
uvicorn app.main:app --reload
app.main: Specifies the module containing the FastAPI application.app: Specifies the variable name of the FastAPI instance withinmain.py. If your app instance has a different name, adjust accordingly.--reload: Enables automatic reloading on code changes (for development).
-
Access the application in your browser:
- Open your web browser and go to
http://127.0.0.1:8000(or the address shown in the Uvicorn output).
- Open your web browser and go to
/(GET): Serves theindex.htmlfile (likely the chatbot interface). Defined inroutes/home.py./chat(POST): Handles chat requests. Takes user input and sends it to the Gemini model via thechat_service. Defined inroutes/chat.py.
app/main.py: The main entry point for the FastAPI application. It initializes the FastAPI app, sets up middleware, and includes the API routers.app/routes/chat.py: Defines the/chatAPI endpoint. It receives user messages, passes them to thechat_service, and returns the model's response.app/services/chat_service.py: Contains the logic for interacting with the Gemini model. It handles authentication, sends requests to the model, and processes the responses.app/config.py: Loads configuration settings from environment variables using theSettingsclass..env: Stores sensitive information like API keys and configuration settings.
The application is configured using environment variables. The following variables are used:
GOOGLE_API_KEY: Required. Your Google API key.GOOGLE_MODEL: The Gemini model to use (default:gemini-2.0-flash).TEMPERATURE: The temperature setting for the model (default:0.5).
The application can be deployed to various platforms, including:
- Google Cloud Platform (GCP): Use Cloud Run or App Engine.
- Heroku: A popular platform-as-a-service.
- AWS: Use Elastic Beanstalk or ECS.
- Docker: Containerize the application for easy deployment.
Example Deployment to Google Cloud Run:
-
Create a Dockerfile:
FROM python:3.9-slim-buster WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]
-
Build the Docker image:
docker build -t alia-chatbot . -
Push the image to Google Container Registry (GCR):
docker tag alia-chatbot gcr.io/<your_gcp_project_id>/alia-chatbot docker push gcr.io/<your_gcp_project_id>/alia-chatbot
-
Deploy to Cloud Run:
gcloud run deploy --image gcr.io/<your_gcp_project_id>/alia-chatbot --platform managed --region <your_gcp_region>
- Replace
<your_gcp_project_id>with your Google Cloud project ID. - Replace
<your_gcp_region>with your desired Google Cloud region.
- Replace
-
Set the
GOOGLE_API_KEYenvironment variable in Cloud Run. You can do this through the Cloud Console or using thegcloudcommand-line tool.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes.
- Write tests for your changes.
- Submit a pull request.