Skip to main content

Prerequisites

Python 3.10+

Requiredpython.org or brew install [email protected]

Git 2.x+

Requiredbrew install git or git-scm.com

Ollama

OptionalOnly for local LLM (MedGemma)

Quick Install (5 Minutes)

1

Clone Repository

git clone <your-repo-url> clinicalpilot
cd clinicalpilot
2

Create Virtual Environment

python3 -m venv venv
source venv/bin/activate
3

Install Dependencies

pip install --upgrade pip
pip install -r requirements.txt
This downloads ~560MB for the spaCy language model. On some systems, spacy download fails — see troubleshooting below.
4

Install SpaCy Model

The PHI anonymization layer requires a spaCy language model. Install directly via pip:
pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.7.1/en_core_web_lg-3.7.1-py3-none-any.whl
For a smaller model (~12MB vs 560MB), use en_core_web_sm and set SPACY_MODEL=en_core_web_sm in .env
5

Configure Environment

cp .env.example .env
# Edit .env with your API keys
Minimum required:
OPENAI_API_KEY=sk-your-key-here
NCBI_EMAIL=[email protected]
6

Run the Server

python -m uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000
Open http://localhost:8000

Detailed Dependencies

Core Framework

fastapi==0.115.0
uvicorn[standard]==0.30.0
python-multipart==0.0.9
python-dotenv==1.0.1
pydantic==2.9.0
pydantic-settings==2.5.0
certifi  # macOS SSL fix

LLM & Agents

openai==1.50.0
groq>=0.9.0  # For AI Chat
langchain==0.3.0
langchain-openai==0.2.0
langchain-community==0.3.0

Vector DB & Embeddings

lancedb==0.13.0
sentence-transformers==3.1.0
LanceDB is embedded/serverless — no separate database server required. It auto-creates at data/lancedb/ on first run.

Document Parsing

PyPDF2==3.0.1
unstructured==0.15.0

PHI Anonymization

presidio-analyzer==2.2.355
presidio-anonymizer==2.2.355
spacy==3.7.0
# Then: pip install en_core_web_lg (see above)

External APIs

biopython==1.84  # PubMed E-utilities
httpx==0.27.0
aiohttp==3.10.0

Observability

langsmith==0.1.120

API Keys Setup

OpenAI (Required)

1

Get API Key

  1. Go to platform.openai.com/api-keys
  2. Create a new API key
  3. Copy the key (starts with sk-)
2

Add to .env

OPENAI_API_KEY=sk-your-key-here
OPENAI_MODEL=gpt-4o
OPENAI_FAST_MODEL=gpt-4o-mini
  • gpt-4o is used for Clinical, Safety, Critic, and Synthesizer agents
  • gpt-4o-mini is used for Literature agent (faster, cheaper)

Groq (Required for AI Chat)

1

Get API Key

  1. Go to console.groq.com/keys
  2. Create a free API key
  3. Copy the key (starts with gsk_)
2

Add to .env

GROQ_API_KEY=gsk_your-key-here
GROQ_MODEL=llama-3.3-70b-versatile
Without this key, the /api/chat endpoint returns 503. The rest of the app works fine.
1

Register

  1. Go to ncbi.nlm.nih.gov/account
  2. Create a free account
  3. Navigate to Settings → API Key Management → Create API Key
2

Add to .env

NCBI_EMAIL=[email protected]
NCBI_API_KEY=your-key-here
Without an API key: PubMed limits you to 3 requests/secondWith an API key: 10 requests/second

LangSmith (Optional — Observability)

1

Sign Up

  1. Go to smith.langchain.com
  2. Sign up (free tier available)
  3. Create an API key
2

Add to .env

LANGSMITH_API_KEY=lsv2_your-key-here
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=clinicalpilot
With LangSmith enabled, you get:
  • Real-time agent call tracing
  • Token usage per agent
  • Latency breakdown
  • Debate round visualization

FDA API (Optional)

1

Request Key

  1. Go to open.fda.gov/apis/authentication
  2. Request an API key (instant approval)
2

Add to .env

FDA_API_KEY=your-key-here
Works without a key but has lower rate limits (240 requests/minute vs 1000 with key).

Data Downloads

DrugBank Open Data (Optional)

1

Download

  1. Go to go.drugbank.com/releases/latest#open-data
  2. Create a free account
  3. Download DrugBank Vocabulary CSV
2

Place in Data Directory

cp ~/Downloads/drugbank_vocabulary.csv data/drugbank/
If you skip this step, the system still works — it uses FDA API and RxNorm for safety checks instead. DrugBank adds offline drug name resolution.

Sample FHIR Data (Included)

The repo includes sample FHIR R4 bundles:
data/sample_fhir/
├── stemi_case.json
├── stroke_case.json
└── pe_case.json
To add your own:
# Export FHIR R4 Bundle JSON from your EHR
# Place in data/sample_fhir/
cp ~/Downloads/patient_bundle.json data/sample_fhir/

# Upload via API
curl -X POST http://localhost:8000/api/upload/fhir \
  -H "Content-Type: application/json" \
  -d @data/sample_fhir/patient_bundle.json

Local LLM Setup (Optional — MedGemma via Ollama)

1

Install Ollama

brew install ollama
2

Start Ollama Server

ollama serve
# Runs on http://localhost:11434 by default
3

Pull MedGemma Model

# ~5GB download, needs 16GB RAM
ollama pull medgemma2:9b
4

Configure .env

