<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[javascript  series]]></title><description><![CDATA[javascript  series]]></description><link>https://javascript-series.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 23:43:58 GMT</lastBuildDate><atom:link href="https://javascript-series.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Retrieval-Augmented Generation (RAG): How It Works, Why It Helps, and Where It Falls Short]]></title><description><![CDATA[Large Language Models (LLMs) like ChatGPT, Claude, and Gemini have transformed the way we interact with AI. They can write code, summarize documents, answer questions, and generate human-like conversa]]></description><link>https://javascript-series.hashnode.dev/retrieval-augmented-generation-rag-how-it-works-why-it-helps-and-where-it-falls-short</link><guid isPermaLink="true">https://javascript-series.hashnode.dev/retrieval-augmented-generation-rag-how-it-works-why-it-helps-and-where-it-falls-short</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[gen ai]]></category><category><![CDATA[llm]]></category><category><![CDATA[RAG ]]></category><category><![CDATA[Chaiaurcode]]></category><dc:creator><![CDATA[Shailja Yadav]]></dc:creator><pubDate>Sun, 19 Jul 2026 15:01:26 GMT</pubDate><content:encoded><![CDATA[<p>Large Language Models (LLMs) like ChatGPT, Claude, and Gemini have transformed the way we interact with AI. They can write code, summarize documents, answer questions, and generate human-like conversations. However, despite their impressive capabilities, they have one significant limitation—they only know what they learned during training.</p>
<p>This limitation becomes a problem when users ask questions about recent events, company-specific documents, or information that was never part of the model's training data.</p>
<p>To solve this challenge, the AI community introduced <strong>Retrieval-Augmented Generation (RAG)</strong>.</p>
<p>RAG allows an LLM to retrieve relevant information from external sources before generating an answer, making responses more accurate, up-to-date, and grounded in real data.</p>
<p>In this article, we'll explore what RAG is, how it works, why it was introduced, and the challenges that come with it.</p>
<hr />
<h1>The Limitations of an LLM Without External Knowledge</h1>
<p>Before understanding RAG, it's important to understand how a traditional LLM works.</p>
<p>An LLM generates responses using patterns learned during training. It does <strong>not</strong> search the internet or your company's database every time you ask a question.</p>
<p>Imagine asking an AI:</p>
<blockquote>
<p>"What is our company's leave policy?"</p>
</blockquote>
<p>Unless that exact policy was part of its training—which is highly unlikely—it has no reliable way to answer.</p>
<p>Similarly, asking:</p>
<blockquote>
<p>"What features were released in version 5.2 of our product?"</p>
</blockquote>
<p>would produce an inaccurate or completely fabricated response because the model has no access to your internal documentation.</p>
<p>This is one of the biggest limitations of standalone LLMs:</p>
<ul>
<li><p>Knowledge becomes outdated.</p>
</li>
<li><p>Private company data is unavailable.</p>
</li>
<li><p>Responses rely only on what the model remembers.</p>
</li>
</ul>
<p>This is exactly the problem that Retrieval-Augmented Generation was designed to solve.</p>
<hr />
<h1>What is Retrieval-Augmented Generation (RAG)?</h1>
<p>Retrieval-Augmented Generation (RAG) is a technique that allows an AI model to retrieve relevant information from an external knowledge source before generating an answer.</p>
<p>Instead of depending only on its training data, the model first searches a collection of documents, retrieves the most relevant pieces of information, and then uses that information to answer the user's question.</p>
<p>Think of it like an open-book exam.</p>
<p>Without RAG:</p>
<blockquote>
<p>The student answers only from memory.</p>
</blockquote>
<p>With RAG:</p>
<blockquote>
<p>The student first opens the textbook, finds the relevant chapter, and then writes the answer.</p>
</blockquote>
<p>The AI becomes significantly more reliable because it can reference actual documents rather than relying entirely on memory.</p>
<hr />
<h1>How a Basic RAG Pipeline Works</h1>
<p>A RAG system generally follows four simple steps.</p>
<h3>Step 1: User asks a question</h3>
<p>Example:</p>
<blockquote>
<p>"What is our remote work policy?"</p>
</blockquote>
<h3>Step 2: Retrieval</h3>
<p>The system searches a knowledge base containing company documents, PDFs, manuals, or databases.</p>
<h3>Step 3: Relevant information is retrieved</h3>
<p>Instead of sending every document to the model, only the most relevant sections are selected.</p>
<h3>Step 4: LLM generates the answer</h3>
<p>The retrieved information is added to the prompt, and the LLM generates a response based on both:</p>
<ul>
<li><p>the user's question</p>
</li>
<li><p>the retrieved context</p>
</li>
</ul>
<h2>Basic RAG Architecture</h2>
<pre><code class="language-plaintext">          User Query
               │
               ▼
     Retrieve Relevant Documents
               │
               ▼
     Relevant Context Retrieved
               │
               ▼
      Large Language Model
               │
               ▼
         Final Response
