<?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>Forem:  Praveen Kumar</title>
    <description>The latest articles on Forem by  Praveen Kumar (@praveensk).</description>
    <link>https://forem.com/praveensk</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F842361%2Fa5b42434-055a-4649-9706-ed998abe1441.JPG</url>
      <title>Forem:  Praveen Kumar</title>
      <link>https://forem.com/praveensk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/praveensk"/>
    <language>en</language>
    <item>
      <title>Improving RAG Systems with PageIndex</title>
      <dc:creator> Praveen Kumar</dc:creator>
      <pubDate>Fri, 13 Mar 2026 23:21:59 +0000</pubDate>
      <link>https://forem.com/praveensk/improving-rag-systems-with-pageindex-dbd</link>
      <guid>https://forem.com/praveensk/improving-rag-systems-with-pageindex-dbd</guid>
      <description>&lt;p&gt;Retrieval-Augmented Generation (RAG) has quickly become one of the most practical ways to build AI applications on top of custom data.&lt;/p&gt;

&lt;p&gt;From documentation assistants to internal company knowledge bots, RAG enables large language models to answer questions using external information instead of relying purely on training data.&lt;/p&gt;

&lt;p&gt;But once your dataset grows beyond a few documents, something frustrating starts happening:&lt;/p&gt;

&lt;p&gt;The model begins returning incomplete or confusing answers.&lt;/p&gt;

&lt;p&gt;Often the issue isn’t the LLM itself — it’s retrieval quality.&lt;/p&gt;

&lt;p&gt;One simple idea that can dramatically improve RAG pipelines is PageIndex.&lt;/p&gt;

&lt;p&gt;The Hidden Problem with Traditional RAG&lt;/p&gt;

&lt;p&gt;Most RAG pipelines follow a similar workflow:&lt;/p&gt;

&lt;p&gt;Documents are split into chunks&lt;/p&gt;

&lt;p&gt;Each chunk is converted into embeddings&lt;/p&gt;

&lt;p&gt;Embeddings are stored in a vector database&lt;/p&gt;

&lt;p&gt;At query time, the system retrieves the most similar chunks&lt;/p&gt;

&lt;p&gt;Those chunks are passed to the LLM as context&lt;/p&gt;

&lt;p&gt;This approach works well initially. But it has a structural weakness.&lt;/p&gt;

&lt;p&gt;Chunks lose their relationship to the document they came from.&lt;/p&gt;

&lt;p&gt;When the system retrieves context, it may pull pieces from completely different parts of the document.&lt;/p&gt;

&lt;p&gt;For example, imagine a research paper structured like this:&lt;/p&gt;

&lt;p&gt;Page 1 — Introduction&lt;/p&gt;

&lt;p&gt;Page 2 — System Architecture&lt;/p&gt;

&lt;p&gt;Page 3 — Implementation Details&lt;/p&gt;

&lt;p&gt;Page 4 — Results&lt;/p&gt;

&lt;p&gt;A typical RAG query might retrieve:&lt;/p&gt;

&lt;p&gt;a chunk from Page 1&lt;/p&gt;

&lt;p&gt;another from Page 4&lt;/p&gt;

&lt;p&gt;and another from Page 2&lt;/p&gt;

&lt;p&gt;The model receives fragmented information with no clear structure.&lt;/p&gt;

&lt;p&gt;Even worse, the missing pieces of context may exist on the same page as the retrieved chunk, but they were not retrieved because they weren’t individually similar enough to the query.&lt;/p&gt;

&lt;p&gt;The result is incomplete answers.&lt;/p&gt;

&lt;p&gt;What is PageIndex RAG?&lt;/p&gt;

&lt;p&gt;PageIndex RAG is a simple improvement that preserves document structure during retrieval.&lt;/p&gt;

&lt;p&gt;Instead of treating each chunk as an isolated piece of information, we attach metadata that records which page the chunk belongs to.&lt;/p&gt;

&lt;p&gt;When a relevant chunk is retrieved, the system can then expand the context by including other chunks from the same page.&lt;/p&gt;

&lt;p&gt;This allows the LLM to see the surrounding information that was originally written together.&lt;/p&gt;

&lt;p&gt;In other words:&lt;/p&gt;

&lt;p&gt;Rather than retrieving isolated fragments, the system reconstructs meaningful sections of the document.&lt;/p&gt;

&lt;p&gt;Why Page Structure Matters&lt;/p&gt;

&lt;p&gt;Most documents are written with deliberate structure.&lt;/p&gt;

&lt;p&gt;Authors group related information together on the same page or section. Important explanations often span multiple paragraphs that were originally meant to be read together.&lt;/p&gt;

&lt;p&gt;When RAG pipelines ignore that structure, they break the logical flow of information.&lt;/p&gt;

&lt;p&gt;PageIndex restores that flow.&lt;/p&gt;

&lt;p&gt;Instead of feeding the model disconnected fragments, it provides coherent blocks of context that preserve how the information was originally organized.&lt;/p&gt;

&lt;p&gt;This small change can significantly improve answer quality.&lt;/p&gt;

&lt;p&gt;How PageIndex Improves Retrieval&lt;/p&gt;

&lt;p&gt;PageIndex adds an additional step between retrieval and generation.&lt;/p&gt;

&lt;p&gt;After the vector database retrieves the most relevant chunks, the system identifies which pages those chunks belong to.&lt;/p&gt;

&lt;p&gt;Then it expands the context by collecting additional chunks from those same pages.&lt;/p&gt;

&lt;p&gt;The final context sent to the LLM contains:&lt;/p&gt;

&lt;p&gt;the relevant chunk that triggered the retrieval&lt;/p&gt;

&lt;p&gt;surrounding chunks from the same page&lt;/p&gt;

&lt;p&gt;ordered content that mirrors the original document structure&lt;/p&gt;

&lt;p&gt;This produces a much more complete context window.&lt;/p&gt;

&lt;p&gt;The Real Benefit: Better Context Reconstruction&lt;/p&gt;

