<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: PandeyC</title>
    <description>The latest articles on DEV Community by PandeyC (@pandeyc005).</description>
    <link>https://dev.to/pandeyc005</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4012191%2F281ccd97-d952-44e6-bf08-ac37e33fc1b3.png</url>
      <title>DEV Community: PandeyC</title>
      <link>https://dev.to/pandeyc005</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pandeyc005"/>
    <language>en</language>
    <item>
      <title>Give Your Chatbot a Memory in Google Colab Before Your Next AI Interview</title>
      <dc:creator>PandeyC</dc:creator>
      <pubDate>Wed, 15 Jul 2026 13:34:07 +0000</pubDate>
      <link>https://dev.to/pandeyc005/give-your-chatbot-a-memory-in-google-colab-before-your-next-ai-interview-4jbb</link>
      <guid>https://dev.to/pandeyc005/give-your-chatbot-a-memory-in-google-colab-before-your-next-ai-interview-4jbb</guid>
      <description>&lt;p&gt;You don't need a vector database to understand LLM memory.&lt;/p&gt;

&lt;p&gt;You don't need LangChain.&lt;/p&gt;

&lt;p&gt;You don't need an API key.&lt;/p&gt;

&lt;p&gt;You need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Google Colab&lt;/li&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;A conversation that keeps growing&lt;/li&gt;
&lt;li&gt;About 15 minutes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In &lt;a href="https://dev.to/pandeyc005/build-a-rag-system-in-google-colab-before-your-next-ai-interview-3jd3"&gt;an earlier article&lt;/a&gt;, we built the retrieval half of RAG — chunking, embeddings, cosine similarity. This one builds the other half every multi-turn LLM app needs: memory. It's the exact mechanism behind the interview question, "how do you manage memory in an LLM application when conversations get long?"&lt;/p&gt;

&lt;p&gt;Let's build it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Are We Building?
&lt;/h2&gt;

&lt;p&gt;An LLM has no memory of its own. Every call only sees what you send it — the context window. Left alone, a growing conversation does this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Turn 1 → Turn 2 → Turn 3 → ... → Turn 50
              ↓
   Send the full history every time
              ↓
   Context window fills, cost climbs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll build the fix: a token counter, a summarization trigger, and a &lt;code&gt;remember()&lt;/code&gt; function that keeps a conversation coherent without sending everything, every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: A Conversation That Won't Stop Growing
&lt;/h2&gt;

&lt;p&gt;Open a Colab notebook and simulate 50 turns of chat — no API needed yet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;approx_tokens&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;0.75&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# a token is roughly 3/4 of a word
&lt;/span&gt;
&lt;span class="n"&gt;history&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;51&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Question &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; about our product.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;assistant&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Answer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;, referencing prior context.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Total turns stored:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: The Cost of "Just Send Everything"
&lt;/h2&gt;

&lt;p&gt;The simplest memory strategy — an in-context buffer — resends the full history on every call. Let's measure what that actually costs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cost_of_turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n_turns&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;sent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;[:&lt;/span&gt; &lt;span class="n"&gt;n_turns&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;approx_tokens&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;turn_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cost_of_turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;turn_50&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cost_of_turn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Turn 2 cost:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;turn_2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Turn 50 cost:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;turn_50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Turn 50 is&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;turn_50&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;turn_2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;x more expensive than turn 2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it. Turn 50 costs roughly &lt;strong&gt;25x&lt;/strong&gt; what turn 2 costs — because turn 50 resends 49 prior turns as input. This is the token cost blowout, and it's a cost problem, not just a UX one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Add a Summarization Trigger
&lt;/h2&gt;

