You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: WRITEUP.md
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,9 @@ Zestic AI partner and builder of Terraphim.
8
8
Background in distributed systems (Rust, async), complex systems, and knowledge graph engineering. Built the full pipeline: entity extraction, knowledge graph, multi-agent orchestration, MedGemma integration, evaluation harness, and edge deployment config.
9
9
Solo submission.
10
10
11
+
**Why Terraphim Embeddings and Knowledge Graph**
12
+
In my previous medical pipeline - The Pattern, platinum winner of $100K "Build on Redis" Hackathon at RedisConf 2021, I built an engineering marvel: with inference on CPU under 2 ms for QA-large-bert uncased model before NVIDIA Ampere architecture was released, yet while I was testing it I always thought: "If my doctor is going to be using my system, I don't want to be the patient". For the past 5 years, I have been building graph embeddings, which have enabled me to achieve 100% accuracy and grounding in medical industry knowledge. And with the industry awakening to the fact that Transformer architecture has its own limitations, Terraphim or terraphim-like graph embeddings can be a new type of tokeniser that will drive new large and small language models.
13
+
11
14
## Problem statement
12
15
13
16
### The Problem: LLMs Hallucinate Dangerous Drug Recommendations
1.**Medical training complements structured knowledge.** MedGemma's parametric knowledge handles clinical reasoning and natural language generation, while the KG provides hard constraints (drug-gene interactions, contraindications, trial evidence). Neither alone is sufficient.
### System 1 + System 2: Why This Architecture Works
68
73
69
-
This pipeline embodies the dual-process model from cognitive science. MedGemma operates as **System 1**— a fast system, intuitive, pattern-matching. It has absorbed millions of clinical documents during training and produces fluent, plausible-sounding recommendations in seconds. Like a clinician's trained intuition, it is usually directionally correct, but prone to confident errors: hallucinating a 10x dose (800mg vs 80mg), suggesting a drug outside the patient's mutation profile, or hedging with vague class-level recommendations ("consider EGFR inhibitor") instead of actionable specifics.
74
+
This pipeline embodies the dual-process model from cognitive science. MedGemma operates as **System 1**— a fast, intuitive, pattern-matching system. It has absorbed millions of clinical documents during training and produces fluent, plausible-sounding recommendations in seconds. Like a clinician's trained intuition, it is usually directionally correct, but prone to confident errors: hallucinating a 10x dose (800mg vs 80mg), suggesting a drug outside the patient's mutation profile, or hedging with vague class-level recommendations ("consider EGFR inhibitor") instead of actionable specifics.
70
75
71
-
The Terraphim knowledge graph operates as **System 2**— slow, deliberate, evidence-based reasoning. Entity extraction with LeftmostLongest matching grounds the clinical text to precise SNOMED CT concepts. The typed graph (27 node types, 65 edge types) traces explicit evidence paths: Drug->Treats->Disease->HasVariant->Gene->CitedIn->Trial. PGx validation checks drug-gene interactions against CPIC guidelines. The safety gate verifies every recommendation against the validated treatment subgraph before it is sent to the clinician.
76
+
The Terraphim knowledge graph operates as **System 2**— slow, deliberate, evidence-based reasoning. Entity extraction with LeftmostLongest matching grounds the clinical text to precise SNOMED CT concepts. The typed graph (27 node types, 65 edge types) traces explicit evidence paths: Drug->Treats->Disease->HasVariant->Gene->CitedIn->Trial. PGx validation checks drug-gene interactions against CPIC guidelines. The safety gate verifies every recommendation against the validated treatment subgraph before sending it to the clinician.
72
77
73
78
Neither system alone is sufficient. System 1 (MedGemma) without System 2 produces hallucinations that look authoritative. System 2 (KG) without System 1 can only retrieve explicitly encoded information -- it cannot reason about novel combinations or generate natural-language explanations. The combination is greater than either part: MedGemma generates candidate recommendations from its vast parametric knowledge, and the knowledge graph validates, constrains, and grounds them in traceable clinical evidence. The result is a system that thinks fast and checks carefully -- the same cognitive architecture that makes expert clinicians effective, implemented as a reproducible, auditable pipeline.
74
79
@@ -108,7 +113,7 @@ Terraphim uses **symbolic graph embeddings** rather than vector embeddings for c
108
113
109
114
**Demonstrated safety gate behaviour:** During real inference, MedGemma recommended "Pembrolizumab 200mg IV every 3 weeks" for an EGFR L858R+ NSCLC patient. The knowledge graph safety gate correctly **blocked this recommendation** -- Pembrolizumab (a PD-1 checkpoint inhibitor) is not in the validated EGFR-NSCLC treatment subgraph. The KG instead grounds the recommendation to Osimertinib per the FLAURA trial. This is not a failure mode -- it is the system working as designed. Across 36 real inference calls (18 CPU + 18 GPU), the safety gate maintained 100% detection of ungrounded recommendations while passing all clinically appropriate ones.
110
115
111
-
The `find_similar()` function enables clinical decision support beyond direct lookups: querying "what is similar to NSCLC?" returns SCLC (high similarity -- sibling lung cancers sharing treatment pathways) over breast cancer (lower similarity -- different organ, different treatment graph). This graph-structural similarity is impossible to replicate reliably with dense embeddings trained on general medical text.
116
+
The `find_similar()` function enables clinical decision support beyond direct lookups: querying "what is similar to NSCLC?" returns SCLC (high similarity -- sibling lung cancers sharing treatment pathways) over breast cancer (lower similarity -- different organ, different treatment graph). This graph-structural similarity cannot be reliably replicated with dense embeddings trained on general medical text.
112
117
113
118
**Built on the terraphim-ai crate ecosystem.** The graph embeddings are not a competition-specific prototype -- they are part of [terraphim-ai](https://github.com/terraphim/terraphim-ai), a production Rust library for knowledge graph-powered semantic search. Two crates are load-bearing in every end-to-end demo:
114
119
@@ -179,7 +184,7 @@ Live mode verified with 8 Playwright e2e tests covering:
**11 Rust crates, 543+ tests, 0 failures, 9 Playwright e2e tests (8 functional + 1 video recording).** The system is implemented in Rust for performance-critical components (entity extraction, KG queries, PGx validation all <1ms) with MedGemma inference via Vertex AI (cloud) or GGUF quantized model (edge). The API server (`terraphim-api`) uses Axum with shared state to serve REST endpoints, WebSocket streaming, and the interactive demo UI.
187
+
**11 Rust crates, 543+ tests, 0 failures, 9 Playwright e2e tests (8 functional + 1 video recording).** The system is implemented in Rust for performance-critical components (entity extraction, KG queries, PGx validation, all <1ms) with MedGemma inference via Vertex AI (cloud) or GGUF quantised model (edge). The API server (`terraphim-api`) uses Axum with shared state to serve REST endpoints, WebSocket streaming, and the interactive demo UI.
0 commit comments