<?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: Rajat Sharma</title>
    <description>The latest articles on DEV Community by Rajat Sharma (@rajatvertexia).</description>
    <link>https://dev.to/rajatvertexia</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%2F4051314%2F7584a1e4-2da9-453e-aab6-a97bba476ded.jpeg</url>
      <title>DEV Community: Rajat Sharma</title>
      <link>https://dev.to/rajatvertexia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajatvertexia"/>
    <language>en</language>
    <item>
      <title>What is RAG and why it was Introduced ?</title>
      <dc:creator>Rajat Sharma</dc:creator>
      <pubDate>Mon, 10 Aug 2026 06:29:20 +0000</pubDate>
      <link>https://dev.to/rajatvertexia/what-is-rag-and-why-it-was-introduced--1lfl</link>
      <guid>https://dev.to/rajatvertexia/what-is-rag-and-why-it-was-introduced--1lfl</guid>
      <description>&lt;p&gt;Large language models (LLMs) are probabilistic in nature.&lt;/p&gt;

&lt;p&gt;Ask one "How are you?" and it does not search for a stored answer. Instead, it generates the reply one token (a word or fragment of one) at a time.&lt;/p&gt;

&lt;p&gt;For example, after writing "I am", it may weigh several possible next tokens:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"fine" → about 40%&lt;/li&gt;
&lt;li&gt;"good" → about 30%&lt;/li&gt;
&lt;li&gt;"doing" → about 15%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F92wlgjs7nhv12bsv58xv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F92wlgjs7nhv12bsv58xv.png" alt="Diagram by @rajatvertexia of a person asking How are you? into a neural network that branches into weighted LLM token predictions fine, good and doing." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The model samples one of them, appends it to the sentence, and predicts the next token again now conditioned on everything written so far. That is why the same question can produce different responses each time. The answer is generated step by step, not looked up from memory.&lt;/p&gt;

&lt;p&gt;Those probabilities come from the model's &lt;strong&gt;weights&lt;/strong&gt;, the billions or trillions of numbers set during training. When training ends the weights stop changing, and everything the model knows is frozen at that date.&lt;/p&gt;

&lt;p&gt;So a frozen model cannot learn from being asked questions. If you tell ChatGPT your name today and it greets you by that name tomorrow, it may look like learning, but nothing inside the model has changed. ChatGPT uses the underlying concept of RAG (Retrieval-Augmented Generation) by storing information outside the model, deciding which pieces of information are worth keeping, and retrieving the relevant ones based on your new question before inserting them into the context.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flwd0f3460g0kbxlgwznk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flwd0f3460g0kbxlgwznk.png" alt="Diagram by @rajatvertexia showing ChatGPT retrieving stored memory into the context window of a GPT neural network to generate a response." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Four things a frozen model cannot do&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;That storing and retrieving is not just a convenience feature. These mechanisms exist because a frozen model fails in four important ways when used in real world systems.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Knowledge cutoff.&lt;/strong&gt; They cannot access real time information or events past their training date.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hallucination.&lt;/strong&gt; As we know, LLMs are mathematically optimized to predict the most likely next word, not to verify absolute truth. When they lack an answer, they confidently generate convincing but completely false information. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No source attribution.&lt;/strong&gt; Knowledge is stored abstractly across billions of weights, making specific citations impossible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No access to private data.&lt;/strong&gt; They are trained primarily on the public internet. They have zero built in access to your organization's private documents, databases, or internal knowledge.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;All four limitations stated above share one root cause: the model builds answers from frozen weights.&lt;br&gt;
&lt;em&gt;But one part of the model is not frozen. **The prompt.&lt;/em&gt;**&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;In-Context Learning&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;LLMs are very good at using &lt;strong&gt;new information that is provided in the current prompt&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;For example, if you paste your company’s refund policy into a chat and ask for the refund deadline, the model can answer correctly even if that document was never public and the model had never seen it before.&lt;/p&gt;

&lt;p&gt;This does &lt;strong&gt;not mean the model learned the policy&lt;/strong&gt;. No training happens, no weights change, and if you start a new chat without pasting the document again, the model no longer has that information.&lt;/p&gt;

&lt;p&gt;This behavior is called &lt;strong&gt;in-context learning&lt;/strong&gt;: the model makes predictions from the text available in the current conversation rather than from knowledge stored in its weights during training.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A &lt;a href="https://arxiv.org/pdf/2301.00234" rel="noopener noreferrer"&gt;Survey on In context Learning&lt;/a&gt;&lt;/em&gt; is the paper that formally defines it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A natural question is: &lt;strong&gt;&lt;em&gt;why not paste the entire company handbook every time?&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In practice, that is usually &lt;strong&gt;not possible&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The first reason is a hard technical limit called the &lt;strong&gt;context window&lt;/strong&gt;. Every LLM can read only a limited number of tokens in a single request. Many modern models support around &lt;strong&gt;200k tokens&lt;/strong&gt;, while a 1,000-page enterprise handbook can easily contain &lt;strong&gt;400k–500k tokens&lt;/strong&gt;. Anything beyond the limit is &lt;strong&gt;not read at all&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Even when the document fits, two practical problems remain.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Cost and latency&lt;/strong&gt; grow quickly as the prompt becomes larger, because the entire document must be processed again for every question.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accuracy also drops in very long prompts.&lt;/strong&gt; The &lt;a href="https://arxiv.org/pdf/2307.03172" rel="noopener noreferrer"&gt;&lt;em&gt;Lost in the Middle&lt;/em&gt;&lt;/a&gt; study tested whether LLMs could find a specific fact hidden inside a long prompt. Models were much better at finding information near the &lt;strong&gt;beginning&lt;/strong&gt; or &lt;strong&gt;end&lt;/strong&gt; of the prompt, and were more likely to miss important details buried in the &lt;strong&gt;middle&lt;/strong&gt;. As the prompt became longer, overall accuracy generally became worse, even for models designed to handle long contexts.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;The best approach is to give the model a short prompt containing only the paragraphs that are relevant to the current question.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is exactly why &lt;strong&gt;RAG (Retrieval-Augmented Generation)&lt;/strong&gt; was introduced.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval:&lt;/strong&gt; Search a large knowledge base and find only the few paragraphs that are relevant to the user’s query.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Augmentation:&lt;/strong&gt; Add those paragraphs to the prompt so the model has the necessary context without overwhelming it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generation:&lt;/strong&gt; The LLM reads that focused prompt and produces an accurate, grounded answer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuef4l0kw4uz6p78vkhy9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuef4l0kw4uz6p78vkhy9.png" alt="Basic RAG architecture diagram by @rajatvertexia showing ingestion, retrieval and generation stages feeding top matching chunks into an LLM to produce a response. Basic RAG Architecture by Rajat Sharma." width="800" height="812"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;RAG works because it avoids sending an entire knowledge base to the model and instead provides &lt;strong&gt;only the small amount of information needed for this specific question&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://rajatvertexia.com/newsletter" rel="noopener noreferrer"&gt;Follow my newsletter to learn everything about LLMs (internals, training, and more)&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>llm</category>
      <category>nlp</category>
    </item>
  </channel>
</rss>