</code></pre>
<p>This simple pipeline dramatically improves the quality of responses.</p>
<h1>Where RAG Works Well</h1>
<p>RAG is particularly effective when information changes frequently or exists in external documents.</p>
<p>Some common applications include:</p>
<h2>Customer Support</h2>
<p>Instead of training an LLM every time documentation changes, a company can simply update its help articles.</p>
<p>Customers always receive answers based on the latest documentation.</p>
<h2>Internal Company Knowledge</h2>
<p>Employees can ask questions like:</p>
<ul>
<li><p>How do I request leave?  </p>
</li>
<li><p>What is our reimbursement policy?  </p>
</li>
<li><p>Where is the deployment guide?</p>
</li>
</ul>
<p>The AI retrieves information from internal documents rather than relying on outdated training data.</p>
<h2>Healthcare</h2>
<p>Doctors and healthcare professionals can retrieve information from updated medical guidelines and research papers.</p>
<h2>Legal Research</h2>
<p>Law firms can retrieve information from legal databases before generating summaries.</p>
<h2>Product Documentation</h2>
<p>Software companies often maintain hundreds of pages of documentation.</p>
<p>Instead of manually searching, developers can ask questions naturally.</p>
<p>Example:</p>
<blockquote>
<p>"How do I authenticate using our REST API?"</p>
</blockquote>
<p>The system retrieves the relevant documentation before generating the answer.</p>
<h1>Why RAG Sometimes Gives Incorrect Answers</h1>
<p>Although RAG greatly improves accuracy, it does <strong>not</strong> guarantee that every answer will be correct.</p>
<p>A RAG system is only as good as the information it retrieves.</p>
<p>Several factors can cause failures.</p>
<h1>Poor Retrieval</h1>
<p>Retrieval is the most important part of a RAG system.</p>
<p>If the retrieval system finds irrelevant documents, the LLM will generate answers using incorrect information.</p>
<p>Example:</p>
<p>User asks:</p>
<blockquote>
<p>"How do I reset my password?"</p>
</blockquote>
<p>The retriever mistakenly finds a document about account creation.</p>
<p>The LLM now answers based on the wrong document.</p>
<p>Even though the AI sounds confident, the answer is incorrect because the wrong context was provided.</p>
<h1>Missing Context</h1>
<p>Sometimes the retriever finds only part of the required information.</p>
<p>Suppose a company policy spans multiple pages.</p>
<p>If only page one is retrieved, the AI may miss critical details contained later in the document.</p>
<p>The result is an incomplete answer.</p>
<h1>Poor Chunking</h1>
<p>Documents are usually divided into smaller pieces called <strong>chunks</strong> before indexing.</p>
<p>The way documents are chunked has a major impact on retrieval quality.</p>
<h3>Good Chunking</h3>
<pre><code class="language-plaintext">Employee Leave Policy

