Clinical Insight Agent is an autonomous AI assistant designed for medical researchers and healthcare professionals to query, analyze, and summarize clinical trial data.
The project utilizes a Hybrid RAG (Retrieval-Augmented Generation) architecture, leveraging both structured SQL databases and semantic vector stores (ChromaDB) simultaneously. The agent autonomously decides whether to perform statistical analysis via SQL or read medical documents for qualitative insights using LangGraph.
The system follows a strict technical pipeline designed for reliability and autonomous reasoning:
- Data Ingestion (ETL): Real-time data is fetched from the ClinicalTrials.gov API, cleaned, and split into structured and unstructured components.
- Hybrid Storage:
- Metadata (SQL): Dates, Phases, Status, and enrollment numbers are stored in a relational database.
- Semantic Data (ChromaDB): Study summaries and eligibility criteria are vectorized using the
all-MiniLM-L6-v2model.
- Autonomous Routing (LangGraph): The agent analyzes the user's intent. It intelligently decides whether to run a SQL query (for statistics) or a Vector Search (for medical context).
- Retrieval & Context Injection: Relevant data is retrieved from the selected source.
- LLM Generation: The retrieved context and prompt are sent to Gemini Flash-Latest to generate an evidence-based, hallucination-free answer.
- Agentic Workflow: It doesn't just retrieve; it thinks. It uses tools dynamically based on the question.
- Hybrid Memory: Combines SQL for exact numbers ("How many phase 3 trials?") and Vector DB for concepts ("How does GZR102 work?").
- Optimized Performance: Uses lightweight embeddings and asynchronous API calls for speed.
- One-Click Setup: Includes automated scripts (
.shand.bat) for instant local environment setup. - Evidence-Based: Every answer is grounded in actual NCT-ID records, minimizing hallucinations.
Below you can see how the agent operates, switching between SQL tools and Vector Search tools based on the user's query.
Click Here to Watch the Demo Video
This project is built on a modern, scalable, and AI-first technology stack:
- π¦οΈπΈοΈ LangGraph β Stateful agentic workflows and decision-making logic
- π§ Google Gemini-Flash-Latest" β High-performance, cost-effective LLM
- π€ HuggingFace Embeddings β Medical text embeddings (
all-MiniLM-L6-v2)
- β‘ FastAPI β High-performance async REST API
- ποΈ SQLAlchemy & SQLite / PostgreSQL β Structured data storage
- π¨ ChromaDB β Vector database for semantic retrieval
- π Streamlit β Interactive and user-friendly UI
- π³ Docker β Optional containerized deployment
- π Custom Logging β Monitoring and debugging support
The system is powered by real-time data from the ClinicalTrials.gov API v2.
-
Extract
Fetches clinical studies for target conditions (e.g., Diabetes, Cancer) -
Transform
- SQL Path: Title, Phase, Status, Dates, Locations
- Vector Path: Brief Summary + Eligibility Criteria β text chunks β embeddings
-
Load
- Relational DB (SQL)
- Vector DB (ChromaDB)
git clone https://github.com/BozyelOzan/Clinical-Insight-Agent.git
cd Clinical-Insight-AgentCreate a .env file in the project root:
# --- API KEYS ---
GOOGLE_API_KEY=your_gemini_api_key_here
# --- DATABASE CONFIG ---
DATABASE_URL=sqlite:///./data/clinical_trials.db
# --- VECTOR DB CONFIG ---
CHROMA_PERSIST_DIR=./data/chroma_db
EMBEDDING_MODEL_NAME=sentence-transformers/all-MiniLM-L6-v2
# --- PROJECT SETTINGS ---
PROJECT_NAME=Clinical Insight Agent
VERSION=1.0.0
LOG_DIR=./data/raw_logs
β οΈ Important: ReplaceGOOGLE_API_KEYwith your actual Gemini API key.
Automated scripts are provided for one-click setup:
-
Windows: Double-click
run_windows.bat -
Linux / macOS:
./run_linux_mac.sh
These scripts will:
- Create a virtual environment
- Install dependencies
- Launch backend & frontend
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtpython -m scripts.bulk_ingestuvicorn backend.main:app --reloadstreamlit run frontend/app.py