<?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[Jerad’s Substack]]></title><description><![CDATA[My personal Substack]]></description><link>https://jeradlu.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!PGih!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9f1f284-a9af-4de1-b4b4-ecdee9704d54_144x144.png</url><title>Jerad’s Substack</title><link>https://jeradlu.substack.com</link></image><generator>Substack</generator><lastBuildDate>Mon, 13 Apr 2026 08:39:58 GMT</lastBuildDate><atom:link href="https://jeradlu.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Jerad]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[jeradlu@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[jeradlu@substack.com]]></itunes:email><itunes:name><![CDATA[Jerad Lu]]></itunes:name></itunes:owner><itunes:author><![CDATA[Jerad Lu]]></itunes:author><googleplay:owner><![CDATA[jeradlu@substack.com]]></googleplay:owner><googleplay:email><![CDATA[jeradlu@substack.com]]></googleplay:email><googleplay:author><![CDATA[Jerad Lu]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Hybrid Advertising Strikes Back]]></title><description><![CDATA[Phenomena George Lucas accurately predicted]]></description><link>https://jeradlu.substack.com/p/consumerism-episode-v-hybrid-advertising</link><guid isPermaLink="false">https://jeradlu.substack.com/p/consumerism-episode-v-hybrid-advertising</guid><dc:creator><![CDATA[Jerad Lu]]></dc:creator><pubDate>Wed, 29 May 2024 17:09:34 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!9MN6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hybrid work is becoming more prevalent, but is &#8216;Hybrid&#8217; actually a deeper consumer trend? We&#8217;re beginning to notice diverse ads&#8212;from digital billboards to TVs in public&#8212; blend in with our everyday, from daily commuting to a late-night grocery runs. </p><h2>The Hybrid Commute Journey</h2><p>To investigate further, let&#8217;s dive into a typical morning commute of someone who is disgruntled with NYC but is also too stubborn to leave (like myself): </p><ol><li><p>We wake up, or if we happen to be an influencer, we record ourselves waking up</p></li><li><p>We try our best to avoid the morning phone check. We usually don&#8217;t succeed. Perhaps the first lucky ad graces us</p></li><li><p>For us unlucky enough to be in NY, we rush to the subway. On the way, we spot a taxi cartop banner showing Lyft<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> or a bus station ad of a Chanel leather watch</p><ol><li><p>Or, maybe it's a heavy downpour with 50-degree weather in April, so we have no choice but to taxi / rideshare</p></li></ol></li><li><p>During our transit, we might catch eye of a few physical + digital banners, from another hims&amp;hers Subway makeover to an assertive Billions Season 7 collage when stepping off the train. Or if we're in an Uber, we see tablet ads of the Chinese Food we didn't order on Uber Eats last week.</p></li><li><p>A few more Subway and Street ads later, we're finally at the office. All of a sudden, we might be dreading to see that new Season of Billions.</p></li></ol><p>&#8216;Hybrid&#8217; advertising&#8212;the blend of physical everyday and digital ads&#8212;has officially slid into our subconscious shopping DMs. </p><h2>Some Quirky Context</h2><p>Let&#8217;s talk about how this came to be from a more dystopian lens. </p><p>Before the advent of the open web&#8212;what George Lucas might have christened &#8216;Episode III - Revenge of the Mainframe Computer&#8217;&#8212;most of us would have appreciated a well-designed physical billboard or flyer. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9MN6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9MN6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg 424w, https://substackcdn.com/image/fetch/$s_!9MN6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg 848w, https://substackcdn.com/image/fetch/$s_!9MN6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!9MN6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9MN6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg" width="640" height="501" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:501,&quot;width&quot;:640,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;r/StarWarsCantina - a movie theater with a movie poster&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="r/StarWarsCantina - a movie theater with a movie poster" title="r/StarWarsCantina - a movie theater with a movie poster" srcset="https://substackcdn.com/image/fetch/$s_!9MN6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg 424w, https://substackcdn.com/image/fetch/$s_!9MN6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg 848w, https://substackcdn.com/image/fetch/$s_!9MN6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!9MN6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b79e36c-f65b-4561-b7c7-5b134dee07db_640x501.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://www.reddit.com/r/StarWarsCantina/comments/gojy17/from_the_premiere_of_the_empire_strikes_back_the/#lightbox">Source</a></figcaption></figure></div><p>Then, as the open web and social media gradually took over, &#8216;Episode IV - The 2020 Quarantine Hope&#8217; emerged, giving us the &#8216;wake-up call&#8217; that we were spending<em> too much</em> time on digital devices. </p><p>As the pendulum has swung from fully physical to fully digital, we&#8217;re noticing a swing back to middle&#8212;and seeing &#8216;Hybrid&#8217; strike back. </p><div id="youtube2-WKDaNZwfWKg" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;WKDaNZwfWKg&quot;,&quot;startTime&quot;:&quot;3s&quot;,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/WKDaNZwfWKg?start=3s&amp;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></p><h2>Geeking Out on &#8216;Hybrid&#8217; Ads</h2><p>So outside of return-to-office, what specific trends have been driving this?</p><ul><li><p>The rise of transportation and retail giants in the quest to become &#8216;Hybrid Walled Gardens&#8217;. A rideshare is now 20 minutes for a brand to gain a connection with a consumer. A trip to the shopping center is now a 1-hour window for brands to capture our attention.</p></li><li><p>The growing concerns regarding open web advertising, from made-for-advertising (MFA) sites to fraud of multiple categories. This has led marketers to look towards avenues like CTV (Connected TV) and Digital Out-Of-Home (DOOH). </p></li><li><p>The ever-increasing demand for 'Omnichannel' campaigns, with 3+ channel campaigns (i.e. web, Out-of-Home, TV and mobile) now becoming a standard</p><p></p></li></ul><p>Pivoting back to our lovely commute journey, I'm not (yet) convinced to buy Chanel leather watches or switch from Taxi to Lyft. But 1-2-5 years from now, there&#8217;s potential for <em>noticeable </em>improvements:</p><ul><li><p>When entering the subway, we see a well-timed ad addressing our entertainment, safety, or financial worries on the Train. We&#8217;re now thinking about helping a sponsored startup solve homelessness at the root rather than subconsciously averting from it. </p></li><li><p>If I'm waiting at a stoplight, I see a Taxi Cartop signaling a pizza joint 5 blocks away that doesn't have 1-dollar slices priced at $3.25. I&#8217;m sold. </p></li><li><p>While ridesharing, we&#8217;re able to spend 20 minutes enjoying VR/AR experiences that capture the commercial, imaginative, and surreal lenses of the city&#8212;rather than zoning into social media or zoning out about our first stressful meeting</p><p></p></li></ul><h2>Pillars of Success </h2><p>In spirit of a promising consumer shift, below are the pillars that I believe can accelerate the process.  Please keep me honest as we examine each success pillar:</p><ul><li><p><strong>Engagement Infrastructure, measured by Ad Engagement Rate.</strong> Behind every great content graph is an effective engagement mechanism. Many marketers still see Digital Billboards or CTV ads as either hard-to-measure or specifically suited for reach. I&#8217;m a fan of the QR code, but we can do better via the following:</p><ul><li><p>Physical Engagement (engaging our five senses, including touch, voice-activation, and visual such as proximal hand-gestures)</p></li><li><p>Mobile-driven Engagement (i.e. easier ways to use our cameras to search for others&#8217; social posts and reactions related to the ad)</p></li><li><p>Contextual Engagement (i.e. easily engage with the ad&#8217;s &#8216;celebrity&#8217; sponsor and discover related hashtags + stories on our phones)</p></li><li><p>Time-Series Engagement (i.e. reliably measure consumer engagement 5-10-30 minutes after seeing the ad in multiple dimensions)</p></li><li><p>Ad Lifetime Engagement (i.e. eventually track all engagement changes in one place across an ad&#8217;s lifecycle)</p></li></ul></li><li><p><strong>Data Interoperability, measured by % of model conflicts across vendors.</strong> With more AdTech vendors building in-house identity and contextual graphs, we want to ensure that the data is interoperable in the following areas:</p><ul><li><p>Across Walled Gardens (rising and established)</p></li><li><p>Across each stage of the programmatic pipes (i.e. what % of conflicts occur when a new sell-side vendor chooses to activate 3+ buyer eid elements?)</p></li><li><p>Across different channels (i.e. Mobile &lt;&gt; Digital &lt;&gt; Out of Home)</p></li></ul></li><li><p><strong>Ecosystem Efficiency,</strong> <strong>measured by total conflict resolution time across ad vendors. </strong><a href="https://news.marketecture.tv/p/did-it-have-to-be-this-way#this-way">We want to ensure that the infrastructure stack is done right from the start.</a></p></li><li><p><strong>Demand, measured by unique Dynamic-Creative Formats: </strong>With end consumers in mind, how can we creatively cater to real-time goals and pain points in ever-changing environments? Below are some possibilities: </p><ul><li><p>Real-Time Ad Adjustments: Ads that can adjust to real-time events or even showcase a collage of meaningful engagement across social media</p></li><li><p>Crowdsourcing: Enabling influencers and SMBs to represent brands in a scalable fashion</p></li><li><p>Generative AI: How can multiple generative tools work together to help marketers serve the best creative?</p></li><li><p>AR/VR and Interactive Formats: I.e. A kiosk ad recently allowed people to swipe payment cards to aid nonprofits and show immediate impact</p></li></ul></li></ul><p>There&#8217;s one last silent but universal success pillar: adoption health, which is technology awareness down the funnel from key decision makers (i.e. real estate owners of digital billboards). Promising technology, as we know very well, is merely the opening. </p><h2>What&#8217;s Next</h2><p>With more and more of us experiencing Hybrid environments, we'll have to wait and see if it&#8217;s either a 5-year company mandate or a greater consumer shift. I&#8217;m excited to see how this paradigm unfolds without any quirky episodes. Thanks for reading.</p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>Lyft has upgraded their cartop displays recently, perhaps to about 5-6 different ads every few hours</p></div></div>]]></content:encoded></item><item><title><![CDATA[Deep-Dive: Creating a Document AI Prototype ]]></title><description><![CDATA[Surprisingly simpler than the title suggests]]></description><link>https://jeradlu.substack.com/p/deep-dive-creating-a-document-ai</link><guid isPermaLink="false">https://jeradlu.substack.com/p/deep-dive-creating-a-document-ai</guid><dc:creator><![CDATA[Jerad Lu]]></dc:creator><pubDate>Thu, 21 Sep 2023 12:02:36 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!l24J!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Update: The GenAI landscape has evolved quite rapidly since this post. There still could be some helpful info, but kindly take everything below with a grain of salt.</em> </p><p>Large Language Models (LLMs) like ChatGPT have now significantly lowered the bar for creating AI prototypes. I can only express appreciation for the meteoric rise of frameworks and communities aimed at helping our AI journey from ground zero all the way to production.  As someone who&#8217;s been a bit behind the curve, I&#8217;ll share my journey of utilizing the popular framework LlamaIndex to get a roughly scalable Document AI prototype to work.</p><h1>Some Background</h1><p>Let&#8217;s talk about the Document AI problem space. Most of us find digging through vast collections of Confluence, Jira, and document spaces to be painful, especially when we&#8217;re just trying to quickly get up to speed on something. At my previous company, perhaps the biggest challenge our product teams faced was digging through fragmented sources of legacy documentation just to understand how to sunset our legacy products. Fortunately, we&#8217;re seeing a major trend in the workplace:</p><ul><li><p>Earlier this year, Atlassian announced its GenAI-assistant <a href="https://www.atlassian.com/blog/announcements/unleashing-power-of-ai">Atlassian Intelligence</a>, enabling users to write simple questions and get quick answers across a company&#8217;s entire Confluence/JIRA space </p></li><li><p>Just this month, Zoom announced its <a href="https://blog.zoom.us/zoom-ai-companion/">AI companion product</a>, allowing users to easily take meeting recordings/transcripts and find the information they need</p></li><li><p>There&#8217;s the big GenAI race between Microsoft and Google to create the most value out of their docs, spreadsheets, and mainstream workplace offerings</p></li><li><p>Finally, most companies are considering building their own GenAI products to help make work tasks easier and faster</p></li></ul><p>This is great. And with companies <a href="https://workspace.google.com/blog/identity-and-security/protecting-your-data-era-generative-ai/">prioritizing AI security and privacy</a>, many of us can feel a bit reassured that this is a promising trend. </p><p>However, this begs the question: With the 10+ GenAI assistants we&#8217;ll eventually have to keep track of, why can&#8217;t we just have <em>one simple</em> tool to do everything? Most of us will reach a point where we get fed up with each company&#8217;s new AI platform; we&#8217;ll just want to get our jobs done. This will certainly be an interesting problem for companies to solve, as we&#8217;re already seeing GenAI assistants becoming fragmented.</p><p>We don&#8217;t know what will eventually happen once everything stabilizes, but we can start experimenting with prototypes to see what&#8217;s initially possible. </p><h1>Prototype Overview</h1><p>The goal of our prototype today is simple. We want it to take in a bunch of uploaded documents and answer any questions about them. And if it shows promise, we can eventually scale it to unify inputs from all data sources (databases, APIs, spaces) and query multiple GenAI products to create the best output.  The prototype&#8212;in its roughest fashion&#8212;will look something like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!l24J!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!l24J!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png 424w, https://substackcdn.com/image/fetch/$s_!l24J!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png 848w, https://substackcdn.com/image/fetch/$s_!l24J!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png 1272w, https://substackcdn.com/image/fetch/$s_!l24J!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!l24J!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png" width="1254" height="714" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:714,&quot;width&quot;:1254,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:56416,&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_!l24J!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png 424w, https://substackcdn.com/image/fetch/$s_!l24J!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png 848w, https://substackcdn.com/image/fetch/$s_!l24J!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png 1272w, https://substackcdn.com/image/fetch/$s_!l24J!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6842ff7b-289a-4cbe-84d7-0ace98676fb2_1254x714.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>If asked how two uploaded files about earnings compare, it will analyze both documents to give me an acceptable answer. </p><p>As you might have guessed, building this from scratch can take a ton of effort:</p><ul><li><p>We first need it to process uploaded documents and make sense of them, regardless of whether they are text, PDF, or doc files. </p></li><li><p>It then needs to store the files and prepare the contents to be LLM-ready. </p></li><li><p>It will then need to work together with an LLM to provide the best answer. If we want to reasonably answer any questions about one or all of the documents uploaded together, the prototype will need to provide the best context possible.</p></li></ul><p>Fortunately, with the help of some popular frameworks and tools, I found this task to be surprisingly reasonable. I&#8217;ll be using <a href="https://docs.llamaindex.ai/en/stable/">Llamaindex&#8217;s framework</a>, which will reduce the backend code we must write by 7-10x. Some platforms like <a href="https://mockitt.wondershare.com/ai-prototype-generator.html">Mockitt</a> may not even require a single line of code to get it up and running. </p><p>We&#8217;ll build this prototype starting with the backend infrastructure, utilizing Llamaindex as the backend to ingest, structure, and access our files. We&#8217;ll then use Flask&#8217;s API Server framework and a rough react frontend to tie everything together. </p><p></p><h2>First Step: Processing and Storing the Documents</h2><p>The first step is to take all of our uploaded documents and store the text in a way that can easily be read by an LLM. Llamaindex can help us accomplish this using 4 major lines of code:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hs2h!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hs2h!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png 424w, https://substackcdn.com/image/fetch/$s_!hs2h!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png 848w, https://substackcdn.com/image/fetch/$s_!hs2h!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png 1272w, https://substackcdn.com/image/fetch/$s_!hs2h!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hs2h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png" width="1137" height="363" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:363,&quot;width&quot;:1137,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:62444,&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_!hs2h!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png 424w, https://substackcdn.com/image/fetch/$s_!hs2h!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png 848w, https://substackcdn.com/image/fetch/$s_!hs2h!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png 1272w, https://substackcdn.com/image/fetch/$s_!hs2h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2fb829-f569-44b0-a423-f15d7db95fcc_1137x363.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Let&#8217;s digest what each of Llamaindex&#8217;s classes (shown in teal above) do:</p><ul><li><p>SimpleDirectoryReader is able to locate documents from a specified directory and read their contents</p></li><li><p>StorageContext is like a router that performs document operations by knowing where and how each document is stored</p></li><li><p>Finally, we use VectorStoreIndex to create indexes out of our documents. First, it breaks the document into small chunks of text as nodes. An example of a node could be [&#8220;the earnings were $200 million&#8221;].  These nodes are then translated into embeddings, which are numerical matrices for LLMs to understand easily. Finally, it stores the nodes and their embeddings into indexes, shown below:</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SvsR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SvsR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png 424w, https://substackcdn.com/image/fetch/$s_!SvsR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png 848w, https://substackcdn.com/image/fetch/$s_!SvsR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png 1272w, https://substackcdn.com/image/fetch/$s_!SvsR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SvsR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png" width="542" height="239.8505747126437" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:385,&quot;width&quot;:870,&quot;resizeWidth&quot;:542,&quot;bytes&quot;:32146,&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_!SvsR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png 424w, https://substackcdn.com/image/fetch/$s_!SvsR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png 848w, https://substackcdn.com/image/fetch/$s_!SvsR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png 1272w, https://substackcdn.com/image/fetch/$s_!SvsR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89bbd20d-7cac-45cf-8ef7-4a9f244825d7_870x385.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Visual representation of an Index</figcaption></figure></div><p></p><p>This brings up the question: <em>why exactly do we need to embed our text? </em>In order for our prototype to create the most accurate answer, it needs to organize all the document data in a way that can easily be used with LLMs. The way LLMs and modern text summarization models train is by learning from <em>a ton</em> of multi-dimensional vectors. Translating the text to vectors allows Llamaindex to best organize and communicate with other LLMs. Fortunately, our VectorStoreIndex class above acts as an embedding model that can translate text into numerical vectors. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fslX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fslX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png 424w, https://substackcdn.com/image/fetch/$s_!fslX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png 848w, https://substackcdn.com/image/fetch/$s_!fslX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png 1272w, https://substackcdn.com/image/fetch/$s_!fslX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fslX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png" width="1083" height="431" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:431,&quot;width&quot;:1083,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:83658,&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_!fslX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png 424w, https://substackcdn.com/image/fetch/$s_!fslX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png 848w, https://substackcdn.com/image/fetch/$s_!fslX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png 1272w, https://substackcdn.com/image/fetch/$s_!fslX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f7ca9d6-70ce-4e39-bb7c-31fe06b288e7_1083x431.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Tying it all together, we can define a simple, re-usable function called <code>insert_into_index()</code> that will take any uploaded document and prepare for its contents to be read by the LLM. It&#8217;ll look somewhat like the below: </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!05fi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!05fi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png 424w, https://substackcdn.com/image/fetch/$s_!05fi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png 848w, https://substackcdn.com/image/fetch/$s_!05fi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png 1272w, https://substackcdn.com/image/fetch/$s_!05fi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!05fi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png" width="1034" height="356" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:356,&quot;width&quot;:1034,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:47188,&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_!05fi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png 424w, https://substackcdn.com/image/fetch/$s_!05fi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png 848w, https://substackcdn.com/image/fetch/$s_!05fi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png 1272w, https://substackcdn.com/image/fetch/$s_!05fi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d8fec3-ddb0-4a95-acc9-0e66a12703ef_1034x356.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>Second Step: Querying </h2><p>So now that the infrastructure is in place, we want to make the prototype answer a question. First, we&#8217;ll need to use an API Server framework like Flask to take in our query text. Setting up Flask looks something like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!h7KT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!h7KT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png 424w, https://substackcdn.com/image/fetch/$s_!h7KT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png 848w, https://substackcdn.com/image/fetch/$s_!h7KT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png 1272w, https://substackcdn.com/image/fetch/$s_!h7KT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!h7KT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png" width="1073" height="350" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:350,&quot;width&quot;:1073,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:29939,&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_!h7KT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png 424w, https://substackcdn.com/image/fetch/$s_!h7KT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png 848w, https://substackcdn.com/image/fetch/$s_!h7KT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png 1272w, https://substackcdn.com/image/fetch/$s_!h7KT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9873b51a-7cd8-471b-976c-cc26fbb9235b_1073x350.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The convenient thing about Flask is that the <code>@app.route() </code>function takes in whatever is passed from the front end and connects it with our existing backend infrastructure. If we run the snippet of code above, since we are defining what happens if nothing is passed, it&#8217;ll return a &#8216;Hello world!&#8217; default.</p><p>From the backend, taking our query and generating a response consists of  these three lines of code:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-r5y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-r5y!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png 424w, https://substackcdn.com/image/fetch/$s_!-r5y!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png 848w, https://substackcdn.com/image/fetch/$s_!-r5y!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png 1272w, https://substackcdn.com/image/fetch/$s_!-r5y!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-r5y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png" width="850" height="129" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:129,&quot;width&quot;:850,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:15812,&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_!-r5y!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png 424w, https://substackcdn.com/image/fetch/$s_!-r5y!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png 848w, https://substackcdn.com/image/fetch/$s_!-r5y!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png 1272w, https://substackcdn.com/image/fetch/$s_!-r5y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff748b1c1-031e-485c-9d9d-366775bb34c3_850x129.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Using Llamaindex&#8217;s VectorStoreIndex class, the query engine takes the query (What did the author do growing up?) and combines it with context from all our uploaded documents to communicate with the LLM. This is essentially how Retrieval-augmented generation (RAG) works, by integrating custom contextual information with the query for an optimal answer. <a href="https://medium.com/better-programming/llamaindex-0-6-0-a-new-query-interface-over-your-data-331996d47e89">The diagram below explains RAG pretty well</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_!RpdS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RpdS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png 424w, https://substackcdn.com/image/fetch/$s_!RpdS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png 848w, https://substackcdn.com/image/fetch/$s_!RpdS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png 1272w, https://substackcdn.com/image/fetch/$s_!RpdS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RpdS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png" width="1147" height="437" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:437,&quot;width&quot;:1147,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:117626,&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_!RpdS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png 424w, https://substackcdn.com/image/fetch/$s_!RpdS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png 848w, https://substackcdn.com/image/fetch/$s_!RpdS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png 1272w, https://substackcdn.com/image/fetch/$s_!RpdS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53a6e4e3-cced-4905-bdf3-eaa6a97a4b84_1147x437.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The main components involved are:</p><ul><li><p>Retriever: It fetches relevant nodes (text blocks) from our document based on the indexes created</p></li><li><p>Response synthesizer: Used for further optimization at scale, by controlling processing and tokenizing parameters to achieve the best performance</p></li><li><p>QueryEngine: Ties everything together and submits the query to the LLM</p></li></ul><p>Utilizing our LLamaindex and Flask building blocks above, we arrive at something like the query function below that allows the prototype to answer our question: </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eKwL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eKwL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png 424w, https://substackcdn.com/image/fetch/$s_!eKwL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png 848w, https://substackcdn.com/image/fetch/$s_!eKwL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png 1272w, https://substackcdn.com/image/fetch/$s_!eKwL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eKwL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png" width="1124" height="381" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:381,&quot;width&quot;:1124,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:68687,&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_!eKwL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png 424w, https://substackcdn.com/image/fetch/$s_!eKwL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png 848w, https://substackcdn.com/image/fetch/$s_!eKwL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png 1272w, https://substackcdn.com/image/fetch/$s_!eKwL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3e5d45a-1bf5-4dff-84d5-91c61a47ff98_1124x381.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>Third Step: Tying it together with a Front-End</h2><p>Now that the backend and API server are set up, we just need a roughly scalable front-end to bring everything together. Its main goals are to (1) handle file uploads and (2) take in our questions. </p><p>Although React is a common choice, any front-end library that integrates well with Flask will do. To handle file uploads, we can use an API call to send any file as an object: </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BOri!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BOri!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png 424w, https://substackcdn.com/image/fetch/$s_!BOri!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png 848w, https://substackcdn.com/image/fetch/$s_!BOri!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png 1272w, https://substackcdn.com/image/fetch/$s_!BOri!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BOri!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png" width="1385" height="533" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:533,&quot;width&quot;:1385,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:69646,&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_!BOri!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png 424w, https://substackcdn.com/image/fetch/$s_!BOri!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png 848w, https://substackcdn.com/image/fetch/$s_!BOri!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png 1272w, https://substackcdn.com/image/fetch/$s_!BOri!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ecdb34f-16ca-411f-bc36-3281e4ec5ff9_1385x533.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>After combining our file upload functionality with a basic question component, we get a roughly working prototype! The main advantage of using React, Flask, and LlamaIndex is that all three technologies can be scaled to accommodate larger data sources of all types. <a href="https://llamahub.ai/">Llama Hub</a> seems to support over 100+ different types of data connectors, so it&#8217;s possible to integrate almost every data source to produce the highest-quality answers.</p><p></p><h2>Conclusion</h2><p>This concludes our attempt at building a document AI prototype. I don&#8217;t believe it&#8217;s going to be long before everyone can build 0-1 prototypes in a matter of hours. Thanks for reading, and if it is of interest, here are two further points of exploration that I recommend:</p><ul><li><p><strong>Breadth: </strong><a href="https://shriftman.substack.com/p/the-building-blocks-of-generative">Building blocks of Generative AI</a> - an overview of the GenAI tech stack and recommendations on how to choose the right technology per use case</p></li><li><p><strong>Depth: </strong><a href="https://www.youtube.com/watch?v=kCc8FmEb1nY&amp;ab_channel=AndrejKarpathy">Let&#8217;s build GPT</a> - perhaps the most  informative deep-dive into the transformer architecture behind LLMs. Opening the video&#8217;s <a href="https://colab.research.google.com/drive/1JMLa53HDuA-i7ZBmqV7ZnA3c_fvtXnx-?usp=sharing">Colab notebook</a> and running anything I didn&#8217;t understand through an LLM (GPT, Bard) helped me immensely. </p></li></ul>]]></content:encoded></item></channel></rss>