&lt;p&gt;Once history crosses a token threshold, compress the old turns into a summary and drop the rest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;SUMMARY_THRESHOLD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;  &lt;span class="c1"&gt;# tokens -- small on purpose, so it triggers a few times in 50 turns
&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;summarize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;turns&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;goal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;turns&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;facts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;turns&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;plan&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Goal: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;goal&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; | Facts: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;facts&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;none stated&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; | Compressed &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;turns&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; turns&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;remember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_msg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;convo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;convo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;convo&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;user&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;user_msg&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
    &lt;span class="n"&gt;full_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;convo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;approx_tokens&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;full_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;SUMMARY_THRESHOLD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;summarize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;convo&lt;/span&gt;&lt;span class="p"&gt;[:&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="n"&gt;convo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;convo&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;convo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A real summary can't just be "the last N words" — that's how you lose facts that fell in the &lt;em&gt;middle&lt;/em&gt; of the conversation. LLMs already attend poorly to the middle of a long context (a property called "lost in the middle"); a lossy summary makes it worse. A summary that survives should always carry four things: the user's goal, key decisions made, open items, and any persistent facts (name, plan tier, stated preferences). Drop any of those and the assistant re-asks a question it already answered.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Watch the Cost Curve Bend
&lt;/h2&gt;

&lt;p&gt;Re-run the growing conversation, but through &lt;code&gt;remember()&lt;/code&gt; this time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;convo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;
&lt;span class="n"&gt;costs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;51&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;convo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;remember&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Question &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;convo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;convo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;role&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;assistant&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Answer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="n"&gt;sent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;summary&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;convo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;costs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;approx_tokens&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Turn 2 cost:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;costs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Turn 50 cost:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;costs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;49&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare &lt;code&gt;costs[49]&lt;/code&gt; here to &lt;code&gt;turn_50&lt;/code&gt; from Step 2 — roughly 28 tokens against roughly 666. It doesn't keep climbing — it stays bounded, because old turns keep getting folded into a fixed-size summary instead of piling up forever.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make It Reusable
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;remember()&lt;/code&gt; is already the reusable piece. In a real app, &lt;code&gt;summarize()&lt;/code&gt; is one extra LLM call instead of the string-matching stub above — same shape, smarter compression. Everything else — the threshold check, the token counter, the trigger — stays exactly as it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Five Colab Experiments to Try
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Set &lt;code&gt;SUMMARY_THRESHOLD = 100&lt;/code&gt; and then &lt;code&gt;1000&lt;/code&gt;. Watch summarization trigger less and less — this threshold is a real production tuning knob.&lt;/li&gt;
&lt;li&gt;Put a fact in turn 1 ("I'm on the Enterprise plan"), then run 30 turns and print &lt;code&gt;summary&lt;/code&gt; after each compression. It survives the &lt;em&gt;first&lt;/em&gt; compression — then quietly disappears on the second one, because &lt;code&gt;summarize()&lt;/code&gt; only reads the current window, not the running summary. Watch it happen.&lt;/li&gt;
&lt;li&gt;Now fix it: change &lt;code&gt;summarize()&lt;/code&gt; to also accept the current &lt;code&gt;summary&lt;/code&gt; string and fold its contents into the new one, instead of overwriting it. Rerun the same 30-turn test — the fact should survive indefinitely this time.&lt;/li&gt;
&lt;li&gt;Print &lt;code&gt;costs&lt;/code&gt; from Step 4 next to &lt;code&gt;[cost_of_turn(n) for n in range(1, 51)]&lt;/code&gt; from Step 2. Chart both — that's the cost-vs-turn graph an interviewer is picturing when they ask about scaling memory.&lt;/li&gt;
&lt;li&gt;Add a &lt;code&gt;user_memory.json&lt;/code&gt; file that saves one fact outside &lt;code&gt;history&lt;/code&gt;/&lt;code&gt;summary&lt;/code&gt; entirely, and load it into a fresh &lt;code&gt;convo&lt;/code&gt;/&lt;code&gt;summary&lt;/code&gt; pair on a new run — that's semantic memory (persists across sessions), as opposed to episodic memory (resets with the conversation).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Interview Questions Hidden Inside This Notebook
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Why not just use a bigger context window?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cost and attention. A 200K-token context costs far more per call than a 4K one when full, and "lost in the middle" gets worse, not better, as the window grows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's the difference between an in-context buffer and summarization memory?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A buffer resends everything and is simplest but unbounded in cost. Summarization compresses old turns into a fixed-size summary once a token threshold is crossed, keeping cost roughly flat.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is "lost in the middle"?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even when a full context fits the window, models recall the beginning and end more reliably than the middle. Summaries have to explicitly preserve key facts — not just compress chronologically — or those facts vanish first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is memory design a cost decision or a UX decision?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Both, but cost drives the threshold. Turn 50 on a raw buffer can cost 25x turn 2 — that's a unit-economics problem before it's ever a UX one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's the difference between episodic and semantic memory?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Episodic memory is what happened this conversation and resets at session end. Semantic memory is persistent facts about the user (plan tier, preferences) that survive across sessions and get injected as context at the start of a new one.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Memory Manager Is the Easy Part
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;remember()&lt;/code&gt; function above is maybe fifteen lines. A production memory layer also has to handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;context poisoning — a bad instruction from turn 1 surviving into every later summary&lt;/li&gt;
&lt;li&gt;composite retrieval queries — for external/vector memory, a follow-up like "show me another one" has no retrieval signal on its own, so the query needs the summary plus the last couple of turns, not just the latest message&lt;/li&gt;
&lt;li&gt;validating that summaries never overwrite system rules with user-turn content&lt;/li&gt;
&lt;li&gt;knowing when to graduate: buffer for short sessions, summarization once you cross a few thousand tokens, external retrieval only once sessions span hours or multiple visits&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Interviewers ask about these because they want to know you've operated a system like this, not just described one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Want to Go Deeper?
&lt;/h2&gt;

&lt;p&gt;If running this left you asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How do I pick a good summarization threshold for my actual traffic?&lt;/p&gt;

&lt;p&gt;When do I need external memory instead of summarization?&lt;/p&gt;

&lt;p&gt;How do I test that my summary isn't silently dropping facts?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Those are exactly the questions the full session covers — plus the 5-beat interview answer for "how do you manage memory in an LLM application":&lt;/p&gt;

&lt;p&gt;&lt;a href="https://confidentprep.com/courses/ai-ml-for-interview/4-context-and-memory-management/" rel="noopener noreferrer"&gt;https://confidentprep.com/courses/ai-ml-for-interview/4-context-and-memory-management/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you'd rather work through this with other developers and ask questions live, join one of the upcoming live sessions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://confidentprep.com/live/" rel="noopener noreferrer"&gt;https://confidentprep.com/live/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Build the small version first. Watch it break at turn 50. Then learn how to explain why — that's a better way to prepare for an AI interview than memorizing another list of memory-management definitions.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>tutorial</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>AI Is Creating More Opportunities Than We Realize</title>
      <dc:creator>PandeyC</dc:creator>
      <pubDate>Tue, 14 Jul 2026 16:35:44 +0000</pubDate>
      <link>https://dev.to/pandeyc005/ai-is-creating-more-opportunities-than-we-realize-10cg</link>
      <guid>https://dev.to/pandeyc005/ai-is-creating-more-opportunities-than-we-realize-10cg</guid>
      <description>&lt;p&gt;The biggest fear around AI is simple: &lt;strong&gt;If two people with AI can do the work of ten people, what happens to the other eight?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is a valid concern. AI will automate tasks. Some teams will shrink. Some skills will lose value.&lt;/p&gt;

&lt;p&gt;But almost every discussion about AI replacing jobs makes one major assumption:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The amount of software the world wants to build will remain constant.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I don't think it will.&lt;/p&gt;

&lt;p&gt;When building becomes dramatically cheaper, we don't just build the same things with fewer people. &lt;strong&gt;We build more things.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. One Startup Needed 10 People. Now One Founder Can Build Four Startups.
&lt;/h2&gt;

&lt;p&gt;Imagine that building a software company previously required ten people. Today, AI coding agents, cloud platforms, automation, and AI-powered support might allow two or three people to build the same product.&lt;/p&gt;

&lt;p&gt;The obvious conclusion is: &lt;strong&gt;eight jobs disappeared.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;But consider another possibility. What if the founder who could previously afford to build &lt;strong&gt;one startup can now launch four products in parallel?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Before:&lt;/strong&gt; 1 startup × 10 people = 10 opportunities&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;After:&lt;/strong&gt; 4 startups × 2–3 people = 8–12 opportunities&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The individual companies became smaller, but the number of companies, products, and experiments increased.&lt;/p&gt;

&lt;p&gt;We are already seeing early signs of this. In 2026, the startup JustPaid reportedly created a team of seven AI coding agents using OpenClaw and Claude Code. In one month, those agents built 10 major features.&lt;/p&gt;

&lt;p&gt;Instead of eliminating every human role, the company redirected people toward higher-priority customer work and even hired a new developer who was trained largely by the AI agents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI doesn't only reduce the number of people required to build something. It increases the number of things people can afford to build.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. We Have Seen This Before With Cloud Computing
&lt;/h2&gt;

&lt;p&gt;Before cloud computing, companies needed people to buy and install servers, manage operating systems, configure networks, maintain storage and backups, provision infrastructure, and operate physical data centers.&lt;/p&gt;

&lt;p&gt;Cloud computing automated or eliminated many of these responsibilities.&lt;/p&gt;

&lt;p&gt;But the technology industry did not disappear. Instead, we created new careers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cloud engineers and solution architects&lt;/li&gt;
&lt;li&gt;DevOps, platform, and Site Reliability Engineers&lt;/li&gt;
&lt;li&gt;Cloud security specialists&lt;/li&gt;
&lt;li&gt;Infrastructure automation and Kubernetes engineers&lt;/li&gt;
&lt;li&gt;FinOps engineers and cloud consultants&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cloud computing removed work, but it also made technology cheaper and accessible to millions of additional companies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI could create the same transformation—much faster.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Millions of AI Agents Will Need Humans Around Them
&lt;/h2&gt;

&lt;p&gt;We are moving from AI systems that answer questions to AI agents that take actions.&lt;/p&gt;

&lt;p&gt;Agents can deploy infrastructure, modify production systems, process customer requests, approve transactions, access company data, and create cloud resources.&lt;/p&gt;

&lt;p&gt;Now imagine an AI cloud agent making the wrong decision. It could delete production infrastructure or create millions of dollars in cloud costs.&lt;/p&gt;

&lt;p&gt;Or imagine a support agent processing one million tickets with a 2% serious error rate. That is &lt;strong&gt;20,000 incorrect decisions.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Someone still has to answer critical questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is the agent safe enough to deploy?&lt;/li&gt;
&lt;li&gt;Which actions can it perform autonomously?&lt;/li&gt;
&lt;li&gt;Which actions require human approval?&lt;/li&gt;
&lt;li&gt;How much money or infrastructure can it control?&lt;/li&gt;
&lt;li&gt;Who monitors its behavior?&lt;/li&gt;
&lt;li&gt;Who investigates failures?&lt;/li&gt;
&lt;li&gt;Who stops it when something goes wrong?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The more autonomous AI becomes, the more valuable human judgment becomes.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The AI Evaluation and Security Economy Is Just Beginning
&lt;/h2&gt;

&lt;p&gt;Traditional software testing will not be enough. AI systems are probabilistic, and agents increasingly have access to real tools, money, infrastructure, and data.&lt;/p&gt;

&lt;p&gt;We will need people and platforms focused on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AI evaluations and continuous testing&lt;/li&gt;
&lt;li&gt;Agent observability and monitoring&lt;/li&gt;
&lt;li&gt;Guardrails and permission boundaries&lt;/li&gt;
&lt;li&gt;Human-in-the-loop approval systems&lt;/li&gt;
&lt;li&gt;AI security and prompt-injection defense&lt;/li&gt;
&lt;li&gt;Cost controls and anomaly detection&lt;/li&gt;
&lt;li&gt;Audit trails, compliance, and governance&lt;/li&gt;
&lt;li&gt;Red teaming and failure investigation&lt;/li&gt;
&lt;li&gt;Rollback and recovery mechanisms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cloud computing created cloud security. APIs created API security. Containers created container security. AI agents will create entirely new security, governance, and operational problems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Automation does not eliminate responsibility. It increases the scale at which mistakes can happen.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Solving these problems will create companies, products, and careers that barely exist today.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. The Biggest Advantage Will Belong to People Who Keep Learning
&lt;/h2&gt;

&lt;p&gt;AI is moving incredibly fast. Skills that are valuable today may become automated tomorrow.&lt;/p&gt;

&lt;p&gt;That creates an unusual opportunity because nobody has twenty years of experience building production AI agents, agent observability platforms, AI evaluation systems, or AI-native software companies.&lt;/p&gt;

&lt;p&gt;The playing field has partially reset.&lt;/p&gt;

&lt;p&gt;Young professionals can enter emerging fields before established career paths exist. Experienced professionals can combine decades of engineering and business judgment with powerful AI tools.&lt;/p&gt;

&lt;p&gt;The advantage will not automatically belong to the youngest or most experienced person.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It will belong to the person willing to keep learning.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Don't Compete With AI. Become Excellent at Using It.
&lt;/h2&gt;

&lt;p&gt;If AI becomes excellent at generating repetitive code, don't build your entire career around writing repetitive code. Move one level higher.&lt;/p&gt;

&lt;p&gt;Learn how to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build real systems using AI&lt;/li&gt;
&lt;li&gt;Evaluate and monitor AI agents&lt;/li&gt;
&lt;li&gt;Secure autonomous systems&lt;/li&gt;
&lt;li&gt;Design human-in-the-loop workflows&lt;/li&gt;
&lt;li&gt;Integrate AI with real businesses&lt;/li&gt;
&lt;li&gt;Identify valuable problems worth solving&lt;/li&gt;
&lt;li&gt;Use AI to launch products that were previously too expensive to build&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The most valuable technology professional of the AI era may not be the person who writes the most code.&lt;/p&gt;

&lt;p&gt;It may be the person who knows:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What should we build? How can AI help us build it? How do we know it actually works? And how do we operate it safely at scale?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;AI will eliminate some jobs. But it will also make thousands of new products economically possible.&lt;/p&gt;

&lt;p&gt;Those products will need to be built, integrated, evaluated, secured, monitored, governed, improved, and turned into businesses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The amount of opportunity in the world is not fixed.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AI is expanding what individuals and small teams can attempt to build. The biggest opportunity is not in competing with the tool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It is in becoming exceptionally good at using it.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Want to Start Learning AI?
&lt;/h2&gt;

&lt;p&gt;The best way to prepare for the AI era is to start building, experimenting, and learning how these systems actually work.&lt;/p&gt;

&lt;p&gt;If you prefer learning interactively, &lt;strong&gt;join the upcoming live AI sessions:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://confidentprep.com/live/" rel="noopener noreferrer"&gt;https://confidentprep.com/live/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or learn at your own pace with &lt;strong&gt;self-paced AI courses and practical assignments:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://confidentprep.com/courses/" rel="noopener noreferrer"&gt;https://confidentprep.com/courses/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don't wait until AI changes your role to start learning AI. Start learning how to use it now.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>career</category>
      <category>discuss</category>
      <category>interview</category>
    </item>
    <item>
      <title>This RAG Interview Question Looks Simple. Many Candidates Still Get It Wrong.</title>
      <dc:creator>PandeyC</dc:creator>
      <pubDate>Tue, 14 Jul 2026 16:18:15 +0000</pubDate>
      <link>https://dev.to/pandeyc005/this-rag-interview-question-looks-simple-many-candidates-still-get-it-wrong-1d14</link>
      <guid>https://dev.to/pandeyc005/this-rag-interview-question-looks-simple-many-candidates-still-get-it-wrong-1d14</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;You have converted 10,000 documents into embeddings and stored them in a vector database. A user asks a question. Explain exactly how the system finds the most relevant chunks to send to the LLM.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Could you answer this clearly in an interview?&lt;/p&gt;

&lt;p&gt;Not just say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We perform semantic search."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But explain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;what happens to the user's question&lt;/li&gt;
&lt;li&gt;why the question must be converted into an embedding&lt;/li&gt;
&lt;li&gt;how it is compared with stored document embeddings&lt;/li&gt;
&lt;li&gt;what cosine similarity is doing&lt;/li&gt;
&lt;li&gt;how the chunks are ranked&lt;/li&gt;
&lt;li&gt;what Top-K retrieval means&lt;/li&gt;
&lt;li&gt;and what is finally sent to the LLM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;You could easily answer if you read this article:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/pandeyc005/build-a-rag-system-in-google-colab-before-your-next-ai-interview-3jd3"&gt;Build a RAG System in Google Colab Before Your Next AI Interview&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The article makes you build the entire retrieval flow yourself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Documents
    ↓
Chunks
    ↓
Embeddings
    ↓
User Question
    ↓
Query Embedding
    ↓
Cosine Similarity
    ↓
Ranked Chunks
    ↓
Top-K Results
    ↓
LLM Prompt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this is exactly why building a small RAG system before an AI interview is useful.&lt;/p&gt;

&lt;p&gt;Many candidates know the architecture diagram.&lt;/p&gt;

&lt;p&gt;Far fewer can explain what actually happens between:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Question → Vector Search → Retrieved Context
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you implement it yourself, questions about embeddings, similarity search, Top-K retrieval, chunking, and context construction become much easier to answer.&lt;/p&gt;

&lt;p&gt;But here is the follow-up question interviewers may ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;If the most relevant chunk is ranked #6, but your system retrieves only Top-5 chunks, what happens? How would you improve the system?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now the discussion moves into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;choosing &lt;code&gt;top_k&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;retrieval recall&lt;/li&gt;
&lt;li&gt;reranking&lt;/li&gt;
&lt;li&gt;hybrid search&lt;/li&gt;
&lt;li&gt;better chunking&lt;/li&gt;
&lt;li&gt;metadata filtering&lt;/li&gt;
&lt;li&gt;retrieval evaluation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is where understanding RAG becomes more important than simply knowing how to call a vector database.&lt;/p&gt;

&lt;p&gt;If you're preparing for AI/ML interviews, you can continue learning about embeddings, vector search, and RAG here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://confidentprep.com/courses/ai-ml-for-interview/3-embeddings-and-rag/" rel="noopener noreferrer"&gt;Embeddings and RAG Interview Preparation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you'd like to practice these concepts through live discussions and interview questions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://confidentprep.com/live/" rel="noopener noreferrer"&gt;Attend an Upcoming Free Live Session&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>interview</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Build a RAG System in Google Colab Before Your Next AI Interview</title>
      <dc:creator>PandeyC</dc:creator>
      <pubDate>Sun, 12 Jul 2026 17:35:47 +0000</pubDate>
      <link>https://dev.to/pandeyc005/build-a-rag-system-in-google-colab-before-your-next-ai-interview-3jd3</link>
      <guid>https://dev.to/pandeyc005/build-a-rag-system-in-google-colab-before-your-next-ai-interview-3jd3</guid>
      <description>&lt;p&gt;You don't need to study machine learning for six months to understand RAG.&lt;/p&gt;

&lt;p&gt;You don't need Kubernetes.&lt;/p&gt;

&lt;p&gt;You don't need a vector database.&lt;/p&gt;

&lt;p&gt;You don't even need an OpenAI API key.&lt;/p&gt;

&lt;p&gt;You need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Google Colab&lt;/li&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;A few paragraphs of text&lt;/li&gt;
&lt;li&gt;About 20 minutes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By the end of this article, you will have built the core retrieval mechanism behind a RAG system.&lt;/p&gt;

&lt;p&gt;More importantly, you will understand what is actually happening when someone says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"We convert documents into embeddings, store them in a vector database, retrieve relevant chunks, and send them to an LLM."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's build it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Are We Building?
&lt;/h2&gt;

&lt;p&gt;Imagine that we have a small knowledge base about AWS services.&lt;/p&gt;

&lt;p&gt;A user asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Which AWS service should I use to decouple applications?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Our system will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Break documents into chunks.&lt;/li&gt;
&lt;li&gt;Convert the chunks into embeddings.&lt;/li&gt;
&lt;li&gt;Convert the question into an embedding.&lt;/li&gt;
&lt;li&gt;Compare the question with every chunk.&lt;/li&gt;
&lt;li&gt;Retrieve the most relevant chunks.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That is the &lt;strong&gt;retrieval&lt;/strong&gt; part of Retrieval-Augmented Generation.&lt;/p&gt;

&lt;p&gt;The architecture looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Documents
    ↓
Chunking
    ↓
Embeddings
    ↓
Vector Store

User Question
    ↓
Question Embedding
    ↓
Similarity Search
    ↓
Relevant Chunks
    ↓
LLM
    ↓
Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a production application, you might use Pinecone, OpenSearch, pgvector, Qdrant, or another vector database.&lt;/p&gt;

&lt;p&gt;For learning, we don't need any of them.&lt;/p&gt;

&lt;p&gt;We will store our embeddings in memory and use cosine similarity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Open Google Colab
&lt;/h2&gt;

&lt;p&gt;Create a new Google Colab notebook.&lt;/p&gt;

&lt;p&gt;Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="n"&gt;sentence&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;transformers&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will use the &lt;code&gt;sentence-transformers&lt;/code&gt; library to generate embeddings.&lt;/p&gt;

&lt;p&gt;No API key is required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create Our Knowledge Base
&lt;/h2&gt;

&lt;p&gt;Let's create a tiny collection of documents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;documents&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Amazon S3 is an object storage service designed for storing
    and retrieving files. It provides high durability and is
    commonly used for backups, static websites, data lakes,
    and application assets.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Amazon SQS is a managed message queue service.

    It allows applications to communicate asynchronously.

    Producers send messages to a queue and consumers process
    those messages independently.

    SQS is commonly used to decouple distributed applications.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    AWS Lambda is a serverless compute service.

    Developers upload code and AWS executes the code in response
    to events.

    Lambda automatically manages servers and scales applications
    based on incoming requests.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Amazon DynamoDB is a managed NoSQL database.

    It provides low-latency access to data and automatically
    scales to handle large workloads.
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obviously, real RAG systems contain thousands or millions of documents.&lt;/p&gt;

&lt;p&gt;But the mechanism is exactly the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Chunk the Documents
&lt;/h2&gt;

&lt;p&gt;Why do we need chunks?&lt;/p&gt;

&lt;p&gt;Because embedding an entire book or a 200-page PDF as one vector would produce a poor representation for individual questions.&lt;/p&gt;

&lt;p&gt;Instead, RAG systems divide documents into smaller pieces.&lt;/p&gt;

&lt;p&gt;Let's write a very simple chunker.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;chunk_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chunk_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;chunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;chunk_size&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;chunk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;chunk_size&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
        &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;


&lt;span class="n"&gt;chunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;document&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;documents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;chunk_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;


&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Number of chunks:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;chunk&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;CHUNK &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Production systems usually use more sophisticated strategies.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;token-based chunking&lt;/li&gt;
&lt;li&gt;overlapping chunks&lt;/li&gt;
&lt;li&gt;recursive text splitting&lt;/li&gt;
&lt;li&gt;semantic chunking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But our goal is to understand the mechanism first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Generate Embeddings
&lt;/h2&gt;

&lt;p&gt;Now we need to convert text into vectors.&lt;/p&gt;

&lt;p&gt;We will use a small embedding model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sentence_transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;SentenceTransformer&lt;/span&gt;

&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SentenceTransformer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;all-MiniLM-L6-v2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now generate embeddings for our chunks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;chunk_embeddings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;chunk_embeddings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something similar to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(4, 384)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What does that mean?&lt;/p&gt;

&lt;p&gt;We have four chunks.&lt;/p&gt;

&lt;p&gt;Each chunk has been converted into a vector containing 384 numbers.&lt;/p&gt;

&lt;p&gt;Something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0.023, -0.041, 0.087, ...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Humans cannot interpret these numbers directly.&lt;/p&gt;

&lt;p&gt;But mathematically, texts with similar meanings tend to have vectors that are closer together.&lt;/p&gt;

&lt;p&gt;That is what makes semantic search possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Ask a Question
&lt;/h2&gt;

&lt;p&gt;Let's ask:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;question&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Which AWS service can help decouple applications?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Convert the question into an embedding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;question_embedding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Documents → Vectors

Question → Vector
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to find which document vectors are closest to the question vector.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Perform Similarity Search
&lt;/h2&gt;

&lt;p&gt;We will use cosine similarity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.metrics.pairwise&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;cosine_similarity&lt;/span&gt;

&lt;span class="n"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cosine_similarity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;question_embedding&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;chunk_embeddings&lt;/span&gt;
&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's inspect the results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;][:&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see the SQS document receive the highest similarity score.&lt;/p&gt;

&lt;p&gt;Now retrieve the best chunk.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;best_chunk_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;argmax&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;retrieved_chunk&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;best_chunk_index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retrieved_chunk&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations.&lt;/p&gt;

&lt;p&gt;You just built semantic retrieval.&lt;/p&gt;

&lt;p&gt;This is the foundation of a RAG system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Make It Reusable
&lt;/h2&gt;

&lt;p&gt;Let's wrap everything into a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;top_k&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;question_embedding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

    &lt;span class="n"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cosine_similarity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;question_embedding&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;chunk_embeddings&lt;/span&gt;
    &lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="n"&gt;top_indices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;argsort&lt;/span&gt;&lt;span class="p"&gt;()[::&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;][:&lt;/span&gt;&lt;span class="n"&gt;top_k&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;top_indices&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;score&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now try asking different questions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;questions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Where should I store application files?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;How can I run code without managing servers?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Which database provides low latency access?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;How can microservices communicate asynchronously?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;questions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;QUESTION:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;score&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][:&lt;/span&gt;&lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You now have a tiny semantic search engine.&lt;/p&gt;

&lt;h2&gt;
  
  
  But Where Is the LLM?
&lt;/h2&gt;

&lt;p&gt;This is where many developers misunderstand RAG.&lt;/p&gt;

&lt;p&gt;The vector database does not answer the question.&lt;/p&gt;

&lt;p&gt;The embedding model does not answer the question.&lt;/p&gt;

&lt;p&gt;The retrieval system finds relevant information.&lt;/p&gt;

&lt;p&gt;The retrieved information is then placed into the prompt sent to the LLM.&lt;/p&gt;

&lt;p&gt;Conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;build_prompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;retrieved_chunks&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;

    &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retrieved_chunks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Answer the question using only the context below.

    CONTEXT:

    &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;

    QUESTION:

    &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;prompt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's generate the prompt.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;question&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Which AWS service should I use to decouple applications?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;retrieved_chunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;prompt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;build_prompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;retrieved_chunks&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prompt could now be sent to an LLM.&lt;/p&gt;

&lt;p&gt;That completes the RAG pipeline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Documents
    ↓
Chunks
    ↓
Embeddings
    ↓
Vector Search
    ↓
Relevant Context
    ↓
Prompt
    ↓
LLM
    ↓
Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Five Experiments You Should Try
&lt;/h2&gt;

&lt;p&gt;Don't stop after running the notebook.&lt;/p&gt;

&lt;p&gt;Change it.&lt;/p&gt;

&lt;p&gt;First, add documents that use similar terminology.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SQS decouples applications.

EventBridge connects applications using events.

SNS distributes messages to multiple subscribers.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Does the correct document still rank first?&lt;/p&gt;

&lt;p&gt;Second, change the chunk size.&lt;/p&gt;

&lt;p&gt;Try:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;chunk_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;chunk_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happens to retrieval quality?&lt;/p&gt;

&lt;p&gt;Third, retrieve more documents.&lt;/p&gt;

&lt;p&gt;Change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;top_k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;top_k&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Would sending more context always produce a better answer?&lt;/p&gt;

&lt;p&gt;Fourth, add irrelevant documents.&lt;/p&gt;

&lt;p&gt;Does retrieval quality change?&lt;/p&gt;

&lt;p&gt;Fifth, ask ambiguous questions.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Which service should I use for messaging?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you are starting to encounter the problems that real RAG systems must solve.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Interview Questions Hidden Inside This Project
&lt;/h2&gt;

&lt;p&gt;If you understand the notebook above, you should be able to discuss several common AI interview questions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do RAG systems chunk documents?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because retrieval usually needs to identify specific passages rather than entire documents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is an embedding?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A numerical representation of data that allows semantic relationships to be compared mathematically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why use cosine similarity?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because it measures the direction between vectors and is commonly used to compare embedding similarity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does a vector database generate answers?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No.&lt;/p&gt;

&lt;p&gt;It stores vectors and helps retrieve relevant information.&lt;/p&gt;

&lt;p&gt;The LLM generates the answer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does retrieving more chunks always improve the answer?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No.&lt;/p&gt;

&lt;p&gt;More context can increase cost, introduce irrelevant information, and make it harder for the model to identify the useful evidence.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens when the correct document isn't retrieved?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The LLM never receives the information required to answer correctly.&lt;/p&gt;

&lt;p&gt;This is why evaluating retrieval quality is one of the most important parts of building a production RAG system.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 20-Line Demo Is the Easy Part
&lt;/h2&gt;

&lt;p&gt;You can build a RAG demo in twenty minutes.&lt;/p&gt;

&lt;p&gt;Production RAG systems are harder.&lt;/p&gt;

&lt;p&gt;You have to make decisions about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;chunk size and overlap&lt;/li&gt;
&lt;li&gt;embedding models&lt;/li&gt;
&lt;li&gt;metadata filtering&lt;/li&gt;
&lt;li&gt;top-k retrieval&lt;/li&gt;
&lt;li&gt;similarity thresholds&lt;/li&gt;
&lt;li&gt;hybrid search&lt;/li&gt;
&lt;li&gt;reranking&lt;/li&gt;
&lt;li&gt;context-window management&lt;/li&gt;
&lt;li&gt;hallucination control&lt;/li&gt;
&lt;li&gt;retrieval evaluation&lt;/li&gt;
&lt;li&gt;answer evaluation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And interviewers increasingly ask about these trade-offs.&lt;/p&gt;

&lt;p&gt;Not because they expect you to memorize definitions.&lt;/p&gt;

&lt;p&gt;They want to know whether you understand how the system behaves.&lt;/p&gt;

&lt;h2&gt;
  
  
  Want to Go Deeper?
&lt;/h2&gt;

&lt;p&gt;If you ran this notebook and found yourself asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How should I choose chunk size?&lt;/p&gt;

&lt;p&gt;When should I use a vector database?&lt;/p&gt;

&lt;p&gt;How do I know whether retrieval is actually working?&lt;/p&gt;

&lt;p&gt;What is the difference between semantic search, hybrid search, and reranking?&lt;/p&gt;

&lt;p&gt;How would I design this system for thousands or millions of documents?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Those are exactly the questions worth exploring next.&lt;/p&gt;

&lt;p&gt;I'm covering embeddings, vector search, RAG architecture, and the engineering decisions behind production AI systems on ConfidentPrep.&lt;/p&gt;

&lt;p&gt;You can explore the deeper RAG learning material here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://confidentprep.com/courses/ai-ml-for-interview/3-embeddings-and-rag/" rel="noopener noreferrer"&gt;https://confidentprep.com/courses/ai-ml-for-interview/3-embeddings-and-rag/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you'd rather learn by discussing these concepts live, asking questions, and working through interview scenarios with other developers, join one of the upcoming live sessions:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://confidentprep.com/live/" rel="noopener noreferrer"&gt;https://confidentprep.com/live/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Build the small version first.&lt;/p&gt;

&lt;p&gt;Understand why it works.&lt;/p&gt;

&lt;p&gt;Then learn how to explain the trade-offs.&lt;/p&gt;

&lt;p&gt;That's a much better way to prepare for an AI interview than memorizing another list of 100 RAG questions.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Your New Prompt 'Feels' Better. That's Not an Eval.</title>
      <dc:creator>PandeyC</dc:creator>
      <pubDate>Sat, 11 Jul 2026 14:59:57 +0000</pubDate>
      <link>https://dev.to/pandeyc005/your-new-prompt-feels-better-thats-not-an-eval-3gan</link>
      <guid>https://dev.to/pandeyc005/your-new-prompt-feels-better-thats-not-an-eval-3gan</guid>
      <description>&lt;p&gt;You tweak the prompt. Run it against the three examples you always use to sanity-check. It looks better. Ship it.&lt;/p&gt;

&lt;p&gt;That's not evaluation. That's vibes with extra steps — and it's the exact habit interviewers are trained to catch with one question.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🎯 &lt;strong&gt;TL;DR:&lt;/strong&gt; One interview question, one real framework: don't trust "it looks better on my usual examples" — build a small eval set, score it the same way every time, and re-run it on every future change. Read the framework, then use it as the literal answer next time someone asks.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  🎭 The question: "How do you know your new prompt is actually better — not just better on the five examples you tried by hand?"
&lt;/h2&gt;

&lt;p&gt;This is one of the fastest ways an interviewer separates "I iterate on prompts" from "I've actually shipped prompt changes to production." Everyone iterates. Almost nobody evaluates.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to answer it:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Name the trap first, out loud: eyeballing a handful of hand-picked examples is confirmation bias, not evaluation. You'll always find a few cases where the new version looks better — that's not evidence, that's cherry-picking with good intentions.&lt;/li&gt;
&lt;li&gt;  Describe a minimal eval set: 20-50 real or realistic input/expected-output pairs, run automatically against both the old and new prompt, scored the same way every time — not re-read by eye each round.&lt;/li&gt;
&lt;li&gt;  Say what "scored" actually means, because this is where most candidates go vague: exact match works for structured output (JSON fields, classifications); for open-ended text, you need a similarity or grounding score against a reference answer.&lt;/li&gt;
&lt;li&gt;  Close with the regression angle: the eval set isn't a one-time gate before this ship — it's something you re-run on every future prompt or retrieval change, so a "small tweak" three weeks from now doesn't quietly break something the old version got right.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🕳️ Why "it looked better to me" is losing you the room
&lt;/h2&gt;

&lt;p&gt;Here's the uncomfortable part: this question isn't really testing whether you know what an eval set is. It's testing whether you've been burned by &lt;em&gt;not&lt;/em&gt; having one — shipped a "better" prompt that regressed silently, found out from a user complaint instead of a dashboard. Candidates who've lived that answer differently than candidates who haven't, and interviewers can usually tell within one follow-up question.&lt;/p&gt;

&lt;p&gt;Somewhere in your interview pool right now, another candidate already built that eval habit into their process — not because a course told them to, but because something broke on them once. That's the gap this question is actually measuring.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔧 What the eval set looks like when it's not hypothetical
&lt;/h2&gt;

&lt;p&gt;Skip the abstraction. In practice it's a spreadsheet or a JSON file with columns: input, expected/reference answer, prompt-A output and score, prompt-B output and score. Twenty rows is enough to start. The moment you can point to a number instead of a feeling, you've already answered this question better than most candidates do.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔬 Next: the 12 lines of code that do the scoring
&lt;/h2&gt;

&lt;p&gt;Saying "similarity score" in an interview is good. Being able to sketch the actual code is better — and next week's post is exactly that: a Colab-ready snippet that scores whether a generated answer is actually grounded in retrieved context, the same technique behind the eval-set scoring above.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The takeaway: "it looks better" is an opinion. A score you can re-run is an answer.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[See the paths that build that judgment →]&lt;br&gt;
&lt;a href="https://confidentprep.com/paths?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=launch-echo-general-article" rel="noopener noreferrer"&gt;https://confidentprep.com/paths&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;🔴 Preparing for AI interviews? Don’t prepare alone. Join a live session where we break down real interview questions like this one, discuss how strong candidates structure their answers, and work through the follow-up questions interviewers actually ask. Bring your questions, test your answers, and learn live with other candidates preparing for AI roles.&lt;/p&gt;

&lt;p&gt;👉 Join the next live AI interview prep session → &lt;br&gt;
&lt;a href="https://confidentprep.com/live/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=launch-echo-general-article" rel="noopener noreferrer"&gt;https://confidentprep.com/live/&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;More from &lt;a href="https://confidentprep.com?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=launch-echo-general-article" rel="noopener noreferrer"&gt;https://confidentprep.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>career</category>
      <category>interview</category>
    </item>
    <item>
      <title>Stop Learning Machine Learning Before GenAI 🤖</title>
      <dc:creator>PandeyC</dc:creator>
      <pubDate>Sat, 11 Jul 2026 04:25:49 +0000</pubDate>
      <link>https://dev.to/pandeyc005/stop-learning-machine-learning-before-genai-22gm</link>
      <guid>https://dev.to/pandeyc005/stop-learning-machine-learning-before-genai-22gm</guid>
      <description>&lt;p&gt;Yes, you read that right.&lt;/p&gt;

&lt;p&gt;If your goal is to understand Generative AI, build LLM-powered applications, or prepare for a GenAI interview, &lt;strong&gt;you don't need to finish learning Machine Learning first.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yet many developers get stuck here.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Should I learn statistics first?&lt;br&gt;
Then Machine Learning?&lt;br&gt;
Then Deep Learning?&lt;br&gt;
Then neural networks?&lt;br&gt;
Then transformers?&lt;br&gt;
And finally Generative AI?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This roadmap may make sense if your goal is to become an ML Engineer, Data Scientist, or AI researcher.&lt;/p&gt;

&lt;p&gt;But for many software developers and technology professionals, it creates an unnecessary barrier.&lt;/p&gt;

&lt;p&gt;You keep preparing to start.&lt;/p&gt;

&lt;p&gt;But never actually start.&lt;/p&gt;

&lt;h2&gt;
  
  
  🚧 Don't Let the AI Roadmap Block You
&lt;/h2&gt;

&lt;p&gt;Machine Learning is a large and valuable field.&lt;/p&gt;

&lt;p&gt;But you don't need to master regression, classification algorithms, backpropagation, or the mathematics of neural networks before you can understand how modern GenAI applications work.&lt;/p&gt;

&lt;p&gt;Start with a simpler question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What do I need to understand to build and discuss a GenAI application?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The answer is much more approachable.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧠 Start With Generative AI Fundamentals
&lt;/h2&gt;

&lt;p&gt;Understand the basic concepts first.&lt;/p&gt;

&lt;p&gt;What is Generative AI?&lt;/p&gt;

&lt;p&gt;What is an LLM?&lt;/p&gt;

&lt;p&gt;What is a prompt?&lt;/p&gt;

&lt;p&gt;What are tokens and context windows?&lt;/p&gt;

&lt;p&gt;Why do LLMs hallucinate?&lt;/p&gt;

&lt;p&gt;How does an application communicate with an LLM?&lt;/p&gt;

&lt;p&gt;What happens when you send a prompt and receive a response?&lt;/p&gt;

&lt;p&gt;You don't need to understand every mathematical detail behind the model.&lt;/p&gt;

&lt;p&gt;But you should be able to explain &lt;strong&gt;what these concepts mean, why they matter, and how they affect real applications.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's a good starting point.&lt;/p&gt;

&lt;h2&gt;
  
  
  🛠️ Then Build Something Small
&lt;/h2&gt;

&lt;p&gt;Call an LLM API.&lt;/p&gt;

&lt;p&gt;Send a prompt.&lt;/p&gt;

&lt;p&gt;Get a response.&lt;/p&gt;

&lt;p&gt;Change the prompt and observe what happens.&lt;/p&gt;

&lt;p&gt;Experiment with model parameters.&lt;/p&gt;

&lt;p&gt;Then build a small application.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A document summarizer&lt;/li&gt;
&lt;li&gt;A question-answering application&lt;/li&gt;
&lt;li&gt;A chatbot&lt;/li&gt;
&lt;li&gt;A structured data extraction tool&lt;/li&gt;
&lt;li&gt;A basic RAG application&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While building, you'll naturally encounter new questions.&lt;/p&gt;

&lt;p&gt;How do I provide my own data to an LLM?&lt;/p&gt;

&lt;p&gt;What are embeddings?&lt;/p&gt;

&lt;p&gt;Why do I need a vector database?&lt;/p&gt;

&lt;p&gt;How should documents be chunked?&lt;/p&gt;

&lt;p&gt;How do I reduce hallucinations?&lt;/p&gt;

&lt;p&gt;How do I evaluate the quality of responses?&lt;/p&gt;

&lt;p&gt;How do I protect an application from prompt injection?&lt;/p&gt;

&lt;p&gt;Now you have a reason to learn these concepts.&lt;/p&gt;

&lt;p&gt;You're learning because you need to solve a problem—not because a massive AI roadmap told you to learn everything first.&lt;/p&gt;

&lt;h2&gt;
  
  
  🎯 Preparing for a GenAI Interview?
&lt;/h2&gt;

&lt;p&gt;The same principle applies.&lt;/p&gt;

&lt;p&gt;Don't wait until you know everything about Machine Learning before preparing.&lt;/p&gt;

&lt;p&gt;Start with the questions that help you understand the GenAI application landscape.&lt;/p&gt;

&lt;p&gt;Can you explain how an LLM-powered application works?&lt;/p&gt;

&lt;p&gt;Can you explain tokens, context windows, and hallucinations?&lt;/p&gt;

&lt;p&gt;Do you understand the difference between prompting, RAG, and fine-tuning?&lt;/p&gt;

&lt;p&gt;Can you explain why an application might use embeddings and a vector database?&lt;/p&gt;

&lt;p&gt;Can you discuss security, cost, latency, evaluation, and reliability?&lt;/p&gt;

&lt;p&gt;Can you describe something you have built, even if it is small?&lt;/p&gt;

&lt;p&gt;These questions give you a practical direction.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚠️ Does This Mean Machine Learning Is Not Important?
&lt;/h2&gt;

&lt;p&gt;No.&lt;/p&gt;

&lt;p&gt;Machine Learning fundamentals become increasingly important depending on the role you are targeting.&lt;/p&gt;

&lt;p&gt;If you want to train models, work deeply with model architectures, become an ML Engineer, or pursue AI research, you will need stronger foundations in Machine Learning, mathematics, and statistics.&lt;/p&gt;

&lt;p&gt;But that's different from saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Everyone must learn Machine Learning before they can start learning Generative AI.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;They don't.&lt;/p&gt;

&lt;p&gt;For many developers, architects, testers, DevOps engineers, and other technology professionals, starting with GenAI applications is a perfectly reasonable path.&lt;/p&gt;

&lt;h2&gt;
  
  
  🌱 Start First. Go Deeper When You Need To.
&lt;/h2&gt;

&lt;p&gt;The AI ecosystem is enormous.&lt;/p&gt;

&lt;p&gt;You can spend months creating the perfect learning roadmap.&lt;/p&gt;

&lt;p&gt;Or you can start.&lt;/p&gt;

&lt;p&gt;Understand what Generative AI is.&lt;/p&gt;

&lt;p&gt;Learn the fundamentals.&lt;/p&gt;

&lt;p&gt;Build something small.&lt;/p&gt;

&lt;p&gt;Prepare for practical interview questions.&lt;/p&gt;

&lt;p&gt;Discover your knowledge gaps.&lt;/p&gt;

&lt;p&gt;Then go deeper.&lt;/p&gt;

&lt;p&gt;If you're preparing for a GenAI interview and don't know where to begin, I've put together a structured guide covering the concepts and questions worth exploring:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://confidentprep.com/interview/ai/?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;Start Preparing for Your AI Interview&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't let the size of Machine Learning stop you from starting with Generative AI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Start small. Understand the fundamentals. Build something. Then go deeper. 🚀&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;→ For more details, see &lt;a href="https://confidentprep.com/interview/ai/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;More from &lt;a href="https://confidentprep.com?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=launch-echo-general-stop-learning-machine-learning-before-genai" rel="noopener noreferrer"&gt;https://confidentprep.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>genai</category>
      <category>beginners</category>
      <category>career</category>
    </item>
  </channel>
</rss>