&lt;p&gt;The main benefit of PageIndex is context reconstruction.&lt;/p&gt;

&lt;p&gt;Large language models perform best when they can see information in a coherent structure.&lt;/p&gt;

&lt;p&gt;If the model receives half an explanation, it may hallucinate the rest.&lt;/p&gt;

&lt;p&gt;But when the surrounding paragraphs are included, the model can reason over the full explanation instead of guessing.&lt;/p&gt;

&lt;p&gt;This dramatically reduces incomplete answers and hallucinations.&lt;/p&gt;

&lt;p&gt;When PageIndex Works Best&lt;/p&gt;

&lt;p&gt;PageIndex is especially useful for documents that have strong structural organization.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;p&gt;research papers&lt;/p&gt;

&lt;p&gt;PDFs&lt;/p&gt;

&lt;p&gt;technical documentation&lt;/p&gt;

&lt;p&gt;legal documents&lt;/p&gt;

&lt;p&gt;reports&lt;/p&gt;

&lt;p&gt;textbooks&lt;/p&gt;

&lt;p&gt;In these types of content, related information is usually grouped together within a page or section.&lt;/p&gt;

&lt;p&gt;By preserving that grouping, PageIndex helps the model understand the material more accurately.&lt;/p&gt;

&lt;p&gt;PageIndex vs Larger Context Windows&lt;/p&gt;

&lt;p&gt;One might argue that increasing the context window could solve the same problem.&lt;/p&gt;

&lt;p&gt;But larger context windows don’t solve retrieval quality.&lt;/p&gt;

&lt;p&gt;If the system retrieves the wrong chunks, a bigger context window simply means more irrelevant information.&lt;/p&gt;

&lt;p&gt;PageIndex improves the quality of the retrieved context, not just the quantity.&lt;/p&gt;

&lt;p&gt;That distinction matters a lot in real-world applications.&lt;/p&gt;

&lt;p&gt;Why This Technique Is Underrated&lt;/p&gt;

&lt;p&gt;Many RAG discussions focus heavily on:&lt;/p&gt;

&lt;p&gt;better embeddings&lt;/p&gt;

&lt;p&gt;hybrid search&lt;/p&gt;

&lt;p&gt;reranking models&lt;/p&gt;

&lt;p&gt;vector database tuning&lt;/p&gt;

&lt;p&gt;Those improvements matter, but they often overlook something simpler:&lt;/p&gt;

&lt;p&gt;document structure.&lt;/p&gt;

&lt;p&gt;PageIndex works because it aligns retrieval with how humans actually organize information.&lt;/p&gt;

&lt;p&gt;Instead of fighting document structure, it leverages it.&lt;/p&gt;

&lt;p&gt;And the best part is that it requires very little complexity to implement.&lt;/p&gt;

&lt;p&gt;Final Thoughts&lt;/p&gt;

&lt;p&gt;RAG pipelines are often treated as purely semantic retrieval systems, but documents themselves carry structural signals that can dramatically improve performance.&lt;/p&gt;

&lt;p&gt;PageIndex is a lightweight technique that restores some of that lost structure.&lt;/p&gt;

&lt;p&gt;By reconnecting chunks with their original pages, you allow the LLM to reason over complete pieces of information instead of fragmented snippets.&lt;/p&gt;

&lt;p&gt;Sometimes the biggest improvements come from the simplest ideas.&lt;/p&gt;

&lt;p&gt;And PageIndex is one of those ideas.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>mcp</category>
    </item>
    <item>
      <title># Understanding RAPTOR: A Powerful Architecture for Hierarchical Retrieval in RAG Systems</title>
      <dc:creator> Praveen Kumar</dc:creator>
      <pubDate>Wed, 11 Mar 2026 21:24:42 +0000</pubDate>
      <link>https://forem.com/praveensk/-understanding-raptor-a-powerful-architecture-for-hierarchical-retrieval-in-rag-systems-5e5n</link>
      <guid>https://forem.com/praveensk/-understanding-raptor-a-powerful-architecture-for-hierarchical-retrieval-in-rag-systems-5e5n</guid>
      <description>&lt;p&gt;In one of the previous posts we discussed about the Hierarchial RAG, so to continue on that we can learn more about the important architecutre called RAPTOR.&lt;/p&gt;

&lt;h1&gt;
  
  
  Understanding RAPTOR: A Powerful Architecture for Hierarchical Retrieval in RAG Systems
&lt;/h1&gt;

&lt;p&gt;Retrieval-Augmented Generation (RAG) has become one of the most widely used architectures for building AI systems that answer questions using external knowledge.&lt;/p&gt;

&lt;p&gt;However, traditional RAG systems struggle with &lt;strong&gt;long documents and complex reasoning across multiple chunks of information&lt;/strong&gt;. When relevant information is spread across many chunks, retrieving only a few fragments may not provide enough context for the LLM to produce a high-quality answer.&lt;/p&gt;

&lt;p&gt;To address this limitation, researchers proposed &lt;strong&gt;RAPTOR (Recursive Abstractive Processing for Tree-Organized Retrieval)&lt;/strong&gt; — an architecture that enables &lt;strong&gt;multi-level retrieval using hierarchical summaries&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this article, we will explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What RAPTOR is&lt;/li&gt;
&lt;li&gt;How it builds a hierarchical knowledge structure&lt;/li&gt;
&lt;li&gt;How retrieval works in RAPTOR&lt;/li&gt;
&lt;li&gt;Why it improves reasoning for long documents&lt;/li&gt;
&lt;li&gt;The limitations of RAPTOR in real-world systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  The Problem with Traditional RAG
&lt;/h1&gt;

&lt;p&gt;A typical RAG system works 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 Database
   ↓
Query → Vector Search
   ↓
Top-K Chunks Retrieved
   ↓
