<?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[The AiEdge Newsletter]]></title><description><![CDATA[A newsletter for continuous learning about Machine Learning applications, Machine Learning System Design, MLOps, the latest techniques and news. 
Subscribe and receive a free Machine Learning book PDF!]]></description><link>https://newsletter.theaiedge.io</link><image><url>https://substackcdn.com/image/fetch/$s_!kRD-!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6e9c582-b22b-45c5-a64e-a9105824fb01_1067x1067.png</url><title>The AiEdge Newsletter</title><link>https://newsletter.theaiedge.io</link></image><generator>Substack</generator><lastBuildDate>Sun, 27 Sep 2026 16:38:11 GMT</lastBuildDate><atom:link href="https://newsletter.theaiedge.io/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[AiEdge]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[damienb@theaiedge.io]]></webMaster><itunes:owner><itunes:email><![CDATA[damienb@theaiedge.io]]></itunes:email><itunes:name><![CDATA[Damien Benveniste]]></itunes:name></itunes:owner><itunes:author><![CDATA[Damien Benveniste]]></itunes:author><googleplay:owner><![CDATA[damienb@theaiedge.io]]></googleplay:owner><googleplay:email><![CDATA[damienb@theaiedge.io]]></googleplay:email><googleplay:author><![CDATA[Damien Benveniste]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[How AI Agent Memory Updates a Changed Preference]]></title><description><![CDATA[Follow one correction from a user message to the active fact a future task retrieves.]]></description><link>https://newsletter.theaiedge.io/p/how-ai-agent-memory-updates-a-changed-preference</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/how-ai-agent-memory-updates-a-changed-preference</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Fri, 25 Sep 2026 15:04:28 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/66908f83-ab4a-4bd8-b3a3-f60d09768c5c_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>An AI coding assistant can remember that you use Python for deployment scripts and still get the next deployment wrong after you switch to Go. The problem is not that it forgot everything. It may remember <strong>both</strong> instructions and have no reliable way to tell which one is current.</p><p>Persistent agent memory tools now let applications carry stored information across sessions and update it, making the quality of that update consequential for later tasks. The question is: when a user changes a standing preference, what must happen so an agent acts on the new one? A useful memory system treats the new message as a proposed change to stored state. It identifies the fact, finds the existing fact about the same thing, reconciles the two, commits the active version, and retrieves that version when the next task needs it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lKkE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lKkE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!lKkE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!lKkE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!lKkE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lKkE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.png" width="1536" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1536,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1359304,&quot;alt&quot;:&quot;Two conflicting remembered script-language preferences converge on one later task.&quot;,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Two conflicting remembered script-language preferences converge on one later task." title="Two conflicting remembered script-language preferences converge on one later task." srcset="https://substackcdn.com/image/fetch/$s_!lKkE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!lKkE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!lKkE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!lKkE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1c4eadc1-4906-4596-b74f-9407734b1e42_1536x1024.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">The future request needs one current preference, but a transcript can offer two.</figcaption></figure></div><p>That differs from appending messages to a transcript. We can see why by following one preference from its first instruction through a correction and a later task. The same failure can affect a project decision or customer preference.</p><h2>What changes when an agent has memory?</h2><p>The model receives a limited working context with each request. A conversation transcript can be placed in that context, but it grows, contains incidental remarks, and may contain claims that no longer hold. <strong>Persistent memory</strong> here means an external store that keeps selected information beyond one request or session. A write operation changes that store; a later read returns a useful part of it to the model. The model's weights are not being retrained every time a preference changes.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fH45!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fH45!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!fH45!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!fH45!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!fH45!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fH45!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png" width="1536" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1536,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1292665,&quot;alt&quot;:&quot;A fact is written outside the model and read into a later session.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A fact is written outside the model and read into a later session." title="A fact is written outside the model and read into a later session." srcset="https://substackcdn.com/image/fetch/$s_!fH45!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!fH45!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!fH45!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!fH45!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a72a9ec-af95-4d21-b1d7-eb77479a4853_1536x1024.png 1456w" sizes="100vw"></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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Persistent memory changes external state, then supplies selected context later.</figcaption></figure></div><p>Suppose a user tells a coding assistant, &#8220;For the Atlas repository, write deployment scripts in Python.&#8221; The assistant might store a compact record with four parts: the user, the Atlas repository, the subject <em>deployment-script language</em>, and the current value <em>Python</em>. The message that supplied the preference is its source. This is more useful than an unqualified memory such as &#8220;prefers Python,&#8221; because the latter could affect unrelated work.</p><p>The store has two distinct paths. On the <strong>write path</strong>, a message or tool result is examined for information worth retaining, then compared with what is already stored. On the <strong>read path</strong>, the next task retrieves applicable memory and places it where the model can use it. If the write path is wrong, fast retrieval brings back a mistake. If the read path misses the right record, a perfect update sits unused.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YZUN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YZUN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!YZUN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!YZUN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!YZUN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YZUN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1159703,&quot;alt&quot;:&quot;A write path maintains stored facts; a read path returns applicable facts to the model.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A write path maintains stored facts; a read path returns applicable facts to the model." title="A write path maintains stored facts; a read path returns applicable facts to the model." srcset="https://substackcdn.com/image/fetch/$s_!YZUN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!YZUN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!YZUN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!YZUN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F615048b0-ae1b-4698-a677-4d0d2de23091_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">A good write is useful only when the later read selects it.</figcaption></figure></div><p>Now the user says, &#8220;For Atlas, use Go for deployment scripts from now on.&#8221; Adding that sentence as a second, equally active memory would leave the future assistant to arbitrate a contradiction each time. A better result is an active Atlas deployment-language preference of <em>Go</em>, with the former Python preference no longer active. The old statement may remain in an audit history, but it should not be presented as another current instruction.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n67r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n67r!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!n67r!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!n67r!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!n67r!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!n67r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1054108,&quot;alt&quot;:&quot;Appending leaves two candidate instructions; updating leaves one active value.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Appending leaves two candidate instructions; updating leaves one active value." title="Appending leaves two candidate instructions; updating leaves one active value." srcset="https://substackcdn.com/image/fetch/$s_!n67r!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!n67r!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!n67r!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!n67r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc56e100f-5ee5-4498-ad99-da38b8fde01b_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">A correction must change what the next read sees.</figcaption></figure></div><p><strong>Remembering a correction means changing the state that future reads see</strong>, not merely remembering that a correction was said. The change has to preserve the subject and scope of the fact, or it will solve one task by creating a wider error.</p><div id="youtube2-5HgG6_K4DYo" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;5HgG6_K4DYo&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/5HgG6_K4DYo?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div>
      <p>
          <a href="https://newsletter.theaiedge.io/p/how-ai-agent-memory-updates-a-changed-preference">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[How LLM Routers Balance Cache Reuse and Queue Time]]></title><description><![CDATA[Four routing strategies, one repeated prompt, and the point where a cold replica wins]]></description><link>https://newsletter.theaiedge.io/p/how-cache-aware-routing-chooses-between-warm-and</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/how-cache-aware-routing-chooses-between-warm-and</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Wed, 23 Sep 2026 15:03:38 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/0523da2d-4b65-4099-911d-4712db320d9c_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>An LLM request router sits in front of several replicas of the same model and chooses which replica should receive each prompt. <strong>Cache-aware routing</strong> makes that placement decision before execution by considering reusable prompt state at each replica, not only how busy it looks. The surprising part is that replicas stop being interchangeable after they begin serving traffic: one may already hold reusable computation for the prompt, while another may have a shorter queue.</p><p>Prefix-aware routing became a managed endpoint option in September 2026, a sign that cache locality has moved from an engine detail into a deployment decision.</p><p>So where should the next request go: to the warm replica or the idle one? The compact answer is to send it where the saved prompt computation is worth more than the extra work already waiting there. A useful router therefore needs two views at once: <strong>what can be reused</strong> and <strong>what must still be processed</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_!T8m-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!T8m-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!T8m-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!T8m-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!T8m-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!T8m-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1091918,&quot;alt&quot;:&quot;One LLM request faces two destinations: a warm replica with a queue and a cold replica with no queue, making the faster choice ambiguous.&quot;,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="One LLM request faces two destinations: a warm replica with a queue and a cold replica with no queue, making the faster choice ambiguous." title="One LLM request faces two destinations: a warm replica with a queue and a cold replica with no queue, making the faster choice ambiguous." srcset="https://substackcdn.com/image/fetch/$s_!T8m-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!T8m-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!T8m-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!T8m-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d246b2c-fdb6-474d-9b13-7b616e92218a_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">The cached destination is not automatically the fastest destination.</figcaption></figure></div><p>To see why, start with the work a cached prefix actually removes. Then we will keep one support prompt fixed while four routing policies make different placement decisions. That comparison will expose the useful rule, its failure modes, and the state a production router has to keep current.</p><h2>What a warm prefix actually saves</h2><p>Before routing makes sense, we need one piece of transformer serving machinery.</p><p>An incoming prompt is a sequence of tokens. During <strong>prefill</strong>, the model processes those input tokens through every transformer layer. In each attention layer it derives a key vector and a value vector for every position. Those vectors are the processed state that later tokens attend to. The first generated token can appear only after this prompt work has finished.</p><p>During <strong>decode</strong>, the model generates one new token, appends its new key and value state, and repeats. Decode can reuse the state for all earlier positions instead of rebuilding it. The stored collection is called the <strong>KV cache</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_!XLMl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XLMl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.png 424w, https://substackcdn.com/image/fetch/$s_!XLMl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.png 848w, https://substackcdn.com/image/fetch/$s_!XLMl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.png 1272w, https://substackcdn.com/image/fetch/$s_!XLMl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XLMl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.png" width="1923" height="817" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:817,&quot;width&quot;:1923,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1198485,&quot;alt&quot;:&quot;Prefill processes all prompt tokens into KV state before the first output token, while decode reuses that state and adds one token at a time.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Prefill processes all prompt tokens into KV state before the first output token, while decode reuses that state and adds one token at a time." title="Prefill processes all prompt tokens into KV state before the first output token, while decode reuses that state and adds one token at a time." srcset="https://substackcdn.com/image/fetch/$s_!XLMl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.png 424w, https://substackcdn.com/image/fetch/$s_!XLMl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.png 848w, https://substackcdn.com/image/fetch/$s_!XLMl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.png 1272w, https://substackcdn.com/image/fetch/$s_!XLMl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d71ed3b-080e-4f22-b562-573ec9d91339_1923x817.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Routing can save prefill work; it cannot make unknown output tokens exist early.</figcaption></figure></div><p>Now consider a support assistant whose prompt begins with 3,200 tokens of policies, tool descriptions, and response rules. Only the short customer question at the end changes. If the engine has already processed the same beginning, it can reuse the matching KV state and prefill only the new suffix.</p><p>Prefix caching does not mean that the model remembers a similar idea. The match is structural. Serving engines divide the prompt into token blocks, identify a block using its tokens and the blocks before it, and reuse only an unbroken matching prefix. If block three changes, later blocks no longer describe the same model state, even if much of their text looks familiar.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w2th!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w2th!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!w2th!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!w2th!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!w2th!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w2th!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1041065,&quot;alt&quot;:&quot;A prompt split into ordered token blocks reuses only the consecutive cached blocks from the beginning, stopping at the first changed block.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A prompt split into ordered token blocks reuses only the consecutive cached blocks from the beginning, stopping at the first changed block." title="A prompt split into ordered token blocks reuses only the consecutive cached blocks from the beginning, stopping at the first changed block." srcset="https://substackcdn.com/image/fetch/$s_!w2th!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!w2th!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!w2th!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!w2th!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff76bb78d-091d-48c2-8ce1-1ba972743c4f_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Prefix reuse is an unbroken chain from the first token, not a bag of similar passages.</figcaption></figure></div><p>That distinction gives prefix caching an honest boundary. It skips model computation already performed for the input prefix. It does not skip the generation of new output tokens, because those tokens do not exist yet. A workload with long repeated inputs and short answers can gain a lot; a workload with unrelated prompts or very long answers may gain little.</p><p>Within one replica, the rule is simple: reuse every valid prefix block that is still resident, prefill the remaining input, then decode normally.</p>
      <p>
          <a href="https://newsletter.theaiedge.io/p/how-cache-aware-routing-chooses-between-warm-and">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[How Test-Time Scaling Allocates LLM Reasoning Across Depth, Width, and Feedback]]></title><description><![CDATA[Why the same inference budget can finish one path, explore alternatives, or learn from a failure]]></description><link>https://newsletter.theaiedge.io/p/how-test-time-scaling-allocates-llm-reasoning</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/how-test-time-scaling-allocates-llm-reasoning</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Mon, 21 Sep 2026 15:01:16 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/d66a9ed7-efcb-487b-a0fa-160ac44e596b_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Test-time compute</strong> is the work an already-trained model performs for one request while producing, checking, or revising its answer. <strong>Test-time scaling</strong> means giving the model more of that request-time work, or allocating it differently, without retraining the model. The extra budget can extend one line of reasoning, generate alternative answers, or use an observation to try again. Those choices are often bundled under &#8216;let it think longer,&#8217; but they do not buy the same thing.</p><p>That distinction is now practical because current OpenAI and Anthropic APIs expose reasoning-effort controls while Google offers an Extended Thinking model for complex live-agent tasks, turning &#8220;let it think&#8221; into a quality, latency, and cost decision for each request.</p><p>The useful question is not simply, &#8220;How much thinking should I buy?&#8221; It is: <strong>where should the extra compute go?</strong> Test-time scaling allocates it to depth, width, or feedback. Depth extends one attempt. Width creates separate attempts. Feedback evaluates work and changes the next attempt. Each repairs a different failure, and none guarantees correctness.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RYXr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RYXr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!RYXr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!RYXr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!RYXr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RYXr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.png" width="1536" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1536,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1228899,&quot;alt&quot;:&quot;The same reasoning model receives one coding task and can spend extra compute on a longer path, parallel paths, or a test-and-revise loop.&quot;,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The same reasoning model receives one coding task and can spend extra compute on a longer path, parallel paths, or a test-and-revise loop." title="The same reasoning model receives one coding task and can spend extra compute on a longer path, parallel paths, or a test-and-revise loop." srcset="https://substackcdn.com/image/fetch/$s_!RYXr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!RYXr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!RYXr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!RYXr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faca30f23-9cd4-41df-bfe4-203d621f5bda_1536x1024.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">One budget can buy three different information flows, so &#8220;more thinking&#8221; is not a complete system description.</figcaption></figure></div><h2>What test-time compute actually is</h2><p>Start with an ordinary request. Training is already over, and the model begins with learned weights that stay fixed while it answers. At each step, the model processes the request and the tokens generated so far to choose the next token. That ordinary generation already consumes test-time compute: computation performed after training for one particular input.</p><p>The term covers more than the model's hidden reasoning tokens. It includes the work the model and its surrounding system perform to produce, inspect, and improve this one answer. Continuing the generation adds more token-level operations to the current history. Starting another generation creates a separate candidate history. Running a test or verifier creates an observation that a later attempt can use. Revising with that observation performs another generation under changed conditions.</p><p><strong>Test-time scaling</strong> is the deliberate decision to increase or reallocate that per-request work relative to a baseline answer. The extra work can matter because it changes the transient information available to a later choice: a longer prefix, a genuinely different candidate, or new evidence about an error. If the added work does not change that state or evidence, it may increase latency and cost without improving the answer.</p><p>This is not training or fine-tuning. Training changes reusable model weights for future requests. Test-time compute leaves those weights alone and is paid again for each request. It is also not synonymous with selecting a larger model or producing a longer visible answer. A system may spend substantial compute on candidates, checks, and revisions that never appear in the final response.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!snz-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!snz-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!snz-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!snz-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!snz-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!snz-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1490843,&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://newsletter.theaiedge.io/i/216478399?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.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_!snz-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!snz-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!snz-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!snz-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dce9978-aa0b-4390-b0fb-3e64295b6179_1536x1024.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Training changes reusable model weights. Test-time scaling leaves those weights fixed and increases or reallocates the work performed for one request.</figcaption></figure></div><p>We will follow one realistic coding task through all three choices. An agent must repair <code>invoice_total</code>, a function that sums prices, applies tax, and returns integer cents. Its contract requires exact decimal arithmetic, an 8 percent tax applied after aggregation, round-half-up once to the nearest cent, then conversion to integer cents. The visible invoice contains items priced at $12.49, $7.25, and $3.10. Hidden tests vary the inputs to expose half-cent rounding, multiple-item accumulation, zero tax, and binary floating-point drift.</p><p>First we need to see why one uninterrupted generation can fail. Then we can spend the same request-time budget on a deeper path, a wider candidate set, or a feedback loop and see what actually changes.</p><h2>Before scaling, identify the one-shot failure</h2><p>An autoregressive language model generates a response one token at a time. At every position it receives the request plus the tokens already written, then assigns probabilities to possible next tokens. Once a token is chosen, that token becomes part of the state used to predict everything that follows.</p><p>This left-to-right process matters because an early choice can narrow the rest of the answer. Suppose our coding agent begins with the assumption that converting dollars to cents is just <code>int(total * 100)</code>. It can write an elegant explanation and many consistent lines of code after that. The later tokens are coherent with the earlier assumption, but coherence does not repair the assumption.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rmv2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rmv2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!rmv2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!rmv2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!rmv2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rmv2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:841835,&quot;alt&quot;:&quot;A left-to-right token sequence branches at an early assumption, and later tokens remain coherent with either the sound or mistaken branch.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A left-to-right token sequence branches at an early assumption, and later tokens remain coherent with either the sound or mistaken branch." title="A left-to-right token sequence branches at an early assumption, and later tokens remain coherent with either the sound or mistaken branch." srcset="https://substackcdn.com/image/fetch/$s_!rmv2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!rmv2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!rmv2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!rmv2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cc538e-8925-4ea0-a79e-3e6d4a4bee44_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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 early token becomes part of the state that produces every later token.</figcaption></figure></div><p>A <strong>one-shot attempt</strong> is one uninterrupted generation from request to answer. It may spend many internal reasoning tokens, but it has no separate alternative to compare with and no external result that changes its course. Its success depends on the model entering a useful line of reasoning and staying there.</p><p>For this lesson, a useful accounting unit is a generated reasoning token, a candidate response, a verifier evaluation, or a tool call such as a test run. These units have different hardware costs, so we will not pretend they are perfectly interchangeable. The important constraint is that the system has a finite request-time budget and must decide how to allocate it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gGOe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gGOe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.png 424w, https://substackcdn.com/image/fetch/$s_!gGOe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.png 848w, https://substackcdn.com/image/fetch/$s_!gGOe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.png 1272w, https://substackcdn.com/image/fetch/$s_!gGOe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gGOe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.png" width="1919" height="820" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:820,&quot;width&quot;:1919,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:916532,&quot;alt&quot;:&quot;A fixed request-time budget is divided among generated tokens, candidate responses, verifier evaluations, and tool calls.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A fixed request-time budget is divided among generated tokens, candidate responses, verifier evaluations, and tool calls." title="A fixed request-time budget is divided among generated tokens, candidate responses, verifier evaluations, and tool calls." srcset="https://substackcdn.com/image/fetch/$s_!gGOe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.png 424w, https://substackcdn.com/image/fetch/$s_!gGOe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.png 848w, https://substackcdn.com/image/fetch/$s_!gGOe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.png 1272w, https://substackcdn.com/image/fetch/$s_!gGOe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2fc8f0e-9f0a-4008-9a13-49ef6c3f92df_1919x820.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">The units have different costs, but all consume finite work after the request arrives.</figcaption></figure></div><p>There are three places to allocate that budget:</p><ol><li><p><strong>Depth:</strong> continue or enrich the same reasoning trajectory.</p></li><li><p><strong>Width:</strong> sample several separate trajectories from the same starting request.</p></li><li><p><strong>Feedback:</strong> inspect work, then condition the next attempt on what the inspection revealed.</p></li></ol><p>The distinction is about information flow. Extra depth sees the same request and its own growing prefix. Width gives each attempt the request but not the siblings' work. Feedback adds a new observation, such as &#8220;the half-cent test failed,&#8221; before the next generation. Width is logical branching; whether those branches run simultaneously is a separate serving decision.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!r5X5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r5X5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!r5X5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!r5X5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!r5X5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r5X5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1098335,&quot;alt&quot;:&quot;Three aligned panels compare depth, width, and feedback by showing which information reaches each new generation step.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Three aligned panels compare depth, width, and feedback by showing which information reaches each new generation step." title="Three aligned panels compare depth, width, and feedback by showing which information reaches each new generation step." srcset="https://substackcdn.com/image/fetch/$s_!r5X5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!r5X5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!r5X5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!r5X5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7261319-ef8c-4aab-b50e-5cf0ddd7dcf4_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Depth extends a prefix, width restarts from the request, and feedback adds a new observation.</figcaption></figure></div><p>That gives us a diagnostic before we spend anything. If the model merely stops before completing a sound plan, buy depth. If different plausible starts lead to different outcomes, buy width. If a checker can reveal what went wrong, buy feedback. A high effort setting may combine these internally, but an application designer still needs this mental model to understand latency, cost, and failure.</p><h2>Depth gives one trajectory room to finish</h2><p>The simplest scaling strategy is to let one attempt run longer. The model can decompose the task, inspect edge cases, and carry intermediate facts farther before committing to the final response. In our invoice task, a deeper trajectory must preserve a specific dependency: represent the prices exactly, sum them to $22.84, apply the 8 percent tax to obtain $24.6672, round that total once to $24.67, then return 2467 cents.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DS5S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DS5S!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!DS5S!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!DS5S!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!DS5S!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DS5S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1262028,&quot;alt&quot;:&quot;One invoice-patch trajectory moves through numeric representation, rounding order, edge cases, and a final patch.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="One invoice-patch trajectory moves through numeric representation, rounding order, edge cases, and a final patch." title="One invoice-patch trajectory moves through numeric representation, rounding order, edge cases, and a final patch." srcset="https://substackcdn.com/image/fetch/$s_!DS5S!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!DS5S!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!DS5S!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!DS5S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0fa7f929-ebd9-47b3-ac63-143f55ca33d8_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Depth preserves dependent intermediate reasoning inside one trajectory.</figcaption></figure></div><p>The benefit is continuity. Every later step sees the reasoning accumulated earlier. Here, the final integer conversion only makes sense after the representation and rounding policy are settled. Once an earlier step truncates a fraction of a cent, no later step can reconstruct it. Proofs, long calculations, and code changes with dependent invariants have the same shape.</p><p>But depth is not the same as recovery. If the trajectory commits early to binary floating point and treats a failing cent as harmless noise, more tokens can reinforce the wrong frame. The model may repeatedly check arithmetic inside a mistaken representation. It is thinking longer, but within a shrinking part of the solution space.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ef3M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ef3M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!ef3M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!ef3M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!ef3M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ef3M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:972290,&quot;alt&quot;:&quot;Two long trajectories begin from different early assumptions; one reaches a sound patch while the other elaborates a floating-point mistake.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Two long trajectories begin from different early assumptions; one reaches a sound patch while the other elaborates a floating-point mistake." title="Two long trajectories begin from different early assumptions; one reaches a sound patch while the other elaborates a floating-point mistake." srcset="https://substackcdn.com/image/fetch/$s_!ef3M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!ef3M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!ef3M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!ef3M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F34f14a22-72bc-46c6-bdb2-f0dd5e0950ea_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">A longer path can complete a good approach or entrench a bad one.</figcaption></figure></div><p>That gives us the first useful rule: <strong>depth helps when a sound path is unfinished, not merely when a path is wrong</strong>. A model that often reaches the correct approach and then runs out of room is a good candidate for higher effort. A model that confidently commits to a bad representation needs an alternative or new evidence, not an even longer monologue.</p><div id="youtube2-YlB7_bsk8sI" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;YlB7_bsk8sI&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/YlB7_bsk8sI?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div>
      <p>
          <a href="https://newsletter.theaiedge.io/p/how-test-time-scaling-allocates-llm-reasoning">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[How Constrained Decoding Makes LLM Outputs Follow a Schema]]></title><description><![CDATA[The decoder can guarantee the shape of a tool call while leaving its values completely wrong.]]></description><link>https://newsletter.theaiedge.io/p/how-constrained-decoding-makes-llm-outputs</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/how-constrained-decoding-makes-llm-outputs</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Fri, 18 Sep 2026 15:04:14 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/4efaddf5-61fe-42d3-b4a0-b87ac07812c4_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>An LLM can return JSON that parses perfectly, matches every required field, and is still dangerous to execute. That is not a contradiction. It is the exact boundary of <strong>constrained decoding</strong>.</p><p>Normally, a language model can choose any token in its vocabulary at each generation step. Constrained decoding inserts a rule checker into that loop. The checker looks at the text already generated and removes every next token that would make the requested structure impossible to complete. The model then chooses among what remains.</p><p>Structured output has become a common connection layer between LLMs, extraction pipelines, and agent tools, yet a recent developer discussion exposed the practical surprise that matters here: a perfectly shaped object can still contain invented values, so schema-valid is not the same as safe to execute.</p><p>The central question is simple: <strong>what does the decoder actually guarantee?</strong> The compact answer is that it can guarantee membership in a supported output language, such as a JSON Schema, by blocking illegal continuations token by token. It does not prove that a legal value came from the input, reflects reality, satisfies a business rule, or deserves permission to trigger an action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aQnP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1085f3f-3983-456c-afd4-f324e3874914_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aQnP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1085f3f-3983-456c-afd4-f324e3874914_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!aQnP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1085f3f-3983-456c-afd4-f324e3874914_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!aQnP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1085f3f-3983-456c-afd4-f324e3874914_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!aQnP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1085f3f-3983-456c-afd4-f324e3874914_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aQnP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1085f3f-3983-456c-afd4-f324e3874914_1536x1024.png" width="1536" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b1085f3f-3983-456c-afd4-f324e3874914_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1536,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1354408,&quot;alt&quot;:&quot;Two schema-valid refund objects pass the same grammar check, but only the object containing 4250 cents matches the source message.&quot;,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Two schema-valid refund objects pass the same grammar check, but only the object containing 4250 cents matches the source message." title="Two schema-valid refund objects pass the same grammar check, but only the object containing 4250 cents matches the source message." srcset="https://substackcdn.com/image/fetch/$s_!aQnP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1085f3f-3983-456c-afd4-f324e3874914_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!aQnP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1085f3f-3983-456c-afd4-f324e3874914_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!aQnP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1085f3f-3983-456c-afd4-f324e3874914_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!aQnP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1085f3f-3983-456c-afd4-f324e3874914_1536x1024.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">The grammar can reject a broken object. It cannot distinguish the stated amount from a plausible but false amount. Step by step, we will see why.</figcaption></figure></div><p>We will follow one support request through the complete mechanism. The request says: <code>Please refund order A-17. The charge was $42.50.</code> The desired output is a small object containing a status, an order identifier, and a refund amount in cents. First we need to separate three ideas that are often collapsed into the word &#8220;valid.&#8221; Then we can compile the schema, watch the token mask change, and see exactly where truth leaves the decoder's jurisdiction.</p><h2>Three different promises hide inside &#8220;valid JSON&#8221;</h2><p>JSON is a text format. A JSON parser checks punctuation and nesting: braces balance, keys are quoted, commas occur in legal places, and values have valid JSON forms. This object is valid JSON:</p><p><code>{"status":"ready","order_id":"A-17","refund_cents":4500}