USE_LOCAL_LLM=true
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=medgemma2:9b
Fallback behavior: If Ollama is unreachable, the system automatically falls back to OpenAI.

LanceDB Initialization

LanceDB is serverless/embedded — no separate server needed.
1

Auto-Creation

The vector store auto-creates at data/lancedb/ on first run. No manual setup required.
2

Manual Initialization (Optional)

python -m backend.rag.lancedb_store --init
3

Add Custom Medical Documents

# Place PDF/TXT files in data/rag_documents/
mkdir -p data/rag_documents
cp ~/medical_papers/*.pdf data/rag_documents/

# Ingest into vector store
python -m backend.rag.lancedb_store --ingest data/rag_documents/

Running the Application

Development Mode

# With auto-reload on code changes
python -m uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000

Production Mode

# Multi-worker for production
python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000 --workers 4

Docker (Optional)

docker-compose up --build

Verification Checklist

After installation, verify everything works:
1

Health Check

curl http://localhost:8000/api/health
Expected:
{
  "status": "ok",
  "service": "clinicalpilot",
  "version": "1.0.0",
  "model": "gpt-4o",
  "local_llm": false
}
2

Test AI Chat

curl -X POST http://localhost:8000/api/chat \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "What are red flags for chest pain?"}]}'
3

Test Analysis Pipeline

curl -X POST http://localhost:8000/api/analyze \
  -H "Content-Type: application/json" \
  -d '{"text": "45-year-old male with acute chest pain radiating to left arm, diaphoresis, SOB. Hx HTN, DM2. Meds: metformin 1000mg BID, lisinopril 20mg daily."}'
This takes ~100 seconds. Returns full SOAP note + debate state + safety panel.
4

Test Emergency Mode

curl -X POST http://localhost:8000/api/emergency \
  -H "Content-Type: application/json" \
  -d '{"text": "Unconscious, no pulse, CPR in progress"}'
Returns in <5 seconds with ESI score + differentials + red flags.
5

Check API Docs

Open http://localhost:8000/docs for interactive API documentation.

Troubleshooting

Ensure you’re running from the project root:
cd /path/to/clinicalpilot
python -m uvicorn backend.main:app --reload
Force reinstall and use direct pip install for the model:
pip install presidio-analyzer presidio-anonymizer --force-reinstall
pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.7.1/en_core_web_lg-3.7.1-py3-none-any.whl
If issues persist, use the smaller model:
pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.1/en_core_web_sm-3.7.1-py3-none-any.whl
echo "SPACY_MODEL=en_core_web_sm" >> .env
The app auto-patches SSL using certifi. If you still see CERTIFICATE_VERIFY_FAILED:
# Option 1: Run macOS certificate installer (recommended)
/Applications/Python\ 3.12/Install\ Certificates.command

# Option 2: Reinstall certifi
pip install certifi --upgrade
pip install lancedb --upgrade
cp .env.example .env
# Edit .env and add your OpenAI API key
nano .env
Find and kill the process:
lsof -ti:8000 | xargs kill -9
Or use a different port:
python -m uvicorn backend.main:app --reload --port 8001
Make sure Ollama is running:
ollama serve
# Check it's accessible
curl http://localhost:11434/api/tags

Platform-Specific Notes

macOS M1/M2/M3

  • All dependencies work natively on Apple Silicon
  • Ollama runs natively with Metal acceleration
  • SpaCy large model may take a few minutes to download
  • SSL certificate fix: The app auto-patches using certifi, but you can also run:
    /Applications/Python\ 3.12/Install\ Certificates.command
    

Environment Variables Reference

VariableRequiredDefaultDescription
OPENAI_API_KEYYes-OpenAI API key for GPT-4o/4o-mini
OPENAI_MODELNogpt-4oModel for main agents
OPENAI_FAST_MODELNogpt-4o-miniModel for Literature agent
GROQ_API_KEYNo*-Groq API key for AI Chat
GROQ_MODELNollama-3.3-70b-versatileGroq model name
USE_LOCAL_LLMNofalseUse Ollama/MedGemma
OLLAMA_BASE_URLNohttp://localhost:11434Ollama server URL
OLLAMA_MODELNomedgemma2:9bOllama model name
NCBI_EMAILYes**-Email for PubMed API
NCBI_API_KEYNo-PubMed API key (10 req/s vs 3)
LANGSMITH_API_KEYNo-LangSmith tracing key
LANGCHAIN_TRACING_V2NofalseEnable LangSmith tracing
LANGCHAIN_PROJECTNoclinicalpilotLangSmith project name
FDA_API_KEYNo-FDA API key (higher limits)
LANCEDB_PATHNodata/lancedbVector store directory
DRUGBANK_CSV_PATHNodata/drugbank/drugbank_vocabulary.csvDrugBank data file
SPACY_MODELNoen_core_web_lgSpaCy model for PHI detection
LOG_LEVELNoINFOLogging level
CORS_ORIGINSNo["*"]CORS allowed origins
EMERGENCY_TIMEOUT_SECNo5Emergency mode timeout
MAX_DEBATE_ROUNDSNo3Max debate iterations
* Required only for AI Chat feature** Required by NCBI for E-utilities access

Updating

To update ClinicalPilot:
git pull
pip install -r requirements.txt --upgrade
# Restart the server

Next Steps

Quickstart

Run your first SOAP note analysis in 5 minutes

Architecture

Learn how the multi-agent debate system works

API Reference

Explore all endpoints and schemas

Configuration

Advanced settings and customization

Build docs developers (and LLMs) love