<?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: Tushar Sharma</title>
    <description>The latest articles on DEV Community by Tushar Sharma (@ts0711).</description>
    <link>https://dev.to/ts0711</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%2F4013284%2F0aa3ae0a-7600-4737-8b71-41848bbdb162.png</url>
      <title>DEV Community: Tushar Sharma</title>
      <link>https://dev.to/ts0711</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ts0711"/>
    <language>en</language>
    <item>
      <title>Why Your RAG Pipeline is Lying to You</title>
      <dc:creator>Tushar Sharma</dc:creator>
      <pubDate>Wed, 29 Jul 2026 23:53:07 +0000</pubDate>
      <link>https://dev.to/ts0711/why-your-rag-pipeline-is-lying-to-you-2662</link>
      <guid>https://dev.to/ts0711/why-your-rag-pipeline-is-lying-to-you-2662</guid>
      <description>&lt;p&gt;RAG (retrieval-augmented generation) is how most AI tools search your company's documents to answer questions. Instead of guessing, the model pulls relevant text from your files and uses it to respond&lt;/p&gt;

&lt;p&gt;Sounds reliable. Usually isn't.&lt;/p&gt;

&lt;p&gt;Last month, our team shipped a RAG-powered search feature to a Fortune 500 client. Three days later, this Slack message showed up :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The AI pulled a revenue number from our Q3 report. But when I checked the PDF, that number was from a footnote about projected revenue, not actual revenue. How did this happen?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We checked the retrieval logs. The system worked exactly as designed. Found the most semantically similar chunk. Returned it with a high confidence score. Even cited the source document.&lt;/p&gt;

&lt;p&gt;And it was wrong.&lt;/p&gt;

&lt;p&gt;The chunk containing "Revenue: $142M" got retrieved, but the chunk was cut mid-paragraph. The preceding sentence ("Based on current growth projections, we estimate...") lived in a different chunk entirely. The system had no way of knowing this was a projection.&lt;/p&gt;

&lt;p&gt;We had an architecture problem. The model did its job. We fed it a fragment without context, and it did exactly what we asked.&lt;/p&gt;

&lt;p&gt;This is what production RAG actually looks like. The pipeline retrieves information that's technically correct but contextually wrong. It happens more than anyone wants to admit.&lt;/p&gt;

&lt;h2&gt;
  
  
  The retrieval failures that keep showing up
&lt;/h2&gt;

&lt;p&gt;After that incident, we audited 50 of our most problematic queries. Same patterns, over and over.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The headless table&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User query: "What's our discount policy for enterprise customers?"&lt;/p&gt;

&lt;p&gt;Retrieved chunk: "| Enterprise | 25% | Annual contract |"&lt;/p&gt;

&lt;p&gt;The column headers were in a previous chunk. The user got a table row but couldn't tell which column was the discount and which was the contract requirement.&lt;/p&gt;

&lt;p&gt;Picture a sales rep about to jump on a call. They ask the AI for pricing tiers. It returns a row of numbers. They quote the wrong one to the customer. That's a citation without context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The orphaned clause&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User query: "Can we terminate the vendor contract early?"&lt;/p&gt;

&lt;p&gt;Retrieved chunk: "Either party may terminate this Agreement with 30 days written notice."&lt;/p&gt;

&lt;p&gt;"Agreement" was defined earlier in the document as the Master Services Agreement, which has a 12-month minimum term. The definitions section was in a completely different chunk. Technically accurate. Operationally misleading.&lt;/p&gt;

&lt;p&gt;Legal teams rely on AI to surface contract terms. When the AI returns a clause stripped of its governing definitions, people make decisions on incomplete information. And they don't realize it until something goes wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the intelligence actually dies
&lt;/h2&gt;

&lt;p&gt;The root cause is in the architecture. Look at the standard RAG pipeline:&lt;/p&gt;

&lt;p&gt;Document → Fixed-size chunks → Embeddings → Vector DB → Retrieval → LLM&lt;/p&gt;

&lt;p&gt;Step 2 is where it falls apart. You take a richly structured document (headings, tables, sections, page numbers, definitions, cross-references) and flatten it into uniform text blobs.&lt;/p&gt;

&lt;p&gt;You destroy the document's organizational intelligence before the AI ever sees it. It's like ripping chapters out of a book, shuffling the pages, and asking someone to answer questions about the plot.&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%2F5nkmx8q59mbhkv5r44pe.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%2F5nkmx8q59mbhkv5r44pe.png" alt="Shredder : structure in, fragments out." width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Section headings tell you what topic you're reading about. Table headers tell you what each column means. Page numbers tell you where you are. Definitions tell you what terms mean. Cross-references point you to related information.&lt;/p&gt;

&lt;p&gt;Flat chunking throws all of that away.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watch a real document get destroyed
&lt;/h2&gt;

&lt;p&gt;Here's a page from an internal operations document:&lt;/p&gt;

&lt;p&gt;SECTION 4: SERVICE LEVEL AGREEMENTS&lt;/p&gt;

&lt;p&gt;4.1 Response Time Requirements&lt;/p&gt;