LLM Generates Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach works well when the answer exists inside &lt;strong&gt;one or two chunks&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But many real-world documents require understanding &lt;strong&gt;multiple sections together&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;A research paper may contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;methodology in one section&lt;/li&gt;
&lt;li&gt;experiments in another section&lt;/li&gt;
&lt;li&gt;conclusions elsewhere&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the system retrieves only a few chunks, the LLM may miss important information.&lt;/p&gt;

&lt;p&gt;This is where RAPTOR helps.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Is RAPTOR?
&lt;/h1&gt;

&lt;p&gt;RAPTOR stands for:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recursive Abstractive Processing for Tree-Organized Retrieval&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The key idea behind RAPTOR is to build a &lt;strong&gt;hierarchical tree of summaries&lt;/strong&gt; from the document chunks.&lt;/p&gt;

&lt;p&gt;Instead of retrieving only small chunks, the system can retrieve &lt;strong&gt;both detailed chunks and higher-level summaries&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This provides the LLM with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;detailed evidence&lt;/li&gt;
&lt;li&gt;high-level context&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  How RAPTOR Builds the Hierarchical Tree
&lt;/h1&gt;

&lt;p&gt;RAPTOR organizes information in a &lt;strong&gt;bottom-up manner&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The process begins with document chunks and recursively builds higher-level summaries.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 — Document Chunking
&lt;/h3&gt;

&lt;p&gt;Documents are split into chunks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Document
   ↓
Chunk1
Chunk2
Chunk3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each chunk is converted into an embedding using an embedding model.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2 — Cluster Similar Chunks
&lt;/h3&gt;

&lt;p&gt;Chunks are grouped using &lt;strong&gt;hierarchical clustering based on embedding similarity&lt;/strong&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cluster A
Chunk1
Chunk2

Cluster B
Chunk3
Chunk4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Chunks that discuss similar topics end up in the same cluster.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 3 — Generate Cluster Summaries
&lt;/h3&gt;

&lt;p&gt;An LLM generates a summary representing each cluster.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Cluster summary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Transformer architectures and attention mechanisms
used for sequence processing."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This summary captures the &lt;strong&gt;main idea of multiple chunks&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 4 — Recursive Clustering
&lt;/h3&gt;

&lt;p&gt;RAPTOR then clusters the summaries themselves.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chunk clusters
   ↓
Summaries
   ↓
Cluster summaries again
   ↓
Generate higher-level summaries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This recursive process continues until the system produces a &lt;strong&gt;hierarchical summary tree&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Root Summary
│
├── Machine Learning
│   ├── Neural Networks
│   │   ├── Chunk
│   │   └── Chunk
│   │
│   └── Transformers
│       ├── Chunk
│       └── Chunk
│
└── Cybersecurity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each node in the tree contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a summary&lt;/li&gt;
&lt;li&gt;an embedding&lt;/li&gt;
&lt;li&gt;references to child nodes&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  How Retrieval Works in RAPTOR
&lt;/h1&gt;

&lt;p&gt;During query time, RAPTOR performs vector search across &lt;strong&gt;all nodes in the tree&lt;/strong&gt;, not just chunks.&lt;/p&gt;

&lt;p&gt;These nodes include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;document chunks&lt;/li&gt;
&lt;li&gt;cluster summaries&lt;/li&gt;
&lt;li&gt;higher-level summaries&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example vector index:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Vector Index
│
├── Chunk nodes (level 0)
├── Cluster summaries (level 1)
├── Topic summaries (level 2)
└── Root summaries (level 3)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a user asks a question, the system converts the query into an embedding and searches the vector index.&lt;/p&gt;

&lt;p&gt;Example query:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How do transformers process sequences?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Retrieved nodes might include:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transformer architecture summary
Attention mechanism chunk
Sequence processing chunk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The LLM then receives both &lt;strong&gt;high-level context and detailed information&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why RAPTOR Improves Retrieval
&lt;/h1&gt;

&lt;p&gt;RAPTOR provides several advantages over traditional RAG.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-Level Context
&lt;/h2&gt;

&lt;p&gt;Instead of retrieving only fragments of text, RAPTOR retrieves information from &lt;strong&gt;multiple abstraction levels&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example context sent to the LLM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transformer architecture summary
+
Chunk explaining self-attention
+
Chunk explaining positional encoding
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helps the LLM understand the &lt;strong&gt;overall concept as well as the details&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Better Handling of Long Documents
&lt;/h2&gt;

&lt;p&gt;Long documents often distribute information across many sections.&lt;/p&gt;

&lt;p&gt;Cluster summaries allow RAPTOR to represent &lt;strong&gt;large groups of chunks in a compact way&lt;/strong&gt;, making retrieval more effective.&lt;/p&gt;




&lt;h2&gt;
  
  
  Improved Recall
&lt;/h2&gt;

&lt;p&gt;Sometimes a query matches a &lt;strong&gt;conceptual summary&lt;/strong&gt; better than individual chunks.&lt;/p&gt;

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

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;How do transformers process sequences?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A chunk might mention &lt;strong&gt;self-attention&lt;/strong&gt;, but the summary captures the broader concept of &lt;strong&gt;transformer sequence modeling&lt;/strong&gt;, improving retrieval quality.&lt;/p&gt;




&lt;h1&gt;
  
  
  When Does RAPTOR Stop Building the Tree?
&lt;/h1&gt;

&lt;p&gt;RAPTOR does not keep clustering indefinitely.&lt;/p&gt;

&lt;p&gt;The recursive clustering stops when certain conditions are met, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;only one cluster remains (root node)&lt;/li&gt;
&lt;li&gt;clusters become too small to summarize&lt;/li&gt;
&lt;li&gt;maximum tree depth is reached&lt;/li&gt;
&lt;li&gt;summaries become too generic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In most implementations, the tree typically contains &lt;strong&gt;3–5 levels&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Limitations of RAPTOR
&lt;/h1&gt;

&lt;p&gt;Although RAPTOR is powerful, it also has some weaknesses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Information Loss During Summarization
&lt;/h2&gt;

&lt;p&gt;Every summarization step compresses information.&lt;/p&gt;

&lt;p&gt;Important details present in chunks may be lost in summaries.&lt;/p&gt;