Eligibility
Annual Leave
Sick Leave
Approval Process
</code></pre>
<p>Everything related stays together.</p>
<h3>Poor Chunking</h3>
<pre><code class="language-plaintext">Employee Leave

Eligibility

Annual Leave

Chapter 2 starts here...

Random paragraph...
</code></pre>
<p>Important information becomes fragmented.</p>
<p>When the retriever searches, it may retrieve incomplete or unrelated chunks, causing the AI to generate confusing answers.</p>
<p>Proper chunking is one of the most important aspects of building an effective RAG system.</p>
<h1>Context Window Limitations</h1>
<p>LLMs can process only a limited amount of text at once, known as the <strong>context window</strong>.</p>
<p>Imagine retrieving 100 pages of documentation.</p>
<p>The model cannot read everything if it exceeds its context limit.</p>
<p>Only a portion of the retrieved content can be included in the prompt.</p>
<pre><code class="language-plaintext">Knowledge Base
──────────────────────────────
Document 1
Document 2
Document 3
Document 4
Document 5
──────────────────────────────

           ▼

Only documents that fit within
the context window are sent
to the LLM.
</code></pre>
<p>If important information lies outside this limit, the model may not consider it when generating its response.</p>
<h1>Hallucinations Can Still Happen</h1>
<p>One common misconception is that RAG completely eliminates hallucinations.</p>
<p>It does not.</p>
<p>Even with accurate retrieved information, an LLM may:</p>
<ul>
<li><p>make unsupported assumptions,  </p>
</li>
<li><p>combine facts incorrectly,  </p>
</li>
<li><p>add information not present in the retrieved context,  </p>
</li>
<li><p>answer confidently despite missing evidence.</p>
</li>
</ul>
<p>For example, if the retrieved document partially answers a question, the model may "fill in the gaps" with plausible-sounding but incorrect information.</p>
<p>RAG reduces hallucinations, but it cannot eliminate them entirely.</p>
<h1>Keeping the Knowledge Base Up to Date</h1>
<p>A RAG system depends on the quality of its knowledge base.</p>
<p>If documents are outdated, the AI will also produce outdated answers.</p>
<p>For example:</p>
<ul>
<li><p>Old HR policies  </p>
</li>
<li><p>Deprecated API documentation  </p>
</li>
<li><p>Expired legal regulations  </p>
</li>
<li><p>Outdated pricing information</p>
</li>
</ul>
<p>All of these lead to incorrect responses.</p>
<p>Maintaining a reliable RAG system requires regularly updating documents, removing obsolete information, and re-indexing the knowledge base when changes occur.</p>
<h1>When RAG Is Not the Right Solution</h1>
<p>Although RAG is powerful, it isn't the best fit for every problem.</p>
<p>It may not be suitable when:</p>
<ul>
<li><p>The task requires reasoning rather than retrieving facts.  </p>
</li>
<li><p>The knowledge base is very small and rarely changes.  </p>
</li>
<li><p>The application doesn't rely on external information.  </p>
</li>
<li><p>Responses require complex calculations or business logic rather than document lookup.</p>
</li>
</ul>
<p>For example, a calculator or a recommendation engine doesn't need document retrieval—it needs computation and algorithms instead.</p>
<p>In these cases, adding RAG introduces unnecessary complexity without improving results.</p>
<h1>Conclusion</h1>
<p>Retrieval-Augmented Generation bridges one of the biggest gaps in traditional language models by giving them access to external knowledge before generating a response.</p>
<p>Instead of relying solely on what the model learned during training, RAG enables it to retrieve relevant information from documents, databases, or other knowledge sources. This makes responses more accurate, current, and useful in domains such as customer support, internal knowledge management, healthcare, legal research, and product documentation.</p>
<p>However, RAG is not a silver bullet. Its effectiveness depends heavily on the quality of retrieval, how documents are chunked, the limitations of the model's context window, and the freshness of the underlying knowledge base. Even with well-designed retrieval, language models can still hallucinate or misinterpret incomplete context.</p>
<p>The key takeaway is that <strong>RAG improves the likelihood of accurate answers—it does not guarantee them</strong>. Building a successful RAG system requires thoughtful document organization, reliable retrieval, and ongoing maintenance of the knowledge base.</p>
<p>When used in the right scenarios, RAG is one of the most effective techniques for making LLM-powered applications more practical, trustworthy, and capable of answering questions grounded in real-world information.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Promises in JavaScript]]></title><description><![CDATA[Promise → something that will happen in the future
In JavaScript, promises are used to handle asynchronous tasks (tasks that take time to complete).
Suppose you order something from Amazon.
The moment]]></description><link>https://javascript-series.hashnode.dev/understanding-promises-in-javascript</link><guid isPermaLink="true">https://javascript-series.hashnode.dev/understanding-promises-in-javascript</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[promises]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Learning Journey]]></category><dc:creator><![CDATA[Shailja Yadav]]></dc:creator><pubDate>Mon, 30 Mar 2026 05:41:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6951617dfdd6cd5c419c0595/56547072-9d60-4efe-b231-01e7a9c1ae0f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2><strong>Promise → something that will happen in the future</strong></h2>
<p>In JavaScript, promises are used to handle <strong>asynchronous tasks</strong> (tasks that take time to complete).</p>
<h2>Suppose you order something from Amazon.</h2>
<p>The moment you click the <strong>“Order”</strong> button:<br />👉 A <em>promise</em> is created</p>
<p>Because:</p>
<ul>
<li><p>You don’t receive the product instantly</p>
</li>
<li><p>You’ll get the result in the future</p>
</li>
</ul>
<h3>📦 Here the confirmation or Order ID you get represents a Promise</h3>
<p>It guarantees that You will receive a result — either success or failure</p>
<h3>Your Promise will either be resolved or rejected</h3>
<h3>1. Promise Resolved (Fulfilled)</h3>
<p>After a few days:</p>
<ul>
<li>Your parcel is delivered</li>
</ul>
<p>This means the promise is <strong>resolved successfully</strong></p>
<h3>2. Promise Rejected</h3>
<p>If something goes wrong:</p>
<ul>
<li><p>Product is out of stock</p>
</li>
<li><p>Delivery failed</p>
</li>
</ul>
<p>You receive a notification/email</p>
<p>This means the promise is <strong>rejected</strong></p>
<h2>PROMISE METHODS</h2>
<h3>The <code>Promise</code> class provides four important methods:</h3>
<h3>1.<code>Promise.all()</code></h3>
<ul>
<li><p>It <strong>resolves only when all promises are fulfilled</strong></p>
</li>
<li><p>If <strong>any one promise fails</strong>, it immediately rejects</p>
</li>
<li><p>It expects an <strong>array of promises</strong></p>
</li>
<li><p>It returns an <strong>array of results (in the same order)</strong></p>
</li>
</ul>
<h3>2. <code>Promise.any()</code></h3>
<ul>
<li><p>It <strong>resolves as soon as any one promise is fulfilled</strong></p>
</li>
<li><p>It <strong>ignores rejected promises</strong></p>
</li>
<li><p>It expects an <strong>array of promises</strong></p>
</li>
<li><p>It returns the <strong>first fulfilled value</strong></p>
</li>
<li><p>If all promises fail, it rejects</p>
</li>
</ul>
<h3>3. <code>Promise.allSettled()</code></h3>
<ul>
<li><p>It <strong>resolves when all promises are settled</strong> (either fulfilled or rejected)</p>
</li>
<li><p>It expects an <strong>array of promises</strong></p>
</li>
<li><p>It returns an <strong>array of objects</strong> with:</p>
<ul>
<li><p><code>status</code> → "fulfilled" or "rejected"</p>
</li>
<li><p><code>value</code></p>
</li>
</ul>
</li>
</ul>
<h3>4. <code>Promise.race()</code></h3>
<ul>
<li><p>It <strong>settles as soon as the first promise settles</strong></p>
</li>
<li><p>it can be fulfilled or rejected</p>
</li>
<li><p>It expects an <strong>array of promises</strong></p>
</li>
<li><p>It returns the <strong>result of the first settled promise</strong></p>
</li>
</ul>
<h3><strong>5.</strong> <code>Promise.resolve()</code></h3>
<ul>
<li><p>Creates a promise that is <strong>already fulfilled (resolved)</strong>.</p>
</li>
<li><p>Returns a <strong>Promise object</strong> with the given resolved value.</p>
</li>
<li><p>If a promise is passed, it simply <strong>returns the same promise</strong>.</p>
</li>
</ul>
<h3><strong>6.</strong> <code>Promise.reject()</code></h3>
<ul>
<li><p>Creates a promise that is <strong>already rejected</strong>.</p>
</li>
<li><p>Returns a <strong>Promise object</strong> with the given rejection reason (error/value).</p>
</li>
<li><p>Should be handled using <code>.catch()</code> or <code>try/catch</code> (in <code>async/await</code>).</p>
</li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/6951617dfdd6cd5c419c0595/245e913f-597a-422f-98b5-a590e5eba9d0.png" alt="" style="display:block;margin:0 auto" />

