<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Standout Systems by Teodora: The Responsible AI Clinic]]></title><description><![CDATA[The Responsible AI Clinic covers practical, end-to-end AI/ML for healthcare - how to design, evaluate, and deploy models responsibly in real clinical workflows. Expect hands-on builds, clinical-grade evaluation checklists, and safety/ethics guardrails you can reuse.]]></description><link>https://teodoracoach.substack.com/s/the-responsible-ai-clinic</link><image><url>https://substackcdn.com/image/fetch/$s_!SPkR!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea332445-8e4c-465e-af9c-2a97c29d2b6e_796x796.png</url><title>Standout Systems by Teodora: The Responsible AI Clinic</title><link>https://teodoracoach.substack.com/s/the-responsible-ai-clinic</link></image><generator>Substack</generator><lastBuildDate>Wed, 15 Apr 2026 00:58:33 GMT</lastBuildDate><atom:link href="https://teodoracoach.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Teodora Szasz]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[dora@teodora.coach]]></webMaster><itunes:owner><itunes:email><![CDATA[dora@teodora.coach]]></itunes:email><itunes:name><![CDATA[Dr Teodora Szasz]]></itunes:name></itunes:owner><itunes:author><![CDATA[Dr Teodora Szasz]]></itunes:author><googleplay:owner><![CDATA[dora@teodora.coach]]></googleplay:owner><googleplay:email><![CDATA[dora@teodora.coach]]></googleplay:email><googleplay:author><![CDATA[Dr Teodora Szasz]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Day 35: THE CAPSTONE - Production Clinical Decision Support Agent with Full Evaluation]]></title><description><![CDATA[RAG for Healthcare | Day 35 of 35 | PREMIUM (Paid Subscribers Only)]]></description><link>https://teodoracoach.substack.com/p/day-35-the-capstone-production-clinical</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-35-the-capstone-production-clinical</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Sat, 11 Apr 2026 03:33:47 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!JxVl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>This Is It.</h2><p><strong>35 days. 5 build projects. </strong><br>Every concept in RAG: from &#8220;what is an embedding&#8221; to self-correcting agentic systems with hallucination guards.</p><p>Today we put <strong>everything</strong> into one system.</p><p>Not a demo. Not a tutorial exercise. A production-pattern clinical decision support agent that ingests multi-source clinical data, routes queries through a LangGraph state machine, retrieves with hybrid search and reranking logic, generates cited answers with confidence scores, self-corrects when retrieval is insufficient, logs every decision for audit, and <strong>evaluates itself</strong> with RAGAS metrics.</p><p>If you have followed this series, you already understand every component. Today you see them work together - the way a real clinical AI system operates.</p><p><strong>This notebook is your portfolio piece.</strong> It demonstrates mastery of the most in-demand AI skill in healthcare. It&#8217;s the project you show in job interviews, present to your CMIO, or use as the foundation for your institution&#8217;s clinical AI initiative.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JxVl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JxVl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png 424w, https://substackcdn.com/image/fetch/$s_!JxVl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png 848w, https://substackcdn.com/image/fetch/$s_!JxVl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png 1272w, https://substackcdn.com/image/fetch/$s_!JxVl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JxVl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png" width="1456" height="977" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:977,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:345312,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193850946?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JxVl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png 424w, https://substackcdn.com/image/fetch/$s_!JxVl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png 848w, https://substackcdn.com/image/fetch/$s_!JxVl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png 1272w, https://substackcdn.com/image/fetch/$s_!JxVl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea254985-942b-49da-83c0-5e7c4467b870_1594x1070.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>What Makes This Different From Every Previous Build Project</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kVXk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kVXk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png 424w, https://substackcdn.com/image/fetch/$s_!kVXk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png 848w, https://substackcdn.com/image/fetch/$s_!kVXk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png 1272w, https://substackcdn.com/image/fetch/$s_!kVXk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kVXk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png" width="530" height="256.36722606120435" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/de89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:490,&quot;width&quot;:1013,&quot;resizeWidth&quot;:530,&quot;bytes&quot;:831858,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193850946?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1009dbd9-5c83-4bdb-a988-99982a879521_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kVXk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png 424w, https://substackcdn.com/image/fetch/$s_!kVXk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png 848w, https://substackcdn.com/image/fetch/$s_!kVXk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png 1272w, https://substackcdn.com/image/fetch/$s_!kVXk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde89f24e-b7b8-46dd-9cef-a6df8eed9cc5_1013x490.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Every row shows a capability that was introduced at some point in the series. Day 35 combines <strong>all of them</strong>.</p><div><hr></div><h2>The Architecture: A Multi-Agent Clinical System</h2><p><strong>A paid subscriber recently asked a great question: <br><br></strong><em><strong>&#8220;How do multi-agent systems actually work in practice? I want to see agents with different roles communicating with each other.&#8221;</strong></em></p><p><strong>This capstone answers that question directly.</strong></p><p>The system has <strong>five specialized agents</strong>: each with a specific role, specific tool access, and specific expertise - orchestrated by a central LangGraph state machine:</p><h3>Agent 1: The Triage Agent</h3><p><strong>Role:</strong> Classify incoming queries:</p><ul><li><p>Is this clinical? </p></li><li><p>Which domain does it belong to: heart failure, renal, pharmacology, electrolytes? </p></li></ul><p><strong>Tools:</strong> LLM classifier with clinical taxonomy. </p><p><strong>Analogy:</strong> The ED triage nurse who assesses acuity and routes to the right department.</p><h3>Agent 2: The Retrieval Agent</h3><p><strong>Role:</strong> Search the right knowledge sources based on the triage classification. </p><ul><li><p>Execute hybrid retrieval (semantic + keyword). </p></li><li><p>Apply metadata filters. </p></li></ul><p><strong>Tools:</strong> Multiple FAISS indices, BM25 retriever, metadata filter engine. </p><p><strong>Analogy:</strong> The medical librarian who knows exactly which shelf, which book, which chapter has the answer.</p><h3>Agent 3: The Grading Agent</h3><p><strong>Role:</strong> Evaluate retrieved documents for relevance. </p><ul><li><p>Decide: proceed to generation, or rewrite the query and re-retrieve? </p></li></ul><p><strong>Tools:</strong> LLM grader with clinical relevance criteria. </p><p><strong>Analogy:</strong> The senior resident who reviews the literature search before it reaches the attending. </p><p><em>&#8220;Did you actually find the renal dosing data, or just the general heart failure guideline?&#8221;</em></p><h3>Agent 4: The Generation Agent</h3><p><strong>Role:</strong> Synthesize a cited, confidence-scored clinical answer from the retrieved evidence. </p><ul><li><p>Apply the production system prompt with citation rules, safety caveats, and &#8220;I don&#8217;t know&#8221; behavior. </p></li></ul><p><strong>Tools:</strong> LLM with clinical system prompt, confidence scorer. </p><p><strong>Analogy:</strong> The consulting physician who reads the evidence and writes the recommendation.</p><h3>Agent 5: The Evaluation Agent</h3><p><strong>Role:</strong> Verify that the generated answer is grounded in the retrieved documents. Score faithfulness. Flag hallucinations. Run RAGAS metrics on demand. </p><p><strong>Tools:</strong> LLM fact-checker, RAGAS evaluation suite. </p><p><strong>Analogy:</strong> The quality assurance pharmacist who double-checks every prescription against the reference before it reaches the patient.</p><h3>How They Communicate</h3><p>Here&#8217;s the key insight most people miss about multi-agent systems: <strong>agents don&#8217;t chat freely.</strong> They share state through a structured, typed state dictionary - the same <code>ClinicalAgentState</code> from <a href="https://teodoracoach.substack.com/p/day-33-building-an-agentic-rag-with">Day 33</a>, now expanded with evaluation fields.<br></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cvxN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cvxN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png 424w, https://substackcdn.com/image/fetch/$s_!cvxN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png 848w, https://substackcdn.com/image/fetch/$s_!cvxN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png 1272w, https://substackcdn.com/image/fetch/$s_!cvxN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cvxN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png" width="307" height="510" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:510,&quot;width&quot;:307,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:286466,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193850946?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9cfcb748-3900-4a26-a669-19829d7a4c57_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cvxN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png 424w, https://substackcdn.com/image/fetch/$s_!cvxN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png 848w, https://substackcdn.com/image/fetch/$s_!cvxN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png 1272w, https://substackcdn.com/image/fetch/$s_!cvxN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c1a0a46-8d13-48d8-bc18-8fe011b4b03a_307x510.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The <strong>central orchestrator</strong> is the LangGraph state machine itself: it routes between agents based on conditional edges. <br><br>No agent decides independently what to do next. The graph decides. This is what makes the system reliable: <strong>the routing logic is explicit, testable, and auditable</strong>.</p><p><strong>Context passing is everything.</strong> If the Evaluation Agent doesn&#8217;t receive the exact documents the Generation Agent used, it can&#8217;t verify grounding. The typed state guarantees every agent has access to the complete context: like every clinician working from the same patient chart.</p><div><hr></div><h2>The RAGAS Evaluation Pipeline</h2><p>The capstone includes a complete evaluation pipeline that you can run on demand or schedule nightly:</p><p><strong>Step 1:</strong> Define test queries with expected answers and expected source documents (the test set from <a href="https://teodoracoach.substack.com/p/day-34-evaluating-your-rag-with-ragas">Day 34</a>).</p>
      <p>
          <a href="https://teodoracoach.substack.com/p/day-35-the-capstone-production-clinical">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 34: Evaluating Your RAG with RAGAS - The Only Metrics That Actually Matter]]></title><description><![CDATA[RAG for Healthcare | Day 34 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-34-evaluating-your-rag-with-ragas</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-34-evaluating-your-rag-with-ragas</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Fri, 10 Apr 2026 02:59:40 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!P_CI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You have built five types of RAG systems across this series - standard, production, multi-source, graph-powered, and agentic. Each one generates confident, well-structured clinical answers.</p><p>But here&#8217;s the question nobody wants to ask: <strong>how do you know they are correct?</strong></p><p>A RAG system that sounds right and <em>is</em> right are two very different things. </p><p><strong>In healthcare, the gap between them is where patients get hurt. </strong></p><p>Today you learn how to measure it.</p><div><hr></div><h2>The Problem with Eyeballing</h2><p>Most RAG developers evaluate their systems by reading a few answers and thinking: <em>&#8220;That looks good.&#8221;</em> This is like a pharmaceutical company testing a drug by having the CEO take it once and saying <em>&#8220;I feel fine.&#8221;</em></p><p>It&#8217;s not evaluation. It&#8217;s hope.</p><p>Real evaluation requires:</p><ul><li><p><strong>Multiple test queries</strong> covering easy, hard, and edge cases</p></li><li><p><strong>Quantitative metrics</strong> that produce numbers, not feelings</p></li><li><p><strong>Specific diagnostics</strong> that tell you <em>which part</em> of the pipeline is failing</p></li></ul><p>RAGAS (Retrieval Augmented Generation Assessment Suite) gives you all three.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2>The Five Metrics That Matter</h2><p>RAGAS provides a toolkit of metrics. Five are essential for healthcare RAG. Each measures a different part of the pipeline.</p><h3>1. Context Precision: Is the retriever finding the right documents?</h3><p><strong>What it measures:</strong> Of the chunks your retriever returned, how many are actually relevant to the query?</p><p><strong>The analogy:</strong> You ask the medical librarian for articles about warfarin dosing in renal impairment. They return 5 articles. Context precision asks: how many of those 5 are actually about warfarin dosing in renal impairment? If 4 of 5 are relevant, precision is 0.80. If only 2 are relevant and the other 3 are about general anticoagulation, precision is 0.40.</p><p><strong>Interpretation:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KKxf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KKxf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png 424w, https://substackcdn.com/image/fetch/$s_!KKxf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png 848w, https://substackcdn.com/image/fetch/$s_!KKxf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png 1272w, https://substackcdn.com/image/fetch/$s_!KKxf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KKxf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png" width="498" height="244.11764705882354" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:475,&quot;width&quot;:969,&quot;resizeWidth&quot;:498,&quot;bytes&quot;:712222,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193754289?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F777f5c6a-cf13-4443-97f9-6a8dedd3ac78_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KKxf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png 424w, https://substackcdn.com/image/fetch/$s_!KKxf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png 848w, https://substackcdn.com/image/fetch/$s_!KKxf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png 1272w, https://substackcdn.com/image/fetch/$s_!KKxf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92bbc1cc-e4ad-4bd6-bd9a-70b5a5e8b280_969x475.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Clinical priority:</strong> Medium. Important for efficiency, but downstream metrics matter more for patient safety.</p><h3>2. Context Recall: Is the retriever finding ALL the right documents?</h3><p><strong>What it measures:</strong> Of all the documents that <em>should</em> have been retrieved, how many did the retriever actually find?</p><p><strong>The analogy:</strong> There are 3 guideline sections relevant to warfarin renal dosing in your knowledge base. The retriever found 2 of them. Context recall is 0.67. It missed one &#8212; and that missing section might contain the critical dose adjustment.</p><p><strong>Interpretation:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!P_CI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!P_CI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png 424w, https://substackcdn.com/image/fetch/$s_!P_CI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png 848w, https://substackcdn.com/image/fetch/$s_!P_CI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png 1272w, https://substackcdn.com/image/fetch/$s_!P_CI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!P_CI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png" width="590" height="303.1672203765227" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:464,&quot;width&quot;:903,&quot;resizeWidth&quot;:590,&quot;bytes&quot;:835264,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193754289?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50d7dead-591d-4333-870c-7b48476363d5_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!P_CI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png 424w, https://substackcdn.com/image/fetch/$s_!P_CI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png 848w, https://substackcdn.com/image/fetch/$s_!P_CI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png 1272w, https://substackcdn.com/image/fetch/$s_!P_CI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82494f66-a20a-4bcf-8711-78692393b5b7_903x464.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The precision-recall tradeoff:</strong> High precision with low recall means you&#8217;re finding good documents but missing important ones. High recall with low precision means you&#8217;re finding everything but burying it in noise. The goal is both above 0.80.</p><p><strong>Clinical priority:</strong> High. Missing a critical guideline section is a patient safety issue.</p><h3>3. Faithfulness: Is the answer grounded in the retrieved context?</h3><p><strong>What it measures:</strong> Of all the claims in the generated answer, how many are supported by the retrieved documents? This is the hallucination detector.</p><p><strong>The analogy:</strong> The LLM generates an answer with 10 clinical claims. RAGAS checks each one against the retrieved context. 8 claims are directly supported by the documents. 2 claims were added from the LLM&#8217;s training data: fabricated or unsourced. Faithfulness score: 0.80.</p><p><strong>Interpretation:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NdnG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NdnG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png 424w, https://substackcdn.com/image/fetch/$s_!NdnG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png 848w, https://substackcdn.com/image/fetch/$s_!NdnG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png 1272w, https://substackcdn.com/image/fetch/$s_!NdnG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NdnG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png" width="512" height="264.49557522123894" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:467,&quot;width&quot;:904,&quot;resizeWidth&quot;:512,&quot;bytes&quot;:823144,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193754289?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a56bfe6-cf01-48dd-a847-645070456139_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!NdnG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png 424w, https://substackcdn.com/image/fetch/$s_!NdnG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png 848w, https://substackcdn.com/image/fetch/$s_!NdnG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png 1272w, https://substackcdn.com/image/fetch/$s_!NdnG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1da6a23a-3373-47e5-b41a-6f0e9cde6087_904x467.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Clinical priority: THE HIGHEST.</strong> <br><br>Faithfulness is the single most important metric for healthcare RAG. <br><br>A system that adds clinical claims from training data (a fabricated dose, an invented trial, a hallucinated contraindication) is actively dangerous. This is the metric your CMIO should see first.</p><h3>4. Factual Correctness: Is the answer actually true?</h3><p><strong>What it measures:</strong> Are the claims in the generated answer factually correct when compared against a ground truth reference?</p><p><strong>The analogy:</strong> The answer says &#8220;target INR for mechanical mitral valve is 2.5&#8211;3.5.&#8221; The ground truth reference confirms this is correct. <br>Factual correctness: &#10003;. <br>If the answer said &#8220;target INR is 2.0&#8211;3.0&#8221; (wrong - that&#8217;s for AFib, not mechanical valves), factual correctness catches it.</p><p><strong>How it differs from faithfulness:</strong> Faithfulness checks if the answer matches the <em>retrieved documents</em>. Factual correctness checks if the answer matches <em>reality</em>. An answer can be faithful to a bad document and still be factually wrong. An answer can be unfaithful (adding training data) and happen to be factually correct.</p><p><strong>Interpretation:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!he07!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!he07!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png 424w, https://substackcdn.com/image/fetch/$s_!he07!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png 848w, https://substackcdn.com/image/fetch/$s_!he07!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png 1272w, https://substackcdn.com/image/fetch/$s_!he07!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!he07!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png" width="558" height="287.3607103218646" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:464,&quot;width&quot;:901,&quot;resizeWidth&quot;:558,&quot;bytes&quot;:895115,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193754289?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2546ab8-68e6-422a-b811-dcacc2f5f8a8_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!he07!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png 424w, https://substackcdn.com/image/fetch/$s_!he07!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png 848w, https://substackcdn.com/image/fetch/$s_!he07!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png 1272w, https://substackcdn.com/image/fetch/$s_!he07!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62878fcb-8bc4-459a-b266-fd86d125aac1_901x464.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Clinical priority:</strong> Very high. Paired with faithfulness, these two metrics are non-negotiable.</p><h3>5. Response Relevancy: Does the answer address the question?</h3><p><strong>What it measures:</strong> How well does the generated answer address the specific question that was asked?</p><p><strong>The analogy:</strong> You ask about warfarin dosing in renal impairment. The answer discusses warfarin drug interactions extensively but barely mentions renal dosing. The information is correct and grounded - but it doesn&#8217;t answer your question. Response relevancy catches this mismatch.</p><p><strong>Interpretation:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EBG9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cceb288-0172-41c5-95f1-2746cb862160_903x462.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EBG9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cceb288-0172-41c5-95f1-2746cb862160_903x462.png 424w, https://substackcdn.com/image/fetch/$s_!EBG9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cceb288-0172-41c5-95f1-2746cb862160_903x462.png 848w, https://substackcdn.com/image/fetch/$s_!EBG9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cceb288-0172-41c5-95f1-2746cb862160_903x462.png 1272w, https://substackcdn.com/image/fetch/$s_!EBG9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cceb288-0172-41c5-95f1-2746cb862160_903x462.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!EBG9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cceb288-0172-41c5-95f1-2746cb862160_903x462.png" width="566" height="289.5813953488372" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8cceb288-0172-41c5-95f1-2746cb862160_903x462.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:462,&quot;width&quot;:903,&quot;resizeWidth&quot;:566,&quot;bytes&quot;:905539,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193754289?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9570bd-9522-4658-8297-228003662f4a_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!EBG9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cceb288-0172-41c5-95f1-2746cb862160_903x462.png 424w, https://substackcdn.com/image/fetch/$s_!EBG9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cceb288-0172-41c5-95f1-2746cb862160_903x462.png 848w, https://substackcdn.com/image/fetch/$s_!EBG9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cceb288-0172-41c5-95f1-2746cb862160_903x462.png 1272w, https://substackcdn.com/image/fetch/$s_!EBG9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cceb288-0172-41c5-95f1-2746cb862160_903x462.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Clinical priority:</strong> Medium. Important for usability, but less critical than faithfulness and factual correctness for safety.</p><div><hr></div><h2>The Healthcare Priority Stack</h2><p>Not all metrics are equal in clinical settings. Here&#8217;s how to prioritize:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!e87P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!e87P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png 424w, https://substackcdn.com/image/fetch/$s_!e87P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png 848w, https://substackcdn.com/image/fetch/$s_!e87P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png 1272w, https://substackcdn.com/image/fetch/$s_!e87P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!e87P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png" width="610" height="293.6542669584245" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:440,&quot;width&quot;:914,&quot;resizeWidth&quot;:610,&quot;bytes&quot;:615109,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193754289?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184f33ac-6943-4bec-a05e-991bd3bebb6a_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!e87P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png 424w, https://substackcdn.com/image/fetch/$s_!e87P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png 848w, https://substackcdn.com/image/fetch/$s_!e87P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png 1272w, https://substackcdn.com/image/fetch/$s_!e87P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F143dfae7-3b36-4af9-95c4-d386fe8cdc9e_914x440.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The rule:</strong> Faithfulness and factual correctness must be above threshold before you even look at the others. A system with 0.99 context precision but 0.60 faithfulness is dangerous - it finds the right documents but generates hallucinated answers from them.</p><div><hr></div><h2>Diagnosing Failures with RAGAS</h2><p>The power of RAGAS isn&#8217;t just the scores - it&#8217;s knowing <em>where</em> to fix problems:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7rRn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7rRn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png 424w, https://substackcdn.com/image/fetch/$s_!7rRn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png 848w, https://substackcdn.com/image/fetch/$s_!7rRn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png 1272w, https://substackcdn.com/image/fetch/$s_!7rRn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7rRn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png" width="954" height="452" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:452,&quot;width&quot;:954,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:787817,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193754289?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0c1f4fe-2d1a-477e-8786-f8699749f3be_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7rRn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png 424w, https://substackcdn.com/image/fetch/$s_!7rRn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png 848w, https://substackcdn.com/image/fetch/$s_!7rRn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png 1272w, https://substackcdn.com/image/fetch/$s_!7rRn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b9e9c3f-814e-4800-b725-08936f9f0142_954x452.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The last row is critical:</strong> If your system is faithfully quoting an outdated 2019 guideline, faithfulness will be high but factual correctness will be low. <br><strong>The fix isn&#8217;t in the RAG pipeline - it&#8217;s in the knowledge base.</strong> <br><br>Remove or update the outdated source documents. <br><br>This is <a href="https://teodoracoach.substack.com/p/day-13-why-bad-retrieval-bad-answers">Day 13</a>&#8217;s Failure Mode 4 (stale chunks) surfacing in evaluation.</p><div><hr></div><h2>Building Your Test Set</h2><p>RAGAS needs test data: queries, expected retrieved documents, and reference answers. For healthcare RAG:</p><p><strong>Start with 20&#8211;30 test queries</strong> covering:</p><ul><li><p>Simple factual questions (5&#8211;10): <em>&#8220;What is the target dose of carvedilol for HFrEF?&#8221;</em></p></li><li><p>Complex multi-factor questions (5&#8211;10): <em>&#8220;Should I start an MRA with eGFR 28 and K+ 4.9?&#8221;</em></p></li><li><p>Edge cases (5): Questions at the boundary of your knowledge base</p></li><li><p>Out-of-scope questions (3&#8211;5): Questions your system should decline to answer</p></li><li><p>Adversarial questions (2&#8211;3): Questions designed to trigger hallucination</p></li></ul><p><strong>Write reference answers</strong> for each query - the gold standard. For clinical RAG, have a clinician write or validate these references.</p><p><strong>Map expected source documents</strong> for each query - which chunks should the retriever find? This is what context precision and recall measure against.</p><p><strong>Run evaluation regularly.</strong> Not once. Every time you change the system prompt, update the knowledge base, swap the embedding model, or adjust retrieval parameters - re-evaluate. RAGAS catches regressions that eyeballing misses.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>RAGAS gives you five metrics that measure every part of your RAG pipeline: </strong></p><ul><li><p><strong>context precision (is the retriever finding the right documents?)</strong></p></li><li><p><strong>context recall (is it finding ALL of them?)</strong></p></li><li><p><strong>faithfulness (is the answer grounded in the evidence?) </strong></p></li><li><p><strong>factual correctness (is the answer actually true?) </strong></p></li><li><p><strong>and response relevancy (does it answer the question?)</strong></p></li></ul><p><strong>For healthcare, faithfulness and factual correctness are non-negotiable - target &#8805;0.95 and &#8805;0.90 respectively.</strong> Stop guessing. Start measuring.</p></blockquote><div><hr></div><h2>Coming Tomorrow: Day 35 (Premium Build Project: THE FINALE)</h2><p><strong>BUILD PROJECT: Production Clinical Decision Support Agent with Full Evaluation</strong></p><p><strong>Tomorrow is the capstone</strong>. Paid subscribers get the final build project:  a complete, agentic clinical decision support system with LangGraph routing, multi-source retrieval, confidence scoring, audit logging, AND a full RAGAS evaluation pipeline. Everything from 35 days, in one system. This is the project that demonstrates mastery of the most in-demand AI skill in healthcare.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare to get the Day 35 Capstone Project.</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Day 33: Building an Agentic RAG with LangGraph - The Step-by-Step Blueprint]]></title><description><![CDATA[RAG for Healthcare | Day 33 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-33-building-an-agentic-rag-with</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-33-building-an-agentic-rag-with</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Thu, 09 Apr 2026 05:52:18 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!D_yY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Yesterday you learned what agentic RAG <em>is</em>. Today you build one - and you will find the complete, runnable Google Colab notebook linked at the bottom of this article.</p><p>Here, I will explain the architecture, the reasoning behind every design decision, and the clinical logic that makes this system work. </p><p>The code implements exactly what you read below.</p><div><hr></div><h2>What We Are Building</h2><p>A clinical triage agent with <strong>five nodes</strong> and <strong>three conditional edges</strong> that mirrors how a senior clinician thinks through a complex case:</p><p><strong>Node 1 - Classify:</strong> Is this even a clinical question? A query like &#8220;what&#8217;s the weather&#8221; gets gated immediately - no retrieval, no generation, no wasted compute. A query about Entresto dosing passes through.</p><p><strong>Node 2 - Retrieve:</strong> Search the clinical knowledge base. For a multi-factor question like &#8220;72M with HFrEF, eGFR 25, K+ 5.2 - should I start Entresto?&#8221;, the retriever needs to surface heart failure GDMT guidelines, renal dosing adjustments, AND potassium management protocols.</p><p><strong>Node 3 - Grade Documents:</strong> An LLM evaluates the retrieved chunks: <em>&#8220;Do these documents actually contain enough information to answer the question?&#8221;</em> If yes, proceed to generation. If no, rewrite the query and search again. This is the self-correction loop - the senior resident who goes back to the chart when the first search didn&#8217;t find what the attending needs.</p><p><strong>Node 4 - Generate:</strong> Synthesize a cited clinical answer from the retrieved evidence. Same system prompt principles from <a href="https://teodoracoach.substack.com/p/day-8-the-system-prompt-teaching">Day 8</a> - answer only from context, cite sources, include safety caveats.</p><p><strong>Node 5 - Check Grounding:</strong> A separate LLM call verifies: <em>&#8220;Is every clinical claim in this answer actually supported by the retrieved documents?&#8221;</em> If the generator added a fabricated dose or an invented trial name, this node catches it and sends the flow back to regenerate. This is the hallucination guard.</p><p>Five nodes. Each does one thing well. The intelligence is in how they connect.</p><div><hr></div><h2>The Three Decisions That Make It Agentic</h2><p>Standard RAG is a straight line: </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pV8-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pV8-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png 424w, https://substackcdn.com/image/fetch/$s_!pV8-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png 848w, https://substackcdn.com/image/fetch/$s_!pV8-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png 1272w, https://substackcdn.com/image/fetch/$s_!pV8-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pV8-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png" width="496" height="164.21621621621622" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:294,&quot;width&quot;:888,&quot;resizeWidth&quot;:496,&quot;bytes&quot;:432172,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193654890?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd37c7fc5-d2ed-4f61-a7bb-aa7073144cfd_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pV8-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png 424w, https://substackcdn.com/image/fetch/$s_!pV8-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png 848w, https://substackcdn.com/image/fetch/$s_!pV8-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png 1272w, https://substackcdn.com/image/fetch/$s_!pV8-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ac549c7-ac8e-45d7-afc8-b8c77f736397_888x294.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Agentic RAG has <strong>branching points</strong> where the system decides what to do next.</p><h3>Decision 1: Is this clinical?</h3><p>After classification, the system routes: clinical queries go to retrieval, non-clinical queries get a polite redirect and exit. <br><br>This saves the retrieval + generation cost (~$0.01&#8211;0.03) for every irrelevant query - which matters at scale.</p><p><strong>The analogy:</strong> The triage nurse in the emergency department. Not every person who walks in needs the full workup. Some need directions to the pharmacy. The triage step prevents the expensive pipeline from running unnecessarily.<br></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HTqz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HTqz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png 424w, https://substackcdn.com/image/fetch/$s_!HTqz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png 848w, https://substackcdn.com/image/fetch/$s_!HTqz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png 1272w, https://substackcdn.com/image/fetch/$s_!HTqz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HTqz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png" width="1214" height="822" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:822,&quot;width&quot;:1214,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:165618,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193654890?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HTqz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png 424w, https://substackcdn.com/image/fetch/$s_!HTqz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png 848w, https://substackcdn.com/image/fetch/$s_!HTqz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png 1272w, https://substackcdn.com/image/fetch/$s_!HTqz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b818a2c-adfd-45ff-bace-41547df075ca_1214x822.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br></p><h3>Decision 2: Are the documents relevant?</h3><p>After grading, the system routes: relevant documents proceed to generation, irrelevant documents trigger a query rewrite and a second retrieval attempt. </p><p>If the second attempt also fails, the system generates from whatever it has - with appropriate caveats about insufficient evidence.</p><p><strong>The analogy:</strong> The attending asking the resident: &#8220;Did you actually find the renal dosing data, or just the general heart failure guideline?&#8221; If the resident didn&#8217;t find it, they don&#8217;t guess - they go back and look specifically for renal dosing.</p><p><strong>The safety cap:</strong> Maximum 2 retrieval attempts. Without this, a query that the knowledge base truly can&#8217;t answer would loop forever. After 2 attempts, the system generates honestly: <em>&#8220;The available guidelines do not contain sufficient information...&#8221;</em> - the same graceful failure from <a href="https://teodoracoach.substack.com/p/day-8-the-system-prompt-teaching">Day 8</a>, Rule 3.</p><h3>Decision 3: Is the answer grounded?</h3><p>After the grounding check, the system routes: grounded answers are returned to the user, ungrounded answers get regenerated. Again, maximum 2 generation attempts to prevent infinite loops.</p><p><strong>The analogy:</strong> The pharmacist who double-checks the prescription against the reference before it goes to the patient. If the dose doesn&#8217;t match the guideline, they don&#8217;t send it - they flag it for correction.</p><p><strong>Why this matters clinically:</strong> The generation step (Node 4) uses the system prompt to <em>request</em> grounded answers. The grounding check (Node 5) <em>verifies</em> that the request was followed. These are two separate defenses against hallucination - the instruction and the verification. Belt and suspenders. In clinical AI, redundant safety is a feature, not a waste.</p><div><hr></div><h2>The State: Shared Memory Across All Nodes</h2><p>Every node reads from and writes to a shared state - a typed dictionary with explicit fields: the query, whether it&#8217;s clinical, the retrieved documents, how many retrieval attempts have been made, whether docs were graded relevant, the generated answer, whether it&#8217;s grounded, and any rewritten queries.</p><p><strong>The analogy:</strong> The patient chart. The triage nurse writes the chief complaint. The lab tech adds the results. The attending writes the assessment. The pharmacist reviews the medications. Everyone works from the same chart - no information is lost between steps, and every subsequent step has the full picture.</p><p><strong>A key design choice:</strong> Retrieved documents <em>accumulate</em> across retrieval attempts. When the agent re-retrieves after a failed grade, the new documents get added to the existing ones. The agent builds evidence across iterations rather than throwing away its first search when it tries again.</p><div><hr></div><h2>The Query Rewriter: The Hidden Power Node</h2><p>When the grader says the retrieved documents aren&#8217;t relevant, the agent doesn&#8217;t just search again with the same query - it <strong>rewrites the query</strong> first.</p><p>The original query: <em>&#8220;72M with HFrEF, eGFR 25, K+ 5.2 - should I start Entresto?&#8221;</em></p><p>The rewritten query might be: <em>&#8220;sacubitril valsartan renal dose adjustment eGFR below 30 hyperkalemia potassium monitoring&#8221;</em></p><p>The rewriter strips the clinical narrative and extracts the specific medical terms that will match guideline content. This dramatically improves the second retrieval&#8217;s precision - the same technique a clinician uses when their first literature search is too broad.</p><div><hr></div><h2>Human-in-the-Loop: The Clinical Safety Gate</h2><p><a href="https://www.langchain.com/langgraph">LangGraph 2.0</a> supports <strong>interrupt gates</strong> - points where the workflow pauses and waits for human approval. For clinical applications, you can pause the agent after document grading and before generation, so a clinical pharmacist reviews the retrieved evidence before the system synthesizes a recommendation.</p><p>This is a one-line configuration change. The agent fetches and grades the documents, then stops. The pharmacist reviews, confirms the evidence is appropriate, and the workflow resumes. If the evidence is wrong, the pharmacist can modify the state and redirect.</p><p><strong>AI proposes. Human approves. System executes.</strong> This is the regulatory pattern that healthcare compliance teams require for clinical decision support.</p><div><hr></div><h2>Adapting the Blueprint</h2><p>The five-node structure is a template. Swap the knowledge base and node logic to build any clinical workflow:</p><p><strong>Drug interaction checker:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!H2YH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!H2YH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png 424w, https://substackcdn.com/image/fetch/$s_!H2YH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png 848w, https://substackcdn.com/image/fetch/$s_!H2YH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png 1272w, https://substackcdn.com/image/fetch/$s_!H2YH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!H2YH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png" width="712" height="227.86912065439674" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:313,&quot;width&quot;:978,&quot;resizeWidth&quot;:712,&quot;bytes&quot;:534148,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193654890?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff25ee132-837b-4de3-a6a9-d9cdf3a16869_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!H2YH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png 424w, https://substackcdn.com/image/fetch/$s_!H2YH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png 848w, https://substackcdn.com/image/fetch/$s_!H2YH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png 1272w, https://substackcdn.com/image/fetch/$s_!H2YH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b9e1ca3-925d-4e68-a119-0a269fd311f1_978x313.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Differential diagnosis agent:</strong> </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ivY4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ivY4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png 424w, https://substackcdn.com/image/fetch/$s_!ivY4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png 848w, https://substackcdn.com/image/fetch/$s_!ivY4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png 1272w, https://substackcdn.com/image/fetch/$s_!ivY4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ivY4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png" width="965" height="315" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:315,&quot;width&quot;:965,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:547392,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193654890?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed624f2-8733-4d01-aa3e-3a8ffd87c6c6_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ivY4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png 424w, https://substackcdn.com/image/fetch/$s_!ivY4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png 848w, https://substackcdn.com/image/fetch/$s_!ivY4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png 1272w, https://substackcdn.com/image/fetch/$s_!ivY4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d415c63-50ed-4823-88d5-1484f0208c8e_965x315.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Adverse event detector:</strong> </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aMk1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aMk1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png 424w, https://substackcdn.com/image/fetch/$s_!aMk1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png 848w, https://substackcdn.com/image/fetch/$s_!aMk1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png 1272w, https://substackcdn.com/image/fetch/$s_!aMk1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aMk1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png" width="952" height="362" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:362,&quot;width&quot;:952,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:624919,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193654890?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb058cec-2537-42fa-8488-5b40111b44b7_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!aMk1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png 424w, https://substackcdn.com/image/fetch/$s_!aMk1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png 848w, https://substackcdn.com/image/fetch/$s_!aMk1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png 1272w, https://substackcdn.com/image/fetch/$s_!aMk1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ab6f35a-e66a-404e-8dec-c6964419dc96_952x362.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Clinical trial matcher:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iN1g!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iN1g!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png 424w, https://substackcdn.com/image/fetch/$s_!iN1g!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png 848w, https://substackcdn.com/image/fetch/$s_!iN1g!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png 1272w, https://substackcdn.com/image/fetch/$s_!iN1g!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iN1g!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png" width="939" height="352" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:352,&quot;width&quot;:939,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:583707,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193654890?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7100f64-620f-45d8-8bfb-b58946b58235_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iN1g!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png 424w, https://substackcdn.com/image/fetch/$s_!iN1g!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png 848w, https://substackcdn.com/image/fetch/$s_!iN1g!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png 1272w, https://substackcdn.com/image/fetch/$s_!iN1g!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36ba760b-67cd-48d2-a927-513c16baaa50_939x352.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Same graph. Same conditional edges. Different nodes. That&#8217;s the power of the blueprint.</p><div><hr></div><h2>What to Watch in the Notebook</h2><p>When you run the seven test queries, pay attention to:</p><p><strong>Query 1 (Entresto + eGFR 25 + K+ 5.2):</strong> Does the agent retrieve from ALL three domains - HF guidelines, renal dosing, and potassium management? Does the answer include the specific eGFR threshold for Entresto (&#8805;20) and the potassium monitoring requirement?</p><p><strong>Query 3 (K+ 5.8 emergency):</strong> Does the grading step recognize this as urgent? Does the answer include the immediate management steps (hold MRA, hold ARNi, consider IV calcium)?</p><p><strong>Query 6 (weather - non-clinical):</strong> Does the classifier gate this immediately? The agent should exit after one LLM call, not run the full pipeline.</p><p><strong>Query 7 (pneumonia - out of scope):</strong> The knowledge base covers heart failure, not pneumonia. Does the grading step recognize the retrieved docs are irrelevant? Does the rewrite help? Ultimately, does the system say &#8220;insufficient information&#8221; rather than hallucinating?</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>An agentic clinical RAG system has five nodes: classify, retrieve, grade, generate, check. And three conditional edges (is it clinical? are docs relevant? is the answer grounded?). <br><br>LangGraph 2.0 wires them into a self-correcting state machine with safety caps on loops and optional human-in-the-loop gates. <br><br>The blueprint is reusable: swap the knowledge base and node logic for any clinical workflow.</strong></p></blockquote><div><hr></div><h2>The Notebook</h2><p><strong><a href="https://colab.research.google.com/drive/1q-QPbUuV662sB1XjocmynKlv2_ExZuVQ?usp=sharing">Google Colab Notebook: Day 33 - Agentic RAG with LangGraph</a></strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!D_yY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D_yY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png 424w, https://substackcdn.com/image/fetch/$s_!D_yY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png 848w, https://substackcdn.com/image/fetch/$s_!D_yY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png 1272w, https://substackcdn.com/image/fetch/$s_!D_yY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D_yY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png" width="1202" height="1110" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1110,&quot;width&quot;:1202,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:338635,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193654890?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!D_yY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png 424w, https://substackcdn.com/image/fetch/$s_!D_yY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png 848w, https://substackcdn.com/image/fetch/$s_!D_yY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png 1272w, https://substackcdn.com/image/fetch/$s_!D_yY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16500a8b-286a-4561-8a22-def67639de0e_1202x1110.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div><hr></div><h2>Coming Tomorrow: Day 34</h2><p><strong>Evaluating Your RAG with RAGAS - The Only Metrics That Actually Matter</strong></p><p>You&#8217;ve built five types of RAG systems across this series. But how do you <em>know</em> if any of them work? <br><br>Tomorrow: RAGAS - the evaluation framework that measures faithfulness, factual correctness, context precision, and response relevancy. The metrics that tell you whether your system is trustworthy or just confident. This is what separates hobby projects from production healthcare AI.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare so you don&#8217;t miss Day 34.</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Day 32: Agentic RAG - When Your AI Decides What to Search]]></title><description><![CDATA[RAG for Healthcare | Day 32 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-32-agentic-rag-when-your-ai-decides</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-32-agentic-rag-when-your-ai-decides</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Tue, 07 Apr 2026 14:09:07 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!-5oi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>For 31 days, your RAG systems have followed orders. You ask a question, the retriever searches, the LLM answers. The human decides what to search. The pipeline obeys.</p><p>Today, the pipeline starts thinking for itself.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><h2>The Problem That Breaks Standard RAG</h2><p>A clinician asks: <em>&#8220;Should I start Entresto in this 72-year-old with HFrEF, eGFR 25, and potassium 5.2?&#8221;</em></p><p><strong>Clinical context:</strong> Entresto (sacubitril/valsartan) is an ARNi - one of the four pillars of guideline-directed therapy for HFrEF (Day 7). But this isn&#8217;t a simple drug question. The eGFR of 25 means the patient has CKD stage 4 - severe kidney impairment. The potassium of 5.2 is above normal (3.5&#8211;5.0 mEq/L), and Entresto can raise potassium further through its effect on the renin-angiotensin system. Three clinical domains collide: heart failure management, renal dosing, and electrolyte safety.</p><p>Your standard RAG system does one search: <em>&#8220;Entresto HFrEF eGFR 25 potassium 5.2.&#8221;</em> It retrieves the 5 most similar chunks. Maybe it gets a heart failure guideline chunk. Maybe a renal dosing chunk. Probably not a potassium monitoring protocol. The retrieval is a single shot - and for a multi-factor clinical question, a single shot isn&#8217;t enough.</p><p><strong>An agentic RAG system handles this differently:</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!PQs3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!PQs3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png 424w, https://substackcdn.com/image/fetch/$s_!PQs3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png 848w, https://substackcdn.com/image/fetch/$s_!PQs3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png 1272w, https://substackcdn.com/image/fetch/$s_!PQs3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!PQs3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png" width="588" height="286.0208768267223" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:466,&quot;width&quot;:958,&quot;resizeWidth&quot;:588,&quot;bytes&quot;:765515,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193420373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9945e9-78fd-46b8-8174-278ddd9aa75f_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!PQs3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png 424w, https://substackcdn.com/image/fetch/$s_!PQs3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png 848w, https://substackcdn.com/image/fetch/$s_!PQs3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png 1272w, https://substackcdn.com/image/fetch/$s_!PQs3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ed3673f-b150-4c6b-b2cc-24dfa19aa269_958x466.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Four separate retrievals. Each one triggered by what the agent <em>learned</em> from the previous retrieval. That&#8217;s what makes it agentic.</p><div><hr></div><h2>What Makes RAG &#8220;Agentic&#8221;</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hdIX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hdIX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png 424w, https://substackcdn.com/image/fetch/$s_!hdIX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png 848w, https://substackcdn.com/image/fetch/$s_!hdIX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png 1272w, https://substackcdn.com/image/fetch/$s_!hdIX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hdIX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png" width="993" height="336" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:336,&quot;width&quot;:993,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:673093,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193420373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F015566d0-8509-4f80-ad2d-9a00f9deb77f_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hdIX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png 424w, https://substackcdn.com/image/fetch/$s_!hdIX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png 848w, https://substackcdn.com/image/fetch/$s_!hdIX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png 1272w, https://substackcdn.com/image/fetch/$s_!hdIX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faee1baaa-e019-47c0-9259-b10de9fc98be_993x336.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Three capabilities make RAG agentic:</p><h3>1. Routing: Deciding WHERE to search</h3><p>The agent reads the query and routes it to the right knowledge source. A drug interaction question goes to the pharmacology index. A dosing question goes to the formulary. A guideline question goes to the clinical guidelines.</p><p><strong>The analogy:</strong> A hospital switchboard operator. <br>When a call comes in: &#8220;I need help with a medication question&#8221; - they don&#8217;t transfer you to every department. They listen, determine it&#8217;s a pharmacy question, and route you directly to the pharmacist. If you also mention a kidney concern, they conference in nephrology.</p><p>In our Entresto example, the agent recognizes three domains (heart failure, renal, electrolytes) and routes to each.</p><h3>2. Self-correction - Deciding IF the retrieval was good enough</h3><p>After retrieving chunks, the agent evaluates: <em>&#8220;Did I get what I need to answer this question?&#8221;</em></p><p>If the retrieved chunks don&#8217;t address the eGFR concern, the agent doesn&#8217;t just generate a partial answer - it <strong>searches again</strong> with a refined query specifically targeting renal dosing guidelines.</p><p><strong>The analogy:</strong> A resident presenting a case to the attending. The attending asks: &#8220;What&#8217;s the renal dosing?&#8221; The resident checks their notes. If the answer isn&#8217;t there, they don&#8217;t make something up - they go back to the chart, look it up, and return with the specific information. Self-correction is the &#8220;go back and look again&#8221; step.</p><h3>3. Multi-step reasoning - Deciding WHAT to do next</h3><p>Each step can trigger a different action: retrieve from a different source, re-query with a refined question, check for contradictions, or decide the answer is complete.</p><p><strong>The analogy:</strong> A clinical reasoning chain. The attending doesn&#8217;t think about a patient in one step. <br>They think: </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rlcg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rlcg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png 424w, https://substackcdn.com/image/fetch/$s_!rlcg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png 848w, https://substackcdn.com/image/fetch/$s_!rlcg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png 1272w, https://substackcdn.com/image/fetch/$s_!rlcg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rlcg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png" width="983" height="143" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:143,&quot;width&quot;:983,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:251932,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193420373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F696d557d-1de4-4d8e-90fd-f1e0664604e8_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rlcg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png 424w, https://substackcdn.com/image/fetch/$s_!rlcg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png 848w, https://substackcdn.com/image/fetch/$s_!rlcg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png 1272w, https://substackcdn.com/image/fetch/$s_!rlcg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe5b74fd-64a2-41a8-9209-d3ab730d349e_983x143.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Each step follows from the previous one. The next step depends on what was learned.</p><div><hr></div><h2>LangGraph: The Framework for Agentic RAG</h2><p><a href="https://www.langchain.com/langgraph">LangGraph 2.0</a> (released February 2026) is the framework that makes agentic RAG possible. It lets you build <strong>state machines</strong>: workflows where the system moves between states based on decisions. It&#8217;s MIT-licensed, free, and has become the dominant orchestration layer for production AI agents.</p><h3>The Mental Model: States and Edges</h3><p>A LangGraph workflow has:</p><ul><li><p><strong>States</strong>: typed snapshots of what the system knows at each point (the query, retrieved chunks, intermediate analyses)</p></li><li><p><strong>Nodes</strong>: actions the system can take (retrieve, analyze, generate, decide)</p></li><li><p><strong>Edges</strong>: transitions between nodes, including <strong>conditional edges</strong> where the next step depends on what happened</p></li><li><p><strong>Checkpoints</strong>: persistent state that survives failures and enables human-in-the-loop review</p></li><li><p><strong>Interrupt gates</strong>: points where the workflow can pause for human approval before proceeding (critical for clinical applications)</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Wreg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Wreg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png 424w, https://substackcdn.com/image/fetch/$s_!Wreg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png 848w, https://substackcdn.com/image/fetch/$s_!Wreg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png 1272w, https://substackcdn.com/image/fetch/$s_!Wreg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Wreg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png" width="497" height="437.5165354330709" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:635,&quot;resizeWidth&quot;:497,&quot;bytes&quot;:595050,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193420373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87fbbb02-637a-4a3e-99da-3d92fc9c0486_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Wreg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png 424w, https://substackcdn.com/image/fetch/$s_!Wreg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png 848w, https://substackcdn.com/image/fetch/$s_!Wreg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png 1272w, https://substackcdn.com/image/fetch/$s_!Wreg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbd928c9-549f-4832-88fb-a1e2cb74c6f2_635x559.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Two conditional edges make this agentic: the <strong>document grader</strong> that re-searches if retrieval is poor, and the <strong>hallucination checker</strong> that regenerates if the answer isn&#8217;t grounded in the retrieved documents. Both are LLM calls that evaluate the system&#8217;s own output - the &#8220;self-correction&#8221; that production agentic RAG requires.</p><h3>The Core Code Pattern (LangGraph 2.0)</h3><p>python</p><pre><code><code>from langgraph.graph import StateGraph, END
from typing import TypedDict, List, Annotated
from operator import add

class AgentState(TypedDict):
    query: str
    domains: List[str]
    retrieved_docs: Annotated[List[str], add]
    docs_relevant: bool
    answer: str
    answer_grounded: bool

def route_query(state):
    """LLM analyzes query and identifies required knowledge domains."""
    ...
    return {"domains": ["heart_failure", "renal_dosing", "electrolytes"]}

def retrieve(state):
    """Search the identified knowledge sources."""
    ...
    return {"retrieved_docs": results}

def grade_documents(state):
    """LLM evaluates: are the retrieved docs relevant to the query?"""
    ...
    return {"docs_relevant": True or False}

def generate(state):
    """Synthesize final answer from all retrieved content."""
    ...
    return {"answer": answer}

def check_hallucination(state):
    """LLM evaluates: is the answer grounded in the retrieved docs?"""
    ...
    return {"answer_grounded": True or False}

# Build the graph
workflow = StateGraph(AgentState)
workflow.add_node("route", route_query)
workflow.add_node("retrieve", retrieve)
workflow.add_node("grade", grade_documents)
workflow.add_node("generate", generate)
workflow.add_node("hallucination_check", check_hallucination)

workflow.set_entry_point("route")
workflow.add_edge("route", "retrieve")
workflow.add_edge("retrieve", "grade")

# Conditional: relevant docs? &#8594; generate. Irrelevant? &#8594; rewrite + retrieve again
workflow.add_conditional_edges(
    "grade",
    lambda state: "generate" if state["docs_relevant"] else "retrieve",
)

workflow.add_edge("generate", "hallucination_check")

# Conditional: grounded? &#8594; done. Not grounded? &#8594; regenerate
workflow.add_conditional_edges(
    "hallucination_check",
    lambda state: END if state["answer_grounded"] else "generate",
)

agent = workflow.compile()</code></code></pre><p>Two conditional edges: document grading and hallucination checking - are the lines that make this agentic. In a clinical context, these loops ensure the system doesn&#8217;t return irrelevant evidence or ungrounded claims.</p><div><hr></div><h2>Standard RAG vs. Agentic RAG</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-5oi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-5oi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png 424w, https://substackcdn.com/image/fetch/$s_!-5oi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png 848w, https://substackcdn.com/image/fetch/$s_!-5oi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png 1272w, https://substackcdn.com/image/fetch/$s_!-5oi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-5oi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png" width="672" height="332.23241590214064" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:485,&quot;width&quot;:981,&quot;resizeWidth&quot;:672,&quot;bytes&quot;:839337,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193420373?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69e8302a-9906-4d8a-9469-5afa9e1bf007_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-5oi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png 424w, https://substackcdn.com/image/fetch/$s_!-5oi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png 848w, https://substackcdn.com/image/fetch/$s_!-5oi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png 1272w, https://substackcdn.com/image/fetch/$s_!-5oi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F896810d8-1b7d-48d7-a678-a13c60e42329_981x485.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The practical rule:</strong> </p><ul><li><p>Use standard RAG for single-factor questions: &#8221;What is the dose of amoxicillin for CAP?&#8221;. </p></li><li><p>Use agentic RAG for multi-factor clinical scenarios where the answer requires information from multiple domains: &#8221;Should I start Entresto given this patient&#8217;s specific renal function and electrolytes?&#8221;</p></li></ul><p>Most production systems use <strong>both</strong>: standard RAG for the 80% of queries that are straightforward, with agentic RAG routing for the 20% that require multi-step reasoning. An initial classifier decides which path each query takes.</p><div><hr></div><h2>Why This Matters for Healthcare</h2><p>Clinical reasoning is inherently agentic. A physician doesn&#8217;t think in a single step. They gather information, identify concerns, seek additional data, reassess, and synthesize. The diagnostic process is a state machine - each finding triggers a new line of inquiry.</p><p>Standard RAG gives you a search engine. Agentic RAG gives you a <strong>clinical reasoning engine</strong> - one that mirrors how clinicians actually think through complex cases.</p><p><strong>Human-in-the-loop is native to LangGraph 2.0.</strong> You can set interrupt gates at any node: for example, pausing before the generation step so a clinical pharmacist can review the retrieved evidence before the system synthesizes a recommendation. </p><p>In healthcare, where autonomous AI recommendations carry patient safety implications, this isn&#8217;t a nice-to-have: it&#8217;s a regulatory expectation. <br><br>LangGraph makes it a one-line configuration: <code>workflow.compile(interrupt_before=["generate"])</code>.</p><p>The Entresto question isn&#8217;t hypothetical. Every hospitalist, cardiologist, and nephrologist faces multi-factor prescribing decisions daily. The AI system that handles these decisions needs the same multi-step reasoning capability that the clinician uses.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>Agentic RAG adds three capabilities to standard RAG: </strong></p><p><strong>(1) routing (choosing where to search), (2) self-correction (evaluating retrieval quality and retrying), (3) and multi-step reasoning (each step informed by the previous). <br><br>LangGraph implements this as a state machine with conditional edges. <br><br>Use standard RAG for simple queries and agentic RAG for complex, multi-factor clinical scenarios that require reasoning across multiple domains.</strong></p></blockquote><div><hr></div><h2>Coming Tomorrow: Day 33</h2><p><strong>Building an Agentic RAG with LangGraph: The Step-by-Step Blueprint</strong></p><p>Today was the concept and architecture. <br><br>Tomorrow you build it: a complete agentic clinical RAG system using LangGraph, with routing across three knowledge sources (guidelines, formulary, lab reference), self-correction when retrieval is insufficient, and multi-step synthesis. Full code.</p><div><hr></div><ul><li><p><strong>Subscribe to RAG for Healthcare so you don&#8217;t miss Day 33.</strong></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Day 31: The CLIP Model - Aligning Medical Images and Text Without Fine-Tuning]]></title><description><![CDATA[RAG for Healthcare | Day 31 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-31-the-clip-model-aligning-medical</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-31-the-clip-model-aligning-medical</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Tue, 07 Apr 2026 01:16:30 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!E6v-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Yesterday you built multimodal RAG using GPT-5.4 Vision as a bridge - image in, text description out, description gets embedded alongside your clinical text. It works. But every image costs $0.01&#8211;0.03 for the Vision API call, and you can&#8217;t do the reverse: upload an image and find matching text.</p><p><strong><a href="https://openai.com/index/clip/">CLIP</a> eliminates both limitations.</strong> It embeds images and text into the <strong>same vector space</strong> directly - no Vision API, no text description step, no per-image cost after the initial embedding. And it works both ways: text query &#8594; find matching images, OR image query &#8594; find matching text.</p><div><hr></div><h2>What CLIP Does (One Sentence)</h2><p>CLIP maps images and text into the same vector space so that an image of a chest X-ray with cardiomegaly and the text <em>&#8220;enlarged cardiac silhouette consistent with cardiomegaly&#8221;</em> end up as <strong>nearby vectors</strong> - even though one is pixels and the other is words.</p><p><strong>The analogy:</strong> Imagine a bilingual translator who can read both English and Mandarin and place every document on the same bookshelf by topic - regardless of language. CLIP is that translator, except the two &#8220;languages&#8221; are images and text. Once both are on the same shelf, you can search in either language and find results in both.</p><div><hr></div><h2>How CLIP Works (3 Minutes)</h2><p><a href="https://openai.com/index/clip/">CLIP (Contrastive Language-Image Pre-training, OpenAI 2021)</a> learns by looking at millions of image-text pairs and learning to match them.</p><h3>The Training Process</h3><p>Given a batch of image-text pairs (e.g., a chest X-ray paired with its radiology report):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Rxr1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Rxr1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png 424w, https://substackcdn.com/image/fetch/$s_!Rxr1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png 848w, https://substackcdn.com/image/fetch/$s_!Rxr1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png 1272w, https://substackcdn.com/image/fetch/$s_!Rxr1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Rxr1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png" width="958" height="448" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:448,&quot;width&quot;:958,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:764695,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193417740?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86b93d0e-cfba-42cb-9940-33fb96b70a3b_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Rxr1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png 424w, https://substackcdn.com/image/fetch/$s_!Rxr1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png 848w, https://substackcdn.com/image/fetch/$s_!Rxr1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png 1272w, https://substackcdn.com/image/fetch/$s_!Rxr1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1989aaaa-9b28-476d-a84e-a0a44e96a94b_958x448.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>After training on hundreds of millions of pairs, the model learns that &#8220;images showing cardiomegaly&#8221; and &#8220;text describing cardiomegaly&#8221; belong in the same region of vector space - without ever being told what cardiomegaly is.</p><p><strong>The analogy:</strong> A medical student who&#8217;s seen thousands of X-rays, each paired with the attending&#8217;s verbal description. After enough examples, they can look at a new X-ray and predict what the attending would say - or hear a description and picture what the X-ray looks like. CLIP learned the same association, at scale.</p><h3>Why &#8220;Contrastive&#8221;</h3><p>The training is called <em>contrastive</em> because the model learns by <strong>contrast</strong> - distinguishing correct pairs from incorrect ones. In a batch of 32,768 image-text pairs, each image has exactly one matching text. The model must identify the correct match out of 32,767 wrong ones. This forces it to learn precise, meaningful alignments.</p><div><hr></div><h2>General CLIP vs. Medical CLIP</h2><p>Standard CLIP was trained on internet image-text pairs: photos, illustrations, memes, product images. It understands &#8220;dog,&#8221; &#8220;sunset,&#8221; and &#8220;red car&#8221; excellently. It understands &#8220;pleural effusion&#8221; poorly.</p><p><strong><a href="https://arxiv.org/abs/2303.00915">BiomedCLIP</a></strong> (Microsoft, 2023) was trained on <strong>15 million biomedical figure-caption pairs</strong> from PubMed articles. It understands:</p><ul><li><p>Chest X-ray findings (consolidation, effusion, cardiomegaly)</p></li><li><p>Histopathology patterns (ductal carcinoma, glandular architecture)</p></li><li><p>Radiology modalities (CT, MRI, ultrasound appearances)</p></li><li><p>Clinical photographs (dermatological lesions, wound staging)</p></li></ul><p><strong><a href="https://aclanthology.org/2023.findings-eacl.88/">PubMedCLIP</a></strong> - trained on PubMed image-text pairs, another strong option for biomedical content.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!E6v-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!E6v-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png 424w, https://substackcdn.com/image/fetch/$s_!E6v-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png 848w, https://substackcdn.com/image/fetch/$s_!E6v-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png 1272w, https://substackcdn.com/image/fetch/$s_!E6v-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!E6v-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png" width="1220" height="524" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:524,&quot;width&quot;:1220,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:178156,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193417740?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!E6v-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png 424w, https://substackcdn.com/image/fetch/$s_!E6v-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png 848w, https://substackcdn.com/image/fetch/$s_!E6v-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png 1272w, https://substackcdn.com/image/fetch/$s_!E6v-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f2f31a5-4c3d-4afd-bd33-0fad198ffc31_1220x524.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The practical rule:</strong> For healthcare multimodal RAG, always use a biomedical CLIP variant. General CLIP will retrieve &#8220;images that look like medical images.&#8221; BiomedCLIP will retrieve &#8220;images showing the specific pathology you asked about.&#8221;</p><div><hr></div><h2>Cross-Modal Search in Code</h2><p>Here&#8217;s the core pattern - embed images and text with the same model, search across both:</p><p>python</p><pre><code><code>from open_clip import create_model_and_transforms, get_tokenizer
import torch
from PIL import Image

# Load BiomedCLIP
model, preprocess_train, preprocess_val = create_model_and_transforms(
    'hf-hub:microsoft/BiomedCLIP-PubMedBERT_256-vit_base_patch16_224'
)
tokenizer = get_tokenizer(
    'hf-hub:microsoft/BiomedCLIP-PubMedBERT_256-vit_base_patch16_224'
)
model.eval()

# - EMBED AN IMAGE &#9472;-
image = preprocess_val(Image.open("chest_xray.jpg")).unsqueeze(0)
with torch.no_grad():
    image_vector = model.encode_image(image)
    image_vector /= image_vector.norm(dim=-1, keepdim=True)  # Normalize

# - EMBED TEXT -
text = tokenizer(["cardiomegaly with pulmonary edema"])
with torch.no_grad():
    text_vector = model.encode_text(text)
    text_vector /= text_vector.norm(dim=-1, keepdim=True)  # Normalize

# - COMPUTE SIMILARITY -
similarity = (image_vector @ text_vector.T).item()
print(f"Image-text similarity: {similarity:.3f}")</code></code></pre><p>Both vectors live in the same space. Cosine similarity between them tells you how well the image matches the text - using the same math from <a href="https://teodoracoach.substack.com/p/day-15-cosine-similarity-deep-dive">Day 15</a>.</p><div><hr></div><h2>Three Search Patterns</h2><h3>Pattern 1: Text &#8594; Image (Find images matching a description)</h3><p><em>&#8220;Show me chest X-rays with bilateral pleural effusions&#8221;</em></p><p>Embed the query text, search against all image vectors, return the top matches.</p><p>python</p><pre><code><code>query_vector = model.encode_text(tokenizer(["bilateral pleural effusions"]))
similarities = query_vector @ all_image_vectors.T
top_matches = similarities.argsort(descending=True)[:5]</code></code></pre><p><strong>Clinical use:</strong> Teaching libraries, case-based learning, clinical reference.</p><h3>Pattern 2: Image &#8594; Text (Find descriptions matching an image)</h3><p>Upload an unknown X-ray, find the most relevant text descriptions or guideline sections.</p><p>python</p><pre><code><code>query_vector = model.encode_image(preprocess_val(unknown_xray).unsqueeze(0))
similarities = query_vector @ all_text_vectors.T
top_matches = similarities.argsort(descending=True)[:5]</code></code></pre><p><strong>Clinical use:</strong> &#8220;What does this look like?&#8221; Find similar cases and their descriptions.</p><h3>Pattern 3: Image &#8594; Image (Find visually similar cases)</h3><p>Upload an echo frame, find the most visually similar echo frames in your database.</p><p>python</p><pre><code><code>query_vector = model.encode_image(preprocess_val(new_echo).unsqueeze(0))
similarities = query_vector @ all_image_vectors.T
top_matches = similarities.argsort(descending=True)[:5]</code></code></pre><p><strong>Clinical use:</strong> &#8220;Find cases similar to this patient&#8217;s echo.&#8221; Powerful for rare findings where a clinician wants to see how similar cases were managed.</p><div><hr></div><h2>Day 30 (GPT Vision) vs. Day 31 (CLIP): When to Use Which</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u46r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u46r!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png 424w, https://substackcdn.com/image/fetch/$s_!u46r!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png 848w, https://substackcdn.com/image/fetch/$s_!u46r!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png 1272w, https://substackcdn.com/image/fetch/$s_!u46r!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u46r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png" width="991" height="453" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:453,&quot;width&quot;:991,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:766407,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193417740?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6055ba-ab2f-4d10-8edb-08e3548a3196_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!u46r!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png 424w, https://substackcdn.com/image/fetch/$s_!u46r!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png 848w, https://substackcdn.com/image/fetch/$s_!u46r!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png 1272w, https://substackcdn.com/image/fetch/$s_!u46r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc77c8184-e7b4-4826-8d39-8bc3977d940a_991x453.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The practical recommendation:</strong></p><ul><li><p><strong>&lt; 1,000 images, need rich descriptions:</strong> Use GPT-5.4 Vision (<a href="https://teodoracoach.substack.com/p/day-30-processing-medical-images">Day 30</a>). The descriptions add value for the LLM generation step.</p></li><li><p><strong>&gt; 1,000 images, need fast search:</strong> Use BiomedCLIP. No per-image API cost, native cross-modal search.</p></li><li><p><strong>PHI-containing images:</strong> Use BiomedCLIP. Everything stays local.</p></li><li><p><strong>Best of both:</strong> Embed with BiomedCLIP for search, generate descriptions with GPT-5.4 Vision only for the top retrieved results. Search is cheap and fast; descriptions are rich and expensive. Combine at the right layer.</p></li></ul><div><hr></div><h2>Limitations for Healthcare</h2><p><strong>Resolution matters.</strong> CLIP processes images at 224&#215;224 pixels. A subtle finding visible on a full-resolution DICOM (3000&#215;3000) may be lost after downscaling. For pathology whole-slide images, you&#8217;ll need to tile the slide and process each tile separately.</p><p><strong>Rare findings are underrepresented.</strong> BiomedCLIP was trained on PubMed figures: biased toward findings that get published. Rare conditions have fewer training examples and weaker representations.</p><p><strong>No spatial reasoning.</strong> CLIP knows &#8220;this image contains cardiomegaly&#8221; but can&#8217;t tell you &#8220;the cardiomegaly is predominantly left-sided&#8221; or &#8220;the effusion is in the right costophrenic angle.&#8221; Spatial understanding requires specialized models.</p><p><strong>Not diagnostic.</strong> Like GPT-5.4 Vision, CLIP is a retrieval and matching tool &#8212; not an FDA-cleared diagnostic system. It finds similar images; a radiologist interprets them. This is also where specialized models like <a href="https://echojepa.com/">EchoJEPA</a> (which I co-authored) push the boundary &#8212; learning visual representations from 18M echocardiography videos specifically for cardiac function assessment.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>CLIP embeds images and text into the same vector space, enabling three search patterns that <a href="https://teodoracoach.substack.com/p/day-30-processing-medical-images">Day 30</a> couldn&#8217;t do: text&#8594;image, image&#8594;text, and image&#8594;image. <br><br>Use BiomedCLIP for medical data: it understands clinical findings, not just generic objects. It runs locally (HIPAA-friendly), costs nothing per query, and scales to millions of images.</strong> <br><br>Combine it with GPT-5.4 Vision descriptions for the best of both worlds: fast search with CLIP, rich descriptions with Vision.</p></blockquote><div><hr></div><h2>Coming Tomorrow: Day 32</h2><p><strong>Agentic RAG: When Your AI Decides What to Search</strong></p><p>For 31 days, your RAG systems have followed a fixed pipeline: query &#8594; retrieve &#8594; generate. <br><br>The human decides what to search. <br><br>Tomorrow, the AI starts deciding. Agentic RAG uses LangGraph to build state machines where the AI routes queries to different knowledge sources, decides whether retrieval quality is sufficient, and self-corrects when it&#8217;s not. <br><br>This is the architecture that powers the most advanced clinical decision support systems being built today.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare so you don&#8217;t miss Day 32.</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Day 30: Processing Medical Images for RAG (X-Rays, Ultrasound, and Pathology Slides)]]></title><description><![CDATA[RAG for Healthcare | Day 30 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-30-processing-medical-images</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-30-processing-medical-images</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Mon, 06 Apr 2026 01:22:37 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/6af3634f-4f7f-417d-b335-dbfddc7eff3e_1322x1056.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Yesterday you learned the three architectures for multimodal RAG. Today you build the pipeline.</p><p>By the end of this article (and the accompanying Google Colab notebook), you&#8217;ll have a system where a query like <em>&#8220;findings consistent with heart failure&#8221;</em> retrieves <strong>both</strong> a guideline text chunk about HFrEF diagnostic criteria <strong>and</strong> a chest X-ray description showing cardiomegaly with pulmonary edema: from the same FAISS index, with a single search.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><h2>The Pipeline: 5 Steps</h2><p>Every medical image goes through the same production pipeline:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MRjz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff23b90e9-27be-4129-975f-a4029260a6d6_396x499.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MRjz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff23b90e9-27be-4129-975f-a4029260a6d6_396x499.png 424w, https://substackcdn.com/image/fetch/$s_!MRjz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff23b90e9-27be-4129-975f-a4029260a6d6_396x499.png 848w, https://substackcdn.com/image/fetch/$s_!MRjz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff23b90e9-27be-4129-975f-a4029260a6d6_396x499.png 1272w, https://substackcdn.com/image/fetch/$s_!MRjz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff23b90e9-27be-4129-975f-a4029260a6d6_396x499.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MRjz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff23b90e9-27be-4129-975f-a4029260a6d6_396x499.png" width="396" height="499" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f23b90e9-27be-4129-975f-a4029260a6d6_396x499.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:499,&quot;width&quot;:396,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:360927,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193293897?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0628e560-6eee-475c-95d4-e272db2b3567_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MRjz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff23b90e9-27be-4129-975f-a4029260a6d6_396x499.png 424w, https://substackcdn.com/image/fetch/$s_!MRjz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff23b90e9-27be-4129-975f-a4029260a6d6_396x499.png 848w, https://substackcdn.com/image/fetch/$s_!MRjz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff23b90e9-27be-4129-975f-a4029260a6d6_396x499.png 1272w, https://substackcdn.com/image/fetch/$s_!MRjz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff23b90e9-27be-4129-975f-a4029260a6d6_396x499.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Steps 1&#8211;3 are image processing. Step 4 is the bridge between visual and textual modalities. Step 5 is standard RAG: your existing pipeline handles it.</p><div><hr></div><h2>Step 1-3: Load, Resize, Encode</h2><p>Medical images come in various formats. The processing needs are simple but the gotchas are format-specific:</p><p><strong>DICOM files</strong> (raw from PACS): Use <code>pydicom</code> to read, extract pixel data, apply windowing (for CT), then convert to PIL Image. DICOM carries metadata (patient ID, study date, modality) - extract it and attach as chunk metadata.</p><p><strong>PNG/JPEG</strong> (exported from viewers): Direct load with <a href="https://pillow.readthedocs.io/en/stable/">PIL</a>. Most teaching collections and public datasets use these formats.</p><p><strong>Video frames</strong> (echo clips): Use <code>cv2.VideoCapture</code> to extract keyframes at specific intervals or at physiologically meaningful timepoints (end-diastole, end-systole for echo).</p><p><strong>Why resize to &#8804;1024px?</strong> GPT-5.4 Vision charges based on image size. A 4000&#215;4000 pathology tile costs ~4x more than a 1024&#215;1024 version - with minimal quality improvement for description generation. Always resize before sending.</p><p><strong>Why base64?</strong> The OpenAI API accepts images as base64-encoded strings embedded in the request JSON. This avoids hosting images on a URL - important for PHI, since the image never touches a public endpoint.</p><p>python</p><pre><code><code>import base64, io
from PIL import Image

def encode_medical_image(filepath, max_size=1024):
    img = Image.open(filepath).convert('RGB')

    if max(img.size) &gt; max_size:
        ratio = max_size / max(img.size)
        img = img.resize((int(img.size[0]*ratio), int(img.size[1]*ratio)))

    buffer = io.BytesIO()
    img.save(buffer, format='PNG')
    return base64.b64encode(buffer.getvalue()).decode('utf-8')</code></code></pre><div><hr></div><h2>Step 4: GPT-5.4 Vision Description (The Bridge)</h2><p>This is where the image becomes text: searchable, embeddable, and retrievable alongside your clinical documents.</p><p>The prompt matters enormously. A generic &#8220;describe this image&#8221; produces a generic description. A clinical prompt produces a structured radiology-style report:</p><p>python</p><pre><code><code>response = client.chat.completions.create(
    model="gpt-5.4",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": """You are a radiologist. Generate a structured report:
1. MODALITY AND VIEW
2. KEY FINDINGS
3. MEASUREMENTS (if applicable)
4. IMPRESSION
Clinical info: 65F with new-onset dyspnea"""},
            {"type": "image_url", "image_url": {
                "url": f"data:image/png;base64,{base64_data}",
                "detail": "high"
            }}
        ]
    }],
    max_completion_tokens=500,
)</code></code></pre><p><strong>Cost:</strong> ~$0.01&#8211;0.03 per image at high detail. For a 500-image teaching library, that&#8217;s $5&#8211;15 one-time indexing cost. Queries after indexing are text-only (no Vision API needed).</p><p><strong>Clinical context:</strong> GPT-5.4 Vision is not FDA-cleared for diagnostic interpretation. The descriptions it generates are for <strong>search indexing</strong>, not clinical diagnosis. A radiologist interprets; the model makes the image searchable. This distinction matters for compliance.</p><div><hr></div><h2>Step 5: Unified Index - Images and Text Together</h2><p>The description from Step 4 becomes a standard LangChain <code>Document</code> with image metadata attached:</p><p>python</p><pre><code><code>from langchain_core.documents import Document

doc = Document(
    page_content=vision_description,  # The GPT-5.4 Vision output
    metadata={
        "source_type": "medical_image",
        "modality": "Chest X-Ray",
        "study": "PA Chest Radiograph",
        "filename": "cxr_001.png",
        "clinical_info": "65F with new-onset dyspnea",
    }
)</code></code></pre><p>This document goes into the same FAISS index as your clinical text chunks. The embedding model maps the radiological description into the same vector space as your guideline text - so a query about &#8220;heart failure imaging&#8221; retrieves both the guideline definition and the X-ray description.</p><div><hr></div><h2>What the Notebook Demonstrates</h2><p>The accompanying Google Colab notebook walks through the complete pipeline with <strong>six medical images</strong> across four modalities:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nvKM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nvKM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png 424w, https://substackcdn.com/image/fetch/$s_!nvKM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png 848w, https://substackcdn.com/image/fetch/$s_!nvKM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png 1272w, https://substackcdn.com/image/fetch/$s_!nvKM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nvKM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png" width="508" height="277.31640625" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:1024,&quot;resizeWidth&quot;:508,&quot;bytes&quot;:677300,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193293897?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nvKM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png 424w, https://substackcdn.com/image/fetch/$s_!nvKM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png 848w, https://substackcdn.com/image/fetch/$s_!nvKM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png 1272w, https://substackcdn.com/image/fetch/$s_!nvKM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed51b0e2-c548-48b2-82d7-4828efb1631c_1024x559.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Plus five clinical text documents on related topics. All indexed together.</p><p><strong>Five cross-modal search tests</strong> demonstrate that text queries retrieve relevant images:</p><ul><li><p><em>&#8220;chest X-ray showing cardiomegaly&#8221;</em> &#8594; finds the cardiomegaly X-ray description</p></li><li><p><em>&#8220;dilated left ventricle with reduced ejection fraction&#8221;</em> &#8594; finds BOTH the echo image AND the HFrEF guideline text</p></li><li><p><em>&#8220;acute ischemic stroke on brain MRI&#8221;</em> &#8594; finds both the MRI description and the stroke management text</p></li></ul><p><strong>Full multimodal RAG</strong> generates answers with image attribution: the response cites which images were used, by modality and study type.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FBY9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FBY9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png 424w, https://substackcdn.com/image/fetch/$s_!FBY9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png 848w, https://substackcdn.com/image/fetch/$s_!FBY9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png 1272w, https://substackcdn.com/image/fetch/$s_!FBY9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FBY9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png" width="798" height="1486" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1486,&quot;width&quot;:798,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:529717,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193293897?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FBY9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png 424w, https://substackcdn.com/image/fetch/$s_!FBY9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png 848w, https://substackcdn.com/image/fetch/$s_!FBY9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png 1272w, https://substackcdn.com/image/fetch/$s_!FBY9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc03077e-7611-4a26-9c67-1d3f664bebb4_798x1486.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>Processing Medical Images at Scale</h2><p>For production deployment, here&#8217;s the practical workflow:</p><p><strong>Teaching libraries (100&#8211;1,000 images):</strong> Process all at once. ~$10&#8211;30 in Vision API costs. Run overnight. Done.</p><p><strong>Active PACS integration (continuous):</strong> Set up a listener that processes new studies as they arrive. Each new image gets described and indexed within minutes of acquisition. This is the architecture for real-time image-searchable clinical systems.</p><p><strong>Large retrospective datasets:</strong> Batch process with rate limiting. </p><ul><li><p><a href="https://www.kaggle.com/datasets/nih-chest-xrays/data">NIH Chest X-ray dataset</a> (100K images) at $0.01/image = $1,000. </p></li><li><p><a href="https://stanfordmlgroup.github.io/competitions/chexpert/">CheXpert</a> (224K images) = $2,240. Significant but one-time. Alternatively, use <a href="https://arxiv.org/abs/2303.00915">BiomedCLIP</a> for native image embedding (Day 31 preview) - no Vision API needed, dramatically cheaper at scale.</p></li></ul><p><strong><a href="https://echonet.github.io/dynamic/">EchoNet-Dynamic</a> (10K echo videos):</strong> Extract keyframes (end-diastole, end-systole - 2 frames per video = 20K images), describe with Vision API = ~$200. For my co-authored work on <a href="https://echojepa.com/">EchoJEPA</a> - a self-supervised model trained on 18M echo videos - we process echocardiography at a scale where native visual encoders become essential.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>Processing medical images for RAG follows a five-step pipeline: </strong></p><ol><li><p><strong>Load </strong></p></li><li><p><strong>Resize </strong></p></li><li><p><strong>Encode to base64</strong></p></li><li><p><strong>Describe with GPT-5.4 Vision</strong></p></li><li><p><strong>Embed the description alongside clinical text. </strong></p><p></p><p><strong>The description is the bridge between visual and textual modalities - once an image has a text description, your existing RAG pipeline handles everything else. Cost is ~$0.01&#8211;0.03 per image for indexing; queries are free.</strong></p></li></ol></blockquote><div><hr></div><h2>The Notebook</h2><p><strong><a href="https://colab.research.google.com/drive/1sJaIahGndomByRnYxlmehPsj-GAx28Ln?usp=sharing">Google Colab Notebook: Day 30 - Medical Image Processing for RAG</a></strong></p><p><em>Six medical images across four modalities, five cross-modal search tests, full multimodal RAG with image attribution. Run in ~60 seconds.</em></p><div><hr></div><h2>Coming Tomorrow: Day 31</h2><p><strong>The CLIP Model - Aligning Medical Images and Text Without Fine-Tuning</strong></p><p>Today you used GPT-5.4 Vision as the bridge between images and text (Approach 1: text-mediated). <br><br>Tomorrow you learn CLIP and BiomedCLIP - models that embed images and text directly into the same vector space (Approach 2: native multimodal embedding). </p><p>No Vision API needed. No per-image description cost. True image-to-text and image-to-image search.</p><div><hr></div><ul><li><p><strong>Subscribe to RAG for Healthcare so you don&#8217;t miss Day 31.</strong></p></li></ul><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Day 29: Multimodal RAG - When Text Alone Is Not Enough]]></title><description><![CDATA[RAG for Healthcare | Day 29 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-29-multimodal-rag-when-text-alone</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-29-multimodal-rag-when-text-alone</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Sat, 04 Apr 2026 15:42:55 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/17b2aabc-ae2b-426c-9528-c34294f06280_256x301.gif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A cardiology fellow asks your RAG system: <em>&#8220;<strong>Show me examples of severe mitral regurgitation on echo.</strong>&#8221;</em></p><p>Your text-based RAG, the one you have spent four weeks building, finds guideline chunks describing severe MR criteria: vena contracta &#8805;7mm, regurgitant volume &#8805;60mL, EROA &#8805;0.40 cm&#178;. Accurate. Cited. Grounded.</p><p>But the fellow doesn&#8217;t need a text definition. They need to <strong>SEE</strong> it. They need the echo clip showing the color Doppler jet filling the left atrium. They need the side-by-side comparison of moderate vs. severe. They need the annotated still frame pointing to the vena contracta measurement.</p><p>Text alone can&#8217;t answer this question. The answer is an image.</p><p><strong>Clinical context:</strong> <a href="https://www.mayoclinic.org/diseases-conditions/mitral-valve-regurgitation/symptoms-causes/syc-20350178">Mitral regurgitation (MR)</a> is backward leakage of blood through the mitral valve during each heartbeat. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jKKY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jKKY!,w_424,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif 424w, https://substackcdn.com/image/fetch/$s_!jKKY!,w_848,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif 848w, https://substackcdn.com/image/fetch/$s_!jKKY!,w_1272,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif 1272w, https://substackcdn.com/image/fetch/$s_!jKKY!,w_1456,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jKKY!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif" width="208" height="244.5625" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:301,&quot;width&quot;:256,&quot;resizeWidth&quot;:208,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Chicago Heart Institute&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Chicago Heart Institute" title="Chicago Heart Institute" srcset="https://substackcdn.com/image/fetch/$s_!jKKY!,w_424,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif 424w, https://substackcdn.com/image/fetch/$s_!jKKY!,w_848,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif 848w, https://substackcdn.com/image/fetch/$s_!jKKY!,w_1272,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif 1272w, https://substackcdn.com/image/fetch/$s_!jKKY!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9aafb8dc-e186-4b70-b5be-9d381477cba1_256x301.gif 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br>Severity is graded by echocardiography using multiple parameters (the size of the regurgitant jet on color Doppler, the width of the vena contracta (the narrowest point of the jet), and quantitative measures of regurgitant volume). Interpreting MR severity is a visual skill: echocardiographers learn it by seeing hundreds of examples, not by reading criteria.</p><p>Healthcare is inherently multimodal. Clinicians don&#8217;t make decisions from text alone: they read notes, scan lab values, examine imaging, listen to heart sounds, and review ECG tracings. A RAG system that only processes text is working with one hand tied behind its back.</p><p>Today we untie it.</p><div><hr></div><h2>What Multimodal RAG Means</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tm_s!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tm_s!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png 424w, https://substackcdn.com/image/fetch/$s_!tm_s!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png 848w, https://substackcdn.com/image/fetch/$s_!tm_s!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png 1272w, https://substackcdn.com/image/fetch/$s_!tm_s!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tm_s!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png" width="897" height="416" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:416,&quot;width&quot;:897,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:627661,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193129916?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ccce664-6252-42f0-9b80-0b4f8d580769_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tm_s!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png 424w, https://substackcdn.com/image/fetch/$s_!tm_s!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png 848w, https://substackcdn.com/image/fetch/$s_!tm_s!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png 1272w, https://substackcdn.com/image/fetch/$s_!tm_s!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08681994-6b91-4efc-a8c2-3ca04038b652_897x416.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The modalities that matter in healthcare:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Mxx7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Mxx7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png 424w, https://substackcdn.com/image/fetch/$s_!Mxx7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png 848w, https://substackcdn.com/image/fetch/$s_!Mxx7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png 1272w, https://substackcdn.com/image/fetch/$s_!Mxx7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Mxx7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png" width="977" height="447" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:447,&quot;width&quot;:977,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:848407,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193129916?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ed63b20-72c4-4b86-9074-74b6e47afeb8_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Mxx7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png 424w, https://substackcdn.com/image/fetch/$s_!Mxx7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png 848w, https://substackcdn.com/image/fetch/$s_!Mxx7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png 1272w, https://substackcdn.com/image/fetch/$s_!Mxx7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85931106-0af3-46a3-8e64-e63716c5c3c6_977x447.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A truly multimodal clinical RAG system can answer: <em>&#8220;Find echo clips similar to this patient&#8217;s parasternal long-axis view&#8221;</em> or <em>&#8220;Show me chest X-rays with findings consistent with the pulmonary edema described in this note.&#8221;</em></p><div><hr></div><h2>The Architecture: Three Approaches</h2><h3>Approach 1: Describe, then retrieve (Text-Mediated)</h3><p>Convert non-text modalities to text descriptions, then use standard text RAG.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0tg1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72265487-e006-4462-adea-ed526981eb0e_958x447.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0tg1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72265487-e006-4462-adea-ed526981eb0e_958x447.png 424w, https://substackcdn.com/image/fetch/$s_!0tg1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72265487-e006-4462-adea-ed526981eb0e_958x447.png 848w, https://substackcdn.com/image/fetch/$s_!0tg1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72265487-e006-4462-adea-ed526981eb0e_958x447.png 1272w, https://substackcdn.com/image/fetch/$s_!0tg1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72265487-e006-4462-adea-ed526981eb0e_958x447.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0tg1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72265487-e006-4462-adea-ed526981eb0e_958x447.png" width="664" height="309.8204592901879" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/72265487-e006-4462-adea-ed526981eb0e_958x447.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:447,&quot;width&quot;:958,&quot;resizeWidth&quot;:664,&quot;bytes&quot;:693534,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193129916?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd97e5db3-e284-45de-9482-4f9d602ca543_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0tg1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72265487-e006-4462-adea-ed526981eb0e_958x447.png 424w, https://substackcdn.com/image/fetch/$s_!0tg1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72265487-e006-4462-adea-ed526981eb0e_958x447.png 848w, https://substackcdn.com/image/fetch/$s_!0tg1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72265487-e006-4462-adea-ed526981eb0e_958x447.png 1272w, https://substackcdn.com/image/fetch/$s_!0tg1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72265487-e006-4462-adea-ed526981eb0e_958x447.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Example:</strong> Feed each echo frame to GPT-5.4 with a prompt: <em>&#8220;Describe the echocardiographic findings in this image.&#8221;</em> The model produces: <em>&#8220;Apical 4-chamber view showing severe mitral regurgitation with a large color Doppler jet occupying &gt;50% of the left atrium. Vena contracta appears wide.&#8221;</em> This description gets embedded and stored alongside a pointer to the original image.</p><p><strong>The analogy:</strong> A radiologist dictating a report. The image is converted to text (the radiology report), and the text is what gets searched. When you find the right report, you pull up the corresponding image.</p><p><strong>Pros:</strong> Uses your existing text RAG pipeline (Days 1&#8211;21). No new infrastructure. <strong>Cons:</strong> The description loses visual details. You can&#8217;t search for &#8220;images that look like this&#8221; - only for &#8220;images described like this.&#8221;</p><p><strong>Best for:</strong> Quick prototyping, lecture slide libraries, annotated teaching collections.</p><h3>Approach 2: Native multimodal embedding (Vision Embeddings)</h3><p>Embed images directly into the same vector space as text, using a multimodal embedding model.<br></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KZWR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KZWR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png 424w, https://substackcdn.com/image/fetch/$s_!KZWR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png 848w, https://substackcdn.com/image/fetch/$s_!KZWR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png 1272w, https://substackcdn.com/image/fetch/$s_!KZWR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KZWR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png" width="702" height="335.32710280373834" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:460,&quot;width&quot;:963,&quot;resizeWidth&quot;:702,&quot;bytes&quot;:797583,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193129916?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0654be76-b15f-4af2-ab00-071f013849ca_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KZWR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png 424w, https://substackcdn.com/image/fetch/$s_!KZWR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png 848w, https://substackcdn.com/image/fetch/$s_!KZWR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png 1272w, https://substackcdn.com/image/fetch/$s_!KZWR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1157deb5-2818-4e7e-9121-3a50a21ba88f_963x460.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>How it works:</strong> Multimodal embedding models (like OpenAI&#8217;s multimodal embeddings, <a href="https://openai.com/index/clip/">CLIP</a>, or <a href="https://arxiv.org/abs/2303.00915">BiomedCLIP</a>) map both text and images into the same vector space. An echo image of severe MR and the text &#8220;severe mitral regurgitation&#8221; end up near each other - because the model has learned to align visual and textual representations of the same concept.</p><p><strong>The analogy:</strong> A bilingual librarian who organizes English and Spanish books on the same shelves by topic. You can search in English and find a Spanish book, because the librarian understands both languages and filed them together by subject.</p><p><strong>Pros:</strong> True cross-modal search. Query with text, retrieve images. Query with an image, retrieve similar images or related text. <br><br><strong>Cons:</strong> Requires multimodal embedding models. Medical-specific models (<a href="https://arxiv.org/abs/2303.00915">BiomedCLIP,</a> <a href="https://github.com/sarahESL/PubMedCLIP">PubMedCLIP</a>) perform significantly better than general-purpose ones on clinical images.</p><p><strong>Best for:</strong> Production multimodal systems, image similarity search, cross-modal retrieval.</p><h3>Approach 3: Parallel retrieval with fusion (Multi-Index)</h3><p>Maintain separate indices for each modality and merge results at query time - the same architecture you built on <a href="https://teodoracoach.substack.com/p/day-21-build-project-multi-source">Day 21</a>, extended to images.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_ckS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_ckS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png 424w, https://substackcdn.com/image/fetch/$s_!_ckS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png 848w, https://substackcdn.com/image/fetch/$s_!_ckS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png 1272w, https://substackcdn.com/image/fetch/$s_!_ckS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_ckS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png" width="682" height="338.21632653061226" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/afceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:486,&quot;width&quot;:980,&quot;resizeWidth&quot;:682,&quot;bytes&quot;:523195,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/193129916?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74bab85c-b59f-4844-9c0f-d7144928ef2c_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_ckS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png 424w, https://substackcdn.com/image/fetch/$s_!_ckS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png 848w, https://substackcdn.com/image/fetch/$s_!_ckS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png 1272w, https://substackcdn.com/image/fetch/$s_!_ckS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafceadc0-c8f0-4a54-9cd6-489081de42e2_980x486.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The analogy:</strong> The consulting physician who checks the chart (text index), pulls up the imaging (image index), and reviews the labs (structured data) - then synthesizes across all three. Each source is searched independently, and the results are merged into a unified clinical picture.</p><p><strong>Pros:</strong> Each modality uses its best-fit embedding model. You can weight modalities differently per query. Modular - add new modalities without rebuilding. <br><br><strong>Cons:</strong> More complex merging logic. Need to maintain multiple indices.</p><p><strong>Best for:</strong> Enterprise clinical decision support, multi-modal teaching systems, comprehensive patient review tools.</p><div><hr></div><h2>The Current State of Medical Multimodal Models</h2><p>The field is moving fast. Here&#8217;s where things stand:</p><p><strong><a href="https://arxiv.org/abs/2303.00915">BiomedCLIP</a></strong>: Trained on PubMed figure-caption pairs. Best open-source option for medical image-text alignment. Understands X-rays, pathology, and clinical photographs significantly better than general CLIP.<br><br><strong>EchoJEPA</strong> (<a href="https://echojepa.com/">echojepa.com</a>) - A self-supervised foundation model trained on 18 million echocardiography videos from 300,000+ patients, which I co-authored. EchoJEPA learns visual representations of cardiac function without labeled data - the kind of pretrained visual encoder that powers the image embedding side of multimodal RAG for cardiology.</p><p><strong>GPT-5.4 Vision</strong>: Processes images natively in the chat completion API. Can describe clinical images with reasonable accuracy but is not FDA-cleared for diagnostic use. Excellent for generating text descriptions (Approach 1).</p><p><strong><a href="https://sites.research.google/gr/med-palm/">Med-PaLM M (Google)</a></strong>: Multimodal medical AI handling text, imaging, and genomics. Research-stage but demonstrates the direction the field is heading.</p><p><strong><a href="https://github.com/HKUDS/RAG-Anything">RAG-Anything (HKUDS, 2025)</a></strong><a href="https://github.com/HKUDS/RAG-Anything">:</a> An extension of LightRAG (Day 24&#8211;26) that processes text, images, tables, and equations in a unified RAG pipeline. Integrates with LightRAG&#8217;s knowledge graph for multimodal graph-based retrieval.</p><p><strong>Clinical context:</strong> No multimodal AI system is currently FDA-cleared for autonomous diagnostic interpretation of medical images in a RAG context. These systems are decision <em>support</em> tools - they surface relevant images and descriptions, but a qualified clinician must interpret and act on the findings.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>Healthcare is multimodal: notes, images, labs, waveforms, audio. <br><br>Text-only RAG answers text questions well but can&#8217;t handle &#8220;show me what severe MR looks like on echo.&#8221; <br><br>Three multimodal RAG architectures exist: </strong></p><ul><li><p><strong>text-mediated (convert images to descriptions)</strong></p></li><li><p><strong>native multimodal embedding (align images and text in the same vector space)</strong></p></li><li><p><strong>parallel multi-index retrieval (separate indices, merged results).</strong> <br><br>Start with text-mediated for quick wins. Move to native multimodal embedding for production image search.</p></li></ul></blockquote><div><hr></div><h2>Coming Tomorrow: Day 30</h2><p><strong>Processing Medical Images for RAG: X-Rays, Ultrasound, and Pathology Slides</strong></p><p>Today was the architecture. Tomorrow is the implementation - how to actually process medical images (DICOM X-rays, ultrasound frames, pathology whole-slide images), generate embeddings, and build a searchable medical image index. <br><br>You&#8217;ll learn which preprocessing matters, which models to use, and the gotchas specific to clinical imaging data.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare so you don&#8217;t miss Day 30.</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Week 4 Recap: Knowledge Graphs - From Entities to Drug Interaction Detection]]></title><description><![CDATA[RAG for Healthcare | Week 4 Summary | Free]]></description><link>https://teodoracoach.substack.com/p/week-4-recap-knowledge-graphs-from</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/week-4-recap-knowledge-graphs-from</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Sat, 04 Apr 2026 01:18:50 GMT</pubDate><enclosure url="https://api.substack.com/feed/podcast/193128791/f8319c270b8d24625073716458050486.mp3" length="0" type="audio/mpeg"/><content:encoded><![CDATA[<p>Four weeks. Four build projects. One drug interaction detector that catches cascades your EHR misses. Watch the video to find more about Week 4.</p><div><hr></div><p>The final week starts tomorrow. Agentic RAG. Self-correcting systems. The capstone.</p><p>&#8594; <strong><a href="https://teodoracoach.substack.com/">Subscribe free</a></strong> for every daily article. </p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><br><br>&#8594; <strong><a href="https://teodoracoach.substack.com/">Subscribe paid</a></strong> for the build projects and notebooks.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><p></p><p><em>- Teodora</em></p>]]></content:encoded></item><item><title><![CDATA[Day 28: BUILD PROJECT - Drug Interaction Detection System with LightRAG]]></title><description><![CDATA[RAG for Healthcare | Day 28 of 35 | PREMIUM (Paid Subscribers Only)]]></description><link>https://teodoracoach.substack.com/p/day-28-build-project-drug-interaction</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-28-build-project-drug-interaction</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Fri, 03 Apr 2026 14:03:44 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!LYbS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bbf0d89-34bd-48f8-83ce-f6ba6cc1f0e6_963x480.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>125,000 Deaths Per Year. This Notebook Addresses Why.</h2><p><strong><a href="https://www.statista.com/chart/6805/drugs-are-killing-more-americans-than-road-crashes/?srsltid=AfmBOoqooUyfNny8r7qhasLrv22egFxwnWu5Y7uRjHUfhDYMl7ixfe-r">Drug interactions kill more Americans annually than car accidents.</a></strong> And the tragic part: most of these interactions are <em>known</em>. They are documented in FDA labeling, in pharmacology textbooks, in drug databases. The information exists.</p><p>The problem is <strong>detection at the point of prescribing.</strong></p><p>Most EHR alert systems use pair-wise lookup tables: </p><p><strong>Drug A + Drug B = alert. </strong></p><p>They catch the obvious ones. <br><br>But they miss <strong>interaction cascades</strong>: the multi-drug pile-ups that happen when three or four medications collide through shared metabolic pathways.</p><p>Here is a real scenario: A cardiologist prescribes amiodarone for a patient already on warfarin. The EHR fires an alert: amiodarone inhibits CYP2C9, warfarin levels will rise, reduce the dose. Good. The pharmacist adjusts.</p><p>But the patient also has a fungal infection, and the ID team adds fluconazole. Fluconazole is <em>also</em> a potent CYP2C9 inhibitor. Now warfarin has two inhibitors blocking its metabolism simultaneously. The additive effect isn&#8217;t 30-50% increase: it&#8217;s potentially catastrophic. The EHR fires two separate pair-wise alerts (warfarin-amiodarone, warfarin-fluconazole), but it doesn&#8217;t flag the <strong>additive cascade</strong>: that dual CYP2C9 inhibition creates a compounding risk far greater than either interaction alone.</p>
      <p>
          <a href="https://teodoracoach.substack.com/p/day-28-build-project-drug-interaction">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 27: Visualizing Your Medical Knowledge Graph]]></title><description><![CDATA[RAG for Healthcare | Day 27 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-27-visualizing-your-medical-knowledge</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-27-visualizing-your-medical-knowledge</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Thu, 02 Apr 2026 14:31:14 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!5faf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You have built a knowledge graph (<a href="https://teodoracoach.substack.com/p/day-25-building-a-medical-knowledge">Day 25</a>) and queried it at multiple levels (<a href="https://teodoracoach.substack.com/p/day-26-dual-level-retrieval-getting">Day 26</a>). But so far, the graph lives entirely in code. Entities and relationships stored as data structures that only developers can inspect.</p><p>Today you make it visible. This is how the graph that we are building today looks like (Python code included):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5faf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5faf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png 424w, https://substackcdn.com/image/fetch/$s_!5faf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png 848w, https://substackcdn.com/image/fetch/$s_!5faf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png 1272w, https://substackcdn.com/image/fetch/$s_!5faf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5faf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png" width="616" height="506" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1196,&quot;width&quot;:1456,&quot;resizeWidth&quot;:616,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5faf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png 424w, https://substackcdn.com/image/fetch/$s_!5faf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png 848w, https://substackcdn.com/image/fetch/$s_!5faf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png 1272w, https://substackcdn.com/image/fetch/$s_!5faf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F892d9f48-7499-409f-a70a-b41af654e91b_1622x1332.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You will extract subgraphs around clinical concepts, render them as interactive HTML visualizations, and produce the artifact that makes a non-technical stakeholder say: <em>&#8220;Now I understand what this system knows.&#8221;</em></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><h2>Why Visualization Matters in Healthcare AI</h2><p>Knowledge graph visualization serves three purposes in a clinical setting:</p><p><strong>1. Validation.</strong> When you visualize the subgraph around &#8220;<code>Warfarin</code>,&#8221; you can immediately see whether the extraction captured the <a href="https://en.wikipedia.org/wiki/CYP2C9">CYP2C9 metabolism</a>, the amiodarone interaction, the INR monitoring requirement, and the pregnancy contraindication. Missing edges are visible at a glance. No need to write test queries for every relationship.</p><p><strong>2. Communication.</strong> Your CMIO doesn&#8217;t read Python dictionaries. But show them an interactive network where &#8220;Warfarin&#8221; connects to &#8220;CYP2C9&#8221; via &#8220;metabolized_by&#8221; and to &#8220;Amiodarone&#8221; via &#8220;interacts_with&#8221;. And they immediately grasp what the system knows and where the gaps are.</p><p><strong>3. Discovery.</strong> Graphs reveal patterns that queries miss. You might notice that three drugs all connect to CYP2C9, suggesting a shared interaction risk you hadn&#8217;t explicitly queried. <strong>Visualization turns passive data into active insight</strong>.</p><p><strong>The analogy:</strong> A medical knowledge graph without visualization is like an MRI without the radiologist&#8217;s report. The data is all there, but no one can interpret it. Visualization is the report: it turns raw structure into clinical meaning.</p><div><hr></div><h2>Tool: PyVis</h2><p><a href="https://pyvis.readthedocs.io/en/latest/">PyVis</a> is a Python library that generates interactive HTML network graphs. You create nodes and edges in Python, and PyVis renders them as a draggable, zoomable visualization you can open in any browser. No JavaScript required.</p><p>python</p><pre><code><code>pip install pyvis</code></code></pre><p>The output is a standalone <code>.html</code> file. No server, no dependencies. Email it to a colleague, embed it in a presentation, or open it on your phone. This portability is why PyVis beats heavier tools for clinical communication.</p><div><hr></div><h2>Extracting Subgraphs from LightRAG</h2><p><a href="https://github.com/hkuds/lightrag">LightRAG</a> stores its knowledge graph internally. To visualize it, we extract the entities and relationships into a format PyVis can render.</p><p>If you want full control over the visualization (recommended for clinical presentations), build the graph from your known entities:</p><p>python</p><pre><code><code>import networkx as nx

G = nx.DiGraph()

# Define entities with types (for color-coding)
drugs = ["Warfarin", "Amiodarone", "Metoprolol", "Diltiazem", "Dapagliflozin"]
conditions = ["Atrial Fibrillation", "HFrEF", "HFpEF", "VTE", "Hypertension"]
enzymes = ["CYP2C9", "CYP3A4", "CYP2D6"]
labs = ["INR", "TSH", "LFTs", "PFTs", "BNP"]
effects = ["Bleeding", "Thyroid Dysfunction", "Pulmonary Toxicity",
           "Bradycardia", "Genital Mycotic Infection"]

for d in drugs:      G.add_node(d, type="drug")
for c in conditions: G.add_node(c, type="condition")
for e in enzymes:    G.add_node(e, type="enzyme")
for l in labs:       G.add_node(l, type="lab")
for ef in effects:   G.add_node(ef, type="adverse_effect")

# Add relationships
edges = [
    ("Warfarin", "Atrial Fibrillation", "treats"),
    ("Warfarin", "VTE", "treats"),
    ("Warfarin", "CYP2C9", "metabolized_by"),
    ("Warfarin", "INR", "monitored_by"),
    ("Warfarin", "Bleeding", "causes"),
    ("Amiodarone", "Atrial Fibrillation", "treats"),
    ("Amiodarone", "CYP2C9", "inhibits"),
    ("Amiodarone", "CYP3A4", "inhibits"),
    ("Amiodarone", "Thyroid Dysfunction", "causes"),
    ("Amiodarone", "Pulmonary Toxicity", "causes"),
    ("Amiodarone", "TSH", "monitored_by"),
    ("Amiodarone", "LFTs", "monitored_by"),
    ("Amiodarone", "PFTs", "monitored_by"),
    ("Amiodarone", "Warfarin", "interacts_with"),
    ("Metoprolol", "HFrEF", "treats"),
    ("Metoprolol", "Atrial Fibrillation", "treats"),
    ("Metoprolol", "Hypertension", "treats"),
    ("Metoprolol", "CYP2D6", "metabolized_by"),
    ("Metoprolol", "Bradycardia", "causes"),
    ("Diltiazem", "Atrial Fibrillation", "treats"),
    ("Diltiazem", "Hypertension", "treats"),
    ("Diltiazem", "CYP3A4", "inhibits"),
    ("Diltiazem", "HFrEF", "contraindicated_in"),
    ("Dapagliflozin", "HFrEF", "treats"),
    ("Dapagliflozin", "HFpEF", "treats"),
    ("Dapagliflozin", "BNP", "monitored_by"),
    ("Dapagliflozin", "Genital Mycotic Infection", "causes"),
    ("Atrial Fibrillation", "VTE", "increases_risk_of"),
]

for src, tgt, rel in edges:
    G.add_edge(src, tgt, relationship=rel)

print(f"Graph: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges")</code></code></pre><div><hr></div><h2>Rendering with PyVis</h2><p>Now turn the NetworkX graph into an interactive visualization:</p><p>python</p><pre><code><code>from pyvis.network import Network

def visualize_graph(G, filename="medical_knowledge_graph.html", height="700px"):
    """Render a NetworkX graph as an interactive HTML visualization."""

    net = Network(height=height, width="100%", directed=True, notebook=True)

    # Color scheme by entity type
    colors = {
        "drug": "#4A90D9",         # Blue
        "condition": "#E74C3C",     # Red
        "enzyme": "#F39C12",        # Orange
        "lab": "#2ECC71",           # Green
        "adverse_effect": "#9B59B6" # Purple
    }

    # Add nodes with styling
    for node in G.nodes():
        node_type = G.nodes[node].get("type", "unknown")
        color = colors.get(node_type, "#95A5A6")
        size = 30 if node_type == "drug" else 20

        net.add_node(
            node,
            label=node,
            color=color,
            size=size,
            title=f"{node} ({node_type})",  # Hover tooltip
        )

    # Add edges with relationship labels
    for src, tgt, data in G.edges(data=True):
        rel = data.get("relationship", "")
        color = "#E74C3C" if rel == "contraindicated_in" else "#CCCCCC"
        width = 3 if rel in ["contraindicated_in", "interacts_with"] else 1

        net.add_edge(src, tgt, title=rel, label=rel, color=color, width=width)

    # Physics settings for readable layout
    net.set_options("""
    {
      "physics": {
        "forceAtlas2Based": {
          "gravitationalConstant": -50,
          "centralGravity": 0.01,
          "springLength": 200
        },
        "solver": "forceAtlas2Based"
      }
    }
    """)

    net.save_graph(filename)
    print(f" Saved to {filename} - open in any browser")

visualize_graph(G)</code></code></pre><p>Open <code>medical_knowledge_graph.html</code> in your browser. You&#8217;ll see an interactive network where:</p><ul><li><p><strong>Blue nodes</strong> are drugs (largest - they&#8217;re the primary entities)</p></li><li><p><strong>Red nodes</strong> are conditions</p></li><li><p><strong>Orange nodes</strong> are metabolizing enzymes</p></li><li><p><strong>Green nodes</strong> are lab tests</p></li><li><p><strong>Purple nodes</strong> are adverse effects</p></li><li><p><strong>Red edges</strong> highlight contraindications and interactions (the dangerous relationships)</p></li><li><p><strong>Hover</strong> over any node to see its type</p></li><li><p><strong>Hover</strong> over any edge to see the relationship</p></li><li><p><strong>Drag</strong> nodes to rearrange the layout</p></li><li><p><strong>Zoom</strong> in/out to explore clusters</p></li></ul><div><hr></div><h2>Extracting Clinical Subgraphs</h2><p>The full graph is useful for overview. Subgraphs are useful for focused clinical questions.</p><h3>Subgraph: Everything connected to Warfarin</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!j5tN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!j5tN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png 424w, https://substackcdn.com/image/fetch/$s_!j5tN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png 848w, https://substackcdn.com/image/fetch/$s_!j5tN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png 1272w, https://substackcdn.com/image/fetch/$s_!j5tN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!j5tN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png" width="494" height="463.44329896907215" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1274,&quot;width&quot;:1358,&quot;resizeWidth&quot;:494,&quot;bytes&quot;:214062,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192906176?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!j5tN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png 424w, https://substackcdn.com/image/fetch/$s_!j5tN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png 848w, https://substackcdn.com/image/fetch/$s_!j5tN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png 1272w, https://substackcdn.com/image/fetch/$s_!j5tN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63ac3a2d-e334-4449-88bd-19bfff10f9cc_1358x1274.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>python</p><pre><code><code>def extract_subgraph(G, center_node, depth=2):
    """Extract all nodes within 'depth' hops of center_node."""
    nodes = set()
    current_layer = {center_node}

    for _ in range(depth):
        next_layer = set()
        for node in current_layer:
            next_layer.update(G.successors(node))
            next_layer.update(G.predecessors(node))
        nodes.update(current_layer)
        current_layer = next_layer - nodes
    nodes.update(current_layer)

    return G.subgraph(nodes).copy()

warfarin_subgraph = extract_subgraph(G, "Warfarin", depth=2)
visualize_graph(warfarin_subgraph, "warfarin_network.html")</code></code></pre><p>Open <code>warfarin_network.html</code> and you see Warfarin&#8217;s complete clinical profile at a glance: CYP2C9 metabolism, INR monitoring, amiodarone interaction (and amiodarone&#8217;s own side effects branching out), bleeding risk, AFib and VTE indications. A pharmacist reviewing this graph can immediately verify that the knowledge base captures the key warfarin considerations.</p><h3>Subgraph: The heart failure treatment landscape</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fAlr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fAlr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png 424w, https://substackcdn.com/image/fetch/$s_!fAlr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png 848w, https://substackcdn.com/image/fetch/$s_!fAlr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png 1272w, https://substackcdn.com/image/fetch/$s_!fAlr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fAlr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png" width="406" height="415.9024390243902" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:924,&quot;width&quot;:902,&quot;resizeWidth&quot;:406,&quot;bytes&quot;:82255,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192906176?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fAlr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png 424w, https://substackcdn.com/image/fetch/$s_!fAlr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png 848w, https://substackcdn.com/image/fetch/$s_!fAlr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png 1272w, https://substackcdn.com/image/fetch/$s_!fAlr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3645f104-a94f-4edb-bc7f-887319dcb4fe_902x924.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><br></h3><p>python</p><pre><code><code>hf_nodes = {"HFrEF", "HFpEF"}
hf_subgraph = nx.DiGraph()

for node in hf_nodes:
    for pred in G.predecessors(node):
        rel = G[pred][node]["relationship"]
        hf_subgraph.add_node(pred, **G.nodes[pred])
        hf_subgraph.add_node(node, **G.nodes[node])
        hf_subgraph.add_edge(pred, node, relationship=rel)

visualize_graph(hf_subgraph, "heart_failure_landscape.html")</code></code></pre><p>This produces a visualization showing every drug that treats or is contraindicated in HFrEF and HFpEF - the complete treatment landscape from a single image. Metoprolol and dapagliflozin treating HFrEF. Dapagliflozin treating HFpEF. Diltiazem contraindicated in HFrEF. The red contraindication edge jumps out visually - exactly the kind of safety signal you want to be immediately obvious.</p><div><hr></div><h2>What to Look for in Your Visualization</h2><p>When you visualize a medical knowledge graph, inspect it like a clinician reviewing a chart:</p><p><strong>Disconnected nodes.</strong> An entity with no edges means the extraction missed its relationships. If &#8220;Metoprolol&#8221; exists but has no &#8220;treats&#8221; edge to any condition, the extraction failed for that drug. Re-examine the source text.</p><p><strong>Missing contraindications.</strong> If you know a drug has a major contraindication but the red edge isn&#8217;t there, your extraction prompt needs improvement. Contraindications are the highest-value relationships in a clinical knowledge graph - they should all be captured.</p><p><strong>Hub nodes.</strong> Entities with many connections (like CYP2C9, which connects to multiple drugs) are clinically important hubs. They represent shared risk factors. A hub node in an enzyme like CYP3A4 means that any inhibitor of CYP3A4 could affect <em>all</em> connected drugs. A multi-drug interaction risk that&#8217;s immediately visible in the graph but hard to spot in flat text.</p><p><strong>Missing edges between entities you know should be connected.</strong> If &#8220;Warfarin&#8221; and &#8220;Amiodarone&#8221; both exist but have no &#8220;interacts_with&#8221; edge, that&#8217;s a critical gap. The visualization makes this gap obvious in a way that querying alone doesn&#8217;t.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><ul><li><p><strong>Visualization transforms a knowledge graph from a data structure into a communication tool. </strong></p></li><li><p><strong>Use PyVis to create interactive HTML visualizations that clinicians and stakeholders can explore in a browser. </strong></p></li><li><p><strong>Extract subgraphs around specific drugs or conditions for focused clinical review. </strong></p></li><li><p><strong>Inspect for disconnected nodes, missing contraindications, and hub entities.</strong> </p><p></p><p>The graph you can see is the graph you can trust.</p></li></ul></blockquote><div><hr></div><h2>Coming Tomorrow: Day 28 (Premium Build Project)</h2><p><strong>BUILD PROJECT: Drug Interaction Detection System with LightRAG</strong></p><p>Tomorrow, paid subscribers get Build Project #4: a complete drug interaction detection system built on LightRAG. </p><p>Feed it a patient&#8217;s medication list, and it automatically identifies interactions, rates their severity, explains the mechanisms, and suggests monitoring or alternatives. </p><p>Full Google Colab notebook with the complete code. This is the knowledge graph in production.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare to get the Day 28 Build Project.</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Day 26: Dual-Level Retrieval - Getting Both the Facts and the Big Picture]]></title><description><![CDATA[RAG for Healthcare | Day 26 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-26-dual-level-retrieval-getting</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-26-dual-level-retrieval-getting</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Wed, 01 Apr 2026 19:43:06 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!fsTk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Yesterday you built a medical knowledge graph from cardiovascular pharmacology content. Today you learn how to query it at the right level of granularity. Because clinical questions aren&#8217;t one-size-fits-all.</p><p><strong>Query A:</strong> <em>&#8220;What is the half-life of amiodarone?&#8221;</em></p><p>One entity, one fact, one number. The answer is 40&#8211;55 days. You need LightRAG to find the specific node, pull the specific property, and return it. Fast, precise, no synthesis required.</p><p><strong>Query B:</strong> <em>&#8220;What are the major challenges in managing antiarrhythmic therapy?&#8221;</em></p><p>No single entity answers this. The answer spans multiple drugs (amiodarone, metoprolol, diltiazem), multiple side effects (thyroid dysfunction, pulmonary toxicity, bradycardia), multiple interactions (CYP inhibition, warfarin dose adjustments), and multiple contraindications (HFrEF, heart block). You need LightRAG to traverse the graph broadly, identify patterns, and synthesize.</p><p>Same knowledge graph. Same LightRAG instance. Two fundamentally different retrieval strategies.</p><div><hr></div><h2>The Four Query Modes</h2><p>LightRAG offers four modes. Each activates a different retrieval strategy.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ub7y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ub7y!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png 424w, https://substackcdn.com/image/fetch/$s_!ub7y!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png 848w, https://substackcdn.com/image/fetch/$s_!ub7y!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png 1272w, https://substackcdn.com/image/fetch/$s_!ub7y!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ub7y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png" width="1024" height="459" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:459,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:935740,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192880739?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8479cec4-b963-4941-a9ff-18208def1908_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ub7y!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png 424w, https://substackcdn.com/image/fetch/$s_!ub7y!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png 848w, https://substackcdn.com/image/fetch/$s_!ub7y!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png 1272w, https://substackcdn.com/image/fetch/$s_!ub7y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F166f9b19-b8aa-469b-accb-56ebca18edf9_1024x459.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><code>naive</code>: Plain vector search (no graph)</h3><p>python</p><pre><code><code>result = await rag.aquery("amiodarone half-life", param=QueryParam(mode="naive"))</code></code></pre><p><strong>What it does:</strong> Standard embedding-based retrieval: finds the most semantically similar text chunks. Ignores the knowledge graph entirely.</p><p><strong>The analogy:</strong> Reading the textbook page by page until you find the relevant paragraph. No index, no table of contents, just brute-force similarity.</p><p><strong>When to use it:</strong> Rarely. This is your baseline for comparison - it&#8217;s traditional RAG without graph enhancement. Use it to measure how much the graph improves your answers.</p><p><strong>Clinical example:</strong> <em>&#8220;Patient presents with progressive dyspnea and bilateral edema.&#8221;</em> A narrative clinical scenario where semantic similarity is sufficient and entity-level precision isn&#8217;t needed.</p><h3><code>local</code>: Entity-focused retrieval</h3><p>python</p><pre><code><code>result = await rag.aquery("amiodarone half-life", param=QueryParam(mode="local"))</code></code></pre><p><strong>What it does:</strong> Identifies specific entities in the query (&#8221;amiodarone&#8221;), retrieves their direct properties and relationships from the graph, and pulls the original text chunks linked to those entities.</p><p><strong>The analogy:</strong> Looking up &#8220;amiodarone&#8221; in the drug handbook index, flipping to that page, and reading the pharmacokinetics section. Direct, precise, no wandering.</p><p><strong>When to use it:</strong> Specific factual questions about named entities.</p><p><strong>Clinical examples:</strong></p><ul><li><p><em>&#8220;What CYP enzyme metabolizes warfarin?&#8221;</em> &#8594; Finds Warfarin node &#8594; follows metabolized_by edge &#8594; CYP2C9</p></li><li><p><em>&#8220;What is the target INR for mechanical mitral valves?&#8221;</em> &#8594; Finds Warfarin node &#8594; follows monitored_by edge &#8594; INR &#8594; reads target range</p></li><li><p><em>&#8220;Is diltiazem contraindicated in HFrEF?&#8221;</em> &#8594; Finds Diltiazem node &#8594; follows contraindicated_in edge &#8594; HFrEF &#8594; Yes</p></li><li><p><em>&#8220;What monitoring does amiodarone require?&#8221;</em> &#8594; Finds Amiodarone node &#8594; follows all monitoring-related edges</p></li></ul><h3><code>global</code>: Theme-focused retrieval</h3><p>python</p><pre><code><code>result = await rag.aquery(
    "What are the major challenges in managing antiarrhythmic therapy?",
    param=QueryParam(mode="global"),
)</code></code></pre><p><strong>What it does:</strong> Generates high-level search keys from the query, retrieves across broad thematic patterns in the graph, and synthesizes information that spans multiple entities and relationships.</p><p><strong>The analogy:</strong> Asking a senior cardiologist to give a 5-minute overview of antiarrhythmic challenges. They draw from their knowledge of multiple drugs, multiple patients, multiple trials - synthesizing a narrative that no single page in the textbook contains.</p><p><strong>When to use it:</strong> Broad conceptual questions, comparative analyses, thematic summaries.</p><p><strong>Clinical examples:</strong></p><ul><li><p><em>&#8220;How do genetic factors influence cardiovascular drug dosing?&#8221;</em> &#8594; Traverses CYP2C9 polymorphisms &#8594; VKORC1 &#8594; CYP2D6 &#8594; synthesizes the pharmacogenomics theme</p></li><li><p><em>&#8220;What are the common side effect patterns across antiarrhythmics?&#8221;</em> &#8594; Traverses amiodarone toxicities + metoprolol bradycardia + diltiazem negative inotropy &#8594; identifies patterns</p></li><li><p><em>&#8220;How has heart failure treatment evolved with SGLT2 inhibitors?&#8221;</em> &#8594; Traverses dapagliflozin &#8594; DAPA-HF &#8594; DELIVER &#8594; HFrEF + HFpEF &#8594; synthesizes the clinical shift</p></li></ul><h3><code>hybrid</code>: Both levels combined (the default)</h3><p>python</p><pre><code><code>result = await rag.aquery(
    "My patient is on warfarin and needs amiodarone - what should I know?",
    param=QueryParam(mode="hybrid"),
)</code></code></pre><p><strong>What it does:</strong> Runs both local and global retrieval, merges the results, and generates from the combined context. Gets the specific interaction facts AND the broader anticoagulation management principles.</p><p><strong>The analogy:</strong> The consulting cardiologist who both looks up the specific interaction in the drug database (local) AND draws on their clinical experience with anticoagulation management (global) to give you a complete, nuanced answer.</p><p><strong>When to use it:</strong> <strong>Most clinical queries.</strong> Real clinical questions almost always need both specific facts and broader context. This should be your default mode.</p><p><strong>Clinical examples:</strong></p><ul><li><p><em>&#8220;Should I start dapagliflozin in a patient with HFrEF and eGFR 22?&#8221;</em> &#8594; Local: dapagliflozin eGFR threshold (&#8805;20) &#8594; Global: SGLT2i evidence in CKD + HF</p></li><li><p><em>&#8220;How should I manage anticoagulation when adding amiodarone?&#8221;</em> &#8594; Local: warfarin-amiodarone interaction details &#8594; Global: anticoagulation monitoring principles</p></li><li><p><em>&#8220;What rate control options are safe in heart failure?&#8221;</em> &#8594; Local: metoprolol (safe in HFrEF) and diltiazem (contraindicated in HFrEF) &#8594; Global: rate control strategy in HF</p></li></ul><div><hr></div><h2>How Dual-Level Retrieval Works Under the Hood</h2><p>When you query in <code>hybrid</code> mode, LightRAG runs two parallel retrieval pipelines:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qhCd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qhCd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png 424w, https://substackcdn.com/image/fetch/$s_!qhCd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png 848w, https://substackcdn.com/image/fetch/$s_!qhCd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png 1272w, https://substackcdn.com/image/fetch/$s_!qhCd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qhCd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png" width="977" height="551" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:551,&quot;width&quot;:977,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:977840,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192880739?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23687554-868d-4519-bd66-47321011da4a_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qhCd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png 424w, https://substackcdn.com/image/fetch/$s_!qhCd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png 848w, https://substackcdn.com/image/fetch/$s_!qhCd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png 1272w, https://substackcdn.com/image/fetch/$s_!qhCd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d81945b-dd69-47ee-94dc-a9b345632af0_977x551.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The merge step deduplicates overlapping content (both pipelines might retrieve the same amiodarone chunk) and orders results by relevance. <br><br>The LLM then generates from this combined context: getting both the &#8220;reduce warfarin by 30&#8211;50%&#8221; fact AND the &#8220;monitor INR within 1 week and reassess at steady state&#8221; management principle.</p><div><hr></div><h2>The Decision Cheat Sheet</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fsTk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fsTk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png 424w, https://substackcdn.com/image/fetch/$s_!fsTk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png 848w, https://substackcdn.com/image/fetch/$s_!fsTk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png 1272w, https://substackcdn.com/image/fetch/$s_!fsTk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fsTk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png" width="954" height="435" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:435,&quot;width&quot;:954,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:752843,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192880739?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaacc1e5-dca4-4858-81e3-9cfc611df47a_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fsTk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png 424w, https://substackcdn.com/image/fetch/$s_!fsTk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png 848w, https://substackcdn.com/image/fetch/$s_!fsTk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png 1272w, https://substackcdn.com/image/fetch/$s_!fsTk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6efd760-0e49-4e8a-9b87-4376a06c5c06_954x435.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The practical rule:</strong> When in doubt, use <code>hybrid</code>. It&#8217;s slightly slower than <code>local</code> or <code>global</code> alone (two retrieval passes instead of one), but the latency difference is typically under 200ms, negligible for clinical use. The accuracy gain from combining both levels consistently outweighs the minor speed cost.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>LightRAG&#8217;s four query modes give you precision when you need it (local), synthesis when you need it (global), and both when you need both (hybrid). </strong></p><ul><li><p><strong>Local mode traverses specific entities and relationships for factual answers.</strong></p></li><li><p><strong>Global mode searches across thematic patterns for broad synthesis. </strong></p></li><li><p><strong>Hybrid mode, your default, combines both for the complete clinical picture.</strong> Match the mode to the question type, and your knowledge graph answers at exactly the right level of granularity.</p></li></ul></blockquote><div><hr></div><h2>Coming Tomorrow: Day 27</h2><p><strong>Visualizing Your Medical Knowledge Graph</strong></p><p>You have built a knowledge graph and queried it at multiple levels. Tomorrow you see it. You will visualize the entity-relationship network, identify clusters, trace multi-hop paths, and produce visuals that make the knowledge structure tangible to clinicians and stakeholders who&#8217;ve never heard of a &#8220;knowledge graph.&#8221; The picture that makes your CMIO say &#8220;I get it.&#8221;</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare so you don&#8217;t miss Day 27.</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p><em>Teodora Szasz, PhD | Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Day 25: Building a Medical Knowledge Graph with LightRAG]]></title><description><![CDATA[RAG for Healthcare | Day 25 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-25-building-a-medical-knowledge</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-25-building-a-medical-knowledge</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Tue, 31 Mar 2026 14:09:46 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Fbrx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Yesterday you learned how <a href="https://lightrag.github.io/">LightRAG</a> works in theory. Today you build one.</p><p>You will feed cardiovascular pharmacology content into LightRAG and watch it automatically extract entities (drug names, conditions, enzymes, lab tests), identify relationships (treats, metabolized_by, contraindicated_in), and build a queryable knowledge graph: in about 30 lines of code.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2>Setup: One Install, One API Key</h2><p>LightRAG is distributed as <code>lightrag-hku</code> on PyPI (currently v1.4.12, March 2026). Install it with:</p><p>python</p><pre><code><code>pip install lightrag-hku</code></code></pre><p>Set your OpenAI API key (LightRAG uses it for both entity extraction and embeddings):</p><p>python</p><pre><code><code>import os
os.environ["OPENAI_API_KEY"] = "your-key-here"</code></code></pre><p>That&#8217;s the entire setup.</p><div><hr></div><h2>The Clinical Data</h2><p>We will use a curated cardiovascular pharmacology reference - the same kind of content you&#8217;d find in a hospital formulary or a WHO Model Formulary chapter:</p><p>python</p><pre><code><code>cardio_pharmacology = """
Warfarin is an oral anticoagulant that inhibits vitamin K epoxide reductase,
preventing the synthesis of vitamin K-dependent clotting factors (II, VII, IX, X).
Warfarin is primarily metabolized by CYP2C9, with minor contribution from CYP3A4.
Genetic polymorphisms in CYP2C9 (particularly *2 and *3 variants) and VKORC1
result in altered warfarin sensitivity, requiring dose adjustments. Warfarin is
monitored by INR, with a therapeutic target of 2.0-3.0 for most indications and
2.5-3.5 for mechanical mitral valves. Warfarin is indicated for atrial fibrillation,
venous thromboembolism, and mechanical heart valves. Warfarin interacts with numerous
medications including amiodarone (increases INR via CYP2C9 inhibition, reduce warfarin
dose by 30-50%), fluconazole (potent CYP2C9 inhibitor, significant INR elevation),
and rifampin (potent CYP inducer, dramatically reduces warfarin effect). Warfarin
is contraindicated in pregnancy (teratogenic, causes warfarin embryopathy).

Amiodarone is a class III antiarrhythmic used for atrial fibrillation and ventricular
tachycardia. Amiodarone has an extremely long half-life of 40-55 days. Amiodarone
causes thyroid dysfunction (both hypothyroidism and hyperthyroidism) due to its
high iodine content and direct thyroid effects. Amiodarone causes pulmonary toxicity
in 1-5% of patients, requiring baseline and annual pulmonary function tests and
chest X-rays. Amiodarone causes hepatotoxicity, requiring liver function monitoring
every 6 months. Amiodarone inhibits CYP2C9, CYP2D6, and CYP3A4, causing interactions
with warfarin, digoxin, and many other medications. When initiating amiodarone in a
patient on warfarin, reduce warfarin dose by 30-50% and check INR within 1 week.

Metoprolol succinate is a selective beta-1 blocker used for heart failure with reduced
ejection fraction, hypertension, and atrial fibrillation rate control. Target dose
for HFrEF is 200mg daily. Metoprolol is metabolized by CYP2D6. Metoprolol should be
started at low doses (12.5-25mg daily) in heart failure and titrated up every 2 weeks.
Metoprolol is contraindicated in decompensated heart failure, severe bradycardia,
and second or third-degree heart block without a pacemaker.

Diltiazem is a non-dihydropyridine calcium channel blocker used for atrial fibrillation
rate control, hypertension, and angina. Diltiazem is contraindicated in heart failure
with reduced ejection fraction due to negative inotropic effects. Diltiazem inhibits
CYP3A4 and can increase levels of drugs metabolized by this enzyme. Diltiazem should
not be combined with beta-blockers in patients with impaired cardiac function due to
risk of severe bradycardia and heart block.

Dapagliflozin is an SGLT2 inhibitor approved for heart failure (both HFrEF and HFpEF),
type 2 diabetes, and chronic kidney disease. Dapagliflozin reduces heart failure
hospitalizations and cardiovascular death based on DAPA-HF and DELIVER trials. Dose
is 10mg daily regardless of diabetes status. Dapagliflozin can be initiated with eGFR
as low as 20 mL/min. Monitor for genital mycotic infections and euglycemic DKA
(rare but serious). Dapagliflozin does not require dose adjustment for renal impairment.
"""</code></code></pre><p>Five drugs. Multiple mechanisms, interactions, contraindications, monitoring requirements, and clinical trial references. Rich relationship territory.</p><div><hr></div><h2>Build the Knowledge Graph: 30 Lines</h2><p>python</p><pre><code><code>import asyncio
from lightrag import LightRAG, QueryParam
from lightrag.llm.openai import gpt_4o_mini_complete, openai_embed
from lightrag.kg.shared_storage import initialize_pipeline_status
from lightrag.utils import setup_logger

setup_logger("lightrag", level="INFO")

async def build_and_query():
    # &#9472;&#9472; INITIALIZE &#9472;&#9472;
    rag = LightRAG(
        working_dir="./cardio_kg",
        llm_model_func=gpt_4o_mini_complete,
        embedding_func=openai_embed,
    )
    await rag.initialize_storages()
    await initialize_pipeline_status()

    # &#9472;&#9472; INGEST (this builds the knowledge graph automatically) &#9472;&#9472;
    await rag.ainsert(cardio_pharmacology)
    print(" Knowledge graph built!")

    # &#9472;&#9472; QUERY: Low-level (specific facts) &#9472;&#9472;
    result = await rag.aquery(
        "What enzyme metabolizes warfarin?",
        param=QueryParam(mode="local"),  # Low-level retrieval
    )
    print(f"\n Low-level: {result}")

    # &#9472;&#9472; QUERY: High-level (themes and synthesis) &#9472;&#9472;
    result = await rag.aquery(
        "How do drug interactions affect anticoagulation management?",
        param=QueryParam(mode="global"),  # High-level retrieval
    )
    print(f"\n High-level: {result}")

    # &#9472;&#9472; QUERY: Hybrid (both levels) &#9472;&#9472;
    result = await rag.aquery(
        "What drugs treat atrial fibrillation and what are their major risks?",
        param=QueryParam(mode="hybrid"),  # Both levels combined
    )
    print(f"\n Hybrid: {result}")

asyncio.run(build_and_query())</code></code></pre><p><strong>That&#8217;s it.</strong> LightRAG reads the text, extracts entities and relationships using the LLM, builds the knowledge graph, and answers queries with three retrieval modes.</p><div><hr></div><h2>What Just Happened Under the Hood</h2><p>When you called <code>rag.ainsert()</code>, LightRAG:</p><ol><li><p><strong>Chunked</strong> the pharmacology text into segments</p></li><li><p><strong>Sent each chunk to GPT-5.4</strong> with an extraction prompt</p></li><li><p><strong>Extracted entities:</strong> Warfarin, CYP2C9, Vitamin K, INR, Amiodarone, Metoprolol, Diltiazem, Dapagliflozin, HFrEF, HFpEF, Atrial Fibrillation, CYP2D6, CYP3A4...</p></li><li><p><strong>Extracted relationships:</strong> Warfarin&#8594;metabolized_by&#8594;CYP2C9, Amiodarone&#8594;inhibits&#8594;CYP2C9, Diltiazem&#8594;contraindicated_in&#8594;HFrEF, Dapagliflozin&#8594;treats&#8594;HFpEF...</p></li><li><p><strong>Deduplicated</strong> entities (merging &#8220;warfarin&#8221; and &#8220;Warfarin&#8221;)</p></li><li><p><strong>Profiled</strong> each entity with a summary description</p></li><li><p><strong>Embedded</strong> entity and relationship descriptions as vectors</p></li><li><p><strong>Stored</strong> everything &#8212; graph structure + original text chunks + vector indices</p></li></ol><p>All of this from a single <code>ainsert()</code> call.</p><div><hr></div><h2>The Three Query Modes</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Fbrx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Fbrx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png 424w, https://substackcdn.com/image/fetch/$s_!Fbrx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png 848w, https://substackcdn.com/image/fetch/$s_!Fbrx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png 1272w, https://substackcdn.com/image/fetch/$s_!Fbrx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Fbrx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png" width="714" height="338.87253886010365" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:458,&quot;width&quot;:965,&quot;resizeWidth&quot;:714,&quot;bytes&quot;:850994,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192689511?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F05a90ef8-ba12-4585-9d4a-8bc628b71e62_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Fbrx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png 424w, https://substackcdn.com/image/fetch/$s_!Fbrx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png 848w, https://substackcdn.com/image/fetch/$s_!Fbrx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png 1272w, https://substackcdn.com/image/fetch/$s_!Fbrx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F038d5ad1-c1c5-4478-905a-33cd2b67ee69_965x458.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Five Queries to Try</h2><p>Once your graph is built, these queries showcase what LightRAG can do that flat RAG can&#8217;t:</p><p>python</p><pre><code><code># Multi-hop: Drug &#8594; Enzyme &#8594; Other drugs sharing that enzyme
"What other drugs are affected by CYP2C9 inhibition?"

# Contraindication check
"Can I give diltiazem to a patient with HFrEF?"

# Interaction chain
"If I start amiodarone, what other medications need dose adjustments?"

# Comparative
"Compare metoprolol and diltiazem for atrial fibrillation rate control"

# Synthesis across mechanisms
"Which cardiovascular drugs require genetic testing before prescribing?"</code></code></pre><p>Each of these requires traversing multiple entities and relationships. The kind of multi-hop reasoning that makes knowledge graphs powerful (<a href="https://teodoracoach.substack.com/p/day-22-knowledge-graphs-101-mapping">Day 22</a>).</p><div><hr></div><h2>Incremental Updates: Add Without Rebuild</h2><p>When new drug information arrives, just insert it:</p><p>python</p><pre><code><code>new_drug_info = """
Rivaroxaban is a direct oral anticoagulant (DOAC) that inhibits Factor Xa.
Unlike warfarin, rivaroxaban does not require INR monitoring...
"""

await rag.ainsert(new_drug_info)
# The knowledge graph updates incrementally &#8212; no rebuild needed</code></code></pre><p>LightRAG extracts new entities, links them to existing ones where they overlap (e.g., &#8220;Rivaroxaban&#8221; gets connected to &#8220;Atrial Fibrillation&#8221; via a <code>treats</code> relationship), and the graph grows organically. This is critical for healthcare, where formularies update monthly and new drug approvals arrive regularly.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>LightRAG turns clinical text into a queryable knowledge graph automatically: extract entities, build relationships, and answer multi-hop clinical questions in ~30 lines of code. </strong></p><p><strong>Three query modes (local, global, hybrid) handle everything from specific drug facts to thematic synthesis. Incremental updates mean your graph grows with your knowledge base.</strong> </p><p>Tomorrow, we go deeper into dual-level retrieval and when each mode shines.</p></blockquote><div><hr></div><h2>Coming Tomorrow: Day 26</h2><p><strong>Dual-Level Retrieval - Getting Both the Facts and the Big Picture</strong></p><p>Today you built the graph and ran basic queries. Tomorrow we explore the dual-level retrieval system in depth - when to use local vs. global vs. hybrid mode, how to tune retrieval parameters for clinical accuracy, and the performance characteristics that matter at scale.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare so you don&#8217;t miss Day 26.</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Day 24: LightRAG - The Graph-Based RAG That Outperforms Everything]]></title><description><![CDATA[RAG for Healthcare | Day 24 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-24-lightrag-the-graph-based-rag</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-24-lightrag-the-graph-based-rag</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Tue, 31 Mar 2026 03:23:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!skFL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!skFL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!skFL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png 424w, https://substackcdn.com/image/fetch/$s_!skFL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png 848w, https://substackcdn.com/image/fetch/$s_!skFL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png 1272w, https://substackcdn.com/image/fetch/$s_!skFL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!skFL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png" width="398" height="362.81335952848724" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:928,&quot;width&quot;:1018,&quot;resizeWidth&quot;:398,&quot;bytes&quot;:941075,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192667850?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!skFL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png 424w, https://substackcdn.com/image/fetch/$s_!skFL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png 848w, https://substackcdn.com/image/fetch/$s_!skFL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png 1272w, https://substackcdn.com/image/fetch/$s_!skFL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38e9cc72-4da5-47e3-be33-ebc51e858f58_1018x928.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">An LLM-generated knowledge graph built using GPT-4 Turbo (<a href="https://microsoft.github.io/graphrag/">Source</a>)</figcaption></figure></div><p>Yesterday you learned that the best healthcare RAG systems combine embeddings (find what&#8217;s relevant) with knowledge graphs (trace how things connect). The three-phase architecture: retrieve, augment, generate.</p><p>The question left hanging: <em>Who builds the knowledge graph?</em></p><p>Manually constructing a knowledge graph from clinical documents (extracting every entity, labeling every relationship, resolving synonyms) is brutally labor-intensive. A 200-page pharmacology textbook might contain 5,000 entities and 15,000 relationships. No one is tagging those by hand.</p><p><strong>LightRAG does it automatically.</strong> You feed it documents. It chunks the text, uses an LLM to extract entities and relationships, builds the knowledge graph, and then combines graph traversal with vector retrieval. All in one framework. <a href="https://arxiv.org/abs/2410.05779">Published in 2024</a>, accepted at EMNLP 2025, and under active development with multimodal support and RAGAS evaluation as of March 2026.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><p>In benchmarks, it outperforms naive RAG, <a href="https://docs.haystack.deepset.ai/docs/hypothetical-document-embeddings-hyde">HyDE</a>, and <a href="https://microsoft.github.io/graphrag/">Microsoft&#8217;s GraphRAG</a> across retrieval accuracy, response quality, and efficiency. Here&#8217;s why.</p><div><hr></div><h2>How LightRAG Works (5 Steps)</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!75t7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!75t7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png 424w, https://substackcdn.com/image/fetch/$s_!75t7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png 848w, https://substackcdn.com/image/fetch/$s_!75t7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png 1272w, https://substackcdn.com/image/fetch/$s_!75t7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!75t7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png" width="1001" height="473" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:473,&quot;width&quot;:1001,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:935370,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192667850?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb08b37bd-03ae-4968-b4c8-2c13f28e25ea_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!75t7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png 424w, https://substackcdn.com/image/fetch/$s_!75t7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png 848w, https://substackcdn.com/image/fetch/$s_!75t7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png 1272w, https://substackcdn.com/image/fetch/$s_!75t7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bd6158e-1b50-476f-bc5e-48d0440d6773_1001x473.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><h2>Step 1: Chunk the documents</h2><p>Same as traditional RAG. The text gets split into manageable chunks.</p><h3>Step 2: Extract entities and relationships with an LLM</h3><p>This is the breakthrough. LightRAG sends each chunk to an LLM (GPT-5.4, <a href="https://qwen.ai/home">Qwen</a>, or any capable model) with an extraction prompt: <em>&#8220;Identify all entities and their relationships in this text.&#8221;</em></p><p>From a pharmacology chunk about warfarin, the LLM extracts:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uci9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uci9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png 424w, https://substackcdn.com/image/fetch/$s_!uci9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png 848w, https://substackcdn.com/image/fetch/$s_!uci9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png 1272w, https://substackcdn.com/image/fetch/$s_!uci9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uci9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png" width="436" height="239.44707347447073" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:441,&quot;width&quot;:803,&quot;resizeWidth&quot;:436,&quot;bytes&quot;:634079,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192667850?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95a21567-d5ec-4d1d-9967-c5b1becdbb0c_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uci9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png 424w, https://substackcdn.com/image/fetch/$s_!uci9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png 848w, https://substackcdn.com/image/fetch/$s_!uci9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png 1272w, https://substackcdn.com/image/fetch/$s_!uci9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68e8f43d-5f22-496b-b717-61e131244ccd_803x441.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Clinical context:</strong> This extraction captures the <em>mechanistic</em> knowledge that flat text retrieval misses. CYP2C9 is the cytochrome P450 enzyme responsible for metabolizing warfarin. Genetic polymorphisms in CYP2C9 (particularly *2 and *3 variants) cause slow warfarin metabolism, requiring lower doses - a pharmacogenomic relationship that LightRAG can extract and traverse.</p><h3>Step 3: Build the knowledge graph</h3><p>Extracted entities become <strong>nodes.</strong> Extracted relationships become <strong>edges.</strong> LightRAG deduplicates entities (merging &#8220;warfarin&#8221; and &#8220;Warfarin&#8221; and &#8220;Coumadin&#8221;), profiles each entity with a summary description, and connects everything into a navigable graph.</p><p><strong>The key design choice:</strong> LightRAG is <strong>chunk-centric</strong>, not triple-centric. Each entity and relationship stays linked to the original text chunk it was extracted from. When you retrieve an entity, you also get the original passage, preserving context that pure triple stores lose.</p><h3>Step 4: Index everything for dual-level retrieval</h3><p>LightRAG creates <strong>two types of search keys:</strong></p><ul><li><p><strong>Low-level keys:</strong> Linked to specific entities and relationships. Answer precise factual questions: <em>&#8220;What enzyme metabolizes warfarin?&#8221;</em></p></li><li><p><strong>High-level keys:</strong> Linked to broader themes and concepts. Answer abstract questions: <em>&#8220;How do genetic polymorphisms affect anticoagulation therapy?&#8221;</em></p></li></ul><p>Both key types get embedded and stored as vectors - so retrieval uses the same fast similarity search you already know (Days 3&#8211;6).</p><h3>Step 5: Retrieve and generate</h3><p>When a query arrives, LightRAG:</p><ol><li><p>Generates low-level and high-level search keys from the query</p></li><li><p>Retrieves matching entities, relationships, and original text chunks</p></li><li><p>Feeds everything - graph structure + source text - to the LLM for generation</p></li></ol><p><strong>The result:</strong> Answers that combine the precision of graph traversal with the contextual richness of the original documents.</p><div><hr></div><h2>Dual-Level Retrieval: Why It Matters for Healthcare</h2><p>This is LightRAG&#8217;s most powerful feature for clinical use.</p><h3>Low-level: Facts and specifics</h3><p><em>&#8220;What is the renal dose adjustment for meropenem?&#8221;</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FG8s!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FG8s!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png 424w, https://substackcdn.com/image/fetch/$s_!FG8s!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png 848w, https://substackcdn.com/image/fetch/$s_!FG8s!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png 1272w, https://substackcdn.com/image/fetch/$s_!FG8s!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FG8s!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png" width="975" height="348" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:348,&quot;width&quot;:975,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:631812,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192667850?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06d344d8-4a79-40c0-b06b-3a2a36fee958_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FG8s!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png 424w, https://substackcdn.com/image/fetch/$s_!FG8s!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png 848w, https://substackcdn.com/image/fetch/$s_!FG8s!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png 1272w, https://substackcdn.com/image/fetch/$s_!FG8s!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c9b04d-96ec-4012-ad61-624d4f3bb647_975x348.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Precise. Deterministic. Exactly what a pharmacist needs.</p><h3>High-level: Themes and synthesis</h3><p><em>&#8220;How has the approach to antibiotic stewardship evolved in the past decade?&#8221;</em></p><p>High-level retrieval aggregates across multiple entities and relationships, connecting stewardship principles, de-escalation evidence, shorter duration trials, and resistance patterns into a thematic summary that no single chunk contains.</p><p><strong>The analogy:</strong> Low-level retrieval is asking the hospital pharmacist a specific drug question - they give you an exact answer. High-level retrieval is asking the infectious disease attending to explain the philosophy behind the stewardship program - they synthesize across their experience.</p><p>Most clinical queries need both. <em>&#8220;Should I de-escalate this patient&#8217;s piperacillin-tazobactam?&#8221;</em> requires specific culture data (low-level) AND understanding of de-escalation principles (high-level). </p><p><strong>LightRAG&#8217;s dual retrieval handles both simultaneously.</strong></p><div><hr></div><h2>LightRAG vs. Naive RAG vs. GraphRAG</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YM-q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faed04845-b964-4193-aa47-580b14f0d882_991x486.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YM-q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faed04845-b964-4193-aa47-580b14f0d882_991x486.png 424w, https://substackcdn.com/image/fetch/$s_!YM-q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faed04845-b964-4193-aa47-580b14f0d882_991x486.png 848w, https://substackcdn.com/image/fetch/$s_!YM-q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faed04845-b964-4193-aa47-580b14f0d882_991x486.png 1272w, https://substackcdn.com/image/fetch/$s_!YM-q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faed04845-b964-4193-aa47-580b14f0d882_991x486.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YM-q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faed04845-b964-4193-aa47-580b14f0d882_991x486.png" width="991" height="486" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aed04845-b964-4193-aa47-580b14f0d882_991x486.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:486,&quot;width&quot;:991,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:945351,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192667850?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d51e63-6c41-4e3f-a9a7-2033d1c5ccfc_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!YM-q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faed04845-b964-4193-aa47-580b14f0d882_991x486.png 424w, https://substackcdn.com/image/fetch/$s_!YM-q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faed04845-b964-4193-aa47-580b14f0d882_991x486.png 848w, https://substackcdn.com/image/fetch/$s_!YM-q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faed04845-b964-4193-aa47-580b14f0d882_991x486.png 1272w, https://substackcdn.com/image/fetch/$s_!YM-q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faed04845-b964-4193-aa47-580b14f0d882_991x486.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The critical advantage for healthcare:</strong> <br><br>LightRAG&#8217;s incremental update capability means you can add new guidelines, new drug approvals, or updated protocols without rebuilding the entire graph. <br><br>In a clinical setting where formularies update monthly and guidelines update annually, this is essential.</p><div><hr></div><h2>What Makes It &#8220;Light&#8221;</h2><p>Three things that make LightRAG faster and cheaper than Microsoft&#8217;s GraphRAG:</p><ol><li><p><strong>No community detection step.</strong> GraphRAG runs the Leiden algorithm to cluster entities into communities, then generates summaries for each community. This is expensive and slow. LightRAG skips it. Entities and relationships are indexed directly.</p></li><li><p><strong>Vector-indexed graph.</strong> Instead of traversing the full graph at query time, LightRAG embeds entity and relationship descriptions as vectors. Retrieval is a fast similarity search (<a href="https://teodoracoach.substack.com/p/day-16-faiss-at-scale-searching-through">Day 16)</a>, not a full graph traversal.</p></li><li><p><strong>Incremental updates.</strong> New documents get chunked, entities extracted, and added to the existing graph - no rebuild required. GraphRAG needs to re-cluster the entire graph when new data arrives.</p></li></ol><div><hr></div><h2>Practical Considerations for Healthcare</h2><p><strong>LLM requirements:</strong> LightRAG uses an LLM for entity extraction (Step 2), which means extraction quality depends on model capability. The project recommends models with at least 32B parameters and 32K+ context. For clinical documents with dense medical terminology, use the strongest model available for extraction - GPT-5.4 or equivalent.</p><p><strong>Cost:</strong> The extraction step (running every chunk through an LLM) is a one-time indexing cost. For a 200-page clinical guideline, expect a few dollars in API costs. Queries after indexing are fast and cheap.</p><p><strong>HIPAA:</strong> If your documents contain PHI, run extraction with a local LLM (Qwen, Llama, etc.) to keep data on-premises. LightRAG supports open-source models for all steps.</p><p><strong>Storage backends:</strong> As of March 2026, LightRAG supports Neo4j, MongoDB, PostgreSQL, and OpenSearch as storage backends - all options that healthcare IT teams are familiar with.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>LightRAG automatically builds knowledge graphs from your documents using LLM-based entity extraction, then combines graph traversal with vector retrieval in a dual-level system - low-level for specific facts, high-level for thematic synthesis. </strong></p><p><strong>It&#8217;s faster and cheaper than GraphRAG, supports incremental updates, and preserves links to original source text.</strong> </p><p>For healthcare, this means you can feed it clinical guidelines and get a system that answers both &#8220;What is the dose of X?&#8221; and &#8220;How has the approach to Y evolved?&#8221; - without manually building a knowledge graph.</p></blockquote><div><hr></div><h2>Coming Tomorrow: Day 25</h2><p><strong>Building a Medical Knowledge Graph with LightRAG</strong></p><p>Today was how LightRAG works. Tomorrow you build one. You will feed clinical pharmacology content into LightRAG, watch it extract entities and relationships, and query it with both low-level and high-level clinical questions. Hands-on, with code.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare so you don&#8217;t miss Day 25.</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Day 23: Embeddings vs. Knowledge Graphs: Competitors or Best Friends?]]></title><description><![CDATA[RAG for Healthcare | Day 23 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-23-embeddings-vs-knowledge-graphs</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-23-embeddings-vs-knowledge-graphs</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Sun, 29 Mar 2026 15:31:54 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!bM0M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Two questions. Same patient. Watch what happens.</p><p><strong>Question 1:</strong> <em>&#8220;Patient presents with crushing substernal chest pain, diaphoresis, and nausea. What should I consider?&#8221;</em></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Your embedding-based RAG nails this. &#8220;Crushing chest pain&#8221; and &#8220;myocardial infarction&#8221; are semantically close (Day 3). The retriever finds ACS management guidelines instantly. Score: 0.93.</p><p><strong>Question 2:</strong> <em>&#8220;This patient is on warfarin, amiodarone, and omeprazole. Are there interactions I should know about?&#8221;</em></p><p>Your embedding-based RAG struggles. It finds chunks <em>mentioning</em> these drugs, but it can&#8217;t trace the specific interaction pathways: warfarin + amiodarone &#8594; potentiated anticoagulation via CYP inhibition &#8594; bleeding risk. It doesn&#8217;t know that omeprazole reduces clopidogrel efficacy but has minimal interaction with warfarin. The answer is vague where it should be precise.</p><p><strong>Clinical context:</strong> The warfarin-amiodarone interaction is one of the most dangerous in cardiology. Amiodarone inhibits CYP2C9, the enzyme that metabolizes warfarin. When both are co-prescribed, warfarin levels can increase 30&#8211;50%, pushing INR into dangerous territory and dramatically increasing bleeding risk. This isn&#8217;t a &#8220;maybe&#8221; - it requires mandatory dose reduction and increased INR monitoring. An imprecise answer here could lead to a hemorrhagic stroke.</p><p>Same RAG system. Same embedding model. Same FAISS index. One question answered brilliantly. One answered dangerously.</p><p><strong>The problem isn&#8217;t your RAG. The problem is using only one tool for two fundamentally different types of questions.</strong></p><div><hr></div><h2>The Two Types of Clinical Questions</h2><p>Every clinical question falls into one of two categories:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GEnh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc214073b-9041-4068-a7a9-883056af83cd_952x444.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GEnh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc214073b-9041-4068-a7a9-883056af83cd_952x444.png 424w, https://substackcdn.com/image/fetch/$s_!GEnh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc214073b-9041-4068-a7a9-883056af83cd_952x444.png 848w, https://substackcdn.com/image/fetch/$s_!GEnh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc214073b-9041-4068-a7a9-883056af83cd_952x444.png 1272w, https://substackcdn.com/image/fetch/$s_!GEnh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc214073b-9041-4068-a7a9-883056af83cd_952x444.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GEnh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc214073b-9041-4068-a7a9-883056af83cd_952x444.png" width="952" height="444" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c214073b-9041-4068-a7a9-883056af83cd_952x444.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:444,&quot;width&quot;:952,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:764261,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192479580?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11429d11-eb75-4ed5-a604-798e29406f10_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!GEnh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc214073b-9041-4068-a7a9-883056af83cd_952x444.png 424w, https://substackcdn.com/image/fetch/$s_!GEnh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc214073b-9041-4068-a7a9-883056af83cd_952x444.png 848w, https://substackcdn.com/image/fetch/$s_!GEnh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc214073b-9041-4068-a7a9-883056af83cd_952x444.png 1272w, https://substackcdn.com/image/fetch/$s_!GEnh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc214073b-9041-4068-a7a9-883056af83cd_952x444.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Type 1: &#8220;What is relevant to this situation?&#8221;</h3><p><em>Find me information that&#8217;s semantically related to what I&#8217;m describing.</em></p><ul><li><p>&#8220;Management of new-onset HFrEF in a 65-year-old&#8221;</p></li><li><p>&#8220;Antibiotic options for hospital-acquired pneumonia&#8221;</p></li><li><p>&#8220;Patient with dyspnea, orthopnea, and bilateral edema&#8221;</p></li></ul><p><strong>Best tool: Embeddings + vector search.</strong> These are open-ended, context-rich questions where semantic similarity excels. You don&#8217;t know exactly which document contains the answer - you need the retriever to <em>find</em> it based on meaning.</p><h3>Type 2: &#8220;What connects X to Y?&#8221;</h3><p><em>Trace specific relationships between named entities.</em></p><ul><li><p>&#8220;What are the drug interactions for warfarin?&#8221;</p></li><li><p>&#8220;Which beta-blockers are contraindicated in asthma?&#8221;</p></li><li><p>&#8220;What labs should I monitor on daptomycin?&#8221;</p></li></ul><p><strong>Best tool: Knowledge graphs.</strong> These are structured, relationship-specific questions where you need deterministic, complete answers. You know the entities - you need the connections between them.</p><p><strong>The insight that changes everything:</strong> Most real clinical questions contain <em>both</em> types. &#8220;My patient has new-onset AFib and is on warfarin for a mechanical valve &#8212; what rate control options are safe?&#8221; This needs semantic retrieval (AFib management guidelines) <em>and</em> relationship traversal (drug interactions with warfarin, contraindications with mechanical valves).</p><p>Neither tool alone gives a complete answer. Together, they do.</p><div><hr></div><h2>The Three-Phase Architecture</h2><p>Here&#8217;s how production healthcare AI systems combine both:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!d6Yx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!d6Yx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png 424w, https://substackcdn.com/image/fetch/$s_!d6Yx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png 848w, https://substackcdn.com/image/fetch/$s_!d6Yx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png 1272w, https://substackcdn.com/image/fetch/$s_!d6Yx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!d6Yx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png" width="656" height="314.88" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:444,&quot;width&quot;:925,&quot;resizeWidth&quot;:656,&quot;bytes&quot;:729185,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192479580?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13111bd8-48e1-48c0-a548-73d5c4462fc9_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!d6Yx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png 424w, https://substackcdn.com/image/fetch/$s_!d6Yx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png 848w, https://substackcdn.com/image/fetch/$s_!d6Yx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png 1272w, https://substackcdn.com/image/fetch/$s_!d6Yx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa3519178-f91e-4c62-9ebf-4f34cf32feae_925x444.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The analogy:</strong> A consulting physician gets a consult request (the query). <br><strong>Phase 1:</strong> they pull the relevant guidelines from the shelf (embeddings). <br><strong>Phase 2</strong>: they check the drug interaction database and the patient&#8217;s allergy list (knowledge graph). <br><strong>Phase 3</strong>: they synthesize both into a recommendation (LLM). <br><br>No good consultant skips either step.</p><h3>What Phase 2 Adds</h3><p>Without the knowledge graph augmentation, the LLM receives guideline chunks that <em>mention</em> warfarin but may not explicitly list every interaction. The LLM might fill the gap from training data - which is hallucination (<a href="https://teodoracoach.substack.com/p/rag-for-healthcare-day-2">Day 2</a>).</p><p>With the knowledge graph, the context now includes:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dwLg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dwLg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png 424w, https://substackcdn.com/image/fetch/$s_!dwLg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png 848w, https://substackcdn.com/image/fetch/$s_!dwLg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png 1272w, https://substackcdn.com/image/fetch/$s_!dwLg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dwLg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png" width="504" height="292.0615384615385" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:452,&quot;width&quot;:780,&quot;resizeWidth&quot;:504,&quot;bytes&quot;:670471,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192479580?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F584b3db3-624c-4dac-93bd-ab27f6e8f56e_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dwLg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png 424w, https://substackcdn.com/image/fetch/$s_!dwLg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png 848w, https://substackcdn.com/image/fetch/$s_!dwLg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png 1272w, https://substackcdn.com/image/fetch/$s_!dwLg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3fe9e45-ef63-4352-82cf-0430e47c2cd5_780x452.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This structured fact gets injected alongside the retrieved chunks. The LLM doesn&#8217;t need to infer the interaction - it&#8217;s explicitly in the context. Grounded. Deterministic. Auditable.</p><div><hr></div><h2>When to Use What</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bM0M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bM0M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png 424w, https://substackcdn.com/image/fetch/$s_!bM0M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png 848w, https://substackcdn.com/image/fetch/$s_!bM0M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png 1272w, https://substackcdn.com/image/fetch/$s_!bM0M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bM0M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png" width="959" height="448" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:448,&quot;width&quot;:959,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:590409,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192479580?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2512062f-8fd5-4a00-9458-d97ed25497e0_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bM0M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png 424w, https://substackcdn.com/image/fetch/$s_!bM0M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png 848w, https://substackcdn.com/image/fetch/$s_!bM0M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png 1272w, https://substackcdn.com/image/fetch/$s_!bM0M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e06d5-d2e4-4c1f-9cb7-0a6e800f1f4d_959x448.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The practical rule:</strong> <br></p><ul><li><p>If the question contains <strong>named clinical entities</strong> (drug names, specific conditions, lab values) AND requires understanding <strong>relationships between them</strong>: use both. </p></li><li><p>If it&#8217;s purely a &#8220;find me something relevant&#8221; question - embeddings are sufficient.</p></li><li><p>If it&#8217;s purely a &#8220;what connects A to B&#8221; question - the knowledge graph alone is faster and more precise.</p></li></ul><div><hr></div><h2>The Cost of Getting This Wrong</h2><p>Using only embeddings when you need a knowledge graph &#8594; <strong>imprecise or incomplete answers</strong> on relationship questions. The warfarin interaction example: a vague answer where a precise one is life-or-death.</p><p>Using only a knowledge graph when you need embeddings &#8594; <strong>brittle, narrow answers</strong> on open-ended questions. A graph can tell you &#8220;metoprolol treats AFib&#8221; but can&#8217;t find a guideline paragraph that discusses rate control strategy in the context of heart failure with preserved ejection fraction and renal impairment.</p><p>Using both when you only need one &#8594; <strong>unnecessary complexity and latency.</strong> A simple &#8220;what is the dose of amoxicillin for CAP?&#8221; doesn&#8217;t need a graph lookup. Don&#8217;t over-engineer.</p><p><strong>The judgment of when to use which tool is the architectural skill</strong> that separates RAG practitioners who build systems that work from those who build systems that impress in demos but fail in production.</p><div><hr></div><h2>Where This Is Heading</h2><p>Tomorrow (Day 24) you will learn <strong>LightRAG</strong>: a graph-based RAG framework that automates the three-phase architecture. It extracts entities and relationships from your documents automatically, builds the knowledge graph for you, and combines graph traversal with vector retrieval in a single query.</p><p>On Day 25, you will learn <strong>GraphRAG</strong> (Microsoft&#8217;s approach) - a different architecture that uses community detection to organize your knowledge graph into hierarchical summaries.</p><p>Both build directly on today&#8217;s conceptual framework. If you understand the three-phase architecture - retrieve, augment, generate - everything that follows will click immediately.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>Embeddings and knowledge graphs are not competitors: they solve different types of questions. <br><br>Embeddings find what&#8217;s relevant (semantic similarity). <br>Knowledge graphs find what&#8217;s connected (explicit relationships). <br><br>The best healthcare RAG systems use both in a three-phase architecture: retrieve with embeddings, augment with knowledge graph facts, generate with the LLM.</strong> <br>This framework guides every architecture decision you&#8217;ll make from here forward.</p></blockquote><div><hr></div><h2>Coming Tomorrow: Day 24</h2><p><strong>LightRAG - The Graph-Based RAG That Outperforms Everything</strong></p><p>Today was the theory. Tomorrow is the tool. LightRAG automatically extracts entities and relationships from your clinical documents, builds a knowledge graph, and combines it with vector retrieval - in one framework. You&#8217;ll see how it handles the queries that stumped pure embedding-based RAG.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare so you don&#8217;t miss Day 24.</strong></p><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Day 22: Knowledge Graphs 101 - Mapping Patient Journeys and Drug Interactions]]></title><description><![CDATA[RAG for Healthcare | Day 22 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-22-knowledge-graphs-101-mapping</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-22-knowledge-graphs-101-mapping</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Sat, 28 Mar 2026 14:33:36 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!TpGR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A cardiologist asks your RAG system: <em>&#8220;What drugs treat atrial fibrillation but are contraindicated in decompensated heart failure?&#8221;</em></p><p>Your retriever: hybrid search, reranked, metadata-filtered, the full Week 3 stack - finds chunks about AFib treatment and chunks about heart failure contraindications. But the answer requires <em>connecting</em> information across those chunks: metoprolol treats AFib, metoprolol is a beta-blocker, beta-blockers should be initiated only in compensated (not decompensated) heart failure, diltiazem treats AFib, diltiazem is contraindicated in HFrEF entirely.</p><p>The retriever found the right documents. But the <em>reasoning</em> (connecting drug to indication to contraindication across multiple relationships) is something flat document retrieval was never designed to do.</p><p><strong>This is where knowledge graphs enter the picture.</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2>What Is a Knowledge Graph</h2><p>A knowledge graph is a structured network of <strong>entities</strong> (things) connected by <strong>relationships</strong> (how things relate to each other).</p><p>Every piece of information is stored as a <strong>triple:</strong> <br><code>Entity &#8594; Relationship &#8594; Entity</code></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zXL2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zXL2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png 424w, https://substackcdn.com/image/fetch/$s_!zXL2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png 848w, https://substackcdn.com/image/fetch/$s_!zXL2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png 1272w, https://substackcdn.com/image/fetch/$s_!zXL2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zXL2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png" width="606" height="330.814453125" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:1024,&quot;resizeWidth&quot;:606,&quot;bytes&quot;:733053,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192257105?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!zXL2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png 424w, https://substackcdn.com/image/fetch/$s_!zXL2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png 848w, https://substackcdn.com/image/fetch/$s_!zXL2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png 1272w, https://substackcdn.com/image/fetch/$s_!zXL2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26598d60-baf4-4b5b-bdbd-f0f6638d32ff_1024x559.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The analogy:</strong> <br><strong>A vector database is a library </strong>- you search by topic similarity and get back relevant pages. <br><br><strong>A knowledge graph is a map</strong> - you navigate by following connections between specific places. <br><br>The library helps you find information <em>about</em> a topic. The map helps you trace <em>paths between</em> topics.</p><p>When the cardiologist asks &#8220;What drugs treat AFib but are contraindicated in decompensated HF?&#8221;, the knowledge graph traces two paths simultaneously: </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lE8T!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lE8T!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png 424w, https://substackcdn.com/image/fetch/$s_!lE8T!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png 848w, https://substackcdn.com/image/fetch/$s_!lE8T!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png 1272w, https://substackcdn.com/image/fetch/$s_!lE8T!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lE8T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png" width="969" height="416" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:416,&quot;width&quot;:969,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:730282,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192257105?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0c65027-8b2e-4054-843c-eb4b015a1f44_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!lE8T!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png 424w, https://substackcdn.com/image/fetch/$s_!lE8T!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png 848w, https://substackcdn.com/image/fetch/$s_!lE8T!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png 1272w, https://substackcdn.com/image/fetch/$s_!lE8T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e906c4a-7d15-4df7-9863-1f4e56e316f6_969x416.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>That&#8217;s a <strong>multi-hop query</strong> - and it&#8217;s what knowledge graphs do best.</p><div><hr></div><h2>The Three Building Blocks</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SZid!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SZid!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png 424w, https://substackcdn.com/image/fetch/$s_!SZid!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png 848w, https://substackcdn.com/image/fetch/$s_!SZid!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png 1272w, https://substackcdn.com/image/fetch/$s_!SZid!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SZid!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png" width="993" height="504" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:504,&quot;width&quot;:993,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:891393,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192257105?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf662855-e49d-4dce-b3c7-09edcecdd28f_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SZid!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png 424w, https://substackcdn.com/image/fetch/$s_!SZid!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png 848w, https://substackcdn.com/image/fetch/$s_!SZid!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png 1272w, https://substackcdn.com/image/fetch/$s_!SZid!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5a4270f-3d9b-4615-a2d7-797dd7eecca3_993x504.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Triples are simple, composable, and machine-readable. <br><br>A graph of 10,000 triples can answer questions that would require reading hundreds of pages of unstructured text.</p><div><hr></div><h2>What Knowledge Graphs Can Do That Vector Search Can&#8217;t</h2><h3>Multi-hop reasoning</h3><p><em>&#8220;What are the side effects of drugs used to treat conditions that increase stroke risk?&#8221;</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pdQT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0228b758-5316-4e01-96b7-197d53520526_911x422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pdQT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0228b758-5316-4e01-96b7-197d53520526_911x422.png 424w, https://substackcdn.com/image/fetch/$s_!pdQT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0228b758-5316-4e01-96b7-197d53520526_911x422.png 848w, https://substackcdn.com/image/fetch/$s_!pdQT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0228b758-5316-4e01-96b7-197d53520526_911x422.png 1272w, https://substackcdn.com/image/fetch/$s_!pdQT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0228b758-5316-4e01-96b7-197d53520526_911x422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pdQT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0228b758-5316-4e01-96b7-197d53520526_911x422.png" width="911" height="422" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0228b758-5316-4e01-96b7-197d53520526_911x422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:422,&quot;width&quot;:911,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:676715,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192257105?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6dcdf5af-eaab-4863-96fd-34f4d1db3931_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pdQT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0228b758-5316-4e01-96b7-197d53520526_911x422.png 424w, https://substackcdn.com/image/fetch/$s_!pdQT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0228b758-5316-4e01-96b7-197d53520526_911x422.png 848w, https://substackcdn.com/image/fetch/$s_!pdQT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0228b758-5316-4e01-96b7-197d53520526_911x422.png 1272w, https://substackcdn.com/image/fetch/$s_!pdQT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0228b758-5316-4e01-96b7-197d53520526_911x422.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A vector search would need to find a single document that connects all three concepts. A knowledge graph walks the path step by step.</p><h3>Explicit contraindication checking</h3><p><em>&#8220;Can I give this patient diltiazem?&#8221;</em> (Patient has HFrEF)</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZfFr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZfFr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png 424w, https://substackcdn.com/image/fetch/$s_!ZfFr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png 848w, https://substackcdn.com/image/fetch/$s_!ZfFr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png 1272w, https://substackcdn.com/image/fetch/$s_!ZfFr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZfFr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png" width="626" height="305.1514543630893" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:486,&quot;width&quot;:997,&quot;resizeWidth&quot;:626,&quot;bytes&quot;:870539,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192257105?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bc1cd3e-a4c3-4353-8ab4-57368edf1d18_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZfFr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png 424w, https://substackcdn.com/image/fetch/$s_!ZfFr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png 848w, https://substackcdn.com/image/fetch/$s_!ZfFr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png 1272w, https://substackcdn.com/image/fetch/$s_!ZfFr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4fc18b44-afa9-4cb4-806b-2845ab368f75_997x486.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Drug interaction networks</h3><p><em>&#8220;What interactions exist for a patient on warfarin, amiodarone, and metformin?&#8221;</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eHfd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eHfd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png 424w, https://substackcdn.com/image/fetch/$s_!eHfd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png 848w, https://substackcdn.com/image/fetch/$s_!eHfd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png 1272w, https://substackcdn.com/image/fetch/$s_!eHfd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eHfd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png" width="642" height="291.6997971602434" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:448,&quot;width&quot;:986,&quot;resizeWidth&quot;:642,&quot;bytes&quot;:792019,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192257105?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5493ed2e-10a9-4ee7-8118-e204d4e49326_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eHfd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png 424w, https://substackcdn.com/image/fetch/$s_!eHfd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png 848w, https://substackcdn.com/image/fetch/$s_!eHfd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png 1272w, https://substackcdn.com/image/fetch/$s_!eHfd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87730ddb-143b-4d93-8198-cfb0767b7e62_986x448.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Temporal patient journeys</h3><p><em>&#8220;What happened to this patient between admission and discharge?&#8221;</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!29hI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!29hI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png 424w, https://substackcdn.com/image/fetch/$s_!29hI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png 848w, https://substackcdn.com/image/fetch/$s_!29hI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png 1272w, https://substackcdn.com/image/fetch/$s_!29hI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!29hI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png" width="612" height="260.3467741935484" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:422,&quot;width&quot;:992,&quot;resizeWidth&quot;:612,&quot;bytes&quot;:772124,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192257105?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc576be45-78d3-4e3a-944d-633927b7201c_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!29hI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png 424w, https://substackcdn.com/image/fetch/$s_!29hI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png 848w, https://substackcdn.com/image/fetch/$s_!29hI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png 1272w, https://substackcdn.com/image/fetch/$s_!29hI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84ef285d-fd45-4296-90cf-60bdf1efde01_992x422.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The graph encodes the clinical reasoning chain as a navigable path.</p><div><hr></div><h2>Healthcare Knowledge Graphs That Already Exist</h2><p>You don&#8217;t need to build a knowledge graph from scratch. <br><br>Several large-scale medical knowledge graphs are publicly available:</p><p><strong><a href="https://arxiv.org/abs/2510.16899">SNOMED CT</a></strong>: the most comprehensive clinical terminology system. Over 350,000 concepts with relationships (is-a, finding-site, causative-agent, etc.). Used by EHR systems worldwide.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_xaF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_xaF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png 424w, https://substackcdn.com/image/fetch/$s_!_xaF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png 848w, https://substackcdn.com/image/fetch/$s_!_xaF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png 1272w, https://substackcdn.com/image/fetch/$s_!_xaF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_xaF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png" width="1256" height="534" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:534,&quot;width&quot;:1256,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:368326,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192257105?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_xaF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png 424w, https://substackcdn.com/image/fetch/$s_!_xaF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png 848w, https://substackcdn.com/image/fetch/$s_!_xaF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png 1272w, https://substackcdn.com/image/fetch/$s_!_xaF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb49c9f8c-cd0a-4cbb-af46-9fc6667aad7b_1256x534.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong><a href="https://www.nlm.nih.gov/research/umls/rxnorm/index.html">RxNorm</a></strong>: maps between drug names, ingredients, dose forms, and strengths. Essential for medication-related graphs. Links brand names, generics, and clinical drug concepts.</p><p><strong><a href="https://www.nlm.nih.gov/research/umls/index.html">UMLS (Unified Medical Language System)</a></strong>:  integrates over 200 biomedical vocabularies including SNOMED CT, RxNorm, ICD-10, MeSH, and others into a single metathesaurus with semantic relationships.</p><p><strong>Drug interaction databases</strong>: <a href="https://go.drugbank.com/">DrugBank</a>, the <a href="https://www.fda.gov/drugs/fda-adverse-event-monitoring-system-aems/fda-adverse-event-monitoring-system-aems-public-dashboard">FDA Adverse Event Reporting System (FAERS)</a>, and commercial databases like <a href="https://store.wolterskluwercdi.com/CDI">Lexicomp</a> encode drug-drug and drug-condition interactions as structured relationships.</p><p><strong>Clinical context:</strong> SNOMED CT is the backbone of clinical documentation in many EHR systems. When a physician enters &#8220;Type 2 Diabetes Mellitus&#8221; in the chart, SNOMED CT provides the concept code (44054006), its hierarchical relationships (is-a Diabetes Mellitus, is-a Metabolic Disease), and its associated findings and procedures. This structure is already a knowledge graph - most institutions just don&#8217;t use it as one.</p><div><hr></div><h2>Knowledge Graphs vs. Vector Databases</h2><p>These are not competitors. They solve different problems:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TpGR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TpGR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png 424w, https://substackcdn.com/image/fetch/$s_!TpGR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png 848w, https://substackcdn.com/image/fetch/$s_!TpGR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png 1272w, https://substackcdn.com/image/fetch/$s_!TpGR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TpGR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png" width="690" height="348.87640449438203" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:495,&quot;width&quot;:979,&quot;resizeWidth&quot;:690,&quot;bytes&quot;:989258,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192257105?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac378f4d-a23a-47f3-9a66-a2c1148321b1_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TpGR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png 424w, https://substackcdn.com/image/fetch/$s_!TpGR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png 848w, https://substackcdn.com/image/fetch/$s_!TpGR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png 1272w, https://substackcdn.com/image/fetch/$s_!TpGR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc0b9727c-9386-474c-8f15-f9589cf6efa4_979x495.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The punchline:</strong> </p><p>Vector databases are great at finding <em>what&#8217;s relevant.</em> </p><p>Knowledge graphs are great at understanding <em>how things connect.</em> </p><p>Tomorrow (Day 23) we combine both - and the result is more powerful than either alone.</p><div><hr></div><h2>A Minimal Knowledge Graph in Python</h2><p>You don&#8217;t need a specialized graph database to start. <br><strong>NetworkX</strong> gives you a working knowledge graph in 10 lines:</p><p>python</p><pre><code><code>import networkx as nx

G = nx.DiGraph()

# Add triples
G.add_edge("Metoprolol", "Atrial Fibrillation", relationship="treats")
G.add_edge("Metoprolol", "Decompensated HF", relationship="contraindicated_in")
G.add_edge("Diltiazem", "Atrial Fibrillation", relationship="treats")
G.add_edge("Diltiazem", "HFrEF", relationship="contraindicated_in")
G.add_edge("Atrial Fibrillation", "Stroke", relationship="increases_risk_of")

# Query: What treats AFib?
afib_drugs = [n for n in G.predecessors("Atrial Fibrillation")
              if G[n]["Atrial Fibrillation"]["relationship"] == "treats"]
print(f"Drugs that treat AFib: {afib_drugs}")
# &#8594; ['Metoprolol', 'Diltiazem']

# Multi-hop: Treats AFib AND contraindicated in something?
for drug in afib_drugs:
    contras = [(drug, target) for target in G.successors(drug)
               if G[drug][target]["relationship"] == "contraindicated_in"]
    for d, c in contras:
        print(f"  {d} treats AFib but is contraindicated in {c}")
# &#8594; Metoprolol treats AFib but is contraindicated in Decompensated HF
# &#8594; Diltiazem treats AFib but is contraindicated in HFrEF</code></code></pre><p>That&#8217;s the cardiologist&#8217;s original question: answered in milliseconds with deterministic accuracy. No embedding model, no similarity threshold, no hallucination risk.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>Knowledge graphs store medical knowledge as entities connected by relationships, triples of the form (Subject, Predicate, Object). <br><br>They excel at multi-hop reasoning, contraindication checking, and drug interaction queries - the relationship-rich questions that vector search handles poorly. <br><br>They complement, not replace, your RAG pipeline.</strong> <br><br>Tomorrow we combine both into something more powerful than either alone.</p></blockquote><div><hr></div><h2>Coming Tomorrow: Day 23</h2><p><strong>Embeddings vs. Knowledge Graphs - Competitors or Best Friends?</strong></p><p>Today you learned what knowledge graphs are. <br><br>Tomorrow you learn how to <em>combine</em> them with the vector-based RAG system you&#8217;ve been building: Graph RAG, where semantic retrieval meets structured reasoning. <br><br>This is where the series crosses from standard RAG into the architecture that the most advanced healthcare AI systems are using right now.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare so you don&#8217;t miss Day 23.</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Week 3 Recap: Advanced Retrieval - The Techniques That Doubled Our Accuracy]]></title><description><![CDATA[RAG for Healthcare | Week 3 Summary | Free]]></description><link>https://teodoracoach.substack.com/p/week-3-recap-advanced-retrieval-the</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/week-3-recap-advanced-retrieval-the</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Fri, 27 Mar 2026 17:12:17 GMT</pubDate><enclosure url="https://api.substack.com/feed/podcast/192254500/486579c281c7b775a2d2a993ff531945.mp3" length="0" type="audio/mpeg"/><content:encoded><![CDATA[<p><a href="https://teodoracoach.substack.com/s/the-responsible-ai-clinic">Three weeks. Three working systems</a>. Above is Week 3 in 60 seconds.</p><p>Week 4 starts tomorrow: Knowledge Graphs, Graph RAG, Evaluation, and Multimodal RAG.</p><p>&#8594; <strong><a href="https://teodoracoach.substack.com/">Subscribe free</a></strong> for every daily article. &#8594; <strong><a href="https://teodoracoach.substack.com/">Subscribe paid</a></strong> for the build projects and notebooks.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p><em>Teodora</em></p>]]></content:encoded></item><item><title><![CDATA[Day 21: BUILD PROJECT - Multi-Source RAG: Clinical Notes + Lab Results + Imaging Reports]]></title><description><![CDATA[RAG for Healthcare | Day 21 of 35 | PREMIUM (Paid Subscribers Only)]]></description><link>https://teodoracoach.substack.com/p/day-21-build-project-multi-source</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-21-build-project-multi-source</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Fri, 27 Mar 2026 14:19:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!xv_r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Let&#8217;s Talk About What&#8217;s at Stake</h2><p>We are at an inflection point. Every hospital, every health system, every clinical research team is about to face the same question: </p><p><em><strong>Can your team build AI that works on real data (clinical or not) - or do you need to hire someone who can?</strong></em></p><p>The people who can answer &#8220;yes, we can build it&#8221; will lead the next decade of  technology (especially in healthcare). <br><br>The people who can&#8217;t will watch from the sidelines while their institutions pay consultants $300/hour to build what you&#8217;re about to build in a notebook.</p><p><strong>This is not about learning a fun new skill.</strong> AI literacy in 2026 is career survival. It&#8217;s institutional survival. The hospital that can build a clinical RAG system over its own data - internally, securely, auditably - has a competitive advantage that no vendor can match. The hospital that can&#8217;t is dependent on every vendor&#8217;s pricing, every vendor&#8217;s timeline, every vendor&#8217;s data privacy policies.</p><p>This series: 35 days, 5 build projects, every concept explained so clearly you can teach it - is the fastest path from &#8220;I&#8217;ve heard of RAG&#8221; to &#8220;I built it, I deployed it, I own it.&#8221;</p><p><strong>Today&#8217;s build project is the one that changes how people see you.</strong></p><div><hr></div><h2>Why Day 21 Is the Most Important Build Project So Far</h2><p><a href="https://teodoracoach.substack.com/p/day-7-build-project-your-first-end">Day 7</a> built a RAG over <em>one</em> document type (guidelines). <a href="https://teodoracoach.substack.com/p/day-14-build-project-production-clinical">Day 14</a> added production features (logging, confidence). Both are single-source systems.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BHhR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BHhR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png 424w, https://substackcdn.com/image/fetch/$s_!BHhR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png 848w, https://substackcdn.com/image/fetch/$s_!BHhR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png 1272w, https://substackcdn.com/image/fetch/$s_!BHhR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BHhR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png" width="1019" height="488" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:488,&quot;width&quot;:1019,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:974457,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192155621?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fade653a6-eeb2-43fe-ab3a-eb9bdd484cbe_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!BHhR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png 424w, https://substackcdn.com/image/fetch/$s_!BHhR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png 848w, https://substackcdn.com/image/fetch/$s_!BHhR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png 1272w, https://substackcdn.com/image/fetch/$s_!BHhR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7fd4b97d-b456-4e6a-b9b3-b04e8d303fac_1019x488.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Real clinical decisions are never single-source.</strong></p><p>When a consulting physician evaluates a patient, they don&#8217;t read just the progress notes. They check the labs. They pull up the imaging. They cross-reference the medication list against the renal function. They synthesize a unified clinical picture from <em>multiple data types</em> - each with different structure, vocabulary, and clinical meaning.</p><p>Today you build an AI that does the same thing.</p><p><strong>Three separate FAISS indices:</strong></p><ul><li><p>One for clinical progress notes. </p></li><li><p>One for laboratory results. </p></li><li><p>One for radiology reports. </p></li></ul><p>When a clinician asks &#8220;What is the trend in this patient&#8217;s renal function and has imaging shown any changes?&#8221; - the system queries all three, merges the results with source attribution, and generates a unified answer that synthesizes across data types.</p><p>This is the architecture used in real clinical decision support systems. And you&#8217;ll have it running in 90 seconds.</p><div><hr></div><h2>What You&#8217;re Getting Today</h2><h3>The Clinical Data</h3><p>Two complete patient stories, spanning multiple days, with realistic clinical detail:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xv_r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xv_r!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png 424w, https://substackcdn.com/image/fetch/$s_!xv_r!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png 848w, https://substackcdn.com/image/fetch/$s_!xv_r!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png 1272w, https://substackcdn.com/image/fetch/$s_!xv_r!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xv_r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png" width="504" height="296.4064864864865" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:544,&quot;width&quot;:925,&quot;resizeWidth&quot;:504,&quot;bytes&quot;:947375,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192155621?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b56442f-3f21-470a-87c7-1ce8f67631f8_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xv_r!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png 424w, https://substackcdn.com/image/fetch/$s_!xv_r!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png 848w, https://substackcdn.com/image/fetch/$s_!xv_r!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png 1272w, https://substackcdn.com/image/fetch/$s_!xv_r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9fbb85d2-6246-4d15-9314-55681aafecca_925x544.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div>
      <p>
          <a href="https://teodoracoach.substack.com/p/day-21-build-project-multi-source">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Day 20: Context Window Management - Feeding the Right Amount of Information to GPT]]></title><description><![CDATA[RAG for Healthcare | Day 20 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-20-context-window-management</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-20-context-window-management</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Thu, 26 Mar 2026 14:33:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Wu5L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You have spent three weeks learning to retrieve the <em>right</em> chunks. Today you learn how many to actually send.</p><p>A clinician asks a complex pharmacology question. </p><p>Your pipeline:</p><p><strong>Hybrid search</strong> (<a href="https://teodoracoach.substack.com/p/day-17-hybrid-search-combining-keyword">Day 17</a>) &#8594; reranking (<a href="https://teodoracoach.substack.com/p/day-18-reranking-the-secret-weapon">Day 18</a>) &#8594; metadata filtering (<a href="http://teodoracoach.substack.com/p/day-19-metadata-filtering-searching">Day 19</a>) retrieves 15 excellent chunks. Concatenated, they total 12,000 tokens. GPT-5.4 has a 1 Million token context window. Plenty of room, right?</p><p>Here is the problem: <strong>more context does not mean better answers.</strong></p><p><strong>Research consistently shows that LLMs pay the most attention to the </strong><em><strong>beginning</strong></em><strong> and </strong><em><strong>end</strong></em><strong> of the context, and tend to ignore information in the middle. </strong>This is the &#8220;Lost in the Middle&#8221; phenomenon. And it means that your 15 carefully retrieved chunks might perform worse than a well-ordered 5.</p><div><hr></div><h2>Lost in the Middle: The Problem</h2><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><p>A landmark study by Liu et al. (<a href="https://cs.stanford.edu/~nfliu/papers/lost-in-the-middle.tacl2023.pdf#:~:text=(2023)%2C%20who%20compare%20question%20answering%20performance%20when,at%20the%20start%20of%20the%20input%20context.">Stanford, 2023</a>) tested LLMs on a task where the answer was placed at different positions within the context. The finding: <strong>accuracy dropped 20&#8211;30% when the relevant information was in the middle</strong> of a long context, compared to when it was at the beginning or end.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dMUr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dMUr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png 424w, https://substackcdn.com/image/fetch/$s_!dMUr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png 848w, https://substackcdn.com/image/fetch/$s_!dMUr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png 1272w, https://substackcdn.com/image/fetch/$s_!dMUr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dMUr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png" width="430" height="388.72767857142856" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:810,&quot;width&quot;:896,&quot;resizeWidth&quot;:430,&quot;bytes&quot;:123085,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192152067?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dMUr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png 424w, https://substackcdn.com/image/fetch/$s_!dMUr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png 848w, https://substackcdn.com/image/fetch/$s_!dMUr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png 1272w, https://substackcdn.com/image/fetch/$s_!dMUr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13ac9b3d-027a-412f-b6bc-f67bb469f4cc_896x810.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Models are better at using relevant information that occurs at the very beginning (primacy bias) or end of its input context (recency bias), and performance degrades significantly when models must access and use information located in the middle of its input context.</figcaption></figure></div><p><strong>The analogy:</strong> A physician reading a 50-page patient chart during a busy shift. They read the first few pages carefully (chief complaint, recent labs). They read the last page carefully (the assessment and plan). The 30 pages in the middle? Skimmed at best. If the critical drug interaction is buried on page 27, it might get missed - not because it wasn&#8217;t in the chart, but because attention is finite.</p><p>LLMs exhibit the same pattern. The context window is technically huge. Effective attention is not.</p><p><strong>Clinical impact:</strong> <strong>If the chunk about warfarin contraindication in pregnancy lands in position 8 of 15, surrounded by general anticoagulation content, the LLM might generate an answer that overlooks it entirely. The information was retrieved. It was in the context. It was ignored.</strong></p><div><hr></div><h2>The Three Rules</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!l52V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!l52V!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png 424w, https://substackcdn.com/image/fetch/$s_!l52V!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png 848w, https://substackcdn.com/image/fetch/$s_!l52V!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png 1272w, https://substackcdn.com/image/fetch/$s_!l52V!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!l52V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png" width="596" height="276.5197969543147" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:457,&quot;width&quot;:985,&quot;resizeWidth&quot;:596,&quot;bytes&quot;:808157,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192152067?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F263a6770-8238-435a-bc51-519ded7305cc_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!l52V!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png 424w, https://substackcdn.com/image/fetch/$s_!l52V!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png 848w, https://substackcdn.com/image/fetch/$s_!l52V!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png 1272w, https://substackcdn.com/image/fetch/$s_!l52V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc26f2995-7ebf-4a01-b60c-5746fd1beff9_985x457.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Rule 1: Fewer, Better Chunks Beat More, Okay Chunks</h3><p>The sweet spot for clinical RAG is <strong>4&#8211;7 chunks.</strong> <br>This isn&#8217;t arbitrary - it balances three factors:</p><ul><li><p><strong>Enough context</strong> to answer complex multi-faceted questions</p></li><li><p><strong>Little enough</strong> that every chunk gets the model&#8217;s full attention</p></li><li><p><strong>Room for the response</strong> within a reasonable token budget</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!z1kn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!z1kn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png 424w, https://substackcdn.com/image/fetch/$s_!z1kn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png 848w, https://substackcdn.com/image/fetch/$s_!z1kn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png 1272w, https://substackcdn.com/image/fetch/$s_!z1kn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!z1kn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png" width="602" height="316.8748707342296" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:509,&quot;width&quot;:967,&quot;resizeWidth&quot;:602,&quot;bytes&quot;:1038435,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192152067?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70ba2ad8-c3a3-42dc-96c6-7cd8617681af_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!z1kn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png 424w, https://substackcdn.com/image/fetch/$s_!z1kn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png 848w, https://substackcdn.com/image/fetch/$s_!z1kn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png 1272w, https://substackcdn.com/image/fetch/$s_!z1kn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd14d082a-a17b-4fae-ad5b-bb8840df61a1_967x509.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The practical approach:</strong> </p><ol><li><p>Retrieve broadly (20 chunks), rerank (<a href="https://teodoracoach.substack.com/p/day-18-reranking-the-secret-weapon">Day 18</a>), then take the top 5. </p></li><li><p>If the question is clearly simple (&#8221;What is first-line for uncomplicated UTI?&#8221;), take the top 3. </p></li><li><p>If the question is complex and multi-faceted (&#8221;Management of HFrEF with CKD stage 4, hyperkalemia, and atrial fibrillation&#8221;), consider the top 7.</p></li></ol><h3>Rule 2: Put the Best Evidence First and Last</h3><p>If you must send more than 5 chunks, order them strategically to exploit the attention pattern:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yAi5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yAi5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png 424w, https://substackcdn.com/image/fetch/$s_!yAi5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png 848w, https://substackcdn.com/image/fetch/$s_!yAi5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png 1272w, https://substackcdn.com/image/fetch/$s_!yAi5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yAi5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png" width="512" height="278.63945578231295" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:480,&quot;width&quot;:882,&quot;resizeWidth&quot;:512,&quot;bytes&quot;:688228,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192152067?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72514082-ee7f-4132-9e4c-ba45d857d77c_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yAi5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png 424w, https://substackcdn.com/image/fetch/$s_!yAi5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png 848w, https://substackcdn.com/image/fetch/$s_!yAi5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png 1272w, https://substackcdn.com/image/fetch/$s_!yAi5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc4d1478c-eb00-46e6-af2d-ba6807355ae1_882x480.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>python</p><pre><code><code>def order_for_attention(chunks_with_scores):
    """Order chunks to exploit beginning/end attention bias."""
    sorted_chunks = sorted(chunks_with_scores, key=lambda x: x[1])  # Best first
    if len(sorted_chunks) &lt;= 3:
        return sorted_chunks

    best = sorted_chunks[:2]          # Top 2 &#8594; beginning
    worst = sorted_chunks[2:-1]       # Middle &#8594; middle (least attention)
    second_best = [sorted_chunks[-1]] # Last strong chunk &#8594; end

    return best + worst + second_best</code></code></pre><p>This is a simple reordering: zero cost, zero latency, measurable improvement on longer contexts.</p><h3>Rule 3: Budget Your Tokens</h3><p>Every API call has a cost. Here&#8217;s the math:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!T46E!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!T46E!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png 424w, https://substackcdn.com/image/fetch/$s_!T46E!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png 848w, https://substackcdn.com/image/fetch/$s_!T46E!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png 1272w, https://substackcdn.com/image/fetch/$s_!T46E!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!T46E!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png" width="522" height="192.54545454545453" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:353,&quot;width&quot;:957,&quot;resizeWidth&quot;:522,&quot;bytes&quot;:566444,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192152067?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e54a733-1edb-438f-9dc3-94902fb2a125_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!T46E!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png 424w, https://substackcdn.com/image/fetch/$s_!T46E!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png 848w, https://substackcdn.com/image/fetch/$s_!T46E!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png 1272w, https://substackcdn.com/image/fetch/$s_!T46E!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5727b34-acd8-4811-95f4-6e1658d5753b_957x353.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>For GPT-5.4 at current pricing, a typical RAG call with 5 chunks, compared with 15 chunks:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YulO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YulO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png 424w, https://substackcdn.com/image/fetch/$s_!YulO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png 848w, https://substackcdn.com/image/fetch/$s_!YulO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png 1272w, https://substackcdn.com/image/fetch/$s_!YulO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YulO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png" width="584" height="269.14285714285717" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/efbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:471,&quot;width&quot;:1022,&quot;resizeWidth&quot;:584,&quot;bytes&quot;:775327,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192152067?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52195f4f-6440-43e0-a238-6c915d224c87_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!YulO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png 424w, https://substackcdn.com/image/fetch/$s_!YulO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png 848w, https://substackcdn.com/image/fetch/$s_!YulO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png 1272w, https://substackcdn.com/image/fetch/$s_!YulO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fefbd0f6f-6507-42ff-98d3-5b53563c67b9_1022x471.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>At 1,000 queries/day: <strong>$14/day</strong> or <strong>$420/month.</strong> Nearly double the cost, with potentially <em>worse</em> answer quality due to lost-in-the-middle.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Wu5L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Wu5L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png 424w, https://substackcdn.com/image/fetch/$s_!Wu5L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png 848w, https://substackcdn.com/image/fetch/$s_!Wu5L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png 1272w, https://substackcdn.com/image/fetch/$s_!Wu5L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Wu5L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png" width="568" height="306.5978494623656" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:502,&quot;width&quot;:930,&quot;resizeWidth&quot;:568,&quot;bytes&quot;:846397,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/192152067?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb424f3cf-d014-4e4b-bf54-95f3c47747f0_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Wu5L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png 424w, https://substackcdn.com/image/fetch/$s_!Wu5L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png 848w, https://substackcdn.com/image/fetch/$s_!Wu5L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png 1272w, https://substackcdn.com/image/fetch/$s_!Wu5L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c046b3d-8e97-423d-bfc0-3d92e448332a_930x502.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This is the rare case where doing less is better on both dimensions.</p><div><hr></div><h2>Dynamic Chunk Selection</h2><p>Not every query needs the same number of chunks. A simple heuristic:</p><p>python</p><pre><code><code>def select_top_k(reranked_chunks, scores):
    """Dynamically choose how many chunks to send."""
    top_score = scores[0]

    # If the best chunk is very strong, fewer chunks suffice
    if top_score &gt; 0.85:
        return reranked_chunks[:4]

    # If scores are moderate, include more context
    if top_score &gt; 0.70:
        return reranked_chunks[:6]

    # If scores are weak, cast a wider net (but cap at 8)
    return reranked_chunks[:8]</code></code></pre><p><strong>The analogy:</strong> When a cardiologist is very confident in a diagnosis (high score), they order 2&#8211;3 targeted tests. When uncertain (moderate score), they order a broader workup. When truly unsure (low score), they cast a wide net - but they don&#8217;t order every test in the hospital.</p><div><hr></div><h2>Counting Tokens Before You Send</h2><p>Always verify your token budget before the API call. Surprises are expensive:</p><p>python</p><pre><code><code>import tiktoken

def count_tokens(text, model="gpt-5.4"):
    encoding = tiktoken.encoding_for_model("gpt-4o")  # Use gpt-4o encoding
    return len(encoding.encode(text))

# Check before sending
total = count_tokens(system_prompt + context + query)
print(f"Input tokens: {total}")

if total &gt; 15000:
    print("&#9888;&#65039; Context may be too large &#8212; consider fewer chunks")</code></code></pre><p>This takes milliseconds and prevents unexpected bills.</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>More context is not better context. <br><br>The &#8220;Lost in the Middle&#8221; phenomenon means LLMs ignore information buried in long contexts. <br><br>The sweet spot for clinical RAG is 4&#8211;7 chunks, ordered with the best evidence at the beginning and end. <br><br>Fewer chunks = better answers + lower cost.</strong> <br><br>Budget your tokens, order your chunks strategically, and dynamically adjust K based on retrieval confidence.</p></blockquote><div><hr></div><h2>Coming Tomorrow: Day 21 (Premium Build Project)</h2><p><strong>BUILD PROJECT: Multi-Source RAG Combining Clinical Notes + Lab Results + Imaging Reports</strong></p><p>Tomorrow, <strong>paid subscribers get Build Project #3 -  a RAG system that ingests multiple data types (clinical notes, lab CSVs, radiology text reports) into a single searchable knowledge base with source-type metadata.</strong> <br><br>You will use hybrid search, reranking, metadata filtering, and context window management - everything from Week 3, running in one pipeline. <br><br>This is the project that proves RAG can handle the messy reality of multi-source clinical data.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare to get the Day 21 Build Project.</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><p><em>Teodora Szasz, PhD &#8212; Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Day 19: Metadata Filtering - Searching by Age, Diagnosis, Department, and Date]]></title><description><![CDATA[RAG for Healthcare | Day 19 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-19-metadata-filtering-searching</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-19-metadata-filtering-searching</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Wed, 25 Mar 2026 14:09:51 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/0e2f3448-fb83-4f16-b6df-dd33d8053d0d_460x246.gif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A pediatric cardiologist queries your RAG system: <em>&#8220;Management of Kawasaki disease.&#8221;</em></p><p>The retriever returns five chunks:</p><ul><li><p>Three are about adult coronary artery disease. </p></li><li><p>One is about pediatric fever workup. </p></li><li><p>One is the actual Kawasaki disease guideline from pediatric cardiology.</p></li></ul><p>The adult coronary artery chunks have high semantic similarity: Kawasaki disease causes coronary artery aneurysms. So <strong>the vocabulary overlaps heavily with adult coronary disease</strong>. <strong>Cosine similarity can&#8217;t tell the difference</strong>. Reranking helps but doesn&#8217;t fully solve it because both topics genuinely involve coronary artery management.</p><p><strong>Clinical context:</strong> Kawasaki disease is a childhood vasculitis (inflammation of blood vessels) that primarily affects children under 5. Without treatment, 25% develop coronary artery aneurysms - ballooning of the coronary arteries that can cause heart attacks in children. Treatment is IV immunoglobulin (IVIG) plus high-dose aspirin, which is completely different from adult coronary disease management. Returning adult guidelines for a Kawasaki query isn&#8217;t just irrelevant - it&#8217;s the wrong treatment paradigm entirely.</p><p>The fix is simple: before the retriever searches, tell it <em>where</em> to look.</p><p><code>department=Pediatrics, age_group=0-18, document_type=clinical_guideline</code></p><p>Now the search only considers pediatric guideline chunks. The adult coronary disease content never enters the results. Problem solved before retrieval even begins.</p><div><hr></div><h2>What Metadata Filtering Is</h2><p>Every chunk in your vector store can carry <strong>metadata</strong> = structured key-value tags attached during ingestion. </p><p><strong>Metadata filtering restricts the search to chunks that match specific criteria </strong><em><strong>before</strong></em><strong> computing similarity scores.</strong></p><p><strong>The analogy:</strong> A hospital has one medical records system, but a pediatric cardiologist doesn&#8217;t search through adult orthopedic surgery records when looking for a patient&#8217;s echo report. The system filters by department, age, and record type first - then searches within that subset.</p><p>Without metadata: searching the entire library for a book, hoping the right one floats to the top. With metadata: walking to the pediatrics section, the cardiology shelf, the guidelines row - then searching.</p><div><hr></div><h2>Designing Your Metadata Schema</h2><p>The metadata you tag during ingestion determines what you can filter on later. You can&#8217;t filter on fields you didn&#8217;t create. Design this upfront.</p><p>Here&#8217;s the schema I recommend for clinical RAG:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0cqD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813c8176-121a-4872-a57f-386003ef6825_968x457.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0cqD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813c8176-121a-4872-a57f-386003ef6825_968x457.png 424w, https://substackcdn.com/image/fetch/$s_!0cqD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813c8176-121a-4872-a57f-386003ef6825_968x457.png 848w, https://substackcdn.com/image/fetch/$s_!0cqD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813c8176-121a-4872-a57f-386003ef6825_968x457.png 1272w, https://substackcdn.com/image/fetch/$s_!0cqD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813c8176-121a-4872-a57f-386003ef6825_968x457.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0cqD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813c8176-121a-4872-a57f-386003ef6825_968x457.png" width="586" height="276.65495867768595" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/813c8176-121a-4872-a57f-386003ef6825_968x457.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:457,&quot;width&quot;:968,&quot;resizeWidth&quot;:586,&quot;bytes&quot;:826136,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/191724949?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8f6ad2d-fa27-4feb-a124-ee1dcb24cab7_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0cqD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813c8176-121a-4872-a57f-386003ef6825_968x457.png 424w, https://substackcdn.com/image/fetch/$s_!0cqD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813c8176-121a-4872-a57f-386003ef6825_968x457.png 848w, https://substackcdn.com/image/fetch/$s_!0cqD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813c8176-121a-4872-a57f-386003ef6825_968x457.png 1272w, https://substackcdn.com/image/fetch/$s_!0cqD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F813c8176-121a-4872-a57f-386003ef6825_968x457.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>The practical rule:</strong> Tag the fields your clinicians would use to narrow a search if they were searching manually. If a cardiologist would say &#8220;I only want the 2024 guidelines, not the 2019 version,&#8221; then <code>year</code> needs to be a metadata field.</p><div><hr></div><h2>Tagging Chunks During Ingestion</h2><p>Metadata is attached when you create your LangChain <code>Document</code> objects before they enter the vector store:</p><p>python</p><pre><code><code>from langchain_core.documents import Document

chunk = Document(
    page_content="Kawasaki disease: administer IVIG 2g/kg as single infusion...",
    metadata={
        "department": "Pediatrics",
        "document_type": "clinical_guideline",
        "year": 2024,
        "age_group": "pediatric",
        "section": "treatment",
        "source": "AHA Kawasaki Disease Guideline 2024",
    }
)</code></code></pre><p>This is what we did in the <a href="https://teodoracoach.substack.com/p/day-14-build-project-production-clinical">Day 14 build project</a>: every chunk carried <code>section</code>, <code>category</code>, and <code>year</code>. Today&#8217;s article extends that pattern to a full clinical metadata schema.</p><div><hr></div><h2>Filtering at Query Time</h2><h3>With FAISS (Manual Filtering)</h3><p>FAISS doesn&#8217;t support native metadata filtering. You filter after retrieval:</p><p>python</p><pre><code><code>results = vector_store.similarity_search_with_score(query, k=20)

# Filter: only pediatric guidelines from 2023+
filtered = [
    (doc, score) for doc, score in results
    if doc.metadata.get("department") == "Pediatrics"
    and doc.metadata.get("year", 0) &gt;= 2023
][:5]  # Take top 5 after filtering</code></code></pre><p><strong>Important:</strong> Retrieve more than you need (k=20), then filter down to your target (top 5). If you retrieve k=5 and then filter, you might end up with 1&#8211;2 results after filtering.</p><h3>With Chroma, Pinecone, or Weaviate (Native Filtering)</h3><p>Managed vector databases support native metadata filtering - the filter is applied <em>during</em> the search, not after:</p><p>python</p><pre><code><code># Chroma example
results = vector_store.similarity_search(
    query,
    k=5,
    filter={"department": "Pediatrics", "year": {"$gte": 2023}},
)</code></code></pre><p>Native filtering is more efficient than post-retrieval filtering because it never computes similarity scores for irrelevant chunks. At scale (500K+ chunks), this matters.</p><div><hr></div><h2>Three Filtering Patterns for Healthcare</h2><h3>Pattern 1: Department Scoping</h3><p>Clinician is a nephrologist. Automatically scope all queries to nephrology content:</p><p>python</p><pre><code><code>filter = {"department": "Nephrology"}</code></code></pre><p>This prevents the cross-specialty pollution from the Kawasaki example. A nephrology query about &#8220;AKI management&#8221; won&#8217;t return the hepatology AKI-in-cirrhosis guidelines unless the clinician explicitly requests it.</p><h3>Pattern 2: Freshness Gating</h3><p>Only return guidelines from the past 2 years:</p><p>python</p><pre><code><code>filter = {"year": {"$gte": 2024}}</code></code></pre><p>This is the direct fix for <a href="https://teodoracoach.substack.com/p/day-13-why-bad-retrieval-bad-answers">Day 13</a>&#8217;s Failure Mode 4 (stale chunks). When you ingest the 2024 AHA heart failure guideline, the 2019 version no longer contaminates results.</p><h3>Pattern 3: Multi-Field Precision</h3><p>Combine filters for highly targeted retrieval:</p><p>python</p><pre><code><code>filter = {
    "department": "Pediatrics",
    "age_group": "pediatric",
    "document_type": "clinical_guideline",
    "year": {"$gte": 2024},
}</code></code></pre><p>Kawasaki query now searches only recent pediatric clinical guidelines. The search space might drop from 100,000 chunks to 2,000, making retrieval faster and dramatically more precise.</p><div><hr></div><h2>Metadata Filtering vs. Reranking vs. Hybrid Search</h2><p>These three techniques aren&#8217;t competitors - they are layers:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AVpe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AVpe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png 424w, https://substackcdn.com/image/fetch/$s_!AVpe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png 848w, https://substackcdn.com/image/fetch/$s_!AVpe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png 1272w, https://substackcdn.com/image/fetch/$s_!AVpe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AVpe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png" width="639" height="312.2025819265144" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:492,&quot;width&quot;:1007,&quot;resizeWidth&quot;:639,&quot;bytes&quot;:926112,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/191724949?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9020d3c4-d9bf-46e1-a55b-ac26822885af_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AVpe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png 424w, https://substackcdn.com/image/fetch/$s_!AVpe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png 848w, https://substackcdn.com/image/fetch/$s_!AVpe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png 1272w, https://substackcdn.com/image/fetch/$s_!AVpe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa1eda2f7-153c-46c8-93c2-050900417bc2_1007x492.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The production pipeline uses all three:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-tP-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-tP-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png 424w, https://substackcdn.com/image/fetch/$s_!-tP-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png 848w, https://substackcdn.com/image/fetch/$s_!-tP-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png 1272w, https://substackcdn.com/image/fetch/$s_!-tP-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-tP-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png" width="519" height="283.3212890625" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:1024,&quot;resizeWidth&quot;:519,&quot;bytes&quot;:511050,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/191724949?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-tP-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png 424w, https://substackcdn.com/image/fetch/$s_!-tP-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png 848w, https://substackcdn.com/image/fetch/$s_!-tP-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png 1272w, https://substackcdn.com/image/fetch/$s_!-tP-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50a06481-6140-4730-a3b5-60c88ead36aa_1024x559.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Metadata filtering is the <em>first</em> step: it reduces the search space before anything else runs. <br><br>Think of it as the bouncer at the door: irrelevant chunks never get inside.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!C0GL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!C0GL!,w_424,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif 424w, https://substackcdn.com/image/fetch/$s_!C0GL!,w_848,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif 848w, https://substackcdn.com/image/fetch/$s_!C0GL!,w_1272,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif 1272w, https://substackcdn.com/image/fetch/$s_!C0GL!,w_1456,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!C0GL!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif" width="460" height="246" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:246,&quot;width&quot;:460,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:8157055,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/gif&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/191724949?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!C0GL!,w_424,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif 424w, https://substackcdn.com/image/fetch/$s_!C0GL!,w_848,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif 848w, https://substackcdn.com/image/fetch/$s_!C0GL!,w_1272,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif 1272w, https://substackcdn.com/image/fetch/$s_!C0GL!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7de78761-1cab-4e0a-a7ff-d43aab458e8f_460x246.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>Metadata filtering adds structure to vector search. <br><br>Tag chunks during ingestion with department, year, document type, and age group. <br><br>Filter at query time to search only the relevant subset. <br><br>This prevents cross-specialty contamination, eliminates stale guidelines, and makes retrieval faster and more precise.</strong> <br><br>Design your metadata schema upfront: you can&#8217;t filter on fields you didn&#8217;t create.</p></blockquote><div><hr></div><h2>Coming Tomorrow: Day 20</h2><p><strong>Context Window Management: Feeding the Right Amount of Information to GPT</strong></p><p>You can now retrieve with precision (metadata filtering), diversity (hybrid search), and relevance (reranking). But how much retrieved content should you actually send to the LLM? Too little and you miss information. Too much and the model gets confused: the &#8220;lost in the middle&#8221; problem. </p><p>Tomorrow: <strong>the science and practice of context window management.</strong></p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare so you don&#8217;t miss Day 20.</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Standout Systems by Teodora is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item><item><title><![CDATA[Day 18: Reranking: The Secret Weapon That Doubles Your RAG Accuracy]]></title><description><![CDATA[RAG for Healthcare | Day 18 of 35 | Free]]></description><link>https://teodoracoach.substack.com/p/day-18-reranking-the-secret-weapon</link><guid isPermaLink="false">https://teodoracoach.substack.com/p/day-18-reranking-the-secret-weapon</guid><dc:creator><![CDATA[Dr Teodora Szasz]]></dc:creator><pubDate>Tue, 24 Mar 2026 14:04:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!u2tq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>A Quick Note Before We Start</h2><p>I sometimes get asked: <em>&#8220;Why should I follow this series when I can just ask ChatGPT or Claude how to build RAG?&#8221;</em></p><p><strong>Try it. Ask an LLM: &#8220;How do I add reranking to my healthcare RAG system?&#8221;</strong></p><p>You wll get a technically correct, generic answer. </p><p>It will mention cross-encoders and maybe show you a code snippet. What it won&#8217;t tell you is <em>why</em> reranking matters specifically for clinical text, which failure mode from <a href="https://teodoracoach.substack.com/p/day-13-why-bad-retrieval-bad-answers">Day 13</a> it fixes, how it interacts with the hybrid search you built yesterday, where to place it relative to your confidence scoring from <a href="https://teodoracoach.substack.com/p/day-14-build-project-production-clinical">Day 14</a>, or that a pharmacist querying &#8220;vancomycin AUC dosing&#8221; needs different reranking behavior than a physician querying &#8220;management of resistant hypertension.&#8221;</p><p>That is the difference between information and curriculum. <br><br>I spent months designing this series so that every concept builds on the last, every example is healthcare-specific, and every technique connects to the system you are actually building. <br><br>An LLM gives you ingredients. This series gives you the recipe, the cooking technique, and the experience to know when to adjust the seasoning.</p><p>Today&#8217;s seasoning adjustment is the highest-ROI improvement in all of RAG.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2>The Problem Reranking Solves</h2><p>Your retriever returns 20 chunks for the query <em>&#8220;atrial fibrillation management in heart failure.&#8221;</em></p><p><strong>Clinical context:</strong> Atrial fibrillation (AF) occurs in 30&#8211;50% of heart failure patients. Managing AF in HF is complex because the treatment priorities can conflict - rate control drugs like diltiazem are effective for AF but contraindicated in HFrEF because they worsen heart failure. Rhythm control with catheter ablation (CASTLE-AF trial) shows improved outcomes in HF patients. Anticoagulation is required but DOACs are preferred over warfarin in most cases. A clinician asking this question needs the <em>intersection</em> of AF and HF management - not either one separately.</p><p>Here&#8217;s what the retriever found:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eGXR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eGXR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg 424w, https://substackcdn.com/image/fetch/$s_!eGXR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg 848w, https://substackcdn.com/image/fetch/$s_!eGXR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!eGXR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eGXR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg" width="584" height="318.27504244482174" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:642,&quot;width&quot;:1178,&quot;resizeWidth&quot;:584,&quot;bytes&quot;:149633,&quot;alt&quot;:&quot;Create a simple clean chart image showing a ranked list of topics by relevance to atrial fibrillation (AF) management in heart failure (HF) patients, with columns: Rank, Topic, Relevance, Notes. The list is: 1. AF rate control strategies (general) - Partially - missing HF context, 2. HFrEF GDMT overview - Partially - missing AF context, 3. AF anticoagulation with DOACs - Partially - no HF-specific guidance, 4. AF management specifically in HF patients - Yes - exactly right, 5. AF rhythm control (general population) - Partially, 6. Heart rate targets in AF - Tangentially, 7. CASTLE-AF trial: ablation in HF + AF - Yes - highly relevant, and more rows continuing the pattern if any. Present as a clear, readable table with bold headers and neat formatting.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Create a simple clean chart image showing a ranked list of topics by relevance to atrial fibrillation (AF) management in heart failure (HF) patients, with columns: Rank, Topic, Relevance, Notes. The list is: 1. AF rate control strategies (general) - Partially - missing HF context, 2. HFrEF GDMT overview - Partially - missing AF context, 3. AF anticoagulation with DOACs - Partially - no HF-specific guidance, 4. AF management specifically in HF patients - Yes - exactly right, 5. AF rhythm control (general population) - Partially, 6. Heart rate targets in AF - Tangentially, 7. CASTLE-AF trial: ablation in HF + AF - Yes - highly relevant, and more rows continuing the pattern if any. Present as a clear, readable table with bold headers and neat formatting." title="Create a simple clean chart image showing a ranked list of topics by relevance to atrial fibrillation (AF) management in heart failure (HF) patients, with columns: Rank, Topic, Relevance, Notes. The list is: 1. AF rate control strategies (general) - Partially - missing HF context, 2. HFrEF GDMT overview - Partially - missing AF context, 3. AF anticoagulation with DOACs - Partially - no HF-specific guidance, 4. AF management specifically in HF patients - Yes - exactly right, 5. AF rhythm control (general population) - Partially, 6. Heart rate targets in AF - Tangentially, 7. CASTLE-AF trial: ablation in HF + AF - Yes - highly relevant, and more rows continuing the pattern if any. Present as a clear, readable table with bold headers and neat formatting." srcset="https://substackcdn.com/image/fetch/$s_!eGXR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg 424w, https://substackcdn.com/image/fetch/$s_!eGXR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg 848w, https://substackcdn.com/image/fetch/$s_!eGXR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!eGXR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac838a96-773b-4682-9975-5690c648add9_1178x642.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The two best chunks are ranked #4 and #7. The top 3 are related but not precisely what the clinician needs. If your system sends only the top 5 chunks to the LLM (<a href="https://teodoracoach.substack.com/p/day-6-similarity-search-how-your">Day 6</a>: K=5), chunk #7 - the CASTLE-AF trial data - doesn&#8217;t even make the cut.</p><p><strong>This is <a href="https://teodoracoach.substack.com/p/day-13-why-bad-retrieval-bad-answers">Day 13</a>&#8217;s Failure Mode 1 in action:</strong> high similarity, low relevance. The chunks are <em>about</em> the right topics but don&#8217;t <em>answer</em> the specific question.</p><p>Reranking fixes this. After reranking, the chunk about AF management in HF moves to #1, the CASTLE-AF trial moves to #2, and the tangentially related chunks drop to the bottom. The top 5 after reranking are dramatically more relevant than the original top 5.</p><p><strong>Ten lines of code. Measurably better answers.</strong></p><div><hr></div><h2>Why Initial Retrieval Gets the Order Wrong</h2><p>Understanding <em>why</em> requires understanding the difference between two types of models:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!It4L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!It4L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png 424w, https://substackcdn.com/image/fetch/$s_!It4L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png 848w, https://substackcdn.com/image/fetch/$s_!It4L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png 1272w, https://substackcdn.com/image/fetch/$s_!It4L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!It4L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png" width="1018" height="484" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:484,&quot;width&quot;:1018,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:897676,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/191725616?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2ba3018-7c8c-4614-9c74-4990a7cccd63_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!It4L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png 424w, https://substackcdn.com/image/fetch/$s_!It4L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png 848w, https://substackcdn.com/image/fetch/$s_!It4L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png 1272w, https://substackcdn.com/image/fetch/$s_!It4L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77694e6a-a80c-4bc9-9525-10ca76fb10f1_1018x484.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><br></p><h3>Bi-encoders (Your Current Retriever)</h3><p>Your embedding model (text-embedding-3-large) is a <strong>bi-encoder.</strong> It encodes the query and each chunk <em>separately</em>, then compares the resulting vectors with cosine similarity.</p><p><strong>The analogy:</strong> Two doctors write independent assessments of the same case without talking to each other. Doctor A writes a summary of the question. Doctor B writes a summary of each chunk. Then you compare their summaries for overlap. They might both mention &#8220;atrial fibrillation&#8221; and &#8220;management&#8221; (so the similarity is high),  but neither summary captures whether the chunk specifically <em>answers</em> the question.</p><p>Bi-encoders are fast (you embed the query once, compare against pre-embedded chunks) but shallow. They measure <em>topical overlap</em>, not <em>answer relevance</em>.</p><h3>Cross-encoders (The Reranker)</h3><p>A cross-encoder takes the query and a chunk <strong>together as a single input</strong> and outputs a relevance score. It reads both simultaneously, attending to the interaction between them.</p><p><strong>The analogy:</strong> A single attending physician reads the clinical question <em>and</em> the reference document side by side, then judges: &#8220;Does this document actually answer this specific question?&#8221; That joint reading - seeing the query and chunk in context together - is fundamentally more accurate than comparing independent summaries.</p><p>Cross-encoders are slow (each query-chunk pair requires a separate model inference) but deep. They measure <em>answer relevance</em>, not just topical similarity.</p><h3>Why Not Just Use Cross-Encoders for Everything?</h3><p><strong>Speed</strong>. A cross-encoder needs to evaluate every query-chunk pair individually. If you have 500,000 chunks, that&#8217;s 500,000 model inferences per query - minutes, not milliseconds.</p><p><strong>The solution:</strong> Use bi-encoders (fast, approximate) to retrieve a broad initial set (20&#8211;50 chunks), then use a cross-encoder (slow, precise) to rerank just those 20&#8211;50. The best of both worlds.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FBQc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe953ff28-511d-4dbb-8554-e341a9336462_902x509.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FBQc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe953ff28-511d-4dbb-8554-e341a9336462_902x509.png 424w, https://substackcdn.com/image/fetch/$s_!FBQc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe953ff28-511d-4dbb-8554-e341a9336462_902x509.png 848w, https://substackcdn.com/image/fetch/$s_!FBQc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe953ff28-511d-4dbb-8554-e341a9336462_902x509.png 1272w, https://substackcdn.com/image/fetch/$s_!FBQc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe953ff28-511d-4dbb-8554-e341a9336462_902x509.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FBQc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe953ff28-511d-4dbb-8554-e341a9336462_902x509.png" width="564" height="318.2660753880266" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e953ff28-511d-4dbb-8554-e341a9336462_902x509.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:509,&quot;width&quot;:902,&quot;resizeWidth&quot;:564,&quot;bytes&quot;:756778,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/191725616?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba551eec-4141-4850-8eb7-40ff65ed72db_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FBQc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe953ff28-511d-4dbb-8554-e341a9336462_902x509.png 424w, https://substackcdn.com/image/fetch/$s_!FBQc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe953ff28-511d-4dbb-8554-e341a9336462_902x509.png 848w, https://substackcdn.com/image/fetch/$s_!FBQc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe953ff28-511d-4dbb-8554-e341a9336462_902x509.png 1272w, https://substackcdn.com/image/fetch/$s_!FBQc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe953ff28-511d-4dbb-8554-e341a9336462_902x509.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Total added latency: ~200ms. Total accuracy improvement: often 20&#8211;40% better retrieval precision. That&#8217;s the ROI.</p><div><hr></div><h2>Implementation: Two Options</h2><h3>Option A: Cohere Rerank API (Easiest)</h3><p>Cohere offers a reranking API: send your query and chunks, get back reranked results. No model hosting, no GPU.</p><p>python</p><pre><code><code># pip install cohere
import cohere

co = cohere.Client("your-cohere-api-key")

results = co.rerank(
    model="rerank-v3.5",
    query="atrial fibrillation management in heart failure",
    documents=[chunk.page_content for chunk in retrieved_chunks],
    top_n=5,
    return_documents=True,
)

for r in results.results:
    print(f"Score: {r.relevance_score:.3f} | {r.document.text[:100]}...")</code></code></pre><p><strong>Pros:</strong> No infrastructure, no GPU, excellent quality, supports 100+ languages. <strong>Cons:</strong> Data sent to Cohere&#8217;s API (same HIPAA considerations as OpenAI - check BAA status), per-query cost ($2 per 1,000 searches).</p><h3>Option B: Open-Source Cross-Encoder (Local, HIPAA-friendly)</h3><p>Run a cross-encoder model locally. No data leaves your infrastructure.</p><p>python</p><pre><code><code># pip install sentence-transformers
from sentence_transformers import CrossEncoder

reranker = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-12-v2")

query = "atrial fibrillation management in heart failure"
pairs = [(query, chunk.page_content) for chunk in retrieved_chunks]
scores = reranker.predict(pairs)

# Sort by reranking score (highest first)
reranked = sorted(
    zip(retrieved_chunks, scores),
    key=lambda x: x[1],
    reverse=True,
)

for chunk, score in reranked[:5]:
    print(f"Score: {score:.3f} | {chunk.page_content[:100]}...")</code></code></pre><p><strong>Pros:</strong> Free, runs locally, no data leaves your network, HIPAA-compatible by default. <strong>Cons:</strong> Requires more compute (a GPU helps but isn&#8217;t required for small batch sizes), slightly lower quality than Cohere for some use cases.</p><p><strong>For healthcare production systems handling PHI:</strong> Option B is the safe default. For prototyping with non-PHI guideline text, Option A is fastest to implement.</p><div><hr></div><h2>Where Reranking Fits in Your Pipeline</h2><p>Here&#8217;s the updated RAG pipeline with every technique from this series:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u2tq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u2tq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png 424w, https://substackcdn.com/image/fetch/$s_!u2tq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png 848w, https://substackcdn.com/image/fetch/$s_!u2tq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png 1272w, https://substackcdn.com/image/fetch/$s_!u2tq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u2tq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png" width="1024" height="559" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:682699,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/191725616?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!u2tq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png 424w, https://substackcdn.com/image/fetch/$s_!u2tq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png 848w, https://substackcdn.com/image/fetch/$s_!u2tq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png 1272w, https://substackcdn.com/image/fetch/$s_!u2tq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc53d154f-f0e2-4d6b-a202-b7cb7d0b52ef_1024x559.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Notice the order:</strong> Retrieve broadly (20 chunks), rerank precisely (reorder those 20), then take the top 5. <br>Reranking sits <em>between</em> retrieval and generation. <br>It doesn&#8217;t replace your retriever - it refines its output.</p><div><hr></div><h2>The Numbers: Before and After</h2><p>On clinical guideline retrieval tasks, adding reranking typically produces:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0KYG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0KYG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png 424w, https://substackcdn.com/image/fetch/$s_!0KYG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png 848w, https://substackcdn.com/image/fetch/$s_!0KYG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png 1272w, https://substackcdn.com/image/fetch/$s_!0KYG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0KYG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png" width="961" height="417" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:417,&quot;width&quot;:961,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:789733,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://teodoracoach.substack.com/i/191725616?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d4842ef-9a5d-49e6-8693-2399ee613db0_1024x559.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0KYG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png 424w, https://substackcdn.com/image/fetch/$s_!0KYG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png 848w, https://substackcdn.com/image/fetch/$s_!0KYG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png 1272w, https://substackcdn.com/image/fetch/$s_!0KYG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eb423e8-4087-4e59-b87a-db70a57eeee9_961x417.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The improvement is largest when the initial retrieval returns chunks that are topically related but don&#8217;t precisely answer the question - which is the most common failure mode in clinical RAG (<a href="https://teodoracoach.substack.com/p/day-13-why-bad-retrieval-bad-answers">Day 13</a>, Failure Mode 1).</p><div><hr></div><h2>Your Takeaway for Today</h2><blockquote><p><strong>Reranking is the single highest-ROI improvement you can make to any existing RAG system. <br><br>Retrieve broadly with bi-encoders (fast, approximate), then rerank with a cross-encoder (slow, precise). <br>The cross-encoder reads query and chunk together, judging answer relevance. Not just topical similarity. </strong></p><p><strong>Ten lines of code, ~200ms of latency, 20&#8211;40% better retrieval precision.</strong> If you do one thing after reading this series, add reranking.</p></blockquote><div><hr></div><h2>Coming Tomorrow: Day 19</h2><p><strong>Metadata Filtering: Searching by Age, Diagnosis, Department, and Date</strong></p><p>Reranking improves <em>ordering</em>. Metadata filtering improves <em>scoping</em> - &#8220;only search cardiology guidelines from 2024&#8221; or &#8220;only retrieve chunks tagged as renal dosing.&#8221; <br><br>Tomorrow you will learn how to tag chunks with structured metadata and filter at retrieval time. This is the fix for <a href="https://teodoracoach.substack.com/p/day-13-why-bad-retrieval-bad-answers">Day 13</a>&#8217;s Failure Mode 4 (stale chunks) and the key to multi-department clinical RAG.</p><div><hr></div><p><strong>&#8594; Subscribe to RAG for Healthcare so you don&#8217;t miss Day 19.</strong></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://teodoracoach.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://teodoracoach.substack.com/subscribe?"><span>Subscribe now</span></a></p><p><em>Teodora Szasz, PhD - Senior Clinical Data Scientist | FDA 510(k) AI | Co-author, EchoJEPA</em></p>]]></content:encoded></item></channel></rss>