&lt;h2&gt;
  
  
  Potential Hallucinations
&lt;/h2&gt;

&lt;p&gt;Since summaries are generated by LLMs, they may occasionally introduce incorrect statements.&lt;/p&gt;

&lt;p&gt;These errors can propagate to higher levels of the tree.&lt;/p&gt;




&lt;h2&gt;
  
  
  Expensive Ingestion Pipeline
&lt;/h2&gt;

&lt;p&gt;Building a RAPTOR tree requires several steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;embedding generation&lt;/li&gt;
&lt;li&gt;hierarchical clustering&lt;/li&gt;
&lt;li&gt;LLM summarization&lt;/li&gt;
&lt;li&gt;recursive clustering&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For very large datasets, this can become computationally expensive.&lt;/p&gt;




&lt;h2&gt;
  
  
  Tree Structure Limitations
&lt;/h2&gt;

&lt;p&gt;RAPTOR organizes knowledge as a &lt;strong&gt;tree&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;However, real-world knowledge often forms &lt;strong&gt;graph-like relationships&lt;/strong&gt;.&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;Drug → treats → Disease
Disease → affects → Organ
Organ → interacts with → Biological systems
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These connections are difficult to represent in a strict tree structure.&lt;/p&gt;




&lt;h1&gt;
  
  
  When RAPTOR Works Best
&lt;/h1&gt;

&lt;p&gt;RAPTOR is particularly effective for knowledge sources with &lt;strong&gt;natural hierarchical structure&lt;/strong&gt;, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;research papers&lt;/li&gt;
&lt;li&gt;legal documents&lt;/li&gt;
&lt;li&gt;textbooks&lt;/li&gt;
&lt;li&gt;technical documentation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These documents already contain layered information, making them a good fit for RAPTOR’s summary tree approach.&lt;/p&gt;




&lt;h1&gt;
  
  
  Limitations of RAPTOR
&lt;/h1&gt;

&lt;p&gt;While RAPTOR significantly improves retrieval quality for long and complex documents, it also introduces several practical challenges that developers should consider before adopting it in production systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Information Loss During Summarization
&lt;/h2&gt;

&lt;p&gt;RAPTOR relies heavily on &lt;strong&gt;LLM-generated summaries&lt;/strong&gt; to build higher levels of the retrieval tree.&lt;/p&gt;

&lt;p&gt;At each level, multiple chunks are compressed into a shorter summary.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Original chunks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chunk 1: Transformers use multi-head attention.
Chunk 2: Attention computes relationships between tokens.
Chunk 3: Positional encoding helps preserve sequence order.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cluster summary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Transformers process sequences using attention mechanisms."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Although this captures the general idea, &lt;strong&gt;important technical details like positional encoding or multi-head attention may be lost&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If retrieval returns only the summary node, the LLM may miss important details.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Potential Hallucinations in Summaries
&lt;/h2&gt;

&lt;p&gt;Since summaries are generated by LLMs, there is always a risk of &lt;strong&gt;hallucinated or inaccurate summaries&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Original cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chunk 1: CNNs use convolution layers.
Chunk 2: Transformers use attention mechanisms.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Possible incorrect summary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Neural networks such as CNNs and transformers both rely on attention mechanisms."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Errors like this can propagate through higher levels of the RAPTOR tree.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Expensive Ingestion Pipeline
&lt;/h2&gt;

&lt;p&gt;Building the RAPTOR tree requires several expensive operations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Chunking
Embedding generation
Hierarchical clustering
LLM summarization
Recursive clustering
Embedding summaries again
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For large datasets containing millions of chunks, this pipeline can become &lt;strong&gt;computationally expensive and time-consuming&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Difficult to Update Incrementally
&lt;/h2&gt;

&lt;p&gt;RAPTOR works best for &lt;strong&gt;static datasets&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If new documents are added frequently, maintaining the tree becomes challenging.&lt;/p&gt;

&lt;p&gt;Adding new documents may require:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;re-clustering nodes
regenerating summaries
rebuilding parts of the tree
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes RAPTOR less suitable for systems where data changes frequently.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Tree Structure Limits Relationship Reasoning
&lt;/h2&gt;

&lt;p&gt;RAPTOR organizes information in a &lt;strong&gt;tree hierarchy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;However, real-world knowledge often contains &lt;strong&gt;cross-topic relationships&lt;/strong&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Drug → treats → Disease
Disease → affects → Organ
Organ → related to → Biological systems
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These connections form a &lt;strong&gt;graph structure&lt;/strong&gt;, not a tree.&lt;/p&gt;

&lt;p&gt;Because RAPTOR uses a hierarchical tree, it may struggle to capture complex relationships across different branches of knowledge.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Retrieval May Return Overly Generic Summaries
&lt;/h2&gt;

&lt;p&gt;Sometimes vector search retrieves &lt;strong&gt;very high-level summaries&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;How does self-attention work?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Retrieved node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Deep learning models used in artificial intelligence."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Such summaries are &lt;strong&gt;too general to provide useful context&lt;/strong&gt; for answering the question.&lt;/p&gt;




&lt;h1&gt;
  
  
  When RAPTOR Still Works Very Well
&lt;/h1&gt;

&lt;p&gt;Despite these limitations, RAPTOR remains extremely effective for datasets with &lt;strong&gt;clear hierarchical structure&lt;/strong&gt;, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;research papers&lt;/li&gt;
&lt;li&gt;textbooks&lt;/li&gt;
&lt;li&gt;legal documents&lt;/li&gt;
&lt;li&gt;structured technical documentation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In these cases, the hierarchical summary tree closely mirrors the structure of the underlying content.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;RAPTOR is a powerful extension of traditional RAG systems, enabling &lt;strong&gt;multi-level retrieval and better reasoning over long documents&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;However, its reliance on recursive summarization and hierarchical trees introduces challenges such as information loss, ingestion cost, and difficulty handling complex relationships.&lt;/p&gt;

