Architecture
Retrieval-augmented eligibility, not a chatbot over PDFs.
Python reference engine in /engine. The production web path is this Next.js service: same parser, same ranker, optional live CT.gov merge.
LangChain-style chain
parse → embed → retrieve → adjudicate → generate
Vector store
pgvector cosine over protocol eligibility
Generator
criterion-level rationale + CT.gov citations
1. Unstructured ingest
Clinical notes arrive as free text — H&P, pathology, infusion summaries. No FHIR required for the demo path. Token counts and section cues are retained for citation.
2. Clinical NER + ICD-10
A lexicon-backed extractor pulls age, sex, stage, ECOG, labs, meds, and biomarkers, then maps diagnoses onto ICD-10. In production this slot is BioBERT / ClinicalBERT NER plus a rules layer for units.
3. Embedding
The phenotype is serialized into a clinical document and encoded. This demo uses a synonym-expanded lexical encoder drop-in compatible with sentence-transformers BioBERT. Vectors are L2-normalized for cosine search.
4. pgvector retrieval
Protocol eligibility text is pre-embedded. Approximate nearest neighbor search returns the top-k trials. Live ClinicalTrials.gov recruiting studies for the primary condition are merged into the same index at query time.
5. Inclusion / exclusion adjudication
Each structured criterion is evaluated against the phenotype: numeric bounds, biomarker membership, hard flags (pregnancy, CNS mets). Unknowns are not treated as fails.
6. RAG report
The ranked list cites the retrieved eligibility clauses, match evidence, and NCT identifiers so medical affairs can audit why a patient hit a protocol.
Stack
Python · BioBERT-compatible encoder · LangChain-style orchestration · pgvector · React / Next.js · ClinicalTrials.gov API v2. Optional SpaceXAI (xAI) Grok pass for narrative rationales when XAI_API_KEY is set.
Run it on a note