&lt;p&gt;The following response times apply to all Priority 1 incidents:&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%2Ftkvgj0w0jur5dzfownbr.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%2Ftkvgj0w0jur5dzfownbr.png" alt="response time" width="672" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: Resolution targets assume standard business hours (9 AM – 6 PM EST). For after-hours coverage, see Section 7.2: On-Call Procedures.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now here's what a standard text splitter does to it:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chunk 1&lt;/strong&gt;: "SECTION 4: SERVICE LEVEL AGREEMENTS 4.1 Response Time Requirements The following response times apply to all Priority 1 incidents:"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chunk 2&lt;/strong&gt;: "| Severity | Initial Response | Resolution Target | | Critical | 15 minutes | 4 hours | | High | 1 hour"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chunk 3&lt;/strong&gt;: "| 8 hours | | Medium | 4 hours | 24 hours | | Low | 24 hours | 5 business days | Note: Resolution targets assume standard business"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chunk 4&lt;/strong&gt;: "hours (9 AM – 6 PM EST). For after-hours coverage, see Section 7.2: On-Call Procedures."&lt;/p&gt;

&lt;p&gt;The section heading got separated from its content. The table was split across three chunks. The header row is in a different chunk than half the data rows. The "Note" about business hours is torn in two. The cross-reference to Section 7.2 is orphaned from everything it relates to.&lt;/p&gt;

&lt;p&gt;If a user asks "What's the resolution time for Critical incidents?", the system might retrieve Chunk 2 or 3. But can it tell the user that resolution times assume business hours? That after-hours procedures are different? No.&lt;/p&gt;

&lt;h2&gt;
  
  
  The chunking paradox
&lt;/h2&gt;

&lt;p&gt;"Just use bigger chunks!" is the first thing everyone tries. Bigger chunks keep more context, right?&lt;/p&gt;

&lt;p&gt;Not quite.&lt;/p&gt;

&lt;p&gt;Bigger chunks mean blurrier embeddings. A 4,000-token chunk might contain 15 different topics. Embed it as a single vector and you get a blurry average. Queries that should match precisely now match vaguely.&lt;/p&gt;

&lt;p&gt;Bigger chunks also waste tokens. You retrieve 4,000 tokens when you needed 200. Your context window fills up with noise. API costs go up. Responses slow down.&lt;/p&gt;

&lt;p&gt;Small chunks give you precision but lose context. Big chunks keep context but lose precision. Neither lets the system decide based on what the query actually needs.&lt;/p&gt;

&lt;p&gt;Sometimes you need one table row plus its headers. Sometimes the full section. Sometimes the entire document. Flat chunking forces you to pick one size for everything.&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%2F7uob926m8ocm870g6dp7.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%2F7uob926m8ocm870g6dp7.png" alt="Graph : chunk size tradeoff" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The detective analogy
&lt;/h2&gt;

&lt;p&gt;You're a detective investigating a complex fraud case. The evidence room hands you a bag of puzzle pieces from 50 different puzzles, all mixed together. Box covers thrown away.&lt;/p&gt;

&lt;p&gt;You can match some pieces that look similar. You might even assemble fragments that seem to form part of a picture. But you'll never know which puzzle you're solving, or if you're missing the piece that cracks the case.&lt;/p&gt;

&lt;p&gt;That's your AI agent reasoning over flat chunks.&lt;/p&gt;

&lt;p&gt;Now picture the alternative: all 50 puzzles in labeled boxes, a photo of each completed puzzle, an index showing which pieces have edge patterns and which have sky. You'd find the right puzzle in seconds, zoom to the relevant section, and pull exactly the pieces you need.&lt;/p&gt;

&lt;p&gt;That's &lt;strong&gt;hierarchical document architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The question worth asking
&lt;/h2&gt;

&lt;p&gt;When your RAG pipeline retrieves a chunk, can it tell you which section of the document it came from? What the nearest heading was? What page it was on? If it's a table row, can it tell you the column headers? If it's a list item, what the parent list was about?&lt;/p&gt;

&lt;p&gt;If the answer is "no" to most of these, you're flying blind. Your citations are technically correct and operationally useless.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building the hierarchy
&lt;/h2&gt;

&lt;p&gt;At &lt;a href="https://pipeshub.com/" rel="noopener noreferrer"&gt;PipesHub&lt;/a&gt; , we spent months figuring out why RAG breaks in production. The answer was better document architecture.&lt;/p&gt;

&lt;p&gt;We built a 4-level hierarchy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Record&lt;/strong&gt;: the complete document&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block Group&lt;/strong&gt;: a logical section (a headed section, a full table, a code listing)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block&lt;/strong&gt;: an atomic unit (a paragraph, a table row, a code block)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chunk&lt;/strong&gt;: an embedding-optimized segment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every level carries metadata. Every level is accessible to the AI agent. When chunks aren't enough, the agent can ask for more context, based on what it actually needs.&lt;/p&gt;

&lt;p&gt;In the next article, we'll get into how this hierarchy works, and the tools that let agents decide how much context they need for any given query. Stay tuned.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