&lt;p&gt;In practice, many modern AI systems combine RAPTOR with other approaches such as &lt;strong&gt;Graph-based retrieval or hybrid RAG architectures&lt;/strong&gt; to overcome these limitations.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;RAPTOR represents an important evolution of traditional RAG architectures.&lt;/p&gt;

&lt;p&gt;By building a &lt;strong&gt;hierarchical summary tree&lt;/strong&gt;, RAPTOR allows AI systems to retrieve information at multiple levels of abstraction, providing both detailed evidence and high-level context to language models.&lt;/p&gt;

&lt;p&gt;While it introduces additional complexity and computational cost, RAPTOR significantly improves retrieval quality for systems dealing with &lt;strong&gt;long documents and complex knowledge bases&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;As RAG systems continue to evolve, RAPTOR remains a key architecture for building more intelligent and context-aware retrieval pipelines.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>rag</category>
    </item>
    <item>
      <title># Building Scalable RAG Systems with Hierarchical Clustering + Hierarchical RAG (and Why Cluster Summaries Matter)</title>
      <dc:creator> Praveen Kumar</dc:creator>
      <pubDate>Wed, 11 Mar 2026 20:43:07 +0000</pubDate>
      <link>https://forem.com/praveensk/-building-scalable-rag-systems-with-hierarchical-clustering-hierarchical-rag-and-why-cluster-398o</link>
      <guid>https://forem.com/praveensk/-building-scalable-rag-systems-with-hierarchical-clustering-hierarchical-rag-and-why-cluster-398o</guid>
      <description>&lt;p&gt;Retrieval-Augmented Generation (RAG) has become the backbone of many AI-powered applications such as knowledge assistants, document search systems, and enterprise copilots.&lt;/p&gt;

&lt;p&gt;However, as datasets grow to &lt;strong&gt;hundreds of thousands or millions of documents&lt;/strong&gt;, traditional RAG systems start facing several challenges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slow retrieval times&lt;/li&gt;
&lt;li&gt;High token usage&lt;/li&gt;
&lt;li&gt;Noisy or irrelevant context&lt;/li&gt;
&lt;li&gt;Poor scalability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One effective solution is to combine &lt;strong&gt;Hierarchical Clustering&lt;/strong&gt; with &lt;strong&gt;Hierarchical RAG&lt;/strong&gt;. This approach organizes the knowledge base into a tree-like structure and retrieves information efficiently by navigating that hierarchy.&lt;/p&gt;

&lt;p&gt;In this article, we’ll explore how these two techniques work together and why &lt;strong&gt;cluster summaries play a critical role in making the system work correctly&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Problem with Standard RAG
&lt;/h1&gt;

&lt;p&gt;A typical RAG pipeline 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 Database
   ↓
Query → Vector Search
   ↓
Retrieve Top K Chunks
   ↓
LLM Generates Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works well for small datasets.&lt;/p&gt;

&lt;p&gt;But imagine a system with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;100,000 documents&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;500,000+ chunks&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every query has to compare against a very large number of embeddings.&lt;/p&gt;

&lt;p&gt;Even with approximate nearest neighbor search, problems appear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;irrelevant chunks may be retrieved&lt;/li&gt;
&lt;li&gt;retrieval time increases&lt;/li&gt;
&lt;li&gt;context becomes noisy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To solve this, we can organize our knowledge base &lt;strong&gt;hierarchically&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 1: Organizing Documents with Hierarchical Clustering
&lt;/h1&gt;

&lt;p&gt;Hierarchical clustering groups similar documents into &lt;strong&gt;nested clusters&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of a flat list of documents, we build a &lt;strong&gt;tree structure of topics&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example document set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Doc1: Neural network optimization
Doc2: Transformer architectures
Doc3: Malware detection techniques
Doc4: Network security policies
Doc5: Corporate travel policy
Doc6: Employee reimbursement rules
Doc7: Stock market forecasting
Doc8: Risk management strategies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After hierarchical clustering, we might get a structure 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;Knowledge Base
│
├── Technology
│   ├── AI
│   │   ├── Doc1
│   │   └── Doc2
│   │
│   └── Cybersecurity
│       ├── Doc3
│       └── Doc4
│
├── HR
│   ├── Travel Policy
│   │   └── Doc5
│   └── Reimbursement
│       └── Doc6
│
└── Finance
    ├── Market Analysis
    │   └── Doc7
    └── Risk Management
        └── Doc8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now our documents are organized by &lt;strong&gt;topic hierarchy&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 2: Generating Cluster Summaries
&lt;/h1&gt;

&lt;p&gt;Once clusters are created, we generate &lt;strong&gt;summaries for each cluster&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;These summaries represent the &lt;strong&gt;core topic of that cluster&lt;/strong&gt; and act as &lt;strong&gt;retrieval signals&lt;/strong&gt; for the system.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI Cluster Summary&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Documents about machine learning models including
neural networks, transformer architectures,
and optimization techniques.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Cybersecurity Cluster Summary&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Documents related to detecting and preventing cyber
attacks, including malware detection and network security.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each summary gets its &lt;strong&gt;own embedding&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;These embeddings represent the &lt;strong&gt;semantic meaning of the cluster&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Cluster Summaries Are Extremely Important
&lt;/h1&gt;

&lt;p&gt;Cluster summaries are not just documentation — they are &lt;strong&gt;critical components of the retrieval system&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In hierarchical RAG, the system does &lt;strong&gt;not initially search the documents themselves&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead it first compares the query with &lt;strong&gt;cluster summaries&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Query
  ↓
Compare with cluster summaries
  ↓
Select best cluster
  ↓
Search documents inside that cluster
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the summary poorly represents the cluster, the system may select the &lt;strong&gt;wrong branch of the hierarchy&lt;/strong&gt;, which leads to incorrect document retrieval.&lt;/p&gt;

&lt;p&gt;In other words:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Cluster summaries act as &lt;strong&gt;routing signals&lt;/strong&gt; that determine where the query travels in the knowledge tree.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  Example: Good vs Bad Cluster Summaries
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Poor Cluster Summary
&lt;/h2&gt;