</code></p><p>A <strong>schema</strong> asks a narrower question about the parsed value. It can require an object, name its allowed properties, require selected keys, restrict a field to an integer, or limit a value to an enumeration. If our schema allows any non-negative integer for <code>refund_cents</code>, then <code>4500</code> passes. The schema has no memory of the user's <code>$42.50</code>.</p><p>Finally, the application asks whether the object means something acceptable in its real environment. Does order A-17 exist? Was the charge really $42.50? Is it refundable? Is this user authorized? Those are evidence, policy, and permission questions. They are not punctuation questions.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Z8-S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Z8-S!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!Z8-S!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!Z8-S!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!Z8-S!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Z8-S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1553733,&quot;alt&quot;:&quot;Four sequential gates distinguish parseable JSON, schema validity, grounded values, and an authorized action.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Four sequential gates distinguish parseable JSON, schema validity, grounded values, and an authorized action." title="Four sequential gates distinguish parseable JSON, schema validity, grounded values, and an authorized action." srcset="https://substackcdn.com/image/fetch/$s_!Z8-S!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!Z8-S!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!Z8-S!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!Z8-S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdae21b19-b913-4fe0-af8f-eb6e44d3ae9b_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Each outer check answers a question the inner check cannot answer.</figcaption></figure></div><p>The checks therefore form a hierarchy:</p><ol><li><p><strong>Parseable</strong> means the text is legal JSON.</p></li><li><p><strong>Schema-valid</strong> means the parsed value also obeys the declared structural rules.</p></li><li><p><strong>Grounded and actionable</strong> means the values are supported by evidence and pass application policy.</p></li></ol><p>Each level can remove failures that the previous level accepts. None can be silently substituted for the next.</p><p>Our refund extractor also needs a way to say that the message is incomplete. If a successful decode must complete a contract where every field is required and <code>refund_cents</code> must be an integer, every successful path puts <em>some</em> integer there even when no amount appears in the input. A better output contract exposes two branches:</p><p><code>{
  "anyOf": [
    {
      "status": "ready",
      "order_id": "string",
      "refund_cents": "non-negative integer"
    },
    {
      "status": "insufficient_info",
      "order_id": null,
      "refund_cents": null
    }
  ]
}
</code></p><p>This is a readable sketch of the contract, not a literal complete JSON Schema. The important move is structural: uncertainty is now a legal output rather than an instruction the model must squeeze into fields that forbid it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qTzE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qTzE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!qTzE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!qTzE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!qTzE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qTzE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1101244,&quot;alt&quot;:&quot;A refund schema branches into a ready object with non-null fields and an insufficient-information object with null fields.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A refund schema branches into a ready object with non-null fields and an insufficient-information object with null fields." title="A refund schema branches into a ready object with non-null fields and an insufficient-information object with null fields." srcset="https://substackcdn.com/image/fetch/$s_!qTzE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!qTzE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!qTzE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!qTzE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ca52c8-6a60-4c7a-bae7-ade45dbd91a3_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">A useful contract makes uncertainty a legal destination instead of forcing the model to guess.</figcaption></figure></div><p>Here is the first design rule worth keeping: <strong>a schema should represent the failure states your application expects</strong>. Constrained decoding can only choose paths you make legal. If the contract requires a confident answer, the decoder cannot invent an abstention branch on your behalf.</p><div id="youtube2-zKO3-1JkmJI" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;zKO3-1JkmJI&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/zKO3-1JkmJI?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div>
      <p>
          <a href="https://newsletter.theaiedge.io/p/how-constrained-decoding-makes-llm-outputs">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[How Sparse Attention Makes Long-Context LLMs Cheaper, and What It Misses]]></title><description><![CDATA[Full reach, sliding windows, and learned selectors turn the same prompt into three different evidence sets.]]></description><link>https://newsletter.theaiedge.io/p/how-sparse-attention-makes-long-context-llms</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/how-sparse-attention-makes-long-context-llms</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Wed, 16 Sep 2026 15:01:07 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/80097b49-e39a-4fe2-bfb2-60ed2d3e0959_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>An LLM can accept a very long prompt without treating every earlier piece the same way. The model represents each piece as an internal token state. Inside each attention layer, an eligibility rule determines which earlier states are available to the current token. Only then does the layer decide how much weight to give the available ones.</p><p>That first decision is the hidden trade-off behind <strong>sparse attention</strong>. The name suggests that the model merely turns down unimportant history. In many designs, it does something more consequential: it prevents most of the history from entering the main attention calculation at all.</p><p>A late-August 2026 Transformers release added Qwen Sparse Attention, while an open-weight Qwen model built on the same block-selection idea prompted immediate questions about long-context latency and cache placement; as more models save work this way, the durable question is which evidence they stop reading.</p><p>So here is the question we will answer: <strong>When sparse attention makes a long context cheaper, what does an LLM stop looking at?</strong></p><p>The compact answer is that every attention pattern creates an eligible set of earlier token states. Full attention admits the whole past. A sliding window admits only nearby history. Content-selected sparse attention uses a cheaper scoring step to choose a small subset that can include distant history, then runs ordinary attention on that subset. Fewer eligible states mean less work, but a clue excluded at this point cannot be rescued by a larger attention weight later.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!83pM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!83pM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.png 424w, https://substackcdn.com/image/fetch/$s_!83pM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.png 848w, https://substackcdn.com/image/fetch/$s_!83pM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.png 1272w, https://substackcdn.com/image/fetch/$s_!83pM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!83pM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.png" width="1942" height="809" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:809,&quot;width&quot;:1942,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1186630,&quot;alt&quot;:&quot;One question token faces a long row of earlier tokens, but three gates expose all tokens, only nearby tokens, or a few selected distant tokens.&quot;,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="One question token faces a long row of earlier tokens, but three gates expose all tokens, only nearby tokens, or a few selected distant tokens." title="One question token faces a long row of earlier tokens, but three gates expose all tokens, only nearby tokens, or a few selected distant tokens." srcset="https://substackcdn.com/image/fetch/$s_!83pM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.png 424w, https://substackcdn.com/image/fetch/$s_!83pM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.png 848w, https://substackcdn.com/image/fetch/$s_!83pM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.png 1272w, https://substackcdn.com/image/fetch/$s_!83pM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0865d28c-0aa9-4345-ad41-2472076f01ca_1942x809.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">The main attention calculation can only weigh the history that its eligibility rule exposes.</figcaption></figure></div><p>We will follow one question through all three patterns. A long incident report contains the deployed database proxy setting, <code>port 6432</code>, near the beginning. Much later, a diagnostic note mentions the default database port, <code>5432</code>. At the end, the reader asks: <strong>Which port did the incident's database proxy actually use?</strong></p><p>This is a useful test because the answer is a tiny exact value separated from the question by a lot of plausible noise. We will hold the tokens, model layer, and question fixed. Only the rule that exposes earlier states to attention will change.</p><h2>Attention makes two decisions, not one</h2><p>An LLM processes text as <strong>tokens</strong>, which are words or pieces of words converted into numerical states. At one layer, every token state is transformed into three useful roles.</p><p>Every token produces all three. When the layer updates the current token, its <strong>query</strong> represents what information it is seeking. The current token and earlier tokens provide <strong>keys</strong>, which can be compared with that query, and <strong>values</strong>, the information that can be carried forward. The query-key comparisons become weights; the weighted values become the context added to the current token's state. The diagram focuses on earlier sources, but causal attention also allows the current token to attend to itself.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jp_y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jp_y!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.png 424w, https://substackcdn.com/image/fetch/$s_!jp_y!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.png 848w, https://substackcdn.com/image/fetch/$s_!jp_y!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.png 1272w, https://substackcdn.com/image/fetch/$s_!jp_y!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jp_y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.png" width="1942" height="809" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:809,&quot;width&quot;:1942,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1050096,&quot;alt&quot;:&quot;A current token becomes a query, earlier token states supply keys and values, and query-key scores control which values are mixed into context.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A current token becomes a query, earlier token states supply keys and values, and query-key scores control which values are mixed into context." title="A current token becomes a query, earlier token states supply keys and values, and query-key scores control which values are mixed into context." srcset="https://substackcdn.com/image/fetch/$s_!jp_y!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.png 424w, https://substackcdn.com/image/fetch/$s_!jp_y!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.png 848w, https://substackcdn.com/image/fetch/$s_!jp_y!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.png 1272w, https://substackcdn.com/image/fetch/$s_!jp_y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854442c8-dbe4-43fd-813c-2bdea8e64620_1942x809.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">The query asks, keys are compared, and values carry information forward.</figcaption></figure></div><p>There is a prerequisite hiding before those comparisons. An attention rule supplies a mask or selection pattern that says which keys and values are eligible. A future token is ineligible in a causal language model because generation cannot look ahead. Sparse patterns add more exclusions among the past.</p><p>It helps to separate two questions:</p><ol><li><p><strong>Eligibility:</strong> may the current token connect to this earlier state?</p></li><li><p><strong>Importance:</strong> among eligible states, how much weight should this one receive?</p></li></ol><p>Full, windowed, and content-selected attention mainly differ on the first question. Once a subset is eligible, the main attention operation can still compare queries with keys and mix values in the familiar way.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_eVw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_eVw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!_eVw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!_eVw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!_eVw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_eVw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1347856,&quot;alt&quot;:&quot;A two-stage diagram first masks candidate token states as eligible or excluded, then assigns attention weights only to the eligible states.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A two-stage diagram first masks candidate token states as eligible or excluded, then assigns attention weights only to the eligible states." title="A two-stage diagram first masks candidate token states as eligible or excluded, then assigns attention weights only to the eligible states." srcset="https://substackcdn.com/image/fetch/$s_!_eVw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!_eVw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!_eVw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!_eVw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F125b523d-f31d-41dc-9142-27299d0f1af8_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Eligibility happens before importance; excluded states never receive an attention weight.</figcaption></figure></div><p>Apply that distinction to our incident report. Full attention places both <code>6432</code> and <code>5432</code> in the candidate set. A four-block sliding window includes only the late diagnostic note and loses the deployed setting. A good content selector reaches back to the configuration block containing <code>6432</code>, while ignoring most of the middle.</p><p>The model still has to interpret the candidates correctly. Full attention could overweight the distracting <code>5432</code>. A selector could choose the wrong block. Eligibility does not guarantee a correct answer; it defines which answer evidence remains possible at this layer.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!W76c!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf39ebba-1020-4699-8605-d1468b5c365b_1942x809.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!W76c!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf39ebba-1020-4699-8605-d1468b5c365b_1942x809.png 424w, https://substackcdn.com/image/fetch/$s_!W76c!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf39ebba-1020-4699-8605-d1468b5c365b_1942x809.png 848w, https://substackcdn.com/image/fetch/$s_!W76c!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf39ebba-1020-4699-8605-d1468b5c365b_1942x809.png 1272w, https://substackcdn.com/image/fetch/$s_!W76c!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf39ebba-1020-4699-8605-d1468b5c365b_1942x809.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!W76c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf39ebba-1020-4699-8605-d1468b5c365b_1942x809.png" width="1942" height="809" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/af39ebba-1020-4699-8605-d1468b5c365b_1942x809.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:809,&quot;width&quot;:1942,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1127772,&quot;alt&quot;:&quot;The same incident-report question sees both port values under full attention, only the late default under a window, and selected early and late evidence under content selection.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The same incident-report question sees both port values under full attention, only the late default under a window, and selected early and late evidence under content selection." title="The same incident-report question sees both port values under full attention, only the late default under a window, and selected early and late evidence under content selection." srcset="https://substackcdn.com/image/fetch/$s_!W76c!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf39ebba-1020-4699-8605-d1468b5c365b_1942x809.png 424w, https://substackcdn.com/image/fetch/$s_!W76c!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf39ebba-1020-4699-8605-d1468b5c365b_1942x809.png 848w, https://substackcdn.com/image/fetch/$s_!W76c!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf39ebba-1020-4699-8605-d1468b5c365b_1942x809.png 1272w, https://substackcdn.com/image/fetch/$s_!W76c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf39ebba-1020-4699-8605-d1468b5c365b_1942x809.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Changing only the eligibility pattern changes which answer evidence remains possible.</figcaption></figure></div><p>That is the first complete mental model: <strong>sparse attention saves work before importance is calculated</strong>. The rest of the article explains how each eligibility rule buys its saving, and the distinct miss it creates.</p><div id="youtube2-E_CLKTsVuE8" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;E_CLKTsVuE8&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/E_CLKTsVuE8?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div>
      <p>
          <a href="https://newsletter.theaiedge.io/p/how-sparse-attention-makes-long-context-llms">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Four Retrieval Techniques for Video Search]]></title><description><![CDATA[Why frame rate, change detection, temporal hierarchy, and targeted rewatching fail in different ways]]></description><link>https://newsletter.theaiedge.io/p/how-ai-searches-hours-of-video-without-seeing</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/how-ai-searches-hours-of-video-without-seeing</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Mon, 14 Sep 2026 15:21:26 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/12e08956-2a68-43a6-916d-6b266d5d7d63_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Video looks like one input, but an AI cannot inspect it as one indivisible object. A two-hour recording is a sequence of changing images, sound, speech, and timestamps. Before a model can answer a question, some system has to decide which pieces of that sequence deserve space in its limited working context.</p><p>The surprising part is that a longer context window does not remove this decision. Each retained frame expands into many pieces the model must process, each second of audio adds more, and the relationships across time still have to be computed. Keeping more evidence can preserve a brief event, but it can also bury that event inside thousands of irrelevant moments.</p><p>Google's September 2026 agentic video mode now lets a model search a timeline and adjust frame rate, resolution, and modality around promising moments, making evidence selection a practical product choice rather than a hidden preprocessing detail.</p><p>So the useful question is: <strong>How can an AI answer a precise question about hours of video without placing every frame in context?</strong></p><p>The compact answer is to treat long video as a budgeted search for evidence. Fixed-rate sampling buys predictable coverage. Change-aware sampling keeps moments when the picture moves or cuts. A temporal hierarchy narrows a long recording to a few candidate intervals. Query-adaptive rewatching then spends dense frames, higher resolution, or audio only where the question needs them.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3K6W!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996c8990-8097-419c-998b-fab946454f22_2043x770.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3K6W!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996c8990-8097-419c-998b-fab946454f22_2043x770.png 424w, https://substackcdn.com/image/fetch/$s_!3K6W!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996c8990-8097-419c-998b-fab946454f22_2043x770.png 848w, https://substackcdn.com/image/fetch/$s_!3K6W!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996c8990-8097-419c-998b-fab946454f22_2043x770.png 1272w, https://substackcdn.com/image/fetch/$s_!3K6W!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996c8990-8097-419c-998b-fab946454f22_2043x770.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3K6W!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996c8990-8097-419c-998b-fab946454f22_2043x770.png" width="2043" height="770" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/996c8990-8097-419c-998b-fab946454f22_2043x770.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:770,&quot;width&quot;:2043,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1308991,&quot;alt&quot;:&quot;A two-hour warehouse timeline is narrowed to a tiny evidence window at 10:04.3 before selected frames enter an evidence packet.&quot;,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A two-hour warehouse timeline is narrowed to a tiny evidence window at 10:04.3 before selected frames enter an evidence packet." title="A two-hour warehouse timeline is narrowed to a tiny evidence window at 10:04.3 before selected frames enter an evidence packet." srcset="https://substackcdn.com/image/fetch/$s_!3K6W!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996c8990-8097-419c-998b-fab946454f22_2043x770.png 424w, https://substackcdn.com/image/fetch/$s_!3K6W!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996c8990-8097-419c-998b-fab946454f22_2043x770.png 848w, https://substackcdn.com/image/fetch/$s_!3K6W!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996c8990-8097-419c-998b-fab946454f22_2043x770.png 1272w, https://substackcdn.com/image/fetch/$s_!3K6W!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F996c8990-8097-419c-998b-fab946454f22_2043x770.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Long-video understanding begins by deciding which tiny part of the timeline deserves detailed inspection.</figcaption></figure></div><p>We will follow one realistic request through all four techniques. A warehouse camera records aisle 7 for two hours. A worker enters at 10:00. A red forklift first touches shelf B at 10:04.3, then backs away. The question is not merely whether both objects appeared. It is: <strong>When did the forklift first touch the shelf after the worker entered?</strong></p><p>That wording matters. The answer needs an identity, an order, and a brief physical relation. A transcript may confirm that a worker called for help. A single frame may show the forklift beside the shelf. Only a short sequence can establish the first contact.</p><div id="youtube2-YJyhrfID9u0" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;YJyhrfID9u0&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/YJyhrfID9u0?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><h2>A video becomes a budgeted evidence packet</h2><p>A <strong>frame</strong> is one still image from the video timeline. In a common transformer-based path, a vision encoder splits that image into patches and converts the patches into numerical representations the language model can process. I will call those representations <strong>visual tokens</strong>. One frame is therefore not one token; it expands into a small field of spatial evidence.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!udbN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!udbN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.png 424w, https://substackcdn.com/image/fetch/$s_!udbN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.png 848w, https://substackcdn.com/image/fetch/$s_!udbN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.png 1272w, https://substackcdn.com/image/fetch/$s_!udbN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!udbN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.png" width="2020" height="778" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:778,&quot;width&quot;:2020,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1170456,&quot;alt&quot;:&quot;One warehouse video frame is divided into image patches and converted into many visual tokens aligned to a timestamp.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="One warehouse video frame is divided into image patches and converted into many visual tokens aligned to a timestamp." title="One warehouse video frame is divided into image patches and converted into many visual tokens aligned to a timestamp." srcset="https://substackcdn.com/image/fetch/$s_!udbN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.png 424w, https://substackcdn.com/image/fetch/$s_!udbN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.png 848w, https://substackcdn.com/image/fetch/$s_!udbN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.png 1272w, https://substackcdn.com/image/fetch/$s_!udbN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ebea03d-0ad5-4465-b004-0952a2058e1f_2020x778.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">A frame expands into multiple visual tokens, so retaining one more image consumes more than one context position.</figcaption></figure></div><p>Video adds a second requirement. The model must connect what appears in one frame with what changes in later frames. That temporal relationship distinguishes "forklift near shelf" from "forklift moves toward shelf, makes contact, then reverses." The model's attention mechanism can compare retained visual tokens across time, but it cannot reconstruct a moment that the input pipeline never kept.</p><p>Audio and transcripts form separate evidence streams. Audio preserves nonverbal signals such as a metallic impact. A transcript is cheaper to search and excellent for spoken names or instructions, but it omits silent motion. Timestamps align the streams so a clue in one can point to a region in another.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eKqq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F342bd03d-9eae-4c21-8509-de128b053d32_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eKqq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F342bd03d-9eae-4c21-8509-de128b053d32_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!eKqq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F342bd03d-9eae-4c21-8509-de128b053d32_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!eKqq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F342bd03d-9eae-4c21-8509-de128b053d32_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!eKqq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F342bd03d-9eae-4c21-8509-de128b053d32_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eKqq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F342bd03d-9eae-4c21-8509-de128b053d32_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/342bd03d-9eae-4c21-8509-de128b053d32_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1124673,&quot;alt&quot;:&quot;Frames, audio, and transcript appear as aligned evidence tracks connected by shared timestamps.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Frames, audio, and transcript appear as aligned evidence tracks connected by shared timestamps." title="Frames, audio, and transcript appear as aligned evidence tracks connected by shared timestamps." srcset="https://substackcdn.com/image/fetch/$s_!eKqq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F342bd03d-9eae-4c21-8509-de128b053d32_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!eKqq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F342bd03d-9eae-4c21-8509-de128b053d32_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!eKqq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F342bd03d-9eae-4c21-8509-de128b053d32_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!eKqq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F342bd03d-9eae-4c21-8509-de128b053d32_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Timestamps let a clue in one modality point the system toward evidence in another.</figcaption></figure></div><p>Now imagine sampling the warehouse video once each second. The system keeps frames at 10:04.0 and 10:05.0. The actual touch at 10:04.3 may fall between them. Raising the rate to ten frames per second makes the event much more likely to appear, but it multiplies the visual evidence for the entire two-hour recording.</p><p>This is the first useful insight: <strong>temporal detail is purchased with context.</strong> The family of techniques differs mainly in who decides where to spend that detail, and when.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ha22!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ha22!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!Ha22!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!Ha22!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!Ha22!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ha22!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.png" width="1774" height="887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:887,&quot;width&quot;:1774,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1255990,&quot;alt&quot;:&quot;The same long video is represented with sparse low-detail samples or dense high-detail samples under a fixed context budget.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The same long video is represented with sparse low-detail samples or dense high-detail samples under a fixed context budget." title="The same long video is represented with sparse low-detail samples or dense high-detail samples under a fixed context budget." srcset="https://substackcdn.com/image/fetch/$s_!Ha22!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!Ha22!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!Ha22!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!Ha22!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a7f5a07-d2a6-4e54-81cb-8b8046b99118_1774x887.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Temporal detail is purchased with context, so the budget must be concentrated somewhere.</figcaption></figure></div>
      <p>
          <a href="https://newsletter.theaiedge.io/p/how-ai-searches-hours-of-video-without-seeing">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Deep Dive: How AI Text Watermarks Work]]></title><description><![CDATA[How a language model leaves a detectable pattern in its word choices, and why copying the text preserves it.]]></description><link>https://newsletter.theaiedge.io/p/deep-dive-how-ai-text-watermarks</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/deep-dive-how-ai-text-watermarks</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Fri, 11 Sep 2026 15:01:39 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/9cab6be4-8baf-4906-97b3-93cf6ae2c7f7_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>An AI text watermark leaves detectable evidence in the words a model chooses. During generation, a secret scoring rule helps select the next piece of text. Later, a detector with the matching key can reconstruct that rule and check whether the finished passage agrees with it unusually often.</p><p>The surprising part is that an exact copy into a plain-text document can preserve the evidence. There is no hidden character to carry along. The ordinary words preserve the choices.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kh9x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kh9x!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!kh9x!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!kh9x!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!kh9x!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kh9x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.png" width="1536" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1536,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1147291,&quot;alt&quot;:&quot;An exact copy of the support reply preserves the same six reconstructed scores, shown separately from the text.&quot;,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="An exact copy of the support reply preserves the same six reconstructed scores, shown separately from the text." title="An exact copy of the support reply preserves the same six reconstructed scores, shown separately from the text." srcset="https://substackcdn.com/image/fetch/$s_!kh9x!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!kh9x!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!kh9x!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!kh9x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9458877f-92ec-44ef-8db7-4451d6f5c850_1536x1024.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">The dots are a detector overlay. Copying the same text preserves the inputs to that check.</figcaption></figure></div><p>If you use AI to draft, proofread, or rewrite, the distinction matters: those operations leave different amounts of freedom for a watermark. And when someone says a passage was &#8220;detected,&#8221; the test matters too. A keyed watermark check measures a deliberately introduced pattern; it does not infer AI use from a writer's style.</p><div id="youtube2-x8SIojReCHI" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;x8SIojReCHI&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/x8SIojReCHI?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div>
      <p>
          <a href="https://newsletter.theaiedge.io/p/deep-dive-how-ai-text-watermarks">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Deep Dive: How Speculative Decoding Makes LLMs Faster]]></title><description><![CDATA[How a smaller model helps a larger model generate text faster without changing its output distribution.]]></description><link>https://newsletter.theaiedge.io/p/deep-dive-how-speculative-decoding</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/deep-dive-how-speculative-decoding</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Wed, 09 Sep 2026 15:03:10 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/e1111f7d-3002-4c50-ba35-7196b33a0eb4_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Speculative decoding can make a coding assistant respond faster by having a small model propose several future tokens for a larger model to check together. The larger model, called the target, still determines the output probabilities. The surprising part is that the small model can guess wrong without changing those probabilities.</p><p>In the two-model version we will follow, the target still does its full computation. The saving comes from arranging that computation differently, so one pass through its layers can advance the answer by several tokens. Whether that saves time depends on how much of the draft survives.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!X0oN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90090915-2b05-4dd5-8088-8a16541c6418_1662x946.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!X0oN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90090915-2b05-4dd5-8088-8a16541c6418_1662x946.png 424w, https://substackcdn.com/image/fetch/$s_!X0oN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90090915-2b05-4dd5-8088-8a16541c6418_1662x946.png 848w, https://substackcdn.com/image/fetch/$s_!X0oN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90090915-2b05-4dd5-8088-8a16541c6418_1662x946.png 1272w, https://substackcdn.com/image/fetch/$s_!X0oN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90090915-2b05-4dd5-8088-8a16541c6418_1662x946.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!X0oN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90090915-2b05-4dd5-8088-8a16541c6418_1662x946.png" width="1662" height="946" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/90090915-2b05-4dd5-8088-8a16541c6418_1662x946.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:946,&quot;width&quot;:1662,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:997329,&quot;alt&quot;:&quot;Two generation paths compare repeated target calls with one full target pass over draft tokens.&quot;,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Two generation paths compare repeated target calls with one full target pass over draft tokens." title="Two generation paths compare repeated target calls with one full target pass over draft tokens." srcset="https://substackcdn.com/image/fetch/$s_!X0oN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90090915-2b05-4dd5-8088-8a16541c6418_1662x946.png 424w, https://substackcdn.com/image/fetch/$s_!X0oN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90090915-2b05-4dd5-8088-8a16541c6418_1662x946.png 848w, https://substackcdn.com/image/fetch/$s_!X0oN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90090915-2b05-4dd5-8088-8a16541c6418_1662x946.png 1272w, https://substackcdn.com/image/fetch/$s_!X0oN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90090915-2b05-4dd5-8088-8a16541c6418_1662x946.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">A draft makes several conditional predictions available for one full target pass.</figcaption></figure></div>
      <p>
          <a href="https://newsletter.theaiedge.io/p/deep-dive-how-speculative-decoding">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[AI Digest: Model Validation, Agents, and Generative AI]]></title><description><![CDATA[Seven visual lessons on testing models, recovering tool calls, speeding up text generation, detecting watermarks, and checking image and document outputs.]]></description><link>https://newsletter.theaiedge.io/p/ai-digest-model-validation-agents</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/ai-digest-model-validation-agents</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Mon, 07 Sep 2026 15:00:49 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/4407d92f-f068-4ae0-a65c-4b6afcc7e4a4_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This edition explores how a model can pass validation for the wrong reason, how an agent can earn a reward without completing its task, and what makes a tool retry safe after a crash.</p><p>We'll also look inside speculative decoding and text watermarking, then turn to two visual problems: why a generated image can look convincing while missing the instructions, and why a fluent document answer can still come from the wrong cell.</p><h2>1. Model validation: a random split can preserve the shortcut</h2><p>Can machine learning validation approve a model that learned the wrong feature? It can, if the validation set repeats the same shortcut!</p><p>Imagine a pneumonia classifier trained on chest X-rays from two hospitals. Hospital A contributed most of the positive cases. Hospital B contributed most of the negative cases.</p><p>Each image contains two usable signals: the lung pattern we care about, and a hospital fingerprint from scanner processing, text markers, or acquisition style. The loss function does not know which explanation we intended. It rewards features that predict the label. If recognizing the hospital offers an easier route to lower loss, the model can use it.</p><p>Now randomly split the rows into training and validation sets. Both sets still contain the same hospitals and the same correlation: Hospital A usually means positive; Hospital B usually means negative. Randomization changes which rows land in each set, but it does not change the process that produced them.</p><p><strong>The validation images are unseen, yet the shortcut is familiar.</strong> A high score can accurately describe performance on this source mixture and still mislead us about deployment.</p><p>Move the model to Hospital C. In this toy example, the disease signal remains valid while the old hospital-label correlation disappears. Prediction quality can drop without any bug in the inference code. The diagram follows that change from collection to deployment.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JIZ1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JIZ1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!JIZ1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!JIZ1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!JIZ1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JIZ1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.png" width="1080" height="1400" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1400,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1605979,&quot;alt&quot;:&quot;Hospital A supplies mostly positive X-rays and Hospital B mostly negative ones. A random train-validation split preserves their source cues. The same classifier can fail at Hospital C; whole-hospital holdouts and cue swaps probe different dependencies.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Hospital A supplies mostly positive X-rays and Hospital B mostly negative ones. A random train-validation split preserves their source cues. The same classifier can fail at Hospital C; whole-hospital holdouts and cue swaps probe different dependencies." title="Hospital A supplies mostly positive X-rays and Hospital B mostly negative ones. A random train-validation split preserves their source cues. The same classifier can fail at Hospital C; whole-hospital holdouts and cue swaps probe different dependencies." srcset="https://substackcdn.com/image/fetch/$s_!JIZ1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!JIZ1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!JIZ1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!JIZ1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47d38fad-e699-4f4e-850d-260303c82b30_1080x1400.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">New rows can preserve the same hospital shortcut. Holding out a hospital tests a change of environment; swapping a cue tests reliance on that feature.</figcaption></figure></div><p>A random row split estimates performance on another row from the same source mixture. It says little about a source absent from that mixture. When the expected novelty is a hospital, camera, customer, region, time period, or device, holding out the entire unit lets validation test that change instead of scattering the unit across both sides.</p><p>I would then ask whether the model is using the particular cue I suspect. Keep the target content fixed, remove or swap the background, marker, source template, or metadata, and watch whether the prediction moves.</p><p>These tests answer different questions. A group holdout tests an environment change. A cue intervention tests dependence on one named feature. Neither proves that the model learned the intended signal: the holdout covers only the environments we chose, and the intervention is trustworthy only if it changes the shortcut without changing the task itself.</p><h2>2. Agent reward hacking: passing the test while leaving the bug</h2><p>Why can AI agent reward hacking produce a perfect score on a task the agent never completed? The reason is simple: the agent optimizes the feedback we expose, not the intention behind it.</p><p>Consider a coding agent asked to fix an invoice calculation. The correct total is $110, but the code returns $100. We use the test suite as the evaluator: a pass earns a reward of +1, and a failure earns 0.</p><p>During reinforcement learning, the agent tries a sequence of actions and receives this reward. The optimizer makes high-reward action sequences more likely in similar situations.</p><p>We expect the agent to fix the calculation, pass the tests, and produce an invoice for $110. But the test suite is also part of the environment. If the agent can modify it, another path becomes available: disable the assertion, pass the tests, and leave the invoice at $100.</p><p>Both paths receive +1. The second path can be reinforced because the remaining failure was never reflected in the score.</p><p>Three different objects matter here:</p><ul><li><p>The <strong>true objective</strong> is a correct invoice.</p></li><li><p>The <strong>proxy reward</strong> is the +1.</p></li><li><p>The <strong>evaluator</strong> is the test suite that decides when to issue it.</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_!NuBf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NuBf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!NuBf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!NuBf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!NuBf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NuBf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.png" width="1080" height="1400" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1400,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1617963,&quot;alt&quot;:&quot;A test suite maps pass to +1 and fail to zero. A coding agent can fix a $100 invoice to the correct $110 or disable an assertion and leave it at $100. Both paths receive +1, illustrating the gap between the objective, evaluator, and reward.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A test suite maps pass to +1 and fail to zero. A coding agent can fix a $100 invoice to the correct $110 or disable an assertion and leave it at $100. Both paths receive +1, illustrating the gap between the objective, evaluator, and reward." title="A test suite maps pass to +1 and fail to zero. A coding agent can fix a $100 invoice to the correct $110 or disable an assertion and leave it at $100. Both paths receive +1, illustrating the gap between the objective, evaluator, and reward." srcset="https://substackcdn.com/image/fetch/$s_!NuBf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!NuBf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!NuBf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!NuBf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb914a173-7a90-4fd3-9fca-d38e76a8f4a8_1080x1400.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Fixing the calculation and changing the test can produce the same reward while leaving different real outcomes. Altering the evaluator is reward tampering.</figcaption></figure></div><p>Exploiting a missing condition in the proxy is usually called specification gaming. Changing the evaluator itself, by editing a test, checklist, log, or scoring process, is the more specific case of reward tampering.</p><p>No human-like intention to cheat is required. From the optimizer's point of view, the two action sequences received the same reward. The number does not contain the missing requirement, so we cannot recover it from the score afterward.</p><p>Greater capability does not settle this problem. Better search can find the correct implementation, but it can also find shortcuts that a weaker agent never discovered. It expands both sets of paths.</p><p>A wrong answer with a low score is ordinary failure. Reward hacking is narrower: the measured score says success while the intended outcome stays unchanged or gets worse. The test suite is another piece of the environment, and its assumptions shape what the agent learns.</p><h2>3. Durable agents: a checkpoint cannot confirm an external payment</h2><p>How can durable execution for AI agents survive a crash and still charge the same invoice twice? The checkpoint remembers where to resume, but it cannot prove whether the outside world already changed!</p><p>Imagine an agent paying a $480 invoice. It records step <code>pay-1</code> as pending, sends the request, and the payment API accepts it. Then the worker crashes before saving the receipt.</p><p>After restart, the execution state still says:</p><p><code>run-42 -&gt; pay-1 -&gt; PENDING</code></p><p>From that saved state alone, the replacement worker cannot tell whether the payment failed or only the acknowledgement failed. We know the API accepted the payment in this example; the worker has no saved receipt to establish that. Retrying may be necessary, but the tool step may execute again.</p><p>An <strong>idempotency key</strong> is a stable identifier that tells the external service that a retry represents the same logical operation. The checkpoint identifies the unfinished step; the key identifies the one external operation that step is allowed to create.</p><p>The diagram uses <code>run-42/pay-1</code> as the key, recorded before the first request. The replacement worker reloads the latest checkpoint, skips completed work, and sends <code>pay-1</code> again with that same key. If the payment service supports idempotency and already processed the key, it returns the original receipt instead of creating another payment. The runtime then saves the receipt, marks the step completed, and continues.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZjIy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZjIy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!ZjIy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!ZjIy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!ZjIy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZjIy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.png" width="1080" height="1400" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1400,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1460361,&quot;alt&quot;:&quot;An agent pays a $480 invoice but crashes before storing the receipt. A replacement worker loads the pending step and retries with key run-42/pay-1. The payment service returns the existing receipt; the worker saves it, marks the step completed, and resumes.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="An agent pays a $480 invoice but crashes before storing the receipt. A replacement worker loads the pending step and retries with key run-42/pay-1. The payment service returns the existing receipt; the worker saves it, marks the step completed, and resumes." title="An agent pays a $480 invoice but crashes before storing the receipt. A replacement worker loads the pending step and retries with key run-42/pay-1. The payment service returns the existing receipt; the worker saves it, marks the step completed, and resumes." srcset="https://substackcdn.com/image/fetch/$s_!ZjIy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!ZjIy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!ZjIy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!ZjIy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe09ac548-1ee9-4a0e-b090-4434a623914a_1080x1400.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">The checkpoint identifies unfinished work. Reusing the same idempotency key lets a supporting payment service return the original receipt without creating another payment.</figcaption></figure></div><p>This is why conversation memory and execution state deserve separate treatment. Conversation memory can hold messages, facts, and user preferences. Execution state needs the run ID, step ID, exact tool arguments, status, approvals, timers, and durable receipts. A sentence saying "the invoice was paid" is not a transaction record.</p><p>The same pattern appears outside payments. A database can reject a duplicate operation through a unique constraint or conditional write. An event consumer can deduplicate using a stable event ID.</p><p>If a tool has no idempotency mechanism, blind retry is the wrong recovery strategy. The agent has to query the external system, run a compensating action that reverses or offsets the first effect, or stop for human review.</p><p>Durable execution preserves progress. It does not make the model correct, permissions safe, or an arbitrary API idempotent. Once an agent can wait for humans, call tools, and run longer than one request, its execution state matters as much as its prompt.</p><h2>4. Speculative decoding: draft several tokens, verify in one pass</h2><p>How can speculative decoding use a smaller language model without inheriting its mistakes? The small model guesses a few tokens ahead, but the large target model verifies the whole guess in one pass and keeps control of the output distribution.</p><p>The usual language-model decoding loop is serial. The target model predicts one token, appends it to the sequence, then runs again. Producing K tokens requires K target-model passes.</p><p>During low-batch decoding, a pass often spends more time moving the model weights than using all the available arithmetic. Scoring a short block can reuse each weight read across several token positions, so it can take close to the time of scoring only one.</p><p>Speculative decoding takes advantage of that opportunity. In the common two-model version, a cheap draft model generates a short continuation one token at a time. The large target model receives the prompt and complete draft, then scores every drafted position in parallel.</p><p>Acceptance still proceeds from left to right. Accepted tokens become final. At the first rejection, every later draft token is discarded because it was conditioned on a prefix the target did not accept. The target samples a correction, and the next drafting round starts from the corrected prefix.</p><p>For the prompt "Water freezes at", imagine the draft proposes:</p><p><code>"0" -&gt; "degrees" -&gt; "Kelvin" -&gt; "."</code></p><p>One target pass can score all four positions. It may accept "0" and "degrees", reject "Kelvin", discard the period, and sample "Celsius" as the correction. That slow pass has finalized three useful tokens instead of one.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ln6R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ln6R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!Ln6R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!Ln6R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!Ln6R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ln6R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.png" width="1080" height="1400" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1400,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1575217,&quot;alt&quot;:&quot;Serial target decoding is compared with a small model drafting 0, degrees, Kelvin, and a period. One target pass scores the draft, accepts the first two tokens, rejects Kelvin, discards the suffix, and samples Celsius using the residual distribution.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Serial target decoding is compared with a small model drafting 0, degrees, Kelvin, and a period. One target pass scores the draft, accepts the first two tokens, rejects Kelvin, discards the suffix, and samples Celsius using the residual distribution." title="Serial target decoding is compared with a small model drafting 0, degrees, Kelvin, and a period. One target pass scores the draft, accepts the first two tokens, rejects Kelvin, discards the suffix, and samples Celsius using the residual distribution." srcset="https://substackcdn.com/image/fetch/$s_!Ln6R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!Ln6R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!Ln6R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!Ln6R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7703519b-7c78-4f6a-bf71-557ccfa87590_1080x1400.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">The target scores a block in parallel but accepts it from left to right. A rejection invalidates the later draft; the acceptance and correction rules preserve the target distribution.</figcaption></figure></div><p>What I find most interesting is how this works for sampled decoding. We cannot simply keep a token when two independent samples happen to match. If draft and target were identical uniform distributions over 100 tokens, their separate draws would match only 1% of the time, despite perfect agreement between the distributions.</p><p>Call the target distribution <code>p</code> and the draft distribution <code>q</code>. A drafted token <code>x</code> is accepted with probability:</p><p><code>min(1, p(x) / q(x))</code></p><p>If it is rejected, the correction is sampled from the normalized positive part of <code>p - q</code>. To build that distribution, keep the positive differences between target and draft probabilities, set the others to zero, and rescale the remaining values so they sum to one. This is the target probability not already covered by the draft.</p><p>Together, the accepted path and correction path reconstruct <code>p</code>. Under this rule, the draft changes latency without biasing the target distribution.</p><p>The benefit depends on the whole serving setup. A slow draft adds too much overhead. A draft with little overlap with the target causes frequent rejections. Hardware that is already compute-saturated has little parallel capacity left to exploit.</p><p>The useful draft is the one whose acceptance rate is worth its cost on the target model and hardware being served. Accuracy of the small model alone does not determine that tradeoff.</p><h2>5. Text watermarking: small token preferences add up to evidence</h2><p>How can generative text watermarking mark a paragraph without adding hidden characters, metadata, or a visible tag? It changes ordinary token choices, then looks for the accumulated pattern!</p><p>At each decoding step, a large language model (LLM) produces a probability distribution over the next token. Several continuations may fit. A normal sampler chooses among them; a watermarking sampler uses one additional input, a secret key.</p><p>One common construction uses the key and recent tokens to pseudorandomly divide the vocabulary into green and red sets. Plausible green tokens get a small boost. The partition is recomputed after every token, so there is no fixed list of suspicious words.</p><p>Consider a toy passage with 100 positions counted by the detector. Without the watermark, we expect roughly 50 green hits by chance. A watermarked sampler might produce 70. No individual token looks unusual; the pattern appears when we aggregate the choices.</p><p>For this simplified 50/50 construction, a one-proportion test gives:</p><p><code>z = (70 - 50) / sqrt(100 &#215; 0.5 &#215; 0.5) = 4</code></p><p>The numerator is the 20 extra green hits. The denominator is 5, the standard deviation of the count under this simplified chance model. The observed count sits four standard deviations above the expected count.</p><p>Other watermark families use different scoring rules. Here, the detector tokenizes the passage, uses the same key to recreate the green and red sets at each position, and tests whether the excess of green tokens is too large to explain by chance. It measures a statistical pattern rather than judging whether the prose sounds robotic.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_lXi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_lXi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!_lXi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!_lXi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!_lXi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_lXi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.png" width="1080" height="1400" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1400,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1548363,&quot;alt&quot;:&quot;A secret key and recent context partition tokens into green and red sets. Green tokens receive a small sampling boost. A detector replays the rule, observes 70 green hits out of 100, and calculates a toy z score of 4; length, constrained text, and editing affect the evidence.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A secret key and recent context partition tokens into green and red sets. Green tokens receive a small sampling boost. A detector replays the rule, observes 70 green hits out of 100, and calculates a toy z score of 4; length, constrained text, and editing affect the evidence." title="A secret key and recent context partition tokens into green and red sets. Green tokens receive a small sampling boost. A detector replays the rule, observes 70 green hits out of 100, and calculates a toy z score of 4; length, constrained text, and editing affect the evidence." srcset="https://substackcdn.com/image/fetch/$s_!_lXi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!_lXi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!_lXi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!_lXi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd7f1ee-1a87-4a86-a604-26038be30ca2_1080x1400.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">A tiny preference becomes detectable across many token choices. The 70-of-100 example is a simplified statistical test, and a positive result does not establish authorship.</figcaption></figure></div><p>Length supplies evidence. A ten-token answer provides very few weak votes; a long passage supplies many more observations. The model also needs freedom to choose. Open prose may offer several reasonable continuations, while code or familiar fixed phrases can have one dominant next token, leaving little room to embed a preference without damaging the output.</p><p>Editing weakens the signal without predictably erasing it. Replacing a token removes one marked choice. In context-dependent schemes, it can also change the expected partition at positions that use the edited context. A substantial rewrite can reduce the evidence dramatically, yet a long paraphrase may preserve enough unaltered fragments to remain detectable.</p><p>A positive result means the text is statistically consistent with one key's watermarking rule. It does not prove who wrote the ideas, and it cannot identify output from a model that never applied that mark. The detector threshold still trades missed detections against false positives.</p><p>That is why a long, open-ended answer can carry strong watermark evidence while a short code completion from the same model may carry almost none.</p><h2>6. Image generation: realism and exact composition are different tests</h2><p>AI image generation can give you a beautiful campaign image and still ignore the requirement that makes it usable! The problem is that a text prompt is not an engineering drawing.</p><p>Consider this request: "three green bottles to the left of one orange box, with FRESH on the label."</p><p>One sentence carries five kinds of constraints: which objects exist, how many of each, which attributes belong to which objects, where they go, and which exact characters appear.</p><p>In many diffusion systems, a text encoder converts the prompt into vectors. Cross-attention lets the denoising network consult those vectors while turning noise into an image. A few words can influence a large visual field without someone hand-coding the scene.</p><p>But the vectors do not arrive as an explicit object table with separate entries for color, count, and coordinates. During denoising, "green", "bottles", "three", and "left of" must all influence one shared visual representation. The model can form a convincing poster while giving you four bottles, coloring the box green, or letting objects overlap.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pKvb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pKvb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!pKvb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!pKvb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!pKvb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pKvb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.png" width="1080" height="1400" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1400,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1586144,&quot;alt&quot;:&quot;A request for three green bottles left of one orange box with FRESH on the label is decomposed into objects, count, color, position, and text. A diffusion illustration leads to a plausible but incorrect layout, contrasted with explicit layout and count, position, and text checks.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A request for three green bottles left of one orange box with FRESH on the label is decomposed into objects, count, color, position, and text. A diffusion illustration leads to a plausible but incorrect layout, contrasted with explicit layout and count, position, and text checks." title="A request for three green bottles left of one orange box with FRESH on the label is decomposed into objects, count, color, position, and text. A diffusion illustration leads to a plausible but incorrect layout, contrasted with explicit layout and count, position, and text checks." srcset="https://substackcdn.com/image/fetch/$s_!pKvb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!pKvb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!pKvb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!pKvb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe470d93e-c1ab-42b7-820b-a266657cfc27_1080x1400.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">A believable image can still violate count, position, color binding, or exact text. Layout guidance and explicit checks help make the requested composition inspectable.</figcaption></figure></div><p>Realism and prompt compliance measure different things. Bottles, an orange box, and text-like marks can all be present while the requested relationships drift. Counting, relative position, and attaching an attribute to the correct object are compositional challenges.</p><p>Saying that image models "cannot count" misses the larger problem. Individually recognizable concepts have to stay attached to the right instance and location throughout generation.</p><p>Sketches, layouts, segmentation maps, and image checks help make some intended state explicit: where an object belongs, how many are needed, and whether a word is exact. The diagram separates guidance from checking: its layout specifies the bottles' positions, while the checks inspect count, position, and the characters in FRESH. These aids do not guarantee a correct result, but they stop the prompt from carrying every constraint alone.</p><p>A creative mood board benefits from the model filling gaps. An asset with exact copy, object counts, or placement can fail precisely when the model fills in a gap you intended to specify.</p><h2>7. Document extraction: connect the answer to the right cell</h2><p>AI document extraction can give you a perfectly grammatical answer that comes from the wrong cell in the document! The reason is that a vision-language model is doing several different jobs before it ever starts reasoning about your PDF.</p><p>Start with a scanned bank statement:</p><ul><li><p>Opening balance: $14,900</p></li><li><p>Deposits: $2,200</p></li><li><p>Closing balance: $17,100</p></li></ul><p>Ask, "How much was deposited?"</p><p>The model does not receive the document as a clean database row. A vision encoder turns pixels into a limited set of visual tokens. Small type, a low-quality scan, and dense tables can make the evidence for a word or nearby number weak or mixed. Some PDF pipelines pass native text separately, which changes the failure mode, but charts, tables, handwriting, and rendered layout still require visual interpretation.</p><p>Then comes binding: "Deposits" must be linked to $2,200. Recognizing all three amounts somewhere on the page is insufficient. The language model uses the visual representations and the question to generate its answer token by token.</p><p>If the deposit label was unclear, or the label-to-value association was wrong, "$17,100" can still be a plausible completion. Fluency tells us the decoder completed a sentence well. It does not tell us which pixels supported the answer.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hKiJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hKiJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!hKiJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!hKiJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!hKiJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hKiJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.png" width="1080" height="1400" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1400,&quot;width&quot;:1080,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1520024,&quot;alt&quot;:&quot;A scanned bank statement lists $14,900 opening balance, $2,200 deposits, and $17,100 closing balance. The visual contrasts linking Deposits to $2,200 with a wrong $17,100 answer, then shows checks for reading glyphs, binding layout, and tracing the answer to evidence.&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A scanned bank statement lists $14,900 opening balance, $2,200 deposits, and $17,100 closing balance. The visual contrasts linking Deposits to $2,200 with a wrong $17,100 answer, then shows checks for reading glyphs, binding layout, and tracing the answer to evidence." title="A scanned bank statement lists $14,900 opening balance, $2,200 deposits, and $17,100 closing balance. The visual contrasts linking Deposits to $2,200 with a wrong $17,100 answer, then shows checks for reading glyphs, binding layout, and tracing the answer to evidence." srcset="https://substackcdn.com/image/fetch/$s_!hKiJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.png 424w, https://substackcdn.com/image/fetch/$s_!hKiJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.png 848w, https://substackcdn.com/image/fetch/$s_!hKiJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.png 1272w, https://substackcdn.com/image/fetch/$s_!hKiJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c8bc1d6-e74a-4860-ac48-c0bcebaca573_1080x1400.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Reading a number is only one step. The answer must preserve its relationship to the requested label and the correct source region.</figcaption></figure></div><p>I separate document extraction into three questions:</p><ol><li><p>Did the system read the relevant glyphs?</p></li><li><p>Did it preserve the relationship between label, row, column, and value?</p></li><li><p>Did the answer come from that evidence, or from a plausible completion?</p></li></ol><p>Optical character recognition (OCR) and coordinates can make the first two steps inspectable. A vision-language model is useful when the final answer needs a comparison, interpretation, or calculation.</p><p>More visual resolution can improve fine detail, but it also costs tokens and latency. It does not automatically recover a missing label-to-value relationship.</p><p>Chart questions have the same difficulty. Reading "Q4" and "47" is insufficient: the system has to connect the right series, axis, and visual mark before it can reason usefully about them.</p>]]></content:encoded></item><item><title><![CDATA[AdalFlow: A PyTorch-Like Framework to Auto-Optimizing Prompt for your LLM agent]]></title><description><![CDATA[AI Agent frameworks are becoming just as important as model training itself!]]></description><link>https://newsletter.theaiedge.io/p/adalflow-a-pytorch-like-framework</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/adalflow-a-pytorch-like-framework</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Mon, 29 Sep 2025 15:01:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!o1BQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>AI Agent frameworks are becoming just as important as model training itself! I am excited to introduce you to <a href="https://www.linkedin.com/in/li-yin-ai/">Li Yin</a>. She is the CEO of <a href="https://github.com/SylphAI-Inc">SylphAI</a> and the founder of <a href="https://github.com/SylphAI-Inc/AdalFlow">AdalFlow</a>, a PyTorch-like open-source library on GitHub that enables developers to build and auto-optimize any Language Model (LM) workflows.</strong></p><p><strong>In this guest post, <a href="https://www.linkedin.com/in/aria-ailearning/">Aria Shi</a>, the Developer Relations lead at SylphAI, walks you through how AdalFlow empowers AI Agent development, highlighting a hands-on example with a <a href="https://github.com/SylphAI-Inc/AdalFlow">LinkedIn Reachout Agent</a>.</strong></p><div><hr></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!o1BQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!o1BQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!o1BQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!o1BQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!o1BQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!o1BQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png" width="554" height="554" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:554,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&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="" title="" srcset="https://substackcdn.com/image/fetch/$s_!o1BQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!o1BQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!o1BQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!o1BQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2431b183-b2fc-4935-87f1-689b6846781a_1024x1024.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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><blockquote><p><em>Say goodbye to manual prompt engineering. <strong><a href="https://github.com/SylphAI-Inc/AdalFlow">AdalFlow</a></strong> is the all-in-one, auto-differentiative solution for optimizing prompts, whether you&#8217;re using zero-shot or few-shot learning. Backed by our state-of-the-art research (LLM-AutoDiff and Learn-to-Reason), our framework achieves the highest accuracy among all automatic prompt optimization libraries.</em></p></blockquote><p>The rise of large language models has completely changed the way we build applications&#8212;whether it&#8217;s chatbots, RAG systems, or fully autonomous agents. But as an AI engineer, trying to bring these models into production often feels like stitching together a bunch of experiments, rather than building a stable and reliable system.</p><p>We introduce AdalFlow: a PyTorch-like library designed to bring structure, clarity, and optimization to the world of LLM application development. Built as a community-driven project, AdalFlow is uniting AI research and production engineering into a single ecosystem.</p><div class="pullquote"><p><strong><a href="https://github.com/SylphAI-Inc/AdalFlow">AdalFlow GitHub Repository</a></strong></p></div><h2>Why We Built AdalFlow</h2><p>Modern AI development faces a paradox. On one hand, researchers push the boundaries of model capabilities with new techniques in prompting, evaluation, and optimization. On the other hand, production teams need reproducibility, scalability, and a way to iterate safely on real-world data.</p><p>Most libraries excel at one side of the equation but leave the other underserved. AdalFlow was born to bridge this gap. With 100% control and clarity of source code, it empowers researchers to experiment freely while giving product engineers the tools to build and ship with confidence.</p><h3>Why AdalFlow Matters</h3><p>By treating prompts as first-class citizens and introducing LLM-AutoDiff, AdalFlow provides what&#8217;s been missing in the LLM ecosystem:</p><ul><li><p>For researchers: A familiar PyTorch-like environment to prototype new prompting and training methods.</p></li><li><p>For engineers: Production-ready workflows that are debuggable, reproducible, and optimizable.</p></li><li><p>For teams: A shared framework that unites research and production into one healthy ecosystem.</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_!HKp4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HKp4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.png 424w, https://substackcdn.com/image/fetch/$s_!HKp4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.png 848w, https://substackcdn.com/image/fetch/$s_!HKp4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.png 1272w, https://substackcdn.com/image/fetch/$s_!HKp4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HKp4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.png" width="724" height="264.0412087912088" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:531,&quot;width&quot;:1456,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!HKp4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.png 424w, https://substackcdn.com/image/fetch/$s_!HKp4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.png 848w, https://substackcdn.com/image/fetch/$s_!HKp4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.png 1272w, https://substackcdn.com/image/fetch/$s_!HKp4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6aa8ef86-71f7-493b-b183-44b000d9c1b8_1600x584.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">The overview of AdalFlow</figcaption></figure></div><h2>Core Philosophy: Prompt Is the New Programming Language</h2><p>If PyTorch turned tensors into the lingua franca of deep learning, AdalFlow treats prompts as the new programming primitives.</p><p>Every LLM application boils down to structured prompts and their transformations. AdalFlow embraces this reality by making prompt engineering explicit and optimizable. Behind the scenes, it uses the <a href="https://jinja.palletsprojects.com/en/stable/">Jinja2</a> templating engine to let developers define composable prompt structures, ensuring that LLM apps are both modular and debuggable.</p><h3>Components: The Building Blocks of LLM Workflows</h3><p>At the heart of AdalFlow lies the Component abstraction. Just as <code>nn.Module</code> became the foundation for PyTorch models, Components unify every stage of an LLM pipeline.</p><div class="pullquote"><p><strong><a href="https://adalflow.sylph.ai/new_tutorials/core_concepts.html">AdalFlow Core Concepts</a></strong></p></div><ul><li><p>Component: The base class for all workflows. Handles both training (forward) and inference (call) modes, with bicall bridging the two.</p></li><li><p>GradComponent: Components capable of backpropagation (e.g., Generators, Retrievers).</p></li><li><p>DataComponent: Lightweight components for formatting and parsing data (e.g., DataClassParser).</p></li><li><p>LossComponent: Wraps evaluation metrics and enables gradient-like feedback for text optimization.</p></li></ul><h3>Example 1: Q&amp;A with Object Counting (Component + DataComponent)</h3><div class="pullquote"><p><strong><a href="https://adalflow.sylph.ai/use_cases/question_answering.html?source=post_page-----84f95a03f22b---------------------------------------">Question Answering - Build and Optimize LM Workflows</a></strong></p></div><pre><code>template = r<strong>"""&lt;START_OF_SYSTEM_PROMPT&gt;
{{system_prompt}}
&lt;END_OF_SYSTEM_PROMPT&gt;
&lt;START_OF_USER&gt;
{{input_str}}
&lt;END_OF_USER&gt;"""</strong>

<strong>@adal.func_to_data_component</strong>
<strong>def</strong> parse_integer_answer(answer: <strong>str</strong>):
    numbers = re.findall(r"\d+", answer)
    <strong>return</strong> <strong>int</strong>(numbers[-1])</code></pre><h4>What&#8217;s happening here?</h4><ul><li><p><code>parse_integer_answer</code> is wrapped with <code>@adal.func_to_data_component</code>.</p></li><li><p>This turns a plain Python function into a <code>DataComponent</code>, which handles structured output parsing.</p></li><li><p>In this case, it ensures the model&#8217;s answer ends with a numerical value.</p></li></ul><p>Next, we define a full pipeline:</p><pre><code><strong>class</strong> ObjectCountTaskPipeline(adal.Component):
    <strong>def</strong> __init__(
            <strong>self</strong>, model_client: adal.ModelClient, model_kwargs: Dict
        ):
        <strong>super</strong>().__init__()
        system_prompt = adal.Parameter(
            data=<strong>"You will answer a reasoning question. Think step by step. The last line should be 'Answer: $VALUE'."</strong>,
            role_desc=<strong>"Task instruction for the model"</strong>,
            requires_opt=<strong>True</strong>,
            param_type=ParameterType.PROMPT,
        )
        <strong>self</strong>.llm_counter = adal.Generator(
            model_client=model_client,
            model_kwargs=model_kwargs,
            template=template,
            prompt_kwargs={<strong>"system_prompt"</strong>: system_prompt},
            output_processors=parse_integer_answer,
        )

    <strong>def</strong> bicall(<strong>self</strong>, question: <strong>str</strong>, id: <strong>str</strong> = <strong>None</strong>):
        <strong>return</strong> self.llm_counter(
              prompt_kwargs={<strong>"input_str"</strong>: question}, id=id
        )</code></pre><p><code>ObjectCountTaskPipeline</code> subclasses Component. Inside it, we define:</p><ul><li><p>A Parameter of type <code>PROMPT</code>, which AdalFlow can later auto-optimize.</p></li><li><p>A Generator (a <code>GradComponent</code>) that executes the prompt, then passes the raw LLM output through our <code>parse_integer_answer</code> <code>DataComponent</code>.</p></li></ul><blockquote><p><em>The workflow is:<br>Prompt &#8594; LLM Generation &#8594; Structured Output Parsing &#8594; Final Numerical Answer.</em></p></blockquote><h3>Example 2: Classification with Structured Output (Component + DataClass)</h3><div class="pullquote"><p><strong><a href="https://adalflow.sylph.ai/use_cases/classification.html?source=post_page-----84f95a03f22b---------------------------------------">Classification Optimization - Build and Optimize LM Workflows</a></strong></p></div><p>Classification tasks are a perfect showcase of AdalFlow&#8217;s DataClass feature.</p><pre><code><strong>@dataclass</strong>
<strong>class</strong> TRECExtendedData(adal.DataClass):
    question: <strong>str</strong> = field(
        metadata={<strong>"desc"</strong>: <strong>"The question to be classified"</strong>}
    )
    rationale: <strong>str</strong> = field(
        metadata={<strong>"desc"</strong>: <strong>"Step-by-step reasoning"</strong>}, default=<strong>None</strong>
    )
    class_name: Literal[
        <strong>"ABBR"</strong>, <strong>"ENTY"</strong>, <strong>"DESC"</strong>, <strong>"HUM"</strong>, <strong>"LOC"</strong>, <strong>"NUM"
    </strong>] = field(
        metadata={<strong>"desc"</strong>: <strong>"The class name"</strong>}, default=<strong>None</strong>
    )

    __input_fields__ = [<strong>"question"</strong>]
    __output_fields__ = [<strong>"rationale"</strong>, <strong>"class_name"</strong>]</code></pre><ul><li><p><code>TRECExtendedData</code> extends <code>DataClass</code>, which (like Pydantic) gives us schema enforcement.</p></li><li><p>Input: a question.</p></li><li><p>Output: a rationale (reasoning trace) and a <code>class_name</code> (final label).</p></li></ul><p>Now let&#8217;s plug it into a pipeline:</p><pre><code><strong>class</strong> TRECClassifierStructuredOutput(adal.Component):
    <strong>def</strong> __init__(
        <strong>self</strong>, model_client: adal.ModelClient, model_kwargs: Dict
    ):
        <strong>super</strong>().__init__()
        <em><strong># Task description prompt</strong></em>
        task_desc_str = adal.Prompt(
            template=task_desc_template,
            prompt_kwargs={
                <strong>"classes"</strong>: [
                    {<strong>"label"</strong>: l, <strong>"desc"</strong>: d} 
                    <strong>for</strong> l, d 
                    <strong>in</strong> <strong>zip</strong>(_COARSE_LABELS, _COARSE_LABELS_DESC)
                ]
            }
        )()

        parser = adal.DataClassParser(
            data_class=TRECExtendedData,
            return_data_class=<strong>True</strong>,
            format_type=<strong>"yaml"</strong>
        )

        prompt_kwargs = {
            <strong>"system_prompt"</strong>: adal.Parameter(
                data=task_desc_str,
                role_desc=<strong>"Task description"</strong>,
                requires_opt=<strong>True</strong>,
                param_type=adal.ParameterType.PROMPT,
            ),
            <strong>"output_format_str"</strong>: parser.get_output_format_str(),
        }

        <strong>self</strong>.llm = adal.Generator(
            model_client=model_client,
            model_kwargs=model_kwargs,
            prompt_kwargs=prompt_kwargs,
            template=template,
            output_processors=parser,
        )

    <strong>def</strong> bicall(<strong>self</strong>, question: <strong>str</strong>, id: Optional[<strong>str</strong>] = <strong>None</strong>):
        <strong>return</strong> <strong>self</strong>.llm(prompt_kwargs={"input_str": question}, id=id)</code></pre><ul><li><p>The Prompt defines the system instruction with class definitions.</p></li><li><p><code>DataClassParser</code> enforces structured YAML output that matches <code>TRECExtendedData</code>.</p></li><li><p>Generator (a GradComponent) runs the LLM with prompt + parser.</p></li><li><p>Output is guaranteed to follow the schema: rationale + class name.</p></li></ul><p>This ensures the model never drifts into free-form answers&#8212;it always returns structured classification results.</p><h3>Example 3: Training With LossComponent</h3><p>Finally, how do we train or optimize these components? That&#8217;s where <code>LossComponent</code> comes in:</p><pre><code>eval_fn = AnswerMatchAcc(type=<strong>"exact_match"</strong>).compute_single_item
loss_fn = adal.EvalFnToTextLoss(
    eval_fn=eval_fn,
    eval_fn_desc=<strong>"exact_match: 1 if str(y) == str(y_gt) else 0"</strong>
)</code></pre><ul><li><p><code>AnswerMatchAcc</code> is the evaluation metric.</p></li><li><p><code>EvalFnToTextLoss</code> wraps it as a <code>LossComponent</code>, enabling LLM-AutoDiff to optimize prompts automatically during training.</p></li></ul><blockquote><p><em>By attaching this to your pipeline, you get a full training loop:<br>Forward pass &#8594; Eval metric &#8594; Backward engine &#8594; Prompt optimization.</em></p></blockquote><h2>Agents: Reasoning Meets Action</h2><p>AdalFlow embraces the ReAct paradigm&#8212;combining reasoning (plan) with acting (tool use)&#8212;to build autonomous, auditable AI systems. An agent reasons about the task, selects tools, executes them, observes results, and iterates until it can deliver a final answer.</p><ul><li><p><a href="https://adalflow.sylph.ai/new_tutorials/agents_runner.html">https://adalflow.sylph.ai/new_tutorials/agents_runner.html</a></p></li><li><p><a href="https://colab.research.google.com/github/SylphAI-Inc/AdalFlow/blob/main/notebooks/agents/agent_tutorial.ipynb">https://colab.research.google.com/github/SylphAI-Inc/AdalFlow/blob/main/notebooks/agents/agent_tutorial.ipynb</a></p></li></ul><h3>Architecture at a Glance</h3><ul><li><p>Agent (planner + tool manager)<br>Handles <em>planning and decision-making</em> via a Generator-based planner, and knows what tools are available and how to call them.</p></li><li><p>Runner (executor + conversation loop)<br>Orchestrates <em>multi-step execution</em>, tool calling, observation handling, timeouts, and final answer synthesis.</p></li></ul><p>This separation lets you swap or customize planning vs. execution independently.</p><h3>Execution Flow (ReAct Loop Recap)</h3><ol><li><p>Planning &#8211; The Agent (Generator planner) analyzes input and proposes the next action.</p></li><li><p>Tool Selection &#8211; Chooses a tool from the registered set.</p></li><li><p>Tool Execution &#8211; The Runner invokes the tool with arguments.</p></li><li><p>Observation &#8211; The result is fed back to the planner.</p></li><li><p>Iteration &#8211; Repeat 1&#8211;4 up to max_steps or until confident.</p></li><li><p>Final Answer &#8211; The planner synthesizes the answer (optionally into a structured type).</p></li></ol><h3>Minimal, End-to-End Example</h3><blockquote><p><em>1) Define a Tool (callable or FunctionTool)</em></p></blockquote><pre><code><em><strong># Tool: a plain Python callable works, or wrap with FunctionTool for extras.</strong></em>
<strong>def</strong> calculator(expression: str) -&gt; <strong>str</strong>:
    <em><strong>"""Evaluate a mathematical expression."""</strong></em>
    <strong>try</strong>:
        result = eval(expression)
        return f<strong>"Result: {result}"</strong>
    <strong>except</strong> Exception <strong>as</strong> e:
        <strong>return</strong> f<strong>"Error: {e}"</strong></code></pre><blockquote><p><em>2) Build the Agent (Planner + Tools)</em></p></blockquote><pre><code><strong>from</strong> adalflow <strong>import</strong> Agent, Runner
<strong>from</strong> adalflow.components.model_client.openai_client <strong>import</strong> OpenAIClient

agent = Agent(
    name=<strong>"CalculatorAgent"</strong>,  <em><strong># Agent identifier</strong></em>
    tools=[calculator],  <em><strong># List of tools (callables or FunctionTool)</strong></em>
    <em><strong># LLM client used by the planner (Generator-based)</strong></em>
    model_client=OpenAIClient(),
    model_kwargs={<strong>"model"</strong>: <strong>"gpt-4o"</strong>, <strong>"temperature"</strong>: 0.3},
    max_steps=6,  <em><strong># Upper bound for ReAct loops</strong></em>
)</code></pre><p>What this maps to:</p><ul><li><p>Planner: An internal Generator that decides the next step (think: &#8220;reasoning trace&#8221;).</p></li><li><p><code>ToolManager</code>: The agent&#8217;s registry of permitted tools.</p></li><li><p>max_steps: Safety rail to prevent runaway loops.</p></li></ul><h4>Model Configuration (Swap Backends Easily)</h4><pre><code><em><strong># OpenAI</strong></em>
<strong>from</strong> adalflow.components.model_client.openai_client <strong>import</strong> OpenAIClient
agent = Agent(
    model_client=OpenAIClient(), 
    model_kwargs={<strong>"model"</strong>: <strong>"gpt-4o"</strong>}
)

<strong># Anthropic</strong>
<strong>from</strong> adalflow.components.model_client.anthropic_client <strong>import</strong> (
    AnthropicAPIClient
)
agent = Agent(
    model_client=AnthropicAPIClient(), 
    model_kwargs={<strong>"model"</strong>: <strong>"claude-3-sonnet-20240229"</strong>}
)</code></pre><blockquote><p><em>3) Execute with the Runner (Multi-step Orchestration)</em></p></blockquote><pre><code><em><strong># Manages turns, tool calls, observations, and finalization</strong></em>
runner = Runner(agent=agent) 

result = runner.call(
    prompt_kwargs={<strong>"input_str"</strong>: <strong>"Invoke the calculator tool and calculate 15 * 7 + 23"</strong>}
)

<strong>print</strong>(result.answer)
<em><strong># -&gt; "The result of 15 * 7 + 23 is 128."</strong></em></code></pre><h4>RunnerResult schema (returned by Runner.call)</h4><pre><code># result has:
# - result.step_history: [StepOutput(...)]  # Each step&#8217;s action + observation
# - result.answer: str | structured type     # Final synthesized answer
# - result.error: None | Exception info      # Error if something failed
# - result.ctx: dict | None                  # Optional execution metadata</code></pre><blockquote><p><em>This is the full ReAct loop in action:</em></p><p><em>Plan &#8594; Select Tool &#8594; Execute &#8594; Observe &#8594; Iterate &#8594; Answer.</em></p></blockquote><div><hr></div><h3>Advanced Features (Production-Ready)</h3><blockquote><p><em>1) Streaming Execution (Real-Time Updates)</em></p></blockquote><pre><code><em><strong># Pseudocode: actual API may differ slightly in your version.</strong></em>
stream = runner.stream(
    prompt_kwargs={<strong>"input_str"</strong>: <strong>"Compute 42 * 73 and explain."</strong>}
)
<strong>for</strong> update <strong>in</strong> stream:
    <em><strong># update contains partial thoughts, tool calls, observations, etc.</strong></em>
    <strong>print</strong>(update)</code></pre><p>Use streaming to surface <em>live</em> reasoning/tool progress in UIs.</p><blockquote><p><em>2) Human-in-the-Loop (Permission Management)</em></p></blockquote><pre><code><strong>from</strong> adalflow.permissions <strong>import</strong> PermissionManager

<strong>class</strong> MyPerms(PermissionManager):
    <strong>def</strong> approve(<strong>self</strong>, tool_name: <strong>str</strong>, args: <strong>dict</strong>) -&gt; <strong>bool</strong>:
        <em><strong># Example policy: only allow calculator; prompt user otherwise</strong></em>
        <strong>return</strong> tool_name == <strong>"calculator"</strong>

agent = Agent(
    name=<strong>"GuardedAgent"</strong>,
    tools=[calculator, search_tool],
    model_client=OpenAIClient(),
    model_kwargs={<strong>"model"</strong>: <strong>"gpt-4o"</strong>},
    permission_manager=MyPerms(),  <em><strong># &lt;- Every tool call can be inspected/approved)</strong></em></code></pre><p>Great for tools that hit external systems (files, emails, APIs).</p><blockquote><p><em>3) Custom System Templates (Planner Behavior)</em></p></blockquote><pre><code>custom_role_desc = <em><strong>"""