<h2><strong>Creating a Promise</strong></h2>
<p>A Promise is created using the <code>new</code> keyword and requires a <strong>resolver (executor) function</strong>.</p>
<p>This function receives two callbacks:</p>
<ul>
<li><p><code>resolve</code></p>
</li>
<li><p><code>reject</code></p>
</li>
</ul>
<p>Since a promise represents a future result, we often introduce delay using <code>setTimeout</code> for asynchronous behavior.</p>
<h2><strong>1. resolve()</strong></h2>
<ul>
<li><p><code>resolve</code> is a function used to indicate that the <strong>asynchronous task has completed successfully</strong></p>
</li>
<li><p>It passes the result to <code>.then()</code></p>
</li>
<li><p>It changes the state of the promise from <strong>pending → fulfilled</strong></p>
</li>
</ul>
<h2><strong>2. reject()</strong></h2>
<ul>
<li><p><code>reject</code> is a function used to indicate that the <strong>asynchronous task has failed</strong></p>
</li>
<li><p>It passes the error to <code>.catch()</code></p>
</li>
<li><p>It changes the state of the promise from <strong>pending → rejected</strong></p>
</li>
<li><p>It can take any value, but usually an <code>Error</code> object is passed for better debugging  </p>
<img src="https://cdn.hashnode.com/uploads/covers/6951617dfdd6cd5c419c0595/eff65f31-71a5-4321-8733-bf0c8d5e43a5.png" alt="" style="display:block;margin:0 auto" /></li>
</ul>
<h2>How to write promises</h2>
<h3></h3>
<p>1. Using <code>.then()</code> / <code>.catch()</code></p>
<pre><code class="language-javascript">const promise = new Promise((resolve, reject) =&gt; {
  setTimeout(() =&gt; {
    const success = true;
    if (success) {
      resolve("Promise Resolved!!!");
    } else {
      reject(new Error("Something went wrong!"));
    }
  }, 2000);
});

  promise.then((value) =&gt; {
    console.log(value);
  })
  .catch((error) =&gt; {
    console.log(error);
  });
</code></pre>
<h3>2. Using <code>async/await</code></h3>
<pre><code class="language-javascript">async function asyncFn() {
  try {
    const result = await promise;  
    console.log(result);
  } catch (error) {
    console.log("error", error);
  }
}

asyncFn();
</code></pre>
]]></content:encoded></item></channel></rss>