&lt;p&gt;Cluster documents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;malware detection&lt;/li&gt;
&lt;li&gt;intrusion detection systems&lt;/li&gt;
&lt;li&gt;firewall monitoring&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bad summary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"This cluster contains cybersecurity information."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Too generic&lt;/li&gt;
&lt;li&gt;Hard to distinguish from other clusters&lt;/li&gt;
&lt;li&gt;Retrieval accuracy decreases&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Strong Cluster Summary
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"This cluster contains documents about detecting and preventing cyber attacks,
including malware detection, intrusion detection systems (IDS),
and firewall monitoring techniques."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why this works better:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;contains important keywords&lt;/li&gt;
&lt;li&gt;captures the topic clearly&lt;/li&gt;
&lt;li&gt;produces a stronger embedding representation&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Step 3: Hierarchical RAG Retrieval
&lt;/h1&gt;

&lt;p&gt;Now we use Hierarchical RAG to navigate the cluster tree during retrieval.&lt;/p&gt;

&lt;p&gt;Instead of searching all documents, we progressively narrow the search.&lt;/p&gt;

&lt;p&gt;Example query:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How do companies detect malware attacks?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Retrieval process:&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 — Top-level cluster search
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Query → compare with cluster summaries
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Technology
HR
Finance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Best match:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Technology
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 2 — Subcluster search
&lt;/h3&gt;

&lt;p&gt;Inside Technology:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AI
Cybersecurity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Best match:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cybersecurity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 3 — Document retrieval
&lt;/h3&gt;

&lt;p&gt;Search only within that cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Doc3: Malware detection techniques
Doc4: Network security policies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Chunks from these documents are retrieved.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 4 — LLM answer generation
&lt;/h3&gt;

&lt;p&gt;The retrieved chunks are sent to the LLM as context.&lt;/p&gt;

&lt;p&gt;The LLM generates the final response.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why This Approach Is Powerful
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Faster Retrieval
&lt;/h2&gt;

&lt;p&gt;Instead of searching:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100,000 chunks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We might search:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;20 cluster summaries
→ 1 cluster
→ 500 chunks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This significantly reduces retrieval cost.&lt;/p&gt;




&lt;h2&gt;
  
  
  Better Context Quality
&lt;/h2&gt;

&lt;p&gt;Queries about malware will never search:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Finance documents
HR policies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The system filters irrelevant topics early.&lt;/p&gt;




&lt;h2&gt;
  
  
  Improved Scalability
&lt;/h2&gt;

&lt;p&gt;Hierarchical RAG works well for knowledge bases containing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;enterprise documentation&lt;/li&gt;
&lt;li&gt;research papers&lt;/li&gt;
&lt;li&gt;legal archives&lt;/li&gt;
&lt;li&gt;internal company data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even datasets with &lt;strong&gt;millions of documents&lt;/strong&gt; can be organized efficiently.&lt;/p&gt;




&lt;h1&gt;
  
  
  Best Practices for Writing Cluster Summaries
&lt;/h1&gt;

&lt;p&gt;To ensure good retrieval performance, summaries should follow a few guidelines:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Keep summaries concise
&lt;/h3&gt;

&lt;p&gt;Typically &lt;strong&gt;50–150 tokens&lt;/strong&gt; works well.&lt;/p&gt;

&lt;p&gt;Too long → noisy embeddings.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Include key concepts
&lt;/h3&gt;

&lt;p&gt;Mention important topics and terminology present in the cluster.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;malware detection
intrusion detection
network monitoring
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  3. Avoid vague descriptions
&lt;/h3&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"This cluster contains various technical documents."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"This cluster contains documents about detecting
and preventing cyber threats including malware detection,
intrusion detection systems, and network security monitoring."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  4. Use representative documents
&lt;/h3&gt;

&lt;p&gt;Instead of summarizing all documents blindly, choose &lt;strong&gt;representative documents or chunks&lt;/strong&gt; and summarize them.&lt;/p&gt;

&lt;p&gt;This produces more accurate summaries.&lt;/p&gt;




&lt;h1&gt;
  
  
  Example System Architecture
&lt;/h1&gt;

&lt;p&gt;A typical pipeline combining hierarchical clustering and hierarchical RAG might look 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;Document Ingestion
        │
        ▼
Embedding Generation
        │
        ▼
Hierarchical Clustering
        │
        ▼
Cluster Tree
        │
        ▼
Cluster Summarization
        │
        ▼
Store Embeddings
        │
        ▼
Hierarchical Retrieval
        │
        ▼
Chunk Retrieval
        │
        ▼
LLM Response Generation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Real-World Applications
&lt;/h1&gt;

&lt;p&gt;Combining hierarchical clustering and hierarchical RAG is useful for many production systems:&lt;/p&gt;

&lt;h3&gt;
  
  
  Enterprise Knowledge Assistants
&lt;/h3&gt;

&lt;p&gt;Large companies often have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;thousands of internal documents&lt;/li&gt;
&lt;li&gt;technical guides&lt;/li&gt;
&lt;li&gt;HR policies&lt;/li&gt;
&lt;li&gt;compliance reports&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hierarchical retrieval helps employees find information faster.&lt;/p&gt;




&lt;h3&gt;
  
  
  Research Paper Search Systems
&lt;/h3&gt;

&lt;p&gt;Academic search tools can organize papers by:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Field → Subfield → Paper
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes retrieval far more accurate.&lt;/p&gt;




&lt;h3&gt;
  
  
  AI-Powered Documentation Assistants
&lt;/h3&gt;

&lt;p&gt;Developer documentation can be structured as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Product → Module → API → Code Examples
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hierarchical retrieval ensures queries reach the correct section quickly.&lt;/p&gt;




&lt;h1&gt;
  
  
  Key Takeaways
&lt;/h1&gt;