You are a careful, step-by-step data analyst.
When you use a tool, explain why and what you expect to get.
"""</strong></em>
agent = Agent(
    name="DataAnalyst",
    <em><strong># Custom planner persona and guardrails</strong></em>
    role_desc=custom_role_desc,        
    model_client=OpenAIClient(),
    model_kwargs={<strong>"model"</strong>: <strong>"gpt-4o"</strong>, <strong>"temperature"</strong>: 0.2},
)</code></pre><blockquote><p><em>4) Tracing (Observability)</em></p></blockquote><pre><code><em><strong># Configure tracing once (destination: console, file, or tracing backend)</strong></em>
<strong>from</strong> adalflow.tracing <strong>import</strong> enable_tracing
enable_tracing(project=<strong>"adalflow-agents-demo"</strong>)

result = runner.call(prompt_kwargs={
    <strong>"input_str"</strong>: <strong>"Use the calculator for 88*19."</strong>
})
<em><strong># Inspect step_history, tool IO, latency, errors, etc.</strong></em></code></pre><p>Agent Summary:</p><ul><li><p>Agent = Reasoning + Tool selection (Generator-based planner + ToolManager)</p></li><li><p>Runner = Controlled execution loop (steps, tools, observations, final answer)</p></li><li><p>Tools = Safe, permissioned extensions to the agent&#8217;s capabilities</p></li><li><p>Production = Streaming, human approvals, tracing, structured outputs</p></li></ul><h2>Real-World Use Case: LinkedIn Recruitment Agent with AdalFlow</h2><p>Hiring top talent is one of the most resource-intensive parts of building a company. Recruiters spend hours scrolling LinkedIn, opening profiles, copying notes, and crafting outreach messages.</p><p>What if we could automate that entire workflow&#8212;turning hours of manual searching into minutes of AI-assisted sourcing?</p><p>That&#8217;s exactly what we built using AdalFlow&#8217;s Agent + Runner architecture combined with browser automation via Chrome DevTools Protocol (CDP).</p><h3>&#10024; Before vs. After</h3><p>Traditional Recruiting Workflow (Manual)</p><blockquote><p><em>&#10060; BEFORE: 2&#8211;3 hours per role</em></p><p><em>1. Navigate to LinkedIn people search</em></p><p><em>2. Type in &#8220;Product Manager, San Francisco&#8221;</em></p><p><em>3. Scroll endlessly, click into profiles</em></p><p><em>4. Skim experience, education, skills</em></p><p><em>5. Take notes in spreadsheets</em></p><p><em>6. Write &amp; send DMs manually</em></p><p><em>Automated Workflow with AdalFlow (Agentic)</em></p><p><em>&#9989; AFTER: 10 minutes per role</em></p><p><em>1. Run: linkedin-agent --query &#8220;Product Manager&#8221; --limit 10</em></p><p><em>2. Agent plans and executes:</em></p><p><em>- Smart search strategy</em></p><p><em>- Extract profiles via browser automation</em></p><p><em>- Evaluate candidates with scoring models</em></p><p><em>- Draft personalized outreach messages</em></p><p><em>3. Get structured output: JSON/CSV with names, titles, LinkedIn URLs, evaluation scores, outreach drafts. Recruiters get to focus on talking to people, not copy-pasting data.</em></p></blockquote><h3>How It Works &#8212; Global State Architecture</h3><p>We structured the solution around a global state shared between tools. Each tool contributes partial data (search results, profiles, evaluations, outreach drafts), which the Agent combines into a full pipeline. Agent combines into a full 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_!OCV8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OCV8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.png 424w, https://substackcdn.com/image/fetch/$s_!OCV8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.png 848w, https://substackcdn.com/image/fetch/$s_!OCV8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.png 1272w, https://substackcdn.com/image/fetch/$s_!OCV8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OCV8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.png" width="1022" height="731" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:731,&quot;width&quot;:1022,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:995168,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OCV8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.png 424w, https://substackcdn.com/image/fetch/$s_!OCV8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.png 848w, https://substackcdn.com/image/fetch/$s_!OCV8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.png 1272w, https://substackcdn.com/image/fetch/$s_!OCV8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F664cc551-6805-4f73-96fe-9e4e1b668a68_1022x731.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Full Pipeline of LinkedInAgent</figcaption></figure></div><h3>Implementation with AdalFlow</h3><p>We implemented the LinkedInAgent by encapsulating:</p><blockquote><p><em>Agent &#8594; Planner + Tools (search, extract, evaluate, outreach)</em></p><p><em>Runner &#8594; Execution loop with error handling and logging</em></p></blockquote><pre><code><strong>class</strong> LinkedInAgent:
<em><strong>    """
    LinkedIn recruitment agent powered by AdalFlow.
    - Encapsulates Agent + Runner
    - Provides default recruitment tools
    - Supports both sync call() and async acall()
    """</strong></em>

    <strong>def</strong> __init__(
        <strong>self</strong>,
        model_client: Optional[OpenAIClient] = <strong>None</strong>,
        model_kwargs: Optional[Dict[<strong>str</strong>, <strong>Any</strong>]] = <strong>None</strong>,
        max_steps: Optional[<strong>int</strong>] = <strong>None</strong>,
        role_desc: Optional[<strong>str</strong>] = <strong>None</strong>,
        **kwargs,
    ):
        <em><strong># Defaults</strong></em>
        model_client = model_client <strong>or</strong> OpenAIClient()
        model_kwargs = model_kwargs <strong>or</strong> {
           <strong>"model"</strong>: <strong>"gpt-4o"</strong>, &#8220;temperature&#8221;: 0.3
        }
        max_steps = max_steps <strong>or</strong> 6

        <em><strong># Recruitment workflow tools</strong></em>
        <strong>self</strong>.tools = [
            <em><strong># 1. Search LinkedIn via CDP</strong></em>
            SmartCandidateSearchTool,
            <em><strong># 2. Extract structured profile data</strong></em>     
            ExtractCandidateProfilesTool, 
            <em><strong># 3. Score candidates</strong></em>   
            CandidateEvaluationTool,
            <em><strong># 4. Draft personalized outreach</strong></em>         
            CandidateOutreachGenerationTool,
            <em><strong># 5. Persist results </strong></em>
            SaveOutreachResultsTool,         
        ]

        <em><strong># Agent role description (personality / instructions)</strong></em>
        role_desc = role_desc <strong>or</strong> <strong>"You are a recruitment assistant that sources and evaluates LinkedIn candidates."</strong>

        <em><strong># Initialize Agent + Runner</strong></em>
        <strong>self</strong>.agent = Agent(
            name=<strong>"LinkedInRecruiter"</strong>,
            tools=<strong>self</strong>.tools,
            model_client=model_client,
            model_kwargs=model_kwargs,
            max_steps=max_steps,
            role_desc=role_desc,
            **kwargs,
        )
        <strong>self</strong>.runner = Runner(agent=<strong>self</strong>.agent, max_steps=max_steps)

    <strong>def</strong> call(
        <strong>self</strong>, query: <strong>str</strong>, context: Optional[Dict[<strong>str</strong>, Any]] = <strong>None</strong>
    ):
        <strong>return</strong> <strong>self</strong>.runner.call(prompt_kwargs={<strong>"input_str"</strong>: query})

    <strong>async</strong> <strong>def</strong> acall(
        <strong>self</strong>, query: <strong>str</strong>, context: Optional[Dict[<strong>str</strong>, Any]] = <strong>None
    </strong>):
        <strong>return</strong> <strong>await</strong> <strong>self</strong>.runner.acall(
            prompt_kwargs={<strong>"input_str"</strong>: query}
        )</code></pre><h4>Full Workflow Execution</h4><p>Here&#8217;s how we stitch the agent into a production workflow:</p><pre><code><strong>def</strong> execute_search_workflow(
    <strong>self</strong>, progress_tracker=None) -&gt; List[Dict[str, Any]]:
    logger = get_logger()
    logger.set_workflow_context(<strong>"workflow_main"</strong>, <strong>"initialization"</strong>)

    log_phase_start(<strong>"WORKFLOW_START"</strong>, f<strong>"Target: {self.limit} candidates for {self.query} in {self.location}"</strong>)

    candidates = []
    <strong>try</strong>:
        log_info(<strong>"&#129302; Initializing LinkedIn agent..."</strong>)
        agent, user_query = <strong>self</strong>.initialize_agent()

        <strong>if</strong> progress_tracker:
            progress_tracker.start_workflow()

        <em><strong># Run full pipeline</strong></em>
        result = agent.call(query=user_query)
        <strong>self</strong>._print_agent_execution_steps(result)

        <em><strong># Collect data from global state</strong></em>
        <strong>from</strong> ..core.workflow_state <strong>import</strong> get_complete_workflow_data
        workflow_data = get_complete_workflow_data()

        candidates = self._build_complete_candidate_data(workflow_data)

        log_info(f<strong>"&#9989; Found {len(candidates)} candidates"</strong>)
        <strong>return</strong> candidates

    <strong>except</strong> Exception <strong>as</strong> e:
        log_error(f<strong>"&#10060; Workflow failed: {e}"</strong>)
        <strong>return</strong> candidates</code></pre><h2>Example Output</h2><p>After running:</p><pre><code>linkedin-agent --query &#8220;Product Manager San Francisco&#8221; --limit 10</code></pre><p>We get structured results like:</p><pre><code>[
  {
    &#8220;name&#8221;: &#8220;Alex Chen&#8221;,
    &#8220;title&#8221;: &#8220;Senior Product Manager @ Stripe&#8221;,
    &#8220;location&#8221;: &#8220;San Francisco Bay Area&#8221;,
    &#8220;profile_url&#8221;: &#8220;https://linkedin.com/in/alexchen&#8221;,
    &#8220;score&#8221;: 0.92,
    &#8220;outreach_message&#8221;: &#8220;Hi Alex, I came across your experience at Stripe...&#8221;
  },
  {
    &#8220;name&#8221;: &#8220;Maria Lopez&#8221;,
    &#8220;title&#8221;: &#8220;PM, Growth @ Airbnb&#8221;,
    &#8220;location&#8221;: &#8220;San Francisco Bay Area&#8221;,
    &#8220;profile_url&#8221;: &#8220;https://linkedin.com/in/marialopez&#8221;,
    &#8220;score&#8221;: 0.88,
    &#8220;outreach_message&#8221;: &#8220;Hi Maria, your background in growth product design really stood out...&#8221;
  }
]</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kb2z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kb2z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.png 424w, https://substackcdn.com/image/fetch/$s_!kb2z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.png 848w, https://substackcdn.com/image/fetch/$s_!kb2z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.png 1272w, https://substackcdn.com/image/fetch/$s_!kb2z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kb2z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.png" width="1456" height="806" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:806,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!kb2z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.png 424w, https://substackcdn.com/image/fetch/$s_!kb2z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.png 848w, https://substackcdn.com/image/fetch/$s_!kb2z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.png 1272w, https://substackcdn.com/image/fetch/$s_!kb2z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02aba8ac-d751-4aa9-a1f3-e35c581ac506_1600x886.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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">Screenshot of the LinkedInAgent</figcaption></figure></div><blockquote><p><em>============================================================</em></p><p><em>WORKFLOW COMPLETION SUMMARY</em></p><p><em>============================================================</em></p><p><em>Success: &#9989; Yes</em></p><p><em>Total Candidates: 2</em></p><p><em>Duration: 68.8 seconds</em></p><p><em>Session: 20250909_220617</em></p><p><em>Log Files:</em></p><p><em>&#8226; Main: logs/workflow_20250909_220617.log</em></p><p><em>&#8226; Debug: logs/debug_20250909_220617.log</em></p><p><em>&#8226; Agent Steps: logs/agent_steps_20250909_220617.log</em></p><p><em>&#8226; Errors: logs/errors_20250909_220617.log</em></p><p><em>============================================================</em></p><p><em>&#127937; MAIN &#9989; COMPLETED - Processed 2 candidates</em></p><p><em>[RESULTS] &#9989; Recruitment workflow completed!</em></p><p><em>[RESULTS] &#128202; Final result: Successfully processed 2 candidates</em></p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FhEb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FhEb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin 424w, https://substackcdn.com/image/fetch/$s_!FhEb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin 848w, https://substackcdn.com/image/fetch/$s_!FhEb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin 1272w, https://substackcdn.com/image/fetch/$s_!FhEb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FhEb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin" width="496" height="333" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:333,&quot;width&quot;:496,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&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="" title="" srcset="https://substackcdn.com/image/fetch/$s_!FhEb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin 424w, https://substackcdn.com/image/fetch/$s_!FhEb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin 848w, https://substackcdn.com/image/fetch/$s_!FhEb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin 1272w, https://substackcdn.com/image/fetch/$s_!FhEb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdbb5d26-0c73-4e5b-99ce-c7f5920e417b_496x333.bin 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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>Looking Ahead</h2><p>As the LLM landscape evolves, frameworks like AdalFlow will become the backbone of application development. Just as PyTorch accelerated deep learning, AdalFlow has the potential to democratize LLM app building&#8212;from chatbots to agents to beyond.</p><p>If you&#8217;re excited about shaping the future of AI workflows, the project is open-source and community-driven. Whether you&#8217;re an AI researcher, product engineer, or just curious about building smarter applications, now&#8217;s the time to get involved.</p><p>&#128640; AdalFlow isn&#8217;t just another library. It&#8217;s a paradigm shift in how we think about programming with language models.</p>]]></content:encoded></item><item><title><![CDATA[Last Week to Register: Build Production-Ready Agentic-RAG Applications From Scratch Course!]]></title><description><![CDATA[Project-Based Course]]></description><link>https://newsletter.theaiedge.io/p/last-week-to-register-build-production</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/last-week-to-register-build-production</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Tue, 23 Sep 2025 15:02:58 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!HM5S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is the last week to register for the <strong><a href="https://maven.com/damien-benveniste/agentic-rag">Build Production-Ready Agentic-RAG Applications From Scratch</a></strong> course! This is a fully hands-on course where we are going to implement step-by-step from scratch a production-ready Agentic-RAG application with LangGraph, FastAPI, and React!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/agentic-rag&quot;,&quot;text&quot;:&quot;Signup!&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://maven.com/damien-benveniste/agentic-rag"><span>Signup!</span></a></p><h2>What we are going to build</h2><p>We are going to build a fun web application where we can demonstrate how to orchestrate a robust RAG application using LangGraph, FastAPI, and React. Here is what we are going to build:</p><ol><li><p>A user can pass a GitHub repository URL</p></li><li><p>The files of the related repository are scraped and indexed in a vector database</p></li><li><p>Now the code is available for the user to ask questions about.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HM5S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HM5S!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 424w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 848w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 1272w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HM5S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png" width="1456" height="899" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:899,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&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_!HM5S!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 424w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 848w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 1272w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>On the frontend, we will need two main functionalities:</p><ul><li><p>A page where we can input the repository URL and start the crawling and indexing processes:</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!g2u1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!g2u1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 424w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 848w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 1272w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!g2u1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png" width="500" height="147.32142857142858" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:429,&quot;width&quot;:1456,&quot;resizeWidth&quot;:500,&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;:false,&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_!g2u1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 424w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 848w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 1272w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><ul><li><p>And a chatbot interface to ask questions about the code in the repository:</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_!v21m!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!v21m!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 424w, https://substackcdn.com/image/fetch/$s_!v21m!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 848w, https://substackcdn.com/image/fetch/$s_!v21m!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 1272w, https://substackcdn.com/image/fetch/$s_!v21m!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!v21m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png" width="498" height="445.3269230769231" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1302,&quot;width&quot;:1456,&quot;resizeWidth&quot;:498,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!v21m!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 424w, https://substackcdn.com/image/fetch/$s_!v21m!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 848w, https://substackcdn.com/image/fetch/$s_!v21m!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 1272w, https://substackcdn.com/image/fetch/$s_!v21m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>On the backend, we will need the related endpoints:</p><ul><li><p>The indexing endpoint will respond to the provided GitHub repository URL and the &#8220;crawl&#8220; action to start the crawling and indexing processes.</p></li><li><p>The chat endpoint that will respond to messages sent by the user from the chatbot interface.</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_!fsuq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fsuq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 424w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 848w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 1272w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fsuq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png" width="1456" height="704" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:704,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!fsuq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 424w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 848w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 1272w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>We are going to use the following tools:</p><ul><li><p><a href="https://react.dev/">React</a> for the frontend</p></li><li><p><a href="https://fastapi.tiangolo.com/">FastAPI</a> for the backend</p></li><li><p><a href="https://langchain-ai.github.io/langgraph/">LangGraph</a> for the agentic orchestration</p></li><li><p><a href="https://docs.pinecone.io/guides/get-started/overview">Pinecone</a> for the vector database</p></li><li><p><a href="https://www.langchain.com/langsmith">Langsmith</a> for observability</p></li><li><p>Deploy everything on Google Cloud!</p></li></ul><h2>Project-based course</h2><p>We will focus on building the project from the ground up, as we would on the job. Here is how we are going to structure the project development:</p><ul><li><p>Introduction</p><ul><li><p>What we want to build</p></li><li><p>Setting up the environment</p></li></ul></li><li><p>The RAG Application</p><ul><li><p>The Data Parsing Pipeline</p></li><li><p>The Indexing Pipeline</p></li><li><p>The Basic RAG Pipeline</p></li><li><p>Adding Observability to the Pipeline with Langsmith</p></li><li><p>Going Agentic</p></li></ul></li><li><p>The Backend Application</p><ul><li><p>The Indexing API Endpoint</p></li><li><p>Adding Memory</p></li><li><p>Administering the Database Data</p></li></ul></li><li><p>The Frontend Application</p><ul><li><p>The Indexing Page</p></li><li><p>The Chatbot Page</p></li></ul></li><li><p>Deploying to GCP</p></li></ul><p>Each session will be a live, hands-on coding session where we are going to implement every component from scratch</p><h2>Going Agentic </h2><p>&#8220;Agentic&#8221; means that we are going to use an LLM as a decision engine to enhance the quality of our pipeline. We will focus on improving the accuracy of the pipeline at the cost of latency and cost, and discuss the opportunities to reduce those induced negative points with small language models and fine-tuning. In the RAG pipeline, we are going to build a subagent for each of the main components:</p><ul><li><p>Intent router: the entry point of the pipeline that will decide if a RAG pipeline is required. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wJDy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wJDy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.png 424w, https://substackcdn.com/image/fetch/$s_!wJDy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.png 848w, https://substackcdn.com/image/fetch/$s_!wJDy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.png 1272w, https://substackcdn.com/image/fetch/$s_!wJDy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wJDy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.png" width="1456" height="597" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/af86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:597,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:84120,&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://newsletter.theaiedge.io/i/174308314?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.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_!wJDy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.png 424w, https://substackcdn.com/image/fetch/$s_!wJDy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.png 848w, https://substackcdn.com/image/fetch/$s_!wJDy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.png 1272w, https://substackcdn.com/image/fetch/$s_!wJDy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf86c946-68f6-44aa-9b75-aea9f8688ee2_1621x665.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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></li><li><p>The retriever: The sub-agent that will extract the right data</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ayDj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ayDj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.png 424w, https://substackcdn.com/image/fetch/$s_!ayDj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.png 848w, https://substackcdn.com/image/fetch/$s_!ayDj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.png 1272w, https://substackcdn.com/image/fetch/$s_!ayDj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ayDj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.png" width="1456" height="874" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:874,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:127989,&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://newsletter.theaiedge.io/i/174308314?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.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_!ayDj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.png 424w, https://substackcdn.com/image/fetch/$s_!ayDj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.png 848w, https://substackcdn.com/image/fetch/$s_!ayDj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.png 1272w, https://substackcdn.com/image/fetch/$s_!ayDj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb186a60e-838d-44ed-9a23-940b84a25fb5_1568x941.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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></li><li><p>The generator: The sub-agent that will generate the response to the user</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nHed!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nHed!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.png 424w, https://substackcdn.com/image/fetch/$s_!nHed!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.png 848w, https://substackcdn.com/image/fetch/$s_!nHed!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.png 1272w, https://substackcdn.com/image/fetch/$s_!nHed!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nHed!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.png" width="1445" height="967" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:967,&quot;width&quot;:1445,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:122152,&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://newsletter.theaiedge.io/i/174308314?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.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_!nHed!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.png 424w, https://substackcdn.com/image/fetch/$s_!nHed!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.png 848w, https://substackcdn.com/image/fetch/$s_!nHed!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.png 1272w, https://substackcdn.com/image/fetch/$s_!nHed!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F97a91147-6c52-460e-972d-c07d99ebbc8f_1445x967.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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></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_!e7NK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!e7NK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 424w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 848w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 1272w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!e7NK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png" width="1452" height="1482" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1482,&quot;width&quot;:1452,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:165873,&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://newsletter.theaiedge.io/i/172452651?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.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_!e7NK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 424w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 848w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 1272w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>Scaling up</h2><p>With this course, I want to focus on what we would need to do to deploy the application to 1M users. We will make sure to design every endpoint to be asynchronous, queue the indexing requests, and deploy the application with elastic load balancing to scale the application horizontally.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NOQR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NOQR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 424w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 848w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 1272w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NOQR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png" width="1456" height="643" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:643,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:120017,&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://newsletter.theaiedge.io/i/172452651?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.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_!NOQR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 424w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 848w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 1272w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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 going to be a fun ride! Make sure to join us!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/agentic-rag&quot;,&quot;text&quot;:&quot;Signup!&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://maven.com/damien-benveniste/agentic-rag"><span>Signup!</span></a></p><h2><strong>The Real-World AI Engineering Roadblocks You Face Today</strong></h2><p>&#128075; <strong>Prototype &#8594; Production Gap</strong> &#8212; Moving from a notebook demo to a secure, observable, multi-tenant service requires orchestration, evals, guardrails, and ops most teams lack.</p><p>&#128075; <strong>&#8220;Easy RAG&#8221; vs &#8220;Reliable RAG&#8221;</strong> &#8212; Anyone can retrieve-then-generate; making answers faithful, fresh, fast, and cost-controlled under real traffic is the hard part.</p><p>&#128075; <strong>Framework Overload</strong> &#8212; The ecosystem is noisy; you need clear criteria (maturity, extensibility, latency, cost) and reference patterns to choose confidently.</p><p>&#128075; <strong>It&#8217;s Software Engineering First</strong> &#8212; Success hinges on clean interfaces, tests, typed configs, tracing, CI/CD, and change management&#8212;not just prompts and models.</p><p>&#128075; <strong>From Laptop to 1M Users</strong> &#8212; Scaling demands streaming, batching, caching, autoscaling, and SLOs, or your p95 explodes and costs spiral.</p><h3><strong>How this course will help you</strong></h3><p>&#9989; <strong>Ship a real Agentic RAG app, not a demo </strong>&#8212; Stand up an end-to-end stack&#8212;LangGraph &#8594; FastAPI &#8594; React, that runs locally today and deploys via a clean, fork-and-ship monorepo.</p><p>&#9989; <strong>Make retrieval dependable, not lucky</strong> &#8212; Adopt schema-aware chunking, strong dense embeddings with sensible metadata filters, and context packing with citations so answers stay faithful, fresh, and concise.</p><p>&#9989; <strong>Harden agentic workflows</strong> &#8212; Design a typed LangGraph state and build nodes for rewrite &#8594; retrieve &#8594; rerank &#8594; synthesize &#8594; cite &#8594; safety-check, with retries and timeouts so plans don&#8217;t loop or stall.</p><p>&#9989; <strong>Scale the experience, not the headaches</strong> &#8212; Enable server-streaming in FastAPI, cap top-k, trim context budgets, and add early-exit rules; deploy with autoscaling so you can serve real traffic without infra fuss.</p><p>&#9989; <strong>See enough to fix things fast</strong> &#8212; Bake in structured logs (no vendor tracing), per-step timing counters, and UI breadcrumbs/citations to follow <em>query &#8594; context &#8594; answer</em> and spot common failure patterns quickly.</p><p>&#9989; <strong>Choose frameworks with confidence</strong> &#8212; Follow an opinionated reference architecture plus a simple choice rubric (maturity, extensibility, latency, cost, swap effort) so you know when to stick&#8212;and how to swap components without rewrites.</p><p>&#9989; <strong>Write maintainable RAG code</strong> &#8212; Use clean module boundaries (ingest / retrieve / rerank / synthesize), typed configs (Pydantic Settings), and sensible secrets/env management so your team can extend it safely.</p><h3><strong>You&#8217;ll walk away with</strong></h3><p>&#10024; A running <strong>Agentic RAG app</strong> (LangGraph + FastAPI + React) in a <strong>fork-and-ship monorepo</strong>.</p><p>&#10024; An <strong>ingestion/indexing</strong> pipeline with metadata, hybrid retrieval, and optional re-ranking.</p><p>&#10024; A <strong>chat UI</strong> with citations, source previews, and conversation memory that behaves.</p><p>&#10024; <strong>Deploy</strong> scripts and env templates to go live right after class.</p><p>&#10024; A <strong>framework choice memo + adapters</strong> to swap models/vector stores without starting over.</p><p><strong>Bottom line:</strong> this isn&#8217;t a vitamin, it&#8217;s a blueprint you can put in production.</p><h3><strong>What you&#8217;ll get out of this course</strong></h3><ul><li><p><strong>Orchestrate complex RAG pipelines with LangGraph and OpenAI API:</strong> Build a typed LangGraph that routes rewrite &#8594; retrieve &#8594; rerank &#8594; synthesize &#8594; cite &#8594; self-check with retries, timeouts, early-exit rules, and real tool calls, exposed as a clean HTTP API.</p></li><li><p><strong>Build scalable asynchronous applications with FastAPI:</strong> Ship async FastAPI endpoints, well-typed request/response models, input validation, and sensible timeouts, ready to run locally and deploy to production.</p></li><li><p><strong>Implement chatbot interfaces with React:</strong> Create a chat UI that shows citations and source previews, lets users scope queries, preserves safe chat history, and handles transient API errors gracefully.</p></li><li><p><strong>Mitigate hallucinations with LLM judges, structured output, and context engineering:</strong> Cut errors via schema-aware chunking, dedupe and budgeted context packing, plus lightweight LLM checks and schema-constrained outputs to verify claims and enforce citations before responding.</p></li><li><p><strong>Design effective LLM prompts for high-level control on generation output:</strong> Write prompts that steer behavior: system prompts, task decomposition, Pydantic/JSON-schema constraints, and clear rules for tone, citations, and safe refusals.</p></li><li><p><strong>Develop end-to-end RAG applications using the software engineering best practices:</strong> Produce a maintainable codebase: clean module boundaries (ingest/retrieve/rerank/synthesize), typed configs, secrets/env management, reproducible local dev, and deploy that mirrors local.</p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/agentic-rag?promoCode=FIRST20&quot;,&quot;text&quot;:&quot;Sign Up!&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://maven.com/damien-benveniste/agentic-rag?promoCode=FIRST20"><span>Sign Up!</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Build Production-Ready Agentic-RAG Applications From Scratch Course: What we are going to build ]]></title><description><![CDATA[On Saturday, September 27th, I am launching a new course: Build Production-Ready Agentic-RAG Applications From Scratch! This is a fully hands-on course where we are going to deploy a production-ready Agentic-RAG application with LangGraph, FastAPI, and React! Here is what we are going to build.]]></description><link>https://newsletter.theaiedge.io/p/build-production-ready-agentic-rag</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/build-production-ready-agentic-rag</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Tue, 02 Sep 2025 15:01:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!HM5S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>On Saturday, September 27th, I am launching a new course: <strong><a href="https://maven.com/damien-benveniste/agentic-rag">Build Production-Ready Agentic-RAG Applications From Scratch</a></strong>! This is a fully hands-on course where we are going to deploy a production-ready Agentic-RAG application with LangGraph, FastAPI, and React! Here is what we are going to build.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/agentic-rag&quot;,&quot;text&quot;:&quot;Signup!&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://maven.com/damien-benveniste/agentic-rag"><span>Signup!</span></a></p><h2>What we are going to build</h2><p>We are going to build a fun web application where we can demonstrate how to orchestrate a robust RAG application using LangGraph, FastAPI, and React. Here is what we are going to build:</p><ol><li><p>A user can pass a GitHub repository URL</p></li><li><p>The files of the related repository are scraped and indexed in a vector database</p></li><li><p>Now the code is available for the user to ask questions about.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HM5S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HM5S!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 424w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 848w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 1272w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HM5S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png" width="1456" height="899" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:899,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&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_!HM5S!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 424w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 848w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.png 1272w, https://substackcdn.com/image/fetch/$s_!HM5S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0f30f1fd-2bcd-4fc4-8ca6-51b4f969edca_1578x974.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>On the frontend, we will need two main functionalities:</p><ul><li><p>A page where we can input the repository URL and start the crawling and indexing processes:</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!g2u1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!g2u1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 424w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 848w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 1272w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!g2u1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png" width="500" height="147.32142857142858" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:429,&quot;width&quot;:1456,&quot;resizeWidth&quot;:500,&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;:false,&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_!g2u1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 424w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 848w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 1272w, https://substackcdn.com/image/fetch/$s_!g2u1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc850272b-747f-42ed-b72a-b4d686a8304e_1526x450.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><ul><li><p>And a chatbot interface to ask questions about the code in the repository:</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_!v21m!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!v21m!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 424w, https://substackcdn.com/image/fetch/$s_!v21m!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 848w, https://substackcdn.com/image/fetch/$s_!v21m!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 1272w, https://substackcdn.com/image/fetch/$s_!v21m!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!v21m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png" width="498" height="445.3269230769231" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1302,&quot;width&quot;:1456,&quot;resizeWidth&quot;:498,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!v21m!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 424w, https://substackcdn.com/image/fetch/$s_!v21m!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 848w, https://substackcdn.com/image/fetch/$s_!v21m!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.png 1272w, https://substackcdn.com/image/fetch/$s_!v21m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff869f440-1d45-4194-aba0-cad9ccfbf4b7_2028x1814.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>On the backend, we will need the related endpoints:</p><ul><li><p>The indexing endpoint will respond to the provided GitHub repository URL and the &#8220;crawl&#8220; action to start the crawling and indexing processes.</p></li><li><p>The chat endpoint that will respond to messages sent by the user from the chatbot interface.</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_!fsuq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fsuq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 424w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 848w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 1272w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fsuq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png" width="1456" height="704" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:704,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&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="" srcset="https://substackcdn.com/image/fetch/$s_!fsuq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 424w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 848w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.png 1272w, https://substackcdn.com/image/fetch/$s_!fsuq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9b4957a-91e3-4656-90b1-3e02d7e65596_1622x784.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>We are going to use the following tools:</p><ul><li><p><a href="https://react.dev/">React</a> for the frontend</p></li><li><p><a href="https://fastapi.tiangolo.com/">FastAPI</a> for the backend</p></li><li><p><a href="https://langchain-ai.github.io/langgraph/">LangGraph</a> for the agentic orchestration</p></li><li><p><a href="https://docs.pinecone.io/guides/get-started/overview">Pinecone</a> for the vector database</p></li><li><p><a href="https://www.langchain.com/langsmith">Langsmith</a> for observability</p></li><li><p>Deploy everything on Google Cloud!</p></li></ul><h2>Project-based course</h2><p>We will focus on building the project from the ground up, as we would on the job. Here is how we are going to structure the project development:</p><ul><li><p>Introduction</p><ul><li><p>What we want to build</p></li><li><p>Setting up the environment</p></li></ul></li><li><p>The RAG Application</p><ul><li><p>The Data Parsing Pipeline</p></li><li><p>The Indexing Pipeline</p></li><li><p>The Basic RAG Pipeline</p></li><li><p>Adding Observability to the Pipeline with Langsmith</p></li><li><p>Going Agentic</p></li></ul></li><li><p>The Backend Application</p><ul><li><p>The Indexing API Endpoint</p></li><li><p>Adding Memory</p></li><li><p>Administering the Database Data</p></li></ul></li><li><p>The Frontend Application</p><ul><li><p>The Indexing Page</p></li><li><p>The Chatbot Page</p></li></ul></li><li><p>Deploying to GCP</p></li></ul><p>Each session will be a live, hands-on coding session where we are going to implement every component from scratch</p><h2>Going Agentic </h2><p>&#8220;Agentic&#8221; means that we are going to use an LLM as a decision engine to enhance the quality of our pipeline. We will focus on improving the accuracy of the pipeline at the cost of latency and cost, and discuss the opportunities to reduce those induced negative points with small language models and fine-tuning. In the RAG pipeline, we are going to build a subagent for each of the main components:</p><ul><li><p>Intent router: the entry point of the pipeline that will decide if a RAG pipeline is required. </p></li><li><p>The retriever: The sub-agent that will extract the right data</p></li><li><p>The generator: The sub-agent that will generate the response to the user</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_!e7NK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!e7NK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 424w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 848w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 1272w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!e7NK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png" width="1452" height="1482" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1482,&quot;width&quot;:1452,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:165873,&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://newsletter.theaiedge.io/i/172452651?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.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_!e7NK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 424w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 848w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.png 1272w, https://substackcdn.com/image/fetch/$s_!e7NK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F820cfde6-8e9c-47b2-b3c2-ce10ca086930_1452x1482.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>Scaling up</h2><p>With this course, I want to focus on what we would need to do to deploy the application to 1M users. We will make sure to design every endpoint to be asynchronous, queue the indexing requests, and deploy the application with elastic load balancing to scale the application horizontally.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NOQR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NOQR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 424w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 848w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 1272w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NOQR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png" width="1456" height="643" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:643,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:120017,&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://newsletter.theaiedge.io/i/172452651?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.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_!NOQR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 424w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 848w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.png 1272w, https://substackcdn.com/image/fetch/$s_!NOQR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd8a1046-e3fa-446e-bb31-f65b7dce728b_1728x763.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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 going to be a fun ride! Make sure to join us!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/agentic-rag&quot;,&quot;text&quot;:&quot;Signup!&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://maven.com/damien-benveniste/agentic-rag"><span>Signup!</span></a></p><p></p><p></p>]]></content:encoded></item><item><title><![CDATA[New Course: Build Production-Ready Agentic-RAG Applications From Scratch]]></title><description><![CDATA[End-to-end: orchestrate and deploy agentic Retrieval-Augmented Generation with LangGraph, FastAPI, and React frontend in 2 weeks.]]></description><link>https://newsletter.theaiedge.io/p/new-course-build-production-ready</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/new-course-build-production-ready</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Mon, 25 Aug 2025 15:01:14 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!pWtL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>On Saturday, September 27th, I am launching a new course: <strong><a href="https://maven.com/damien-benveniste/agentic-rag?promoCode=FIRST20">Build Production-Ready Agentic-RAG Applications From Scratch</a></strong>! This is a fully hands-on course where we are going to deploy a production-ready Agentic-RAG application with LangGraph, FastAPI, and React! <strong>The first 30 people to sign up will get a 20% discount by applying the promo code <a href="https://maven.com/damien-benveniste/agentic-rag?promoCode=FIRST20">FIRST20</a>!</strong> So make sure to sign up early:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/agentic-rag?promoCode=FIRST20&quot;,&quot;text&quot;:&quot;Sign Up!&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://maven.com/damien-benveniste/agentic-rag?promoCode=FIRST20"><span>Sign Up!</span></a></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pWtL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pWtL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png 424w, https://substackcdn.com/image/fetch/$s_!pWtL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png 848w, https://substackcdn.com/image/fetch/$s_!pWtL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!pWtL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pWtL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2377137,&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://newsletter.theaiedge.io/i/171854996?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.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_!pWtL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png 424w, https://substackcdn.com/image/fetch/$s_!pWtL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png 848w, https://substackcdn.com/image/fetch/$s_!pWtL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!pWtL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11f819bf-fb63-4c76-a1e6-521888220f3d_2560x1440.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>From Prototype to Production: Ship Reliable and Scalable RAG Pipelines</h2><h3>The Real-World AI Engineering Roadblocks You Face Today</h3><p>&#128075; <strong>Prototype &#8594; Production Gap</strong> &#8212; Moving from a notebook demo to a secure, observable, multi-tenant service requires orchestration, evals, guardrails, and ops most teams lack.</p><p>&#128075; <strong>&#8220;Easy RAG&#8221; vs &#8220;Reliable RAG&#8221;</strong> &#8212; Anyone can retrieve-then-generate; making answers faithful, fresh, fast, and cost-controlled under real traffic is the hard part.</p><p>&#128075; <strong>Framework Overload</strong> &#8212; The ecosystem is noisy; you need clear criteria (maturity, extensibility, latency, cost) and reference patterns to choose confidently.</p><p>&#128075; <strong>It&#8217;s Software Engineering First</strong> &#8212; Success hinges on clean interfaces, tests, typed configs, tracing, CI/CD, and change management&#8212;not just prompts and models.</p><p>&#128075; <strong>From Laptop to 1M Users</strong> &#8212; Scaling demands streaming, batching, caching, autoscaling, and SLOs, or your p95 explodes and costs spiral.</p><h3>How this course will help you</h3><p>&#9989; <strong>Ship a real Agentic RAG app, not a demo </strong>&#8212; Stand up an end-to-end stack&#8212;LangGraph &#8594; FastAPI &#8594; React, that runs locally today and deploys via a clean, fork-and-ship monorepo.</p><p>&#9989; <strong>Make retrieval dependable, not lucky</strong> &#8212; Adopt schema-aware chunking, strong dense embeddings with sensible metadata filters, and context packing with citations so answers stay faithful, fresh, and concise.</p><p>&#9989; <strong>Harden agentic workflows</strong> &#8212; Design a typed LangGraph state and build nodes for rewrite &#8594; retrieve &#8594; rerank &#8594; synthesize &#8594; cite &#8594; safety-check, with retries and timeouts so plans don&#8217;t loop or stall.</p><p>&#9989; <strong>Scale the experience, not the headaches</strong> &#8212; Enable server-streaming in FastAPI, cap top-k, trim context budgets, and add early-exit rules; deploy with autoscaling so you can serve real traffic without infra fuss.</p><p>&#9989; <strong>See enough to fix things fast</strong> &#8212; Bake in structured logs (no vendor tracing), per-step timing counters, and UI breadcrumbs/citations to follow <em>query &#8594; context &#8594; answer</em> and spot common failure patterns quickly.</p><p>&#9989; <strong>Choose frameworks with confidence</strong> &#8212; Follow an opinionated reference architecture plus a simple choice rubric (maturity, extensibility, latency, cost, swap effort) so you know when to stick&#8212;and how to swap components without rewrites.</p><p>&#9989; <strong>Write maintainable RAG code</strong> &#8212; Use clean module boundaries (ingest / retrieve / rerank / synthesize), typed configs (Pydantic Settings), and sensible secrets/env management so your team can extend it safely.</p><h3>You&#8217;ll walk away with</h3><p>&#10024; A running <strong>Agentic RAG app</strong> (LangGraph + FastAPI + React) in a <strong>fork-and-ship monorepo</strong>.</p><p>&#10024; An <strong>ingestion/indexing</strong> pipeline with metadata, hybrid retrieval, and optional re-ranking.</p><p>&#10024; A <strong>chat UI</strong> with citations, source previews, and conversation memory that behaves.</p><p>&#10024; <strong>Deploy</strong> scripts and env templates to go live right after class.</p><p>&#10024; A <strong>framework choice memo + adapters</strong> to swap models/vector stores without starting over.</p><p><strong>Bottom line:</strong> this isn&#8217;t a vitamin, it&#8217;s a blueprint you can put in production.</p><h3>What you&#8217;ll get out of this course</h3><ul><li><p><strong>Orchestrate complex RAG pipelines with LangGraph and OpenAI API:</strong> Build a typed LangGraph that routes <strong>rewrite &#8594; retrieve &#8594; rerank &#8594; synthesize &#8594; cite &#8594; self-check</strong> with <strong>retries, timeouts, early-exit rules</strong>, and real tool calls, exposed as a clean HTTP API.</p></li><li><p><strong>Build scalable asynchronous applications with FastAPI:</strong> Ship <strong>async</strong> FastAPI endpoints, well-typed request/response models, input validation, and sensible timeouts, ready to run locally and <strong>deploy to production</strong>.</p></li><li><p><strong>Implement chatbot interfaces with React:</strong> Create a<strong> chat UI</strong> that shows citations and source previews, lets users scope queries, preserves <strong>safe chat history</strong>, and handles transient API errors gracefully.</p></li><li><p><strong>Mitigate hallucinations with LLM judges, structured output, and context engineering:</strong> Cut errors via <strong>schema-aware chunking</strong>, dedupe and budgeted context packing, plus <strong>lightweight LLM checks</strong> and <strong>schema-constrained outputs</strong> to verify claims and enforce citations before responding.</p></li><li><p><strong>Design effective LLM prompts for high-level control on generation output:</strong> Write prompts that <strong>steer behavior</strong>: system prompts, task decomposition, <strong>Pydantic/JSON-schema</strong> constraints, and clear rules for tone, citations, and safe refusals.</p></li><li><p><strong>Develop end-to-end RAG applications using the software engineering best practices:</strong> Produce a maintainable codebase: <strong>clean module boundaries</strong> (ingest/retrieve/rerank/synthesize), <strong>typed configs</strong>, secrets/env management, reproducible local dev, and deploy that mirrors local.</p><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/agentic-rag?promoCode=FIRST20&quot;,&quot;text&quot;:&quot;Sign Up!&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://maven.com/damien-benveniste/agentic-rag?promoCode=FIRST20"><span>Sign Up!</span></a></p></li></ul><p></p>]]></content:encoded></item><item><title><![CDATA[Mixture-of-Experts: Early Sparse MoE Prototypes in LLMs]]></title><description><![CDATA[Mixture-of-Experts might be one of the most important improvements in the Transformer architecture!]]></description><link>https://newsletter.theaiedge.io/p/mixture-of-experts-early-sparse-moe</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/mixture-of-experts-early-sparse-moe</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Fri, 22 Aug 2025 15:01:43 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!2RgN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F40a6fd37-5d37-49e4-b10f-d641af576d04_1500x918.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em><strong>Mixture-of-Experts might be one of the most important improvements in the Transformer architecture! It allows for scaling the number of model parameters while keeping the latency associated with the forward and backward pass of the backpropagation algorithm almost constant. Scaling in the width direction, as opposed to the depth of the model, allows for keeping the gradient paths short, improving the stability of the training. We explore here 2 early models:</strong></em></p><ul><li><p><em><strong>The Sparsely-Gated Mixture-of-Experts Layer</strong></em></p></li><li><p><em><strong>GShard</strong></em></p></li></ul><div><hr></div><h2>The First Mixture-of-Experts</h2><p>The concept of the Mixture of Experts (MoE) architecture was introduced in 1991 by <a href="https://www.cs.toronto.edu/~fritz/absps/jjnh91.pdf">Jacobs et al</a>. The idea was to combine the learning of parallel learners using a gating mechanism. The goal was to increase the model's capacity while maintaining stable training and achieving faster convergence. Deep networks tend to suffer from vanishing or exploding gradients, and extending the capacity in the width direction allows for the learning of more complex statistical patterns while keeping short gradient paths. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4QZ-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4QZ-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.png 424w, https://substackcdn.com/image/fetch/$s_!4QZ-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.png 848w, https://substackcdn.com/image/fetch/$s_!4QZ-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.png 1272w, https://substackcdn.com/image/fetch/$s_!4QZ-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4QZ-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.png" width="430" height="391.0164835164835" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1324,&quot;width&quot;:1456,&quot;resizeWidth&quot;:430,&quot;bytes&quot;:262551,&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://newsletter.theaiedge.io/i/171576302?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.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_!4QZ-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.png 424w, https://substackcdn.com/image/fetch/$s_!4QZ-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.png 848w, https://substackcdn.com/image/fetch/$s_!4QZ-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.png 1272w, https://substackcdn.com/image/fetch/$s_!4QZ-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfda17ce-cd0f-4574-9126-cf8f3391df3a_1500x1364.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>An "expert" <em><strong>E<sub>i</sub></strong></em> can be a simple feed-forward network. For example:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;E_i(\\mathbf{h})= \\text{ReLU}\\left(W_1^i\\mathbf{h} + \\mathbf{b}_1\\right)W_2^i + \\mathbf{b}_2&quot;,&quot;id&quot;:&quot;LKAUJBTGBW&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em><strong>W<sub>1</sub><sup>i</sup></strong></em> and <em><strong>W<sub>2</sub><sup>i</sup></strong></em> may have different dimensions depending on the expert. The gating mechanism generates a weight <em><strong>g<sub>i</sub>(h)</strong></em> for each expert, and the MoE output is a weighted average of the experts' outputs:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\mathbf{y} = \\sum_{i=1}^n g_i(\\mathbf{h})E_i(\\mathbf{h})&quot;,&quot;id&quot;:&quot;GLFBQMREAH&quot;}" data-component-name="LatexBlockToDOM"></div><p><em><strong>g<sub>i</sub>(h)</strong></em> is typically the softmax transformation of a linear projection <em><strong>W<sub>g</sub></strong></em> of the input features:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{g}(\\mathbf{h}) = \\text{Softmax}\\left(W_g\\mathbf{h} + \\mathbf{b}_g\\right)&quot;,&quot;id&quot;:&quot;NYHNOGHFLO&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em><strong>W<sub>g</sub></strong></em> is a linear layer of dimension <em><strong>|h| &#10761; n</strong></em>. The softmax transformation yields a probability-like value that captures the proportion of contributions for each expert.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ScTf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ScTf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.png 424w, https://substackcdn.com/image/fetch/$s_!ScTf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.png 848w, https://substackcdn.com/image/fetch/$s_!ScTf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.png 1272w, https://substackcdn.com/image/fetch/$s_!ScTf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ScTf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.png" width="1456" height="812" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:812,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:327568,&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://newsletter.theaiedge.io/i/171576302?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.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_!ScTf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.png 424w, https://substackcdn.com/image/fetch/$s_!ScTf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.png 848w, https://substackcdn.com/image/fetch/$s_!ScTf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.png 1272w, https://substackcdn.com/image/fetch/$s_!ScTf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11c30f39-add8-4c0f-b788-a4e05033d997_1500x837.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>Early Sparse MoE Prototypes in LLMs</h2><h3>The Sparsely-Gated Mixture-of-Experts Layer</h3><h4>The Sparse mechanism</h4><p>The sparse Mixture of Experts (MoE) architecture was introduced by <a href="https://arxiv.org/pdf/1701.06538">Shazeer et al</a> in January 2017 in LSTM-based language models as a way to drastically scale the model capacity while keeping the number of operations constant, independent of the number of experts. RNN models are hard to scale because the LSTM operations are intrinsically iterative, preventing the high parallelism provided by other computational units. Scaling in depth with more LSTM units induces high latency, while scaling with feed-forward networks limits the ability of the LSTM layers to capture long-range coherence of the input sequences. Scaling in width with many parallel experts permits the LSTM to learn the long-term dependencies while keeping the latency to a minimum.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7hh0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7hh0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.png 424w, https://substackcdn.com/image/fetch/$s_!7hh0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.png 848w, https://substackcdn.com/image/fetch/$s_!7hh0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.png 1272w, https://substackcdn.com/image/fetch/$s_!7hh0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7hh0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.png" width="1456" height="1185" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1185,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:549233,&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://newsletter.theaiedge.io/i/171576302?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.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_!7hh0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.png 424w, https://substackcdn.com/image/fetch/$s_!7hh0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.png 848w, https://substackcdn.com/image/fetch/$s_!7hh0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.png 1272w, https://substackcdn.com/image/fetch/$s_!7hh0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F51128362-bd33-4d24-81cc-d16fc3d4e050_1500x1221.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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 class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!t2a2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!t2a2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.png 424w, https://substackcdn.com/image/fetch/$s_!t2a2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.png 848w, https://substackcdn.com/image/fetch/$s_!t2a2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.png 1272w, https://substackcdn.com/image/fetch/$s_!t2a2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!t2a2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.png" width="1456" height="1357" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1357,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:579829,&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://newsletter.theaiedge.io/i/171576302?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.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_!t2a2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.png 424w, https://substackcdn.com/image/fetch/$s_!t2a2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.png 848w, https://substackcdn.com/image/fetch/$s_!t2a2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.png 1272w, https://substackcdn.com/image/fetch/$s_!t2a2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c4cb031-9c90-48de-8cc5-bd3575331727_1500x1398.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>To keep the number of operations independent of the number of experts, they introduced a routing mechanism that selects the top<em>-k</em> experts for each token. They tested a total number of experts that ranged between 4 and 131,072, but only the top-4 experts were used for each token. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5GWW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5GWW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.png 424w, https://substackcdn.com/image/fetch/$s_!5GWW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.png 848w, https://substackcdn.com/image/fetch/$s_!5GWW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.png 1272w, https://substackcdn.com/image/fetch/$s_!5GWW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5GWW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.png" width="534" height="351.3543956043956" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:958,&quot;width&quot;:1456,&quot;resizeWidth&quot;:534,&quot;bytes&quot;:283242,&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://newsletter.theaiedge.io/i/171576302?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.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_!5GWW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.png 424w, https://substackcdn.com/image/fetch/$s_!5GWW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.png 848w, https://substackcdn.com/image/fetch/$s_!5GWW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.png 1272w, https://substackcdn.com/image/fetch/$s_!5GWW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa19d20e5-172d-43d8-844c-fa114d7baae1_1500x987.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>For the sparse MoE, the architecture is the same for every expert <em><strong>i</strong></em>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;E_i(\\mathbf{h})= \\text{ReLU}\\left(W_1^i\\mathbf{h} + \\mathbf{b}_1\\right)W_2^i + \\mathbf{b}_2&quot;,&quot;id&quot;:&quot;ZZQVVILKDI&quot;}" data-component-name="LatexBlockToDOM"></div><p>The gating mechanism is, as before, induced by a linear layer <em><strong>W<sub>g</sub></strong></em> mapping from hidden size <em><strong>d<sub>model</sub></strong></em> to <em><strong>n</strong></em> with an added normal noise <em><strong>&#1013;</strong></em>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{l}(\\mathbf{h}) = W_g \\mathbf{h} + \\epsilon&quot;,&quot;id&quot;:&quot;TGLEQGWXHN&quot;}" data-component-name="LatexBlockToDOM"></div><p>The noise allows the model to uniformly explore the different experts in the early part of the training and prevents the collapse onto a handful of "favorite" experts. To generate the noise, the input vector is first projected with another linear layer <em><strong>W<sub>n</sub></strong></em> passed through a softplus transformation:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\sigma(\\mathbf{h}) = \\text{Softplus}(W_n \\mathbf{h}) = \\log(1 + \\exp(W_n \\mathbf{h})) &quot;,&quot;id&quot;:&quot;NWRFLCSWGK&quot;}" data-component-name="LatexBlockToDOM"></div><p>The resulting value <em><strong>&#120532;(h)</strong></em> is used as the standard deviation to generate the normal noise:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\epsilon \\sim \\mathcal{N}(0, \\sigma(\\mathbf{h}))&quot;,&quot;id&quot;:&quot;YEMXDNKTUR&quot;}" data-component-name="LatexBlockToDOM"></div><p>The standard deviation <em><strong>&#120532;(h)</strong></em> controls how much randomness is injected for each expert on that particular input token. Larger <em><strong>&#120532;(h)</strong></em> will lead to more exploration, and smaller <em><strong>&#120532;(h)</strong></em> will push the gate to behave almost deterministically. Softplus is basically a "soft" version of ReLU: for large positive values, it increases linearly and flattens near 0. It is used here to make sure the learned noise scale <em><strong>&#120532;(h)</strong></em> is positive and differentiable everywhere. Because the noise is input&#8209;adaptive, the router can start off as a near&#8209;uniform sampler (large <em><strong>&#120532;(h)</strong></em>) and gradually anneal into a confident switch (small <em><strong>&#120532;(h)</strong></em>).</p><p>Once the logits <em><strong>l(x) = {l<sub>1</sub>(h), l<sub>2</sub>(h), &#8230;, l<sub>n</sub>(h)} </strong></em>have been computed, we mask the non-top-<em><strong>k</strong></em>'s contribution with <em><strong>-&#8734;</strong></em>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\overline{l}_i(\\mathbf{h})=\n\n\\begin{cases}\n\nl_i(\\mathbf{h}), &amp; \\text{if } l_i(\\mathbf{h})\\text{ is in the top-}k,\\\\\n\n-\\infty, &amp; \\text{otherwise}.\n\n\\end{cases}&quot;,&quot;id&quot;:&quot;SXFEJQAATB&quot;}" data-component-name="LatexBlockToDOM"></div><p>And we perform a softmax transformation to obtain the contribution of each top-<em>k</em> expert:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{g}(\\mathbf{h}) = \\frac{e^{\\overline{\\mathbf{l}}(\\mathbf{h})}}{\\sum_{i=1}^n e^{\\overline{l}_i(\\mathbf{h})}}&quot;,&quot;id&quot;:&quot;FRJJRPBOTM&quot;}" data-component-name="LatexBlockToDOM"></div><p>The <em><strong>-&#8734;</strong></em> masks will lead to <em><strong>g<sub>i</sub>(h) = 0</strong></em> contribution for every non-top-<em>k</em> expert while keeping the softmax normalization as if only the top-<em>k</em> experts contributed to the sum. The resulting hidden state <em><strong>y(h)</strong></em> is the weighted average of top-<em>k</em> experts' output:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\mathbf{y}(\\mathbf{h})=\\sum_{i\\in \\text{top-}k} g_i(\\mathbf{h})E_i(\\mathbf{h})&quot;,&quot;id&quot;:&quot;XZDHWESRLK&quot;}" data-component-name="LatexBlockToDOM"></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LmkM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LmkM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.png 424w, https://substackcdn.com/image/fetch/$s_!LmkM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.png 848w, https://substackcdn.com/image/fetch/$s_!LmkM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.png 1272w, https://substackcdn.com/image/fetch/$s_!LmkM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LmkM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.png" width="1456" height="639" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:639,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:211407,&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://newsletter.theaiedge.io/i/171576302?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.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_!LmkM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.png 424w, https://substackcdn.com/image/fetch/$s_!LmkM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.png 848w, https://substackcdn.com/image/fetch/$s_!LmkM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.png 1272w, https://substackcdn.com/image/fetch/$s_!LmkM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7429def3-c09e-4645-ad77-aa90b7a95f42_1500x658.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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><h4>Hierarchical Mixture of Experts</h4><p>In the Sparsely-Gated Mixture-of-Experts, they scaled the number of experts up to 131,072! With naive MoE, the gate and noise projection layers <em><strong>W<sub>g</sub></strong></em> and <em><strong>W<sub>n</sub></strong></em> would require a dimension <em><strong>(n &#10761; d<sub>model</sub>)</strong></em> ~ 67M parameters (with <em><strong>d<sub>model </sub></strong></em>= 512), with as many operations for each token in the input sequence. At this scale, the gating mechanism becomes the bottleneck. Instead, they introduced a hierarchical gating process where the experts were grouped into <em><strong>a </strong></em>blocks of <em><strong>b</strong></em> experts. The first gate projects from <em><strong>d<sub>model</sub></strong></em> to <em><strong>a</strong></em> blocks:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{l}^{(1)}(\\mathbf{h}) = W_g^{(1)} \\mathbf{h} + \\epsilon^{(1)}&quot;,&quot;id&quot;:&quot;KBASKINGAG&quot;}" data-component-name="LatexBlockToDOM"></div><p>From this first set of logits, we can pick the top-<em><strong>k<sub>1</sub></strong></em> expert blocks:</p>
      <p>
          <a href="https://newsletter.theaiedge.io/p/mixture-of-experts-early-sparse-moe">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Last Week to Register to the Build Production-Ready LLMs From Scratch Course!]]></title><description><![CDATA[From Prototype to Production: Ship Scalable LLM Systems in 6 Weeks]]></description><link>https://newsletter.theaiedge.io/p/last-week-to-register-to-the-build-417</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/last-week-to-register-to-the-build-417</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Wed, 09 Jul 2025 15:02:40 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!xOou!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This Saturday, we kick off the latest cohort of the <strong><a href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms">Build Production-Ready LLMs From Scratch</a></strong> course! This is the last week to register, so make sure to join us if you want to get the right skills as a Machine Learning engineer! This is a 6-week program to learn to build scalable LLMs from scratch and ship them to production. It will run between July 12th and Aug 17th, 2025. It includes 12 live sessions, 6 real-world hands-on projects, 64 recorded lectures, and more material.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms&quot;,&quot;text&quot;:&quot;Enroll&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms"><span>Enroll</span></a></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xOou!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xOou!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png 424w, https://substackcdn.com/image/fetch/$s_!xOou!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png 848w, https://substackcdn.com/image/fetch/$s_!xOou!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png 1272w, https://substackcdn.com/image/fetch/$s_!xOou!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xOou!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png" width="1352" height="1062" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1062,&quot;width&quot;:1352,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:437035,&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://newsletter.theaiedge.io/i/167788158?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.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_!xOou!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png 424w, https://substackcdn.com/image/fetch/$s_!xOou!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png 848w, https://substackcdn.com/image/fetch/$s_!xOou!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.png 1272w, https://substackcdn.com/image/fetch/$s_!xOou!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92b8d44d-fe3e-4574-a114-21e1fbfa9b15_1352x1062.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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><strong>The Real-World LLM Engineering Roadblocks You Face Today</strong></h3><p><strong>&#128075; Transitioning from General ML to LLM Specialization:</strong> You&#8217;ve built recommendation engines or classifier models, but moving into Transformer&#8209;centric development feels like learning a whole new discipline&#8212;no clear roadmap exists.</p><p><strong>&#128075; Lack of LLM&#8209;Specific Career Path: </strong>You see &#8220;LLM Engineer&#8221; roles popping up on LinkedIn, but your current CV only shows &#8220;Data Scientist&#8221; or &#8220;ML Engineer.&#8221; You need hands&#8209;on projects and artifacts to credibly make the jump.</p><p><strong>&#128075; Career Stalled by &#8220;Academic&#8221; Skillset:</strong> You can recite Transformer papers, but when asked, &#8220;Have you shipped an LLM feature end&#8209;to&#8209;end?&#8221; you have no answer&#8212;and no portfolio to prove it!</p><p><strong>&#128075; Prototype Meltdown Under Production Load: </strong>You&#8217;ve fine&#8209;tuned a small model locally, but when you switch from 1 to 100 concurrent requests, your GPU memory spikes and inference grinds to a halt, because you&#8217;ve never applied continuous batching, KV caching, or paged&#8209;attention in a live setting.</p><p><strong>&#128075; RAG Integration Headaches: </strong>Turning a standalone model into a live, Retriever&#8209;Augmented Generation service becomes a multi&#8209;week integration nightmare.</p><h3>How this course will help you</h3><p>Because we&#8217;ve <strong>packaged every stage</strong> of the LLM lifecycle, <strong>from career transition to production rollout</strong>, into a <strong>six&#8209;week bootcamp</strong> that:</p><p>&#9989; <strong>Guides Your Career Pivot: </strong>You&#8217;ll emerge with six polished GitHub projects, a deployment playbook, and RAG demos that transform your resume from &#8220;ML generalist&#8221; to &#8220;LLM Specialist.&#8221;</p><p>&#9989; <strong>Attacks Each Pain&#8209;Point Head&#8209;On: </strong>Attacks each pain point head&#8209;on with six job&#8209;mirroring projects (from scratch &#8594; RLHF &#8594; scaling &#8594; deployment &#8594; RAG), so you never waste time on dead&#8209;end tutorials</p><p>&#9989; <strong>Live Code&#8209;Along Workshops &amp; Office Hours: </strong>Tackle your own fine&#8209;tuning bugs, scaling hiccups, and deployment errors alongside Damien in dedicated sessions, so you get hands&#8209;on fixes for the exact issues you&#8217;ll face on the job.</p><p>&#9989; <strong>Ready&#8209;to&#8209;Use Repos &amp; Playbooks: </strong>Grab our curated starter code, development scripts, deployment templates, and debugging checklists, so you can plug them straight into your next project without reinventing the wheel.</p><p>&#9989; <strong>A Portfolio of Six Production&#8209;Grade Projects: </strong>Leave with six end&#8209;to&#8209;end deliverables, from a Transformer built from scratch to a live RAG API, ready to showcase on GitHub, in performance reviews, or to hiring managers.</p><p>No more scattered blog-hopping or generic bootcamps, this is <strong>the only</strong> cohort where you&#8217;ll <strong>master</strong> Transformer internals <em>and</em> <strong>ship</strong> production&#8209;grade LLM systems while making the career leap you&#8217;ve been aiming for.</p><h3>What You&#8217;ll Actually Build and Ship</h3><p>Across six hands&#8209;on projects, you&#8217;ll deliver deployable LLM components and applications, no fluff, just job&#8209;ready code:</p><p>&#9989; <strong>A Modern Transformer Architecture from scratch: </strong>Implement a sliding&#8209;window multihead attention to slash O(N&#178;) to O(N&#183;w), RoPE for relative positional encoding, and the Mixture-of-Expert architecture for improved performance, all in PyTorch.</p><p>&#9989; <strong>Instruction&#8209;Tuned LLM: </strong>Fine&#8209;tune a model with supervised learning, RLHF, DPO, and ORPO for instruction following on a real benchmark and compare performance gains.</p><p>&#9989; <strong>Scalable Training Pipeline: </strong>Containerize a multi&#8209;GPU job with DeepSpeed ZeRO on SageMaker to maximize throughput and minimize cost.</p><p>&#9989; <strong>Extended&#8209;Context Model: </strong>Modify RoPE scaling, apply 4/8&#8209;bit quantization, and inject LoRA adapters to double your context window.</p><p>&#9989; <strong>Multi&#8209;Mode Deployment: </strong>Stand up a Hugging Face endpoint, a vLLM streaming API, and an OpenAI&#8209;compatible server, all Dockerized and optimized for low latency.</p><p>&#9989; <strong>End&#8209;to&#8209;End RAG Chat App: </strong>Build a FastAPI backend with conversational memory and a Streamlit UI for live Retrieval&#8209;Augmented Generation.</p><p>By the end of Week 6, you won&#8217;t just know these techniques, you&#8217;ll have shipped six production&#8209;grade artifacts, each reflecting the exact pipelines, optimizations, and deployment routines you&#8217;ll use on the job.</p><h3>Live &amp; Recorded Content: Reinforce, Deepen, Accelerate</h3><p>&#10024; <strong>12 Interactive Live Workshops (3 hrs each): </strong>Each session follows the Concept &#8594; Code flow. I&#8217;ll introduce the day&#8217;s core topic (e.g. self-attention, LoRA, vLLM optimizations, ...), and we&#8217;ll implement the features step&#8209;by&#8209;step in code so you see exactly how theory maps to code. Bring your questions!</p><p>&#10024; <strong>10 + Hours of On&#8209;Demand Deep&#8209;Dive Lectures: </strong>Short videos (10&#8211;20 min) on Transformer internals, fine-tuning tricks, deployment optimizations. Watch before each project to hit the ground running. Step through every line of code at your own pace; perfect for review or catching up if you miss a live session. Downloadable slide decks, annotated notebooks, and cheat sheets you&#8217;ll reference long after graduation.</p><p><strong>Why This Matters:</strong> Live workshops turn recorded concepts into <strong>actionable skills</strong>. You&#8217;ll see how theory maps directly onto code, get instant feedback, and internalize best practices. Then, recorded lectures become your <strong>asynchronous safety net</strong>, letting you revisit tricky topics, prepare for upcoming labs, and solidify your understanding on demand.</p><p>Let me know if you have any questions. I hope to see you there!  </p>]]></content:encoded></item><item><title><![CDATA[Build Production-Ready LLMs From Scratch Starting on July 12th!]]></title><description><![CDATA[From Prototype to Production: Ship Scalable LLM Systems in 6 Weeks]]></description><link>https://newsletter.theaiedge.io/p/build-production-ready-llms-from-c43</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/build-production-ready-llms-from-c43</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Mon, 16 Jun 2025 15:02:40 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!J9Vr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Get ready! The latest iteration of the <strong><a href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first">Build Production-Ready LLMs From Scratch</a></strong> live course is starting on <strong>July 12th</strong>! This is a 6-week program to learn to build scalable LLMs from scratch and ship them to production. It will run between July 12th and August 17, 2025. It includes 12 live sessions, 6 real-world hands-on projects, 64 recorded lectures, and more material. <strong>The first 30 people to sign up will get a 20% discount by applying the promo code <a href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first">FIRST</a>!</strong> So make sure to sign up early:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first&quot;,&quot;text&quot;:&quot;Signup&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first"><span>Signup</span></a></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!J9Vr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 424w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 848w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png" width="574" height="322.875" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:574,&quot;bytes&quot;:3569157,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first&quot;,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://newsletter.theaiedge.io/i/161774781?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.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_!J9Vr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 424w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 848w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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><strong>The Real-World LLM Engineering Roadblocks You Face Today</strong></h3><p><strong>&#128075; Transitioning from General ML to LLM Specialization:</strong> You&#8217;ve built recommendation engines or classifier models, but moving into Transformer&#8209;centric development feels like learning a whole new discipline&#8212;no clear roadmap exists.</p><p><strong>&#128075; Lack of LLM&#8209;Specific Career Path: </strong>You see &#8220;LLM Engineer&#8221; roles popping up on LinkedIn, but your current CV only shows &#8220;Data Scientist&#8221; or &#8220;ML Engineer.&#8221; You need hands&#8209;on projects and artifacts to credibly make the jump.</p><p><strong>&#128075; Career Stalled by &#8220;Academic&#8221; Skillset:</strong> You can recite Transformer papers, but when asked, &#8220;Have you shipped an LLM feature end&#8209;to&#8209;end?&#8221; you have no answer&#8212;and no portfolio to prove it!</p><p><strong>&#128075; Prototype Meltdown Under Production Load: </strong>You&#8217;ve fine&#8209;tuned a small model locally, but when you switch from 1 to 100 concurrent requests, your GPU memory spikes and inference grinds to a halt, because you&#8217;ve never applied continuous batching, KV caching, or paged&#8209;attention in a live setting.</p><p><strong>&#128075; RAG Integration Headaches: </strong>Turning a standalone model into a live, Retriever&#8209;Augmented Generation service becomes a multi&#8209;week integration nightmare.</p><h3><strong>How this course will help you</strong></h3><p>Because we&#8217;ve <strong>packaged every stage</strong> of the LLM lifecycle, <strong>from career transition to production rollout</strong>, into a <strong>six&#8209;week bootcamp</strong> that:</p><p>&#9989; <strong>Guides Your Career Pivot: </strong>You&#8217;ll emerge with six polished GitHub projects, a deployment playbook, and RAG demos that transform your resume from &#8220;ML generalist&#8221; to &#8220;LLM Specialist.&#8221;</p><p>&#9989; <strong>Attacks Each Pain&#8209;Point Head&#8209;On: </strong>Attacks each pain point head&#8209;on with six job&#8209;mirroring projects (from scratch &#8594; RLHF &#8594; scaling &#8594; deployment &#8594; RAG), so you never waste time on dead&#8209;end tutorials</p><p>&#9989; <strong>Live Code&#8209;Along Workshops &amp; Office Hours: </strong>Tackle your own fine&#8209;tuning bugs, scaling hiccups, and deployment errors alongside Damien in dedicated sessions, so you get hands&#8209;on fixes for the exact issues you&#8217;ll face on the job.</p><p>&#9989; <strong>Ready&#8209;to&#8209;Use Repos &amp; Playbooks: </strong>Grab our curated starter code, development scripts, deployment templates, and debugging checklists, so you can plug them straight into your next project without reinventing the wheel.</p><p>&#9989; <strong>A Portfolio of Six Production&#8209;Grade Projects: </strong>Leave with six end&#8209;to&#8209;end deliverables, from a Transformer built from scratch to a live RAG API, ready to showcase on GitHub, in performance reviews, or to hiring managers.</p><p>No more scattered blog-hopping or generic bootcamps, this is <strong>the only</strong> cohort where you&#8217;ll <strong>master</strong> Transformer internals <em>and</em> <strong>ship</strong> production&#8209;grade LLM systems while making the career leap you&#8217;ve been aiming for.</p><h3><strong>What You&#8217;ll Actually Build and Ship</strong></h3><p>Across six hands&#8209;on projects, you&#8217;ll deliver deployable LLM components and applications, no fluff, just job&#8209;ready code:</p><p>&#9989; <strong>A Modern Transformer Architecture from scratch: </strong>Implement a sliding&#8209;window multihead attention to slash O(N&#178;) to O(N&#183;w), RoPE for relative positional encoding, and the Mixture-of-Expert architecture for improved performance, all in PyTorch.</p><p>&#9989; <strong>Instruction&#8209;Tuned LLM: </strong>Fine&#8209;tune a model with supervised learning, RLHF, DPO, and ORPO for instruction following on a real benchmark and compare performance gains.</p><p>&#9989; <strong>Scalable Training Pipeline: </strong>Containerize a multi&#8209;GPU job with DeepSpeed ZeRO on SageMaker to maximize throughput and minimize cost.</p><p>&#9989; <strong>Extended&#8209;Context Model: </strong>Modify RoPE scaling, apply 4/8&#8209;bit quantization, and inject LoRA adapters to double your context window.</p><p>&#9989; <strong>Multi&#8209;Mode Deployment: </strong>Stand up a Hugging Face endpoint, a vLLM streaming API, and an OpenAI&#8209;compatible server, all Dockerized and optimized for low latency.</p><p>&#9989; <strong>End&#8209;to&#8209;End RAG Chat App: </strong>Build a FastAPI backend with conversational memory and a Streamlit UI for live Retrieval&#8209;Augmented Generation.</p><p>By the end of Week 6, you won&#8217;t just know these techniques, you&#8217;ll have shipped six production&#8209;grade artifacts, each reflecting the exact pipelines, optimizations, and deployment routines you&#8217;ll use on the job.</p><h3><strong>Live &amp; Recorded Content: Reinforce, Deepen, Accelerate</strong></h3><p>&#10024; <strong>12 Interactive Live Workshops (3 hrs each): </strong>Each session follows the Concept &#8594; Code flow. I&#8217;ll introduce the day&#8217;s core topic (e.g. self-attention, LoRA, vLLM optimizations, ...), and we&#8217;ll implement the features step&#8209;by&#8209;step in code so you see exactly how theory maps to code. Bring your questions!</p><p>&#10024; <strong>10 + Hours of On&#8209;Demand Deep&#8209;Dive Lectures: </strong>Short videos (10&#8211;20 min) on Transformer internals, fine-tuning tricks, deployment optimizations. Watch before each project to hit the ground running. Step through every line of code at your own pace; perfect for review or catching up if you miss a live session. Downloadable slide decks, annotated notebooks, and cheat sheets you&#8217;ll reference long after graduation.</p><p><strong>Why This Matters:</strong> Live workshops turn recorded concepts into <strong>actionable skills</strong>. You&#8217;ll see how theory maps directly onto code, get instant feedback, and internalize best practices. Then, recorded lectures become your <strong>asynchronous safety net</strong>, letting you revisit tricky topics, prepare for upcoming labs, and solidify your understanding on demand.</p><p>Let me know if you have any questions. I hope to see you there!</p>]]></content:encoded></item><item><title><![CDATA[Last Week to Register to the Build Production-Ready LLMs From Scratch Course!]]></title><description><![CDATA[From Prototype to Production: Ship Scalable LLM Systems in 6 Weeks]]></description><link>https://newsletter.theaiedge.io/p/last-week-to-register-to-the-build</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/last-week-to-register-to-the-build</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Mon, 19 May 2025 15:54:44 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!J9Vr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This Saturday, we kick off the <strong><a href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms">Build Production-Ready LLMs From Scratch</a></strong> course! This is the last week to register, so make sure to join us if you want to get the right skills as a Machine Learning engineer! This is a 6-week program to learn to build scalable LLMs from scratch and ship them to production. It will run between May 24th and June 29, 2025. It includes 12 live sessions, 6 real-world hands-on projects, 64 recorded lectures, and more material.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms&quot;,&quot;text&quot;:&quot;Enroll&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms"><span>Enroll</span></a></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!J9Vr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 424w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 848w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png" width="574" height="322.875" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:574,&quot;bytes&quot;:3569157,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms&quot;,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://newsletter.theaiedge.io/i/161774781?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.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_!J9Vr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 424w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 848w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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><strong>The Real-World LLM Engineering Roadblocks You Face Today</strong></h3><p><strong>&#128075; Transitioning from General ML to LLM Specialization:</strong> You&#8217;ve built recommendation engines or classifier models, but moving into Transformer&#8209;centric development feels like learning a whole new discipline&#8212;no clear roadmap exists.</p><p><strong>&#128075; Lack of LLM&#8209;Specific Career Path: </strong>You see &#8220;LLM Engineer&#8221; roles popping up on LinkedIn, but your current CV only shows &#8220;Data Scientist&#8221; or &#8220;ML Engineer.&#8221; You need hands&#8209;on projects and artifacts to credibly make the jump.</p><p><strong>&#128075; Career Stalled by &#8220;Academic&#8221; Skillset:</strong> You can recite Transformer papers, but when asked, &#8220;Have you shipped an LLM feature end&#8209;to&#8209;end?&#8221; you have no answer&#8212;and no portfolio to prove it!</p><p><strong>&#128075; Prototype Meltdown Under Production Load: </strong>You&#8217;ve fine&#8209;tuned a small model locally, but when you switch from 1 to 100 concurrent requests, your GPU memory spikes and inference grinds to a halt, because you&#8217;ve never applied continuous batching, KV caching, or paged&#8209;attention in a live setting.</p><p><strong>&#128075; RAG Integration Headaches: </strong>Turning a standalone model into a live, Retriever&#8209;Augmented Generation service becomes a multi&#8209;week integration nightmare.</p><h3>How this course will help you</h3><p>Because we&#8217;ve <strong>packaged every stage</strong> of the LLM lifecycle, <strong>from career transition to production rollout</strong>, into a <strong>six&#8209;week bootcamp</strong> that:</p><p>&#9989; <strong>Guides Your Career Pivot: </strong>You&#8217;ll emerge with six polished GitHub projects, a deployment playbook, and RAG demos that transform your resume from &#8220;ML generalist&#8221; to &#8220;LLM Specialist.&#8221;</p><p>&#9989; <strong>Attacks Each Pain&#8209;Point Head&#8209;On: </strong>Attacks each pain point head&#8209;on with six job&#8209;mirroring projects (from scratch &#8594; RLHF &#8594; scaling &#8594; deployment &#8594; RAG), so you never waste time on dead&#8209;end tutorials</p><p>&#9989; <strong>Live Code&#8209;Along Workshops &amp; Office Hours: </strong>Tackle your own fine&#8209;tuning bugs, scaling hiccups, and deployment errors alongside Damien in dedicated sessions, so you get hands&#8209;on fixes for the exact issues you&#8217;ll face on the job.</p><p>&#9989; <strong>Ready&#8209;to&#8209;Use Repos &amp; Playbooks: </strong>Grab our curated starter code, development scripts, deployment templates, and debugging checklists, so you can plug them straight into your next project without reinventing the wheel.</p><p>&#9989; <strong>A Portfolio of Six Production&#8209;Grade Projects: </strong>Leave with six end&#8209;to&#8209;end deliverables, from a Transformer built from scratch to a live RAG API, ready to showcase on GitHub, in performance reviews, or to hiring managers.</p><p>No more scattered blog-hopping or generic bootcamps, this is <strong>the only</strong> cohort where you&#8217;ll <strong>master</strong> Transformer internals <em>and</em> <strong>ship</strong> production&#8209;grade LLM systems while making the career leap you&#8217;ve been aiming for.</p><h3>What You&#8217;ll Actually Build and Ship</h3><p>Across six hands&#8209;on projects, you&#8217;ll deliver deployable LLM components and applications, no fluff, just job&#8209;ready code:</p><p>&#9989; <strong>A Modern Transformer Architecture from scratch: </strong>Implement a sliding&#8209;window multihead attention to slash O(N&#178;) to O(N&#183;w), RoPE for relative positional encoding, and the Mixture-of-Expert architecture for improved performance, all in PyTorch.</p><p>&#9989; <strong>Instruction&#8209;Tuned LLM: </strong>Fine&#8209;tune a model with supervised learning, RLHF, DPO, and ORPO for instruction following on a real benchmark and compare performance gains.</p><p>&#9989; <strong>Scalable Training Pipeline: </strong>Containerize a multi&#8209;GPU job with DeepSpeed ZeRO on SageMaker to maximize throughput and minimize cost.</p><p>&#9989; <strong>Extended&#8209;Context Model: </strong>Modify RoPE scaling, apply 4/8&#8209;bit quantization, and inject LoRA adapters to double your context window.</p><p>&#9989; <strong>Multi&#8209;Mode Deployment: </strong>Stand up a Hugging Face endpoint, a vLLM streaming API, and an OpenAI&#8209;compatible server, all Dockerized and optimized for low latency.</p><p>&#9989; <strong>End&#8209;to&#8209;End RAG Chat App: </strong>Build a FastAPI backend with conversational memory and a Streamlit UI for live Retrieval&#8209;Augmented Generation.</p><p>By the end of Week 6, you won&#8217;t just know these techniques, you&#8217;ll have shipped six production&#8209;grade artifacts, each reflecting the exact pipelines, optimizations, and deployment routines you&#8217;ll use on the job.</p><h3>Live &amp; Recorded Content: Reinforce, Deepen, Accelerate</h3><p>&#10024; <strong>12 Interactive Live Workshops (3 hrs each): </strong>Each session follows the Concept &#8594; Code flow. I&#8217;ll introduce the day&#8217;s core topic (e.g. self-attention, LoRA, vLLM optimizations, ...), and we&#8217;ll implement the features step&#8209;by&#8209;step in code so you see exactly how theory maps to code. Bring your questions!</p><p>&#10024; <strong>10 + Hours of On&#8209;Demand Deep&#8209;Dive Lectures: </strong>Short videos (10&#8211;20 min) on Transformer internals, fine-tuning tricks, deployment optimizations. Watch before each project to hit the ground running. Step through every line of code at your own pace; perfect for review or catching up if you miss a live session. Downloadable slide decks, annotated notebooks, and cheat sheets you&#8217;ll reference long after graduation.</p><p><strong>Why This Matters:</strong> Live workshops turn recorded concepts into <strong>actionable skills</strong>. You&#8217;ll see how theory maps directly onto code, get instant feedback, and internalize best practices. Then, recorded lectures become your <strong>asynchronous safety net</strong>, letting you revisit tricky topics, prepare for upcoming labs, and solidify your understanding on demand.</p><p>Let me know if you have any questions. I hope to see you there!  </p>]]></content:encoded></item><item><title><![CDATA[All About The Modern Positional Encodings In LLMs]]></title><description><![CDATA[The Positional Encoding in LLMs may appear somewhat mysterious the first time we come across the concept, and for good reasons!]]></description><link>https://newsletter.theaiedge.io/p/all-about-the-modern-positional-encodings</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/all-about-the-modern-positional-encodings</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Mon, 28 Apr 2025 15:02:32 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72b3b068-0cc6-47c5-b160-3d3b07548912_5372x2875.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em><strong>The Positional Encoding in LLMs may appear somewhat mysterious the first time we come across the concept, and for good reasons! Over the years, researchers have found many different ad-hoc ways to encode positions and relative positions in the attention mechanism. The most recent surprise to me is the emergence of NoPE (no positional encoding) as being better for generalization on longer sequences. Today, we look at:</strong></em></p><ul><li><p><em><strong>Additive Relative Positional Embeddings</strong></em></p></li><li><p><em><strong>Multiplicative Relative Positional Embeddings</strong></em></p></li><li><p><em><strong>ALiBi: Attention With Linear Biases</strong></em></p></li><li><p><em><strong>RoPE:  Rotary Position Embedding</strong></em></p><ul><li><p><em><strong>The Complex Number Representation</strong></em></p></li><li><p><em><strong>Increasing The Context Window With RoPE</strong></em></p></li></ul></li><li><p><em><strong>No Position Encoder: NoPE</strong></em></p><ul><li><p><em><strong>How NoPE Can Learn Relation Positional Information</strong></em></p></li><li><p><em><strong>Better Generalization for Longer Distance</strong></em></p></li><li><p><em><strong>Llama 4's iRoPE</strong></em></p></li></ul></li></ul><div><hr></div><p>The original positional encoding scheme introduced in <a href="https://arxiv.org/pdf/1706.03762">"Attention is All You Need"</a> uses sinusoidal functions to create absolute position representations, but this approach revealed significant shortcomings when handling longer sequences or transferring to different sequence lengths: </p><ul><li><p><strong>Fixed context windows and poor extrapolation:</strong> When faced with sequences longer than this predefined limit, the model must either truncate the input or use positional values it never encountered during training. Perhaps the most significant limitation is that vanilla encodings represent absolute positions rather than relationships between tokens.</p></li><li><p><strong>The absolute vs. relative position problem:</strong> In language, relative positions often matter more than absolute ones. Consider the sentence: "The dog that chased the cat ran away." The relationship between "dog" and "ran" remains the same whether this is the opening sentence of a document or appears on page fifty, but absolute encodings fail to directly capture this invariance.</p></li><li><p><strong>Information dilution through layers: </strong>As signals propagate through the multiple layers of a Transformer, the influence of the original positional information tends to weaken. The model must work harder to maintain positional awareness in deeper layers, especially for distant tokens.</p></li><li><p><strong>Limited inductive bias for local relationships:</strong> Natural language exhibits a locality bias as nearby words often have stronger relationships than distant ones. The vanilla encoding doesn't naturally encode this bias, treating position 5 and position 500 as equally valid attention targets from a structural perspective, requiring the model to learn this pattern from data alone.</p></li><li><p><strong>Mathematical constraints:</strong> The sinusoidal functions used in the original formulation were chosen partly for their theoretical ability to generalize to unseen positions. However, in practice, they still struggle with significant extrapolation beyond the training range. The model learns to associate specific patterns with specific position ranges, and these associations become increasingly unreliable as we move farther from the training distribution.</p></li></ul><p>These limitations collectively motivated researchers to develop more sophisticated positional encoding schemes, from Shaw's direct relative encodings to Transformer-XL's decomposed approach, ALiBi's distance-based penalties, and RoPE's elegant rotational solution, each addressing different aspects of these fundamental challenges.</p><p>You can find the discussion about the original positional encoding here:</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;5fc75b4b-f26e-41bf-85f2-040fa233fd6e&quot;,&quot;caption&quot;:&quot;&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;md&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Attention Is All You Need: The Original Transformer Architecture&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:24785675,&quot;name&quot;:&quot;Damien Benveniste&quot;,&quot;bio&quot;:&quot;I specialize in building large scale end to end Machine Learning capabilities. After a PhD in Physics, I have been a Data Scientist, ML Engineer and Software Engineer for the past 10 years. Until recently, I was a Machine Learning Tech Lead at Meta.\n&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2157884e-8c5d-4cde-ab33-455fa623975d_2060x2061.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:100}],&quot;post_date&quot;:&quot;2025-02-12T16:02:31.464Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feede3dd0-159d-43f2-a620-0f34b8d81652_4800x3037.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://newsletter.theaiedge.io/p/attention-is-all-you-need-the-original&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:156937078,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:20,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;The AiEdge Newsletter&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6e9c582-b22b-45c5-a64e-a9105824fb01_1067x1067.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><h2>Additive Relative Positional Embeddings</h2><p>One of the first works addressing capturing the relative position between tokens instead of the absolute ones was done by <a href="https://arxiv.org/pdf/1803.02155">Shaw et al in 2018</a>. It addressed many of the original positional encoding's shortcomings. Instead of having an embedding matrix added to the semantic representation of the tokens, it modifies directly the computation of the attention layers with two positional embeddings. The first one <em><strong>a<sub>ij</sub><sup>K</sup></strong></em> is added to the key representation, and the second <em><strong>a<sub>ij</sub><sup>V</sup></strong></em>, to the value representation:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\n    \\mathbf{k}_j \\rightarrow \\mathbf{k}_j + \\mathbf{a}_{ij}^K \\nonumber\\\\\n\n   \\mathbf{v}_j \\rightarrow \\mathbf{v}_j + \\mathbf{a}_{ij}^V \n\n\\end{align}&quot;,&quot;id&quot;:&quot;NBSRMDTYCR&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em><strong>a<sub>ij</sub><sup>K</sup></strong></em> and <em><strong>a<sub>ij</sub><sup>V</sup></strong></em> are learned embeddings of size <em><strong>d<sub>model</sub></strong></em> that depend only on the relative distance <em><strong>j-i</strong></em>. Those embeddings are learned in each attention layer and influence more directly the interactions between tokens. Ignoring the attention heads for simplicity, the computation of a context vector <em><strong>c<sub>i</sub></strong></em> is modified as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;  \\mathbf{c}_i = \\sum_{j=1}^N \\text{Softmax}\\left(\\frac{\\mathbf{q}_i^T\\left(\\mathbf{k}_j+\\mathbf{a}_{ij}^K\\right)}{\\sqrt{d_\\text{model}}}\\right)\\left(\\mathbf{v}_j+\\mathbf{a}_{ij}^V\\right)&quot;,&quot;id&quot;:&quot;DPPBNZTUMK&quot;}" data-component-name="LatexBlockToDOM"></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!E3zP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!E3zP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.png 424w, https://substackcdn.com/image/fetch/$s_!E3zP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.png 848w, https://substackcdn.com/image/fetch/$s_!E3zP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.png 1272w, https://substackcdn.com/image/fetch/$s_!E3zP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!E3zP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.png" width="1456" height="787" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:787,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:434965,&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://newsletter.theaiedge.io/i/162302291?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.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_!E3zP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.png 424w, https://substackcdn.com/image/fetch/$s_!E3zP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.png 848w, https://substackcdn.com/image/fetch/$s_!E3zP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.png 1272w, https://substackcdn.com/image/fetch/$s_!E3zP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ef5038e-1daa-4602-ac45-f5dee9a72b6a_1500x811.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>They clip the maximum relative distance to a constant <em><strong>L</strong></em>, learning only <em><strong>2L+1</strong></em> position embeddings for each positional encoding. If we call the matrices of learned positions <em><strong>w<sup>K</sup></strong></em> and <em><strong>w<sup>V</sup></strong></em>, the actual relative position representations that are added to keys and values are the clipped version of those matrices:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\n    \\mathbf{a}_{ij}^K = w^K_{\\text{clip}(j-i, L)} \\nonumber\\\\\n\n    \\mathbf{a}_{ij}^V = w^V_{\\text{clip}(j-i, L)}\n\n\\end{align}&quot;,&quot;id&quot;:&quot;WECGVRDLAI&quot;}" data-component-name="LatexBlockToDOM"></div><p>where</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{clip}(j-i, L)=\\max\\left(-L, \\min\\left(L, j-i\\right)\\right)&quot;,&quot;id&quot;:&quot;MJPSUATWIQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>which clamps the relative distance to the range <em><strong>[&#8722;L, L]</strong></em>. This means that for any relative distance <em><strong>j-i &gt; L</strong></em>, </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{a}_{ij}^K = \\mathbf{a}_{i,i+L}^K&quot;,&quot;id&quot;:&quot;QZMCUELNLY&quot;}" data-component-name="LatexBlockToDOM"></div><p>and any relative distance<em><strong> j-i &lt; -L</strong></em>, </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{a}_{ij}^K = \\mathbf{a}_{i,i-L}^K&quot;,&quot;id&quot;:&quot;BDZUAUVDIO&quot;}" data-component-name="LatexBlockToDOM"></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qpP0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qpP0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.png 424w, https://substackcdn.com/image/fetch/$s_!qpP0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.png 848w, https://substackcdn.com/image/fetch/$s_!qpP0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.png 1272w, https://substackcdn.com/image/fetch/$s_!qpP0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qpP0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.png" width="1456" height="617" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:617,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:410044,&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://newsletter.theaiedge.io/i/162302291?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.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_!qpP0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.png 424w, https://substackcdn.com/image/fetch/$s_!qpP0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.png 848w, https://substackcdn.com/image/fetch/$s_!qpP0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.png 1272w, https://substackcdn.com/image/fetch/$s_!qpP0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F671af1e7-6bfd-497c-8851-ad9fa43532ee_1500x636.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>In practice, <em><strong>L</strong></em> can be chosen quite small as the performance remained relatively stable for <em><strong>L &gt; 2</strong></em> (testing <em><strong>L = 4</strong></em>, <em><strong>L = 16</strong></em>, <em><strong>L = 64</strong></em>, and <em><strong>L = 256</strong></em>). This suggests that distinguishing the precise relative distances of tokens becomes less important beyond a few positions away. The model primarily needs fine-grained position information for nearby contexts, while more distant relationships can be effectively captured with less positional precision, allowing the content representations themselves to drive attention patterns at longer distances. Even with a very small clipping window (<em><strong>L = 2</strong></em>), the model with relative positional encoding achieved substantial improvements over absolute positioning.</p><p>Despite the added performance gain, it is important to note that it is at the cost of added parameters and added time complexity. At the time, Shaw et al. performed their experiments with a 65M parameters transformer model with 6 layers and <em><strong>d<sub>model</sub></strong></em><strong> = 512</strong>. We need two new parameter layers of size <em><strong>(2L+1) x d<sub>model</sub></strong></em>, and with <em><strong>L = 16</strong></em>, it is ~200K additional parameters, which is negligible compared to the overall size of the model. More importantly, computing all the relative distances between the <em><strong>N</strong></em> tokens, the constant memory access, and adding the related embeddings is an <em><strong>O(N<sup>2</sup>)</strong></em> process that imposes a significant additional computational work on top of the already quadratic complexity of attention.     </p><h2>Multiplicative Relative Positional Embeddings</h2><p>In a previous <a href="https://newsletter.theaiedge.io/p/how-to-construct-self-attention-mechanisms">newsletter</a>, we introduced the attention mechanism developed with <a href="https://arxiv.org/pdf/1901.02860">Transformer-XL</a> to handle arbitrarily long sequences, but we left out the discussion about the positional encoding. Developing a new relative positional encoding was one of the critical pieces to handle longer sequences. The approach is based on the following analysis we provided in a <a href="https://newsletter.theaiedge.io/p/attention-is-all-you-need-the-original">previous newsletter</a> for the original positional encoding:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\ne_{i,i+k}\\sqrt{d_\\text{model}} &amp;= \\quad\\underbrace{\\mathbf{x}_i^\\top W^{Q\\top} W^K \\mathbf{x}_{i+k}}_{\\text{Token-Token Interaction}} \\nonumber\\\\\n\n&amp;+\\quad \\underbrace{\\mathbf{x}_i^\\top W^{Q\\top} W^K \\mathbf{PE}(i) R(k)}_{\\text{Token-Position Interaction}} \\nonumber\\\\\n\n&amp;+ \\quad\\underbrace{\\mathbf{PE}(i)^\\top W^{Q\\top} W^K \\mathbf{x}_{i+k}}_{\\text{Position-Token Interaction}}\\nonumber\\\\\n\n&amp;+\\quad \\underbrace{\\mathbf{PE}(i)^\\top W^{Q\\top} W^K \\mathbf{PE}(i) R(k)}_{{\\text{Position-Position Interaction}}}\n\n\\end{align}&quot;,&quot;id&quot;:&quot;GQFDRZMCNU&quot;}" data-component-name="LatexBlockToDOM"></div><p>In this equation, we decomposed the contributions from the different content and positional components for the first attention layer in the model when using the vanilla absolute positional encoding. We showed how <em><strong>R(k)</strong></em> was capturing the relative positional information between tokens, and we hope for the model to learn <em><strong>W<sup>Q</sup></strong></em> and <em><strong>W<sup>K</sup></strong></em> such that it can effectively utilize that information. To help the model capture better the content and position interactions between tokens, the relative positional encoding introduced in Transformer-XL modified this original equation. The relative positional encoding will now be applied within every layer following this strategy:</p><ul><li><p><em><strong> x<sub>i</sub><sup>T</sup> W<sup>QT</sup> W<sup>K</sup> x<sub>i+k</sub></strong></em> originally captured the pure content-based interaction between tokens. <em><strong>x<sub>i</sub></strong></em>, in the original Transformer, represents the embedding vector from the token embedding, and the related hidden state <em><strong>h<sub>i</sub></strong></em> is the sum of the token embedding and the positional encoding:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\mathbf{h}_{i} = \\mathbf{x}_{i} + \\mathbf{PE}(i)&quot;,&quot;id&quot;:&quot;QPQARHPJBS&quot;}" data-component-name="LatexBlockToDOM"></div><p>We modify this interaction by applying it directly to the hidden states <em><strong>h<sub>i</sub></strong></em> and <em><strong>h<sub>i+k</sub></strong></em> where<em><strong> k</strong></em> is the distance between the related tokens:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\mathbf{h}_i^\\top W^{Q\\top} W^K_E \\mathbf{h}_{i+k}&quot;,&quot;id&quot;:&quot;UAFQVFLKYB&quot;}" data-component-name="LatexBlockToDOM"></div><p>We specifically distinguish the projection <em><strong>W<sub>E</sub><sup>K</sup></strong></em> to be content-specific. </p></li><li><p><em><strong>x<sub>i</sub><sup>T</sup> W<sup>QT</sup> W<sup>K</sup> PE(i) R(k)</strong></em> or equivalently <em><strong>x<sub>i</sub><sup>T</sup> W<sup>QT</sup> W<sup>K</sup> PE(i+k) R(k)</strong></em> captured a token's preference for attending to positions was tied to fixed locations. However, this is confusing for the model because <em><strong>PE(i+k)</strong></em> depends on the specific position of <em><strong>x<sub>i</sub></strong></em>. Instead, in the <em>Transformer-XL</em>, they modified this interaction only accounting for the relative distance <em><strong>k</strong></em> from the hidden state <em><strong>h<sub>i</sub></strong></em>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{h}_i^\\top W^{Q\\top} W^K_R \\mathbf{r}_k&quot;,&quot;id&quot;:&quot;NLLRNWGAPI&quot;}" data-component-name="LatexBlockToDOM"></div><p><em><strong>r<sub>k</sub></strong></em> is a vector of the positional encoding matrix <em><strong>R</strong></em>. As for the additive relative positional embeddings, <em><strong>R</strong></em> is a <em><strong>(2L+1) x d<sub>model</sub></strong></em> matrix where <em><strong>r<sub>k</sub></strong></em> only depends on the relative distance between <em><strong>h<sub>i</sub></strong></em> and <em><strong>h<sub>i+k</sub></strong></em>, and <em><strong>L</strong></em> is a constant chosen to clip the maximum distances that can be represented. However, <em><strong>R</strong></em> is not a learned parameter matrix, but a fixed encoding as in the original Transformer architecture. <em><strong>W<sub>R</sub><sup>K</sup></strong></em> (different from <em><strong>W<sub>E</sub><sup>K</sup></strong></em>) is a specialized weight matrix that further enhances this separation of positional processing. </p></li><li><p><em><strong>PE(i)<sup>T</sup> W<sup>QT</sup> W<sup>K</sup> x<sub>i+k</sub></strong></em> is a position-dependent bias for attending to content. This is a strange term because it has more or less weight depending on the position of the query. To make it position independent, we replace <em><strong>PE(i)<sup>T</sup> W<sup>QT</sup></strong></em> with a global learnable parameter <em><strong>u<sup>T</sup></strong></em>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{u}^\\top W^K_E \\mathbf{h}_{i+k}&quot;,&quot;id&quot;:&quot;QIJGSPEEIQ&quot;}" data-component-name="LatexBlockToDOM"></div><p><em><strong>u</strong></em> is a vector of size <em><strong>d<sub>model</sub></strong></em>. This reflects an insight that the attentive bias toward different content should remain consistent regardless of the query position. In other words, the importance of certain word types doesn't need to depend on position, so a single global parameter can replace position-specific queries. This simplifies the model while maintaining expressiveness.</p></li><li><p><em><strong>PE(i)<sup>T</sup> W<sup>QT</sup> W<sup>K</sup> PE(i+k)</strong></em> is a position-position iteration term that depends on the specific position of the query. To make it position independent while keeping the relative positional information, we introduce another global learnable parameter <em><strong>v<sup>T</sup></strong></em> of size <em><strong>d<sub>model</sub></strong></em> to replace <em><strong>PE(i)<sup>T</sup> W<sup>QT</sup></strong></em>, and use again the relative positional encoding <em><strong>R</strong></em>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\mathbf{v}^\\top W^K_R \\mathbf{r}_k&quot;,&quot;id&quot;:&quot;TTTYOEQMAZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>As before, we use the position-specific projection <em><strong>W<sub>R</sub><sup>K</sup></strong></em>. The intuition is that certain relative distances might be generally more important than others, regardless of the absolute positions involved. For example, adjacent tokens (small <em><strong>k</strong></em>) might generally be more related than distant ones, regardless of their absolute positions in the sequence. </p></li></ul><p>This leads to redefining the alignment scores as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\ne_{i,i+k}\\sqrt{d_\\text{model}} &amp;= \\quad\\underbrace{\\mathbf{h}_i^\\top W^{Q\\top} W^K_E \\mathbf{h}_{i+k}}_{\\text{Token-Token Interaction}} \\nonumber\\\\\n\n&amp;+\\quad \\underbrace{\\mathbf{h}_i^\\top W^{Q\\top} W^K_R \\mathbf{r}_k}_{\\text{Token-Position Interaction}} \\nonumber\\\\\n\n&amp;+ \\quad\\underbrace{\\mathbf{u}^\\top W^K_E \\mathbf{h}_{i+k}}_{\\text{Position-Token Interaction}}\\nonumber\\\\\n\n&amp;+\\quad \\underbrace{\\mathbf{v}^\\top W^K_R \\mathbf{r}_k}_{\\text{Position-Position Interaction}}\n\n\\end{align}&quot;,&quot;id&quot;:&quot;TNHBEWUFNA&quot;}" data-component-name="LatexBlockToDOM"></div><p>with <em><strong>W<sup>Q</sup>h<sub>i</sub> = q<sub>i</sub></strong></em>, the query and <em><strong>W<sub>E</sub><sup>K</sup>h<sub>i+k</sub> = k<sub>i+k</sub></strong></em>, the key, we can regroup the terms:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; e_{i,i+k}\\sqrt{d_\\text{model}} = \\left(\\mathbf{q}_i+\\mathbf{u}\\right)^\\top\\mathbf{k}_{i+k}+\\left(\\mathbf{q}_i+\\mathbf{v}\\right)^\\top W_R^K\\mathbf{r}_{k}&quot;,&quot;id&quot;:&quot;EWSUNANZAY&quot;}" data-component-name="LatexBlockToDOM"></div><p>with</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\left(\\mathbf{q}_i+\\mathbf{u}\\right)^\\top\\mathbf{k}_{i+k}&quot;,&quot;id&quot;:&quot;ZXTHXTWYNJ&quot;}" data-component-name="LatexBlockToDOM"></div><p>being a pure content interaction term and </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\left(\\mathbf{q}_i+\\mathbf{v}\\right)^\\top W_R^K\\mathbf{r}_{k}&quot;,&quot;id&quot;:&quot;ADIUGMANNX&quot;}" data-component-name="LatexBlockToDOM"></div><p>representing a content-to-relative distance interaction term. <em><strong>W<sub>E</sub><sup>K</sup>h<sub>i+k</sub> = k<sub>i+k</sub></strong></em> can be thought of as a content contribution to the key, while <em><strong>W<sub>R</sub><sup>K</sup>r<sub>k</sub></strong></em> is the relative positional piece of the key. The global parameters <em><strong>u</strong></em> and <em><strong>v</strong></em> can be seen as providing "default query projections" that are active regardless of the specific query token. This ensures that important content and positional patterns always receive some attention.</p><p><em><strong>R</strong></em> follows the same sinusoidal encoding function as the original Transformer, just applied to relative positions instead of absolute positions:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{R}(k, j)\n\n= \n\n\\begin{cases}\n\n\\sin\\left(\\frac{k}{10000^{j/d_\\text{model}}}\\right) &amp; \\text{if $j$ is even} ,\\\\\n\n\\cos\\left(\\frac{k}{10000^{(j-1)/d_\\text{model}}}\\right) &amp; \\text{if $j$ is odd},\n\n\\end{cases}&quot;,&quot;id&quot;:&quot;WCFNZERAIT&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em><strong>k</strong></em> is the relative distance between positions, ranging from <em><strong>&#8722;L</strong></em> to <em><strong>+L,</strong></em> and <em><strong>j</strong></em> is the dimension index from 0 to <em><strong>d<sub>model</sub></strong></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_!Zsqx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zsqx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.png 424w, https://substackcdn.com/image/fetch/$s_!Zsqx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.png 848w, https://substackcdn.com/image/fetch/$s_!Zsqx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.png 1272w, https://substackcdn.com/image/fetch/$s_!Zsqx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zsqx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.png" width="1456" height="985" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:985,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:389195,&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://newsletter.theaiedge.io/i/162302291?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.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_!Zsqx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.png 424w, https://substackcdn.com/image/fetch/$s_!Zsqx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.png 848w, https://substackcdn.com/image/fetch/$s_!Zsqx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.png 1272w, https://substackcdn.com/image/fetch/$s_!Zsqx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9b8b5a2-25a8-4bfd-aa6d-47296feaf8a8_1500x1015.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>Computing </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\left(\\mathbf{q}_i+\\mathbf{v}\\right)^\\top W_R^K\\mathbf{r}_{k}&quot;,&quot;id&quot;:&quot;TVOSSZWGAZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>requires careful thought to limit the complexity of the problem. With <em><strong>N</strong></em> tokens, we could naively extract all the <em><strong>N<sup>2</sup></strong></em> related <em><strong>r<sub>k</sub></strong></em> since there are <em><strong>N<sup>2</sup></strong></em> pairs of tokens. However, there would be many duplicate vectors since different pairs of tokens have the same distance between them. Instead, we can directly use the whole <em><strong>R</strong></em> matrix and pass it through the linear layer <em><strong>W<sub>R</sub><sup>K</sup></strong></em>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;K_R=W_R^KR&quot;,&quot;id&quot;:&quot;SLABKMYRRF&quot;}" data-component-name="LatexBlockToDOM"></div><p><em><strong>R</strong></em> is a <em><strong>(2L+1) x d<sub>model</sub></strong></em>, and <em><strong>W<sub>R</sub><sup>K</sup></strong></em> is a <em><strong>d<sub>model</sub> x d<sub>model</sub></strong></em> matrix, therefore the "positional keys" <em><strong>K<sub>R</sub></strong></em> is a <em><strong>(2L+1) x d<sub>model</sub></strong></em> matrix. As a consequence </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\left(\\mathbf{q}_i+\\mathbf{v}\\right)^\\top W_R^K\\mathbf{r}_{k}&quot;,&quot;id&quot;:&quot;MVCOXWETSQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>is a <em><strong>(2L+1)</strong></em> dimensional vector which leads to a <em><strong>(2L+1) x N</strong></em> content to position alignment matrix for <em><strong>N</strong></em> queries.  </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zM5u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zM5u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.png 424w, https://substackcdn.com/image/fetch/$s_!zM5u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.png 848w, https://substackcdn.com/image/fetch/$s_!zM5u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.png 1272w, https://substackcdn.com/image/fetch/$s_!zM5u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zM5u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.png" width="510" height="295.98214285714283" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:845,&quot;width&quot;:1456,&quot;resizeWidth&quot;:510,&quot;bytes&quot;:699786,&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://newsletter.theaiedge.io/i/162302291?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.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_!zM5u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.png 424w, https://substackcdn.com/image/fetch/$s_!zM5u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.png 848w, https://substackcdn.com/image/fetch/$s_!zM5u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.png 1272w, https://substackcdn.com/image/fetch/$s_!zM5u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f7cf736-1738-44e8-959c-071f27723bad_4344x2522.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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 class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qwtn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qwtn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.png 424w, https://substackcdn.com/image/fetch/$s_!qwtn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.png 848w, https://substackcdn.com/image/fetch/$s_!qwtn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.png 1272w, https://substackcdn.com/image/fetch/$s_!qwtn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qwtn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.png" width="1456" height="809" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:809,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:837244,&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://newsletter.theaiedge.io/i/162302291?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.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_!qwtn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.png 424w, https://substackcdn.com/image/fetch/$s_!qwtn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.png 848w, https://substackcdn.com/image/fetch/$s_!qwtn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.png 1272w, https://substackcdn.com/image/fetch/$s_!qwtn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6fbf0b85-7d6d-4fe9-927c-bcf44342f5da_5722x3181.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>Let's make sure we understand the different tensors in play. We have the queries <em><strong>Q = [q<sub>1</sub>, &#8230;, q<sub>N</sub>]</strong></em>, the keys <em><strong>K = [k<sub>1</sub>, &#8230;, k<sub>N</sub>]</strong></em>, and the positional equivalent to the keys <em><strong>K<sub>R</sub> =[W<sub>R</sub><sup>K</sup>r<sub>-L</sub>, &#8230;, W<sub>R</sub><sup>K</sup>r<sub>L</sub>]</strong></em>. The relative positions in <em><strong>K<sub>R</sub></strong></em> are not aligned with the relative positions of <em><strong>K</strong></em> with respect to <em><strong>Q</strong></em>. This means we cannot simply add </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;(Q + \\mathbf{u})^\\top K \\quad\\text{with}\\quad (Q + \\mathbf{v})^\\top K_R&quot;,&quot;id&quot;:&quot;XKVUWGAPOD&quot;}" data-component-name="LatexBlockToDOM"></div><p>because of the misalignment in the key ordering. We just need to change the indices of the elements in <em><strong>(Q + v)<sup>T</sup> K<sub>R</sub></strong></em>. For query position <em><strong>i</strong></em>, we need:</p><ul><li><p>For key position 0: a relative distance i&#8722;0 = i</p></li><li><p>For key position 1: a relative distance i&#8722;1</p></li><li><p>For key position 2: a relative distance i&#8722;2</p></li><li><p>And so on...</p></li></ul><p>In other words, for the <em><strong>i-</strong></em>th row of the content to position alignment matrix <em><strong>P = (Q + v)<sup>T</sup> K<sub>R</sub></strong></em>, we need to select values in a specific pattern. The solution is to reshape and shift the <em><strong>P</strong></em> matrix so that the correct relative position scores align with the positions we need in the final attention matrix. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!e-Lh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!e-Lh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.png 424w, https://substackcdn.com/image/fetch/$s_!e-Lh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.png 848w, https://substackcdn.com/image/fetch/$s_!e-Lh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.png 1272w, https://substackcdn.com/image/fetch/$s_!e-Lh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!e-Lh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.png" width="1456" height="956" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:956,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:272820,&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://newsletter.theaiedge.io/i/162302291?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.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_!e-Lh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.png 424w, https://substackcdn.com/image/fetch/$s_!e-Lh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.png 848w, https://substackcdn.com/image/fetch/$s_!e-Lh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.png 1272w, https://substackcdn.com/image/fetch/$s_!e-Lh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b812f-ce39-4e8e-b048-e7bfeb498a24_1500x985.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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 class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!smTf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!smTf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.png 424w, https://substackcdn.com/image/fetch/$s_!smTf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.png 848w, https://substackcdn.com/image/fetch/$s_!smTf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.png 1272w, https://substackcdn.com/image/fetch/$s_!smTf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!smTf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.png" width="1456" height="852" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fc805bb8-e797-4c05-bc07-167400163b89_1500x878.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:852,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:253204,&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://newsletter.theaiedge.io/i/162302291?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.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_!smTf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.png 424w, https://substackcdn.com/image/fetch/$s_!smTf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.png 848w, https://substackcdn.com/image/fetch/$s_!smTf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.png 1272w, https://substackcdn.com/image/fetch/$s_!smTf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc805bb8-e797-4c05-bc07-167400163b89_1500x878.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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 class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Aumn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Aumn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.png 424w, https://substackcdn.com/image/fetch/$s_!Aumn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.png 848w, https://substackcdn.com/image/fetch/$s_!Aumn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.png 1272w, https://substackcdn.com/image/fetch/$s_!Aumn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Aumn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.png" width="1456" height="883" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:883,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:418807,&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://newsletter.theaiedge.io/i/162302291?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.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_!Aumn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.png 424w, https://substackcdn.com/image/fetch/$s_!Aumn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.png 848w, https://substackcdn.com/image/fetch/$s_!Aumn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.png 1272w, https://substackcdn.com/image/fetch/$s_!Aumn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F14230fa9-fcb7-4e53-ab1c-431b086f41ae_1500x910.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>In the case of <em>Transformer-XL</em>, remember that the sequences are processed in segments of size n &#171; N, and the attention mechanism per segment follows an <em><strong>O(n<sup>2</sup>)</strong></em> time complexity. <em><strong>W<sub>R</sub><sup>K</sup>R</strong></em> also operates on segments, and the time complexity is </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathcal{O}\\left((2L+1)nd_\\text{model}\\right)=\\mathcal{O}\\left(Lnd_\\text{model}\\right)&quot;,&quot;id&quot;:&quot;ILJXPDETCM&quot;}" data-component-name="LatexBlockToDOM"></div><p>The shift operation needs at least <em><strong>O(n<sup>2</sup>)</strong></em> operations to reindex the alignment score matrix. Therefore, the overall time complexity associated with the relative positional encoding follows the asymptotic behavior <em><strong>O(n<sup>2</sup>)</strong></em>.</p><p><em>Transformer-XL</em> showed improvements in the model's ability to utilize longer contexts. When trained with segments of length 128 but evaluated with various attention lengths, the model showed continued improvements in perplexity up to 640 tokens. The paper reported improved perplexity metric when increasing evaluation context length beyond training length, something absolute encoding couldn't achieve.</p><h2>ALiBi: Attention With Linear Biases</h2><p>The relative positional encoding developed in <em>Transformer-XL</em> is designed to handle very long sequences, but it adds complexity to the attention layer, and, while it can handle longer contexts through its recurrence mechanism, it was not specifically designed for extrapolation to arbitrary lengths beyond training. <a href="https://arxiv.org/pdf/2108.12409">ALiBi</a> (<strong>A</strong>ttention With <strong>Li</strong>near <strong>Bi</strong>ases) was introduced in 2021 as a simpler approach that could easily be extrapolated to much longer sequences than the ones seen during training. It does not require any model parameters and can be expressed as a penalty on the alignment score:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;e_{ij} = \\mathbf{q}_i^\\top \\mathbf{k}_j + m_h\\left(j-i\\right)&quot;,&quot;id&quot;:&quot;DAYWUGTTGR&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em><strong>j-i</strong></em> is the distance between the query <em><strong>q<sub>i</sub></strong></em> and the key <em><strong>k<sub>j</sub></strong></em>, and <em><strong>m<sub>h</sub></strong></em> is a head-specific constant, with <em><strong>h</strong></em> being the index of the head. In the case of causal language modeling, we always have j-i &#8804; 0, leading to lower attention for far-away tokens. ALiBi tends to sacrifice true long-range modeling for extrapolation capability. <em><strong>m<sub>h</sub></strong></em> is chosen as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;m_h=2^{-\\frac{8h}{n_\\text{head}}}&quot;,&quot;id&quot;:&quot;XQTFZKJXQM&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em><strong>h &#8712; [0, &#8230;, n<sub>head</sub> -1]</strong></em>. For example, if we have 8 heads, the first head would have <em><strong>m<sub>0 </sub>= 2<sup>0 </sup>= 1</strong></em>, and the last head <em><strong>m<sub>7</sub> = 2<sup>-7</sup> = 0.0078125</strong></em>, with a spectrum of the different intermediary slopes in between. For <em><strong>j-i = 1000</strong></em>, for example, we get <em><strong>m<sub>7</sub>(j-i)~ -7.8</strong></em>, which is a substantial penalty to capture long-range interaction between tokens. This suggests that ALiBi may not be optimal for tasks requiring very long-range dependencies (like book-length coherence), but it represents a valuable engineering trade-off that improves efficiency without sacrificing performance on many practical tasks. </p><p>Despite this limitation, ALiBi works well for extrapolation for several reasons:</p><ul><li><p>Graduated attention ranges: The different head slopes create a spectrum of attention distances. While no head truly specializes in very long-range attention, the collection of heads creates a gradient of focus distances.</p></li><li><p>Local coherence dominance: Language has a hierarchical structure where local coherence (within paragraphs or nearby sentences) often matters more than very distant relationships. The bias aligns with this natural property of language.</p></li><li><p>Information propagation: Information can still flow across long distances through multiple layers of the transformer. Even if direct attention across 1000 tokens is penalized, information can propagate through intermediate positions across layers.</p></li><li><p>Relative vs. absolute positioning: Unlike sinusoidal embeddings that break down completely outside their training range, ALiBi's linear bias at least provides a consistent, predictable signal at any distance.</p></li></ul><p>The paper showed that a model trained on 512 tokens could handle sequences of 3072 tokens with better perplexity than a sinusoidal model trained on 3072 tokens. A 1.3 billion parameter model trained on 1024 tokens achieved the same perplexity as a sinusoidal model trained on 2048 tokens when evaluated on 2048-token sequences. As input length increases beyond training length, sinusoidal models' performance degrades almost immediately while ALiBi's performance continues improving up to ~2-3x training length before plateauing.</p><h2>RoPE:  Rotary Position Embedding</h2><p>The <a href="https://arxiv.org/pdf/2104.09864">Rotary Position Embedding</a> (RoPE) is now one of the most common strategies used to inject the relative positional information within the attention mechanism. The idea behind RoPE is to rotate the keys and queries based on the position of the related tokens in the input sequences. This will inject the absolute positional information directly into the queries and keys. Let's look at a toy example to understand the logic. Let's consider a 2-dimensional query <em><strong>q<sub>i</sub></strong></em> and a 2-dimensional key <em><strong>k<sub>j</sub></strong></em>. To rotate 2-dimensional vectors, we use rotation matrices:</p>
      <p>
          <a href="https://newsletter.theaiedge.io/p/all-about-the-modern-positional-encodings">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Join us for a Free LIVE Coding Event: Build The Self-Attention in PyTorch From Scratch]]></title><description><![CDATA[Next Friday, I am inviting you to join me for an exciting live coding event. It is a completely free event where I will explain the basics of the self-attention layer and implement it from scratch in PyTorch. From the vanilla self-attention to the multi-head attention layer, I will walk you through all the little details.]]></description><link>https://newsletter.theaiedge.io/p/join-us-for-a-free-live-coding-event</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/join-us-for-a-free-live-coding-event</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Fri, 25 Apr 2025 15:00:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!yF_u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Next Friday, I am inviting you to join me for <strong><a href="https://maven.com/p/bdd423/build-the-self-attention-in-py-torch-from-scratch">an exciting live coding event</a></strong>. It is a completely free event where I will explain the basics of the self-attention layer and implement it from scratch in PyTorch. From the vanilla self-attention to the multi-head attention layer, I will walk you through all the little details.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://maven.com/p/bdd423/build-the-self-attention-in-py-torch-from-scratch" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yF_u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.png 424w, https://substackcdn.com/image/fetch/$s_!yF_u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.png 848w, https://substackcdn.com/image/fetch/$s_!yF_u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.png 1272w, https://substackcdn.com/image/fetch/$s_!yF_u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yF_u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.png" width="459" height="258.1875" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/328ab538-6fba-487e-bc25-01621bb57109_3200x1800.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:459,&quot;bytes&quot;:1538362,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://maven.com/p/bdd423/build-the-self-attention-in-py-torch-from-scratch&quot;,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://newsletter.theaiedge.io/i/162099225?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.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_!yF_u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.png 424w, https://substackcdn.com/image/fetch/$s_!yF_u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.png 848w, https://substackcdn.com/image/fetch/$s_!yF_u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.png 1272w, https://substackcdn.com/image/fetch/$s_!yF_u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F328ab538-6fba-487e-bc25-01621bb57109_3200x1800.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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>Over the past few years, I have realized that the logic behind self-attention still eludes many people who want to dive deeper into the field. For me, implementing from scratch is the best way to learn this core element of every LLM. Once the self-attention implementation becomes more intuitive, it opens the doors to understanding all the small improvements that have led to the level of maturity we have today in the field of LLMs.   </p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/p/bdd423/build-the-self-attention-in-py-torch-from-scratch&quot;,&quot;text&quot;:&quot;Signup&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://maven.com/p/bdd423/build-the-self-attention-in-py-torch-from-scratch"><span>Signup</span></a></p><p>This is an opportunity to talk face-to-face and ask questions. The event is on May 2nd at 9:30 AM PST. I hope to see you there!    </p>]]></content:encoded></item><item><title><![CDATA[Build Production-Ready LLMs From Scratch]]></title><description><![CDATA[From Prototype to Production: Ship Scalable LLM Systems in 6 Weeks]]></description><link>https://newsletter.theaiedge.io/p/build-production-ready-llms-from</link><guid isPermaLink="false">https://newsletter.theaiedge.io/p/build-production-ready-llms-from</guid><dc:creator><![CDATA[Damien Benveniste]]></dc:creator><pubDate>Mon, 21 Apr 2025 15:03:03 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!J9Vr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Big news! I am now partnering with <a href="https://maven.com/">Maven</a> as an instructor to teach the <strong><a href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first">Build Production-Ready LLMs From Scratch</a></strong> live course! This is a 6-week program to learn to build scalable LLMs from scratch and ship them to production. It will run between May 24th and June 29, 2025. It includes 12 live sessions, 6 real-world hands-on projects, 64 recorded lectures, and more material. <strong>The first 30 people to sign up will get a 20% discount by applying the promo code <a href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first">FIRST</a>!</strong> So make sure to sign up early:</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first&quot;,&quot;text&quot;:&quot;Signup&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first"><span>Signup</span></a></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!J9Vr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 424w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 848w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png" width="574" height="322.875" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:574,&quot;bytes&quot;:3569157,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:&quot;https://maven.com/damien-benveniste/train-fine-tune-and-deploy-llms?promoCode=first&quot;,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://newsletter.theaiedge.io/i/161774781?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.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_!J9Vr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 424w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 848w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.png 1272w, https://substackcdn.com/image/fetch/$s_!J9Vr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dc84db0-31c2-46eb-a37e-754282b2fe22_2560x1440.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 buttonBase-GK1x3M"><svg aria-hidden="true" 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" class="icon-noB79L"><g><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 buttonBase-GK1x3M"><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 icon-noB79L"><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><strong>The Real-World LLM Engineering Roadblocks You Face Today</strong></h3><p><strong>&#128075; Transitioning from General ML to LLM Specialization:</strong> You&#8217;ve built recommendation engines or classifier models, but moving into Transformer&#8209;centric development feels like learning a whole new discipline&#8212;no clear roadmap exists.</p><p><strong>&#128075; Lack of LLM&#8209;Specific Career Path: </strong>You see &#8220;LLM Engineer&#8221; roles popping up on LinkedIn, but your current CV only shows &#8220;Data Scientist&#8221; or &#8220;ML Engineer.&#8221; You need hands&#8209;on projects and artifacts to credibly make the jump.</p><p><strong>&#128075; Career Stalled by &#8220;Academic&#8221; Skillset:</strong> You can recite Transformer papers, but when asked, &#8220;Have you shipped an LLM feature end&#8209;to&#8209;end?&#8221; you have no answer&#8212;and no portfolio to prove it!</p><p><strong>&#128075; Prototype Meltdown Under Production Load: </strong>You&#8217;ve fine&#8209;tuned a small model locally, but when you switch from 1 to 100 concurrent requests, your GPU memory spikes and inference grinds to a halt, because you&#8217;ve never applied continuous batching, KV caching, or paged&#8209;attention in a live setting.</p><p><strong>&#128075; RAG Integration Headaches: </strong>Turning a standalone model into a live, Retriever&#8209;Augmented Generation service becomes a multi&#8209;week integration nightmare.</p><h3>How this course will help you</h3><p>Because we&#8217;ve <strong>packaged every stage</strong> of the LLM lifecycle, <strong>from career transition to production rollout</strong>, into a <strong>six&#8209;week bootcamp</strong> that:</p><p>&#9989; <strong>Guides Your Career Pivot: </strong>You&#8217;ll emerge with six polished GitHub projects, a deployment playbook, and RAG demos that transform your resume from &#8220;ML generalist&#8221; to &#8220;LLM Specialist.&#8221;</p><p>&#9989; <strong>Attacks Each Pain&#8209;Point Head&#8209;On: </strong>Attacks each pain point head&#8209;on with six job&#8209;mirroring projects (from scratch &#8594; RLHF &#8594; scaling &#8594; deployment &#8594; RAG), so you never waste time on dead&#8209;end tutorials</p><p>&#9989; <strong>Live Code&#8209;Along Workshops &amp; Office Hours: </strong>Tackle your own fine&#8209;tuning bugs, scaling hiccups, and deployment errors alongside Damien in dedicated sessions, so you get hands&#8209;on fixes for the exact issues you&#8217;ll face on the job.</p><p>&#9989; <strong>Ready&#8209;to&#8209;Use Repos &amp; Playbooks: </strong>Grab our curated starter code, development scripts, deployment templates, and debugging checklists, so you can plug them straight into your next project without reinventing the wheel.</p><p>&#9989; <strong>A Portfolio of Six Production&#8209;Grade Projects: </strong>Leave with six end&#8209;to&#8209;end deliverables, from a Transformer built from scratch to a live RAG API, ready to showcase on GitHub, in performance reviews, or to hiring managers.</p><p>No more scattered blog-hopping or generic bootcamps, this is <strong>the only</strong> cohort where you&#8217;ll <strong>master</strong> Transformer internals <em>and</em> <strong>ship</strong> production&#8209;grade LLM systems while making the career leap you&#8217;ve been aiming for.</p><h3>What You&#8217;ll Actually Build and Ship</h3><p>Across six hands&#8209;on projects, you&#8217;ll deliver deployable LLM components and applications, no fluff, just job&#8209;ready code:</p><p>&#9989; <strong>A Modern Transformer Architecture from scratch: </strong>Implement a sliding&#8209;window multihead attention to slash O(N&#178;) to O(N&#183;w), RoPE for relative positional encoding, and the Mixture-of-Expert architecture for improved performance, all in PyTorch.</p><p>&#9989; <strong>Instruction&#8209;Tuned LLM: </strong>Fine&#8209;tune a model with supervised learning, RLHF, DPO, and ORPO for instruction following on a real benchmark and compare performance gains.</p><p>&#9989; <strong>Scalable Training Pipeline: </strong>Containerize a multi&#8209;GPU job with DeepSpeed ZeRO on SageMaker to maximize throughput and minimize cost.</p><p>&#9989; <strong>Extended&#8209;Context Model: </strong>Modify RoPE scaling, apply 4/8&#8209;bit quantization, and inject LoRA adapters to double your context window.</p><p>&#9989; <strong>Multi&#8209;Mode Deployment: </strong>Stand up a Hugging Face endpoint, a vLLM streaming API, and an OpenAI&#8209;compatible server, all Dockerized and optimized for low latency.</p><p>&#9989; <strong>End&#8209;to&#8209;End RAG Chat App: </strong>Build a FastAPI backend with conversational memory and a Streamlit UI for live Retrieval&#8209;Augmented Generation.</p><p>By the end of Week 6, you won&#8217;t just know these techniques, you&#8217;ll have shipped six production&#8209;grade artifacts, each reflecting the exact pipelines, optimizations, and deployment routines you&#8217;ll use on the job.</p><h3>Live &amp; Recorded Content: Reinforce, Deepen, Accelerate</h3><p>&#10024; <strong>12 Interactive Live Workshops (3 hrs each): </strong>Each session follows the Concept &#8594; Code flow. I&#8217;ll introduce the day&#8217;s core topic (e.g. self-attention, LoRA, vLLM optimizations, ...), and we&#8217;ll implement the features step&#8209;by&#8209;step in code so you see exactly how theory maps to code. Bring your questions!</p><p>&#10024; <strong>10 + Hours of On&#8209;Demand Deep&#8209;Dive Lectures: </strong>Short videos (10&#8211;20 min) on Transformer internals, fine-tuning tricks, deployment optimizations. Watch before each project to hit the ground running. Step through every line of code at your own pace; perfect for review or catching up if you miss a live session. Downloadable slide decks, annotated notebooks, and cheat sheets you&#8217;ll reference long after graduation.</p><p><strong>Why This Matters:</strong> Live workshops turn recorded concepts into <strong>actionable skills</strong>. You&#8217;ll see how theory maps directly onto code, get instant feedback, and internalize best practices. Then, recorded lectures become your <strong>asynchronous safety net</strong>, letting you revisit tricky topics, prepare for upcoming labs, and solidify your understanding on demand.</p><p>Let me know if you have any questions. I hope to see you there!</p><p></p>]]></content:encoded></item></channel></rss>