NG12 Cancer Risk Assessor
A clinical decision support system that uses RAG to assess cancer risk based on NICE NG12 guidelines.
Overview
This application ingests the NICE NG12 PDF (Suspected Cancer: Recognition and Referral), parses it into structured chunks, stores them in ChromaDB vector collections, and provides two AI-powered interfaces:
Part 1 — Patient Assessment: Given a patient's clinical data (age, symptoms, smoking history, gender), the system retrieves relevant guideline passages and uses Gemini 2.0 Flash to assess cancer risk, producing structured recommendations with citations.
Part 2 — Conversational Chat: A multi-turn Q&A interface where clinicians can ask questions about NG12 guidelines. Features dual guardrails (input classification + output quality assessment), context-aware follow-up handling, and grounded answers with citations.
Tech Stack
Quick Start
1. Configure credentials
2a. Run with Docker (recommended)
2b. Run locally
Then open http://localhost:8000
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /assess/patients | List all test patients for quick-select |
| POST | /assess/{patient_id} | Run clinical risk assessment for a patient |
| POST | /chat | Send a chat message (session_id, message) |
| GET | /chat/history/{session_id} | Retrieve conversation history |
| DELETE | /chat/history/{session_id} | Clear conversation history |
| GET | /admin/stats | ChromaDB collection statistics |
| GET | /admin/chunks | Browse chunks with filters & pagination |
| POST | /admin/refresh | Re-ingest PDF and rebuild collections |
Project Structure
Prompt Files
app/prompts/assessment.py — Part 1: Clinical Decision Support prompts.
Contains the system and user prompts used by the assessment workflow (/assess/{patient_id})
to instruct Gemini on how to evaluate patient data against NG12 guideline passages and return structured JSON results.
app/prompts/chat.py — Part 2: Conversational Chat prompts.
Contains the system and user prompts for the chat workflow (/chat),
including query rewriting, qualification, refusal templates, and citation formatting helpers.
ChromaDB Collections
| Collection | Contents | Purpose | Query Method |
|---|---|---|---|
ng12_canonical | rule_canonical | Verbatim PDF text for citation display | ID-based lookup |
ng12_guidelines | rule_search | Template-enriched text with synonym expansion for better vector retrieval | Vector similarity (filtered by doc_type=rule_search) |
ng12_guidelines | symptom_index | Symptom-to-cancer mapping with cross-references back to Part A rules | Vector similarity (filtered by doc_type=symptom_index) |