&lt;p&gt;Hierarchical clustering and hierarchical RAG work together to build scalable retrieval systems.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Hierarchical clustering&lt;/strong&gt; organizes documents into a topic tree.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cluster summaries&lt;/strong&gt; represent each node of the hierarchy and act as routing signals.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hierarchical RAG&lt;/strong&gt; navigates that structure during retrieval&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>llm</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>How QR Code Works .....</title>
      <dc:creator> Praveen Kumar</dc:creator>
      <pubDate>Thu, 05 Mar 2026 20:01:15 +0000</pubDate>
      <link>https://forem.com/praveensk/how-qr-code-works--4o28</link>
      <guid>https://forem.com/praveensk/how-qr-code-works--4o28</guid>
      <description>&lt;h1&gt;
  
  
  From Text to Black-and-White Squares
&lt;/h1&gt;

&lt;p&gt;QR codes are everywhere today: payments, restaurant menus, login links, tickets, and product information. You simply point your camera at a square pattern and instantly get a website or some text.&lt;/p&gt;

&lt;p&gt;But what’s actually happening behind the scenes?&lt;/p&gt;

&lt;p&gt;How does a &lt;strong&gt;simple grid of black and white squares store text like &lt;code&gt;https://example.com&lt;/code&gt; or &lt;code&gt;HI&lt;/code&gt; or &lt;code&gt;Payment Information&lt;/code&gt;&lt;/strong&gt; ?&lt;/p&gt;

&lt;p&gt;In this article we'll break down the full process step-by-step — from &lt;strong&gt;text → binary → grid → scanning → decoding&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  1. What Is a QR Code?
&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;QR (Quick Response) code&lt;/strong&gt; is a type of &lt;strong&gt;2-dimensional barcode&lt;/strong&gt; invented in 1994 by engineers at &lt;strong&gt;Denso Wave&lt;/strong&gt; in Japan.&lt;/p&gt;

&lt;p&gt;Unlike traditional barcodes that store information in one direction (lines), QR codes store information &lt;strong&gt;both horizontally and vertically&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This allows them to store much more data.&lt;/p&gt;

&lt;p&gt;For example, a QR code can store:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;URLs&lt;/li&gt;
&lt;li&gt;text&lt;/li&gt;
&lt;li&gt;WiFi credentials&lt;/li&gt;
&lt;li&gt;contact cards&lt;/li&gt;
&lt;li&gt;payment data&lt;/li&gt;
&lt;li&gt;event tickets&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  2. QR Code Structure
&lt;/h1&gt;

&lt;p&gt;A QR code is not random pixels. It has several &lt;strong&gt;structured components&lt;/strong&gt; that help scanners detect and decode it.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Finder Patterns (Corner Squares)
&lt;/h3&gt;

&lt;p&gt;These are the &lt;strong&gt;three big squares in the corners&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Their job is to help the scanner:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;detect that the image is a QR code&lt;/li&gt;
&lt;li&gt;determine orientation&lt;/li&gt;
&lt;li&gt;locate the grid&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They have a distinctive pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Black
White
Black
White
Black
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pattern has a ratio of &lt;strong&gt;1:1:3:1:1&lt;/strong&gt;, which scanners search for in camera images.&lt;/p&gt;

&lt;p&gt;Sometimes people refer to them informally as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Outer eye&lt;/strong&gt; → the large outer black square&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inner eye&lt;/strong&gt; → the smaller black square inside&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These squares &lt;strong&gt;do not contain data&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Timing Patterns
&lt;/h3&gt;

&lt;p&gt;Between the finder patterns are alternating modules:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;█ ░ █ ░ █ ░ █
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These help scanners determine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;module size&lt;/li&gt;
&lt;li&gt;spacing between grid cells&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. Alignment Pattern
&lt;/h3&gt;

&lt;p&gt;Larger QR codes include smaller squares that help correct distortion if the QR code is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;curved&lt;/li&gt;
&lt;li&gt;tilted&lt;/li&gt;
&lt;li&gt;printed on uneven surfaces&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  4. Data Area
&lt;/h3&gt;

&lt;p&gt;The remaining squares contain the &lt;strong&gt;actual encoded data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Each small square is called a &lt;strong&gt;module&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Black module = 1
White module = 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  3. Step 1 — Converting Text Into Binary
&lt;/h1&gt;

&lt;p&gt;Before data can be placed in the QR code, it must be converted into &lt;strong&gt;binary&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Computers represent characters using encoding systems such as &lt;strong&gt;ASCII&lt;/strong&gt; or &lt;strong&gt;UTF-8&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example text:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HI
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ASCII values:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Character&lt;/th&gt;
&lt;th&gt;ASCII&lt;/th&gt;
&lt;th&gt;Binary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;H&lt;/td&gt;
&lt;td&gt;72&lt;/td&gt;
&lt;td&gt;01001000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;I&lt;/td&gt;
&lt;td&gt;73&lt;/td&gt;
&lt;td&gt;01001001&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Binary stream:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0100100001001001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This binary sequence is what will be stored inside the QR code.&lt;/p&gt;




&lt;h1&gt;
  
  
  4. Step 2 — Adding QR Metadata
&lt;/h1&gt;

&lt;p&gt;Before storing the data, the QR generator adds extra information:&lt;/p&gt;

&lt;h3&gt;
  
  
  Mode indicator
&lt;/h3&gt;

&lt;p&gt;Specifies the type of data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;numeric&lt;/li&gt;
&lt;li&gt;alphanumeric&lt;/li&gt;
&lt;li&gt;byte&lt;/li&gt;
&lt;li&gt;kanji&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Character count
&lt;/h3&gt;

&lt;p&gt;How many characters are stored.&lt;/p&gt;

&lt;h3&gt;
  
  
  Error correction data
&lt;/h3&gt;

&lt;p&gt;Extra redundancy so the QR code still works if damaged.&lt;/p&gt;

&lt;p&gt;QR codes use &lt;strong&gt;Reed–Solomon error correction&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Four levels exist:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Level&lt;/th&gt;
&lt;th&gt;Recovery&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;L&lt;/td&gt;
&lt;td&gt;7% damage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;M&lt;/td&gt;
&lt;td&gt;15% damage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Q&lt;/td&gt;
&lt;td&gt;25% damage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;H&lt;/td&gt;
&lt;td&gt;30% damage&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is why QR codes still work even if part of them is scratched or covered by a logo.&lt;/p&gt;




&lt;h1&gt;
  
  
  5. Step 3 — QR Code Grid
&lt;/h1&gt;

&lt;p&gt;QR codes come in &lt;strong&gt;40 versions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Each version defines the grid size.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;21 × 21&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;25 × 25&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;57 × 57&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;177 × 177&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The smallest QR code (Version 1) is &lt;strong&gt;21 × 21 modules&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Some modules are reserved for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;finder patterns&lt;/li&gt;
&lt;li&gt;timing patterns&lt;/li&gt;
&lt;li&gt;format information&lt;/li&gt;
&lt;li&gt;alignment patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The remaining modules are used to store data.&lt;/p&gt;




&lt;h1&gt;
  
  
  6. Step 4 — Mapping Binary Into the Grid (Zig-Zag Pattern)
&lt;/h1&gt;

&lt;p&gt;Data is &lt;strong&gt;not written left-to-right or top-to-bottom&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead, QR codes fill modules using a &lt;strong&gt;vertical zig-zag path&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The rules are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Start at the &lt;strong&gt;bottom-right corner&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Fill &lt;strong&gt;two columns at a time&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Move &lt;strong&gt;upwards&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;When reaching the top, shift &lt;strong&gt;two columns left&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Move &lt;strong&gt;downwards&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Repeat&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Visual idea:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;↑
│
│
↓
│
│
↑
│
│
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example simplified grid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;16 15
13 14
12 11
 9 10
 8  7
 5  6
 4  3
 1  2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each position gets the &lt;strong&gt;next bit from the binary stream&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 → black
0 → white
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the zig-zag path encounters reserved modules (finder patterns, timing lines), those cells are &lt;strong&gt;skipped&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  7. Step 5 — Masking
&lt;/h1&gt;

&lt;p&gt;After placing the data bits, the QR generator applies a &lt;strong&gt;mask pattern&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Masking prevents patterns that could confuse scanners (for example large blocks of black or white).&lt;/p&gt;

&lt;p&gt;Example mask rule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (row + column) % 2 == 0
    flip bit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are &lt;strong&gt;8 possible mask patterns&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The QR code stores which mask was used so the scanner can reverse it.&lt;/p&gt;




&lt;h1&gt;
  
  
  8. Final Result
&lt;/h1&gt;

&lt;p&gt;After all steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Text
↓
Binary encoding
↓
Add metadata
↓
Add error correction
↓
Place bits in zig-zag path
↓
Apply mask
↓
QR code pattern
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This produces the final black-and-white square pattern.&lt;/p&gt;




&lt;h1&gt;
  
  
  9. How a Phone Scans a QR Code
&lt;/h1&gt;

&lt;p&gt;When you scan a QR code with your camera, the process works roughly like this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 — Detect finder patterns
&lt;/h3&gt;

&lt;p&gt;The scanner searches the image for the &lt;strong&gt;1:1:3:1:1 pattern&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If it finds &lt;strong&gt;three of them&lt;/strong&gt;, it identifies a QR code.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 2 — Determine orientation
&lt;/h3&gt;

&lt;p&gt;Because the three squares form an &lt;strong&gt;L shape&lt;/strong&gt;, the scanner knows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;where the top is&lt;/li&gt;
&lt;li&gt;whether the code is rotated&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Step 3 — Correct rotation, skew, and perspective
&lt;/h3&gt;

&lt;p&gt;In real life the QR code may appear distorted.&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;QR code rotated sideways
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;QR looks like a parallelogram
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;QR looks like a trapezoid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the positions of the finder patterns, the scanner calculates a &lt;strong&gt;perspective transform&lt;/strong&gt; that mathematically "unwarps" the QR code back into a perfect square grid.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 4 — Measure module size
&lt;/h3&gt;

&lt;p&gt;Timing patterns help determine the spacing between modules.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 5 — Read modules
&lt;/h3&gt;

&lt;p&gt;The scanner samples each module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Black → 1
White → 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Step 6 — Reverse masking
&lt;/h3&gt;

&lt;p&gt;The scanner removes the mask pattern.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 7 — Apply error correction
&lt;/h3&gt;

&lt;p&gt;Reed-Solomon error correction reconstructs missing bits if part of the code is damaged.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 8 — Decode data
&lt;/h3&gt;

&lt;p&gt;The binary stream is converted back into characters.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;01001000 → H
01001001 → I
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Final result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HI
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  10. Why QR Codes Work So Reliably
&lt;/h1&gt;

&lt;p&gt;QR codes are robust because they include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;strong pattern detection&lt;/li&gt;
&lt;li&gt;perspective correction&lt;/li&gt;
&lt;li&gt;error correction&lt;/li&gt;
&lt;li&gt;masking to avoid visual confusion&lt;/li&gt;
&lt;li&gt;distributed data layout&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This allows them to be scanned even if they are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;partially damaged&lt;/li&gt;
&lt;li&gt;rotated&lt;/li&gt;
&lt;li&gt;tilted&lt;/li&gt;
&lt;li&gt;printed on curved surfaces&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;A QR code might look like random squares, but it's actually a carefully designed system.&lt;/p&gt;

&lt;p&gt;The entire process 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;Text
→ Character encoding
→ Binary data
→ Error correction
→ Zig-zag data placement
→ Masking
→ QR grid
→ Camera detection
→ Perspective correction
→ Binary decoding
→ Original text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next time you scan a QR code, remember that your phone is performing &lt;strong&gt;image recognition, geometry correction, error recovery, and binary decoding — all in milliseconds&lt;/strong&gt;.&lt;/p&gt;




</description>
      <category>opensource</category>
      <category>community</category>
    </item>
  </channel>
</rss>
