How It Works
The EMR agent combines three AI models in a sophisticated pipeline that runs entirely on your local hardware:- Vision Language Model (VLM) - The Gemma-4-E4B-it model “sees” the intake form image and extracts text using a carefully crafted prompt that guides it to identify specific fields (name, DOB, allergies, medications, etc.). Unlike traditional OCR, the VLM understands context—it knows that “DOB” means date of birth and can handle handwritten entries, checkboxes, and varied form layouts.
- LLM Validation & Querying - The Qwen3.5-35B-A3B-GGUF model (a Mixture-of-Experts architecture that activates only 3B parameters per inference) validates extracted data, handles natural language queries, and generates SQL to search the patient database. When you ask “Which patients have penicillin allergies?”, the LLM translates this to proper SQL.
-
Embedding Model - The
user.embeddinggemma-300m-GGUF(EmbeddingGemma 300M) model creates vector embeddings for semantic similarity search, enabling fuzzy matching when looking up returning patients or finding related records.
Why Local Matters: Running on-device with AMD Ryzen AI means sub-second inference latency, no per-request API costs, and complete data sovereignty. A typical intake form processes in 10-15 seconds on AMD Ryzen AI MAX+ hardware.
Key Features
- Automatic file watching - Monitors a directory for new intake forms
- Drag-and-drop upload - Drop files directly into the Watch Folder panel
- VLM-powered extraction - Uses Gemma-4-E4B-it for OCR and data extraction
- Local database storage - SQLite with full patient record schema
- New/returning detection - Identifies returning patients and flags changes
- Critical alerts - Automatic alerts for allergies and missing fields
- Web dashboard - Real-time monitoring with SSE updates
- Cumulative efficiency metrics - Track total time saved across all processed forms
Required Models
The EMR agent uses three models, downloaded automatically on first run viagaia-emr init:
Disk Space: Ensure you have at least 25 GB of free disk space for model downloads.
Prerequisites
Complete the Setup guide first to install Lemonade Server anduv. Then install GAIA with the EMR extras in a Python 3.12 virtual environment.
- Windows
- Linux
- From Source (Dev)
The
api extra provides FastAPI and uvicorn for the web dashboard; the rag extra provides PyMuPDF for PDF processing. uv downloads Python 3.12 automatically if it isn’t already installed.Quick Start
Step 1: Initialize (First Time Only)
Download and load all required models before first use:- Checks Lemonade server is running and context size is configured
- Downloads and loads all required models:
- VLM: Gemma-4-E4B-it-GGUF (form extraction)
- LLM: Qwen3.5-35B-A3B-GGUF (chat/query processing)
- Embedding: user.embeddinggemma-300m-GGUF (similarity search)
- Verifies all models are loaded and ready
Partial Success: If the LLM fails to download but VLM succeeds, form extraction will still work. Chat queries and natural language patient search require the LLM. Run
gaia-emr init again to retry failed downloads.Step 2: Launch
- CLI App
- Desktop App
Download sample forms
Download sample intake forms from GitHub and save them to a local directory (e.g.,./intake-forms/).Dev Install: See the EMR agent source at
hub/agents/python/emr/ for sample forms and configuration.Start watching for forms
Example Output
Example Output
Query patients
Once processing completes, you can query the database using natural language. The agent uses tool calling to translate your questions into SQL queries and retrieve results from the SQLite database.quit or press Ctrl+C to stop.CLI Commands Reference
Supported Intake Form Formats
The agent accepts scanned or photographed intake forms in these formats:Under the Hood
- Image preprocessing — Before reaching the VLM, forms are auto-rotated from EXIF orientation (critical for phone photos), scaled to a max 1024px dimension, and JPEG-compressed (quality 85) to balance extraction quality against image token count.
- Returning-patient detection — A multi-signal lookup combines exact name + DOB match, fuzzy matching for misspellings (“Jon Smith” → “John Smith”), and
user.embeddinggemma-300m-GGUFvector similarity. When a returning patient is detected, changes from their previous record (new allergies, updated insurance) are highlighted. - Real-time dashboard — The FastAPI backend streams processing events to the React frontend over Server-Sent Events (SSE), so the UI updates within ~100ms of file detection without polling or WebSockets.
- Safe DB queries — Natural language questions are answered via LLM tool calling: the model never writes SQL directly, it calls predefined, validated tools (e.g.
search_patients) that construct queries safely.
Troubleshooting
Context Size Too Small
Model Download Failed / Init Fails
gaia-emr init again to resume. If it keeps failing, close any apps using the model files, delete the partial/corrupted model folder from Lemonade’s cache (Windows: %LOCALAPPDATA%\AMD\LemonadeModels\, Linux: ~/.local/share/lemonade/models/), restart Lemonade Server, then re-run gaia-emr init.
PyMuPDF Required
pip install "amd-gaia[rag]".
JSON Parse Failed
gaia-emr test <file> to inspect the raw extraction.
Database Locked
gaia-emr processes pointed at the same --db path.
Learn More
Part 1: Getting Started
Build this agent from scratch and understand the core components
Part 2: Dashboard & API
Deep dive into the web dashboard and REST API endpoints
Part 3: Architecture
Database schema, processing pipeline, and system design