<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abhay Raj on Medium]]></title>
        <description><![CDATA[Stories by Abhay Raj on Medium]]></description>
        <link>https://medium.com/@techwithabhay?source=rss-5e858b130ff6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_5lViunGn0AVgCLrIQq9Zw.jpeg</url>
            <title>Stories by Abhay Raj on Medium</title>
            <link>https://medium.com/@techwithabhay?source=rss-5e858b130ff6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 04:50:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@techwithabhay/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Beyond Linear RAG: Declarative Routing in Docling Pipelines]]></title>
            <link>https://medium.com/@techwithabhay/beyond-linear-rag-declarative-routing-in-docling-pipelines-9eba77b438f0?source=rss-5e858b130ff6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9eba77b438f0</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[unstructured-data]]></category>
            <category><![CDATA[docling]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[rags]]></category>
            <dc:creator><![CDATA[Abhay Raj]]></dc:creator>
            <pubDate>Thu, 10 Sep 2026 06:00:13 GMT</pubDate>
            <atom:updated>2026-09-10T06:00:13.912Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to split and merge PyArrow streams using BranchingOperator and MergeOperator for non-uniform document corpora.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8Z5YIvQgS-Y-zDUszAtWA.png" /></figure><p>Most document processing pipelines are linear. Every document goes through every step in the same order. That works fine when your corpus is uniform. But real-world corpora are not uniform.</p><p>Some of your documents are 5,000 words long. Others are 50. Some are in English. Others are in French. Some are legal contracts that need deep enrichment. Others are short receipts where a lightweight pass is enough.</p><blockquote>A linear pipeline treats all of them identically — either over-processing the simple ones or under-processing the complex ones.</blockquote><p>Over-processing costs you time and LLM API credits. Under-processing leaves you with shallow embeddings and degraded retrieval quality.</p><p><strong>Docling Pipelines</strong> is an open-source framework for building modular document processing workflows. You define your pipeline as a JSON configuration — a directed acyclic graph (DAG) of operators — and the framework handles execution, batching, and orchestration. Two operators in particular unlock something most RAG data pipelines cannot do: conditional routing based on document properties, declared entirely in configuration.</p><p>Those operators are BranchingOperator and MergeOperator. Let&#39;s look at how they can make your RAG pipeline smarter, cheaper, and more accurate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zc5kGuQZK5nq6VE0TIEPAw.png" /><figcaption><strong>From unstructured documents to intelligent semantic retrieval.</strong></figcaption></figure><h4>The Problem with Linear Pipelines</h4><p>Here is a typical Docling Pipelines flow:</p><p>Ingest → Extract → Lang Detect → Doc Quality → Readability → Embed → VectorDB</p><p>Every document follows the same path. The quality operators run on everything. That is fine. But what if you want to run <strong>ML Enrichment</strong> — a deeper, more expensive feature extraction step — <em>only</em> on long, high-quality documents? What if short documents should just pass through with no extra processing? What if you want to generate embeddings from two different models and store both vectors per document?</p><p>None of these are possible in a linear flow. You need conditional routing.</p><h4>Meet BranchingOperator</h4><p>The BranchingOperator (short name: branching) takes a single PyArrow table as input and splits it into multiple output tables — one per branch — based on filter conditions you define. Documents that satisfy a branch&#39;s criteria go into that branch&#39;s output. Documents that do not are filtered out.</p><p>Importantly, <strong>a document can appear in more than one branch</strong> if it satisfies multiple criteria sets. The branches are not mutually exclusive by default — you make them mutually exclusive by writing non-overlapping conditions.</p><h4>Configuration structure</h4><p>The operator takes a branches object. Each key in that object is a branch ID. Each branch has an optional human-readable link_name, and its filter criteria defined either as a SQL-like list or as structured JSON.</p><pre>{<br>  &quot;name&quot;: &quot;quality_branching&quot;,<br>  &quot;type&quot;: &quot;branching&quot;,<br>  &quot;depends_on&quot;: [&quot;readability&quot;],<br>  &quot;config&quot;: {<br>    &quot;branches&quot;: {<br>      &quot;long_docs_branch&quot;: {<br>        &quot;link_name&quot;: &quot;Long Documents&quot;,<br>        &quot;criteria_json&quot;: {<br>          &quot;criteria_list&quot;: [<br>            { &quot;variable&quot;: &quot;docq_total_words&quot;, &quot;operator&quot;: &quot;&gt;=&quot;, &quot;value&quot;: 98 }<br>          ],<br>          &quot;logical_operator&quot;: &quot;AND&quot;<br>        }<br>      },<br>      &quot;short_docs_branch&quot;: {<br>        &quot;link_name&quot;: &quot;Short Documents&quot;,<br>        &quot;criteria_json&quot;: {<br>          &quot;criteria_list&quot;: [<br>            { &quot;variable&quot;: &quot;docq_total_words&quot;, &quot;operator&quot;: &quot;&lt;&quot;, &quot;value&quot;: 78 }<br>          ],<br>          &quot;logical_operator&quot;: &quot;AND&quot;<br>        }<br>      }<br>    }<br>  }<br>}</pre><p>The criteria can reference <strong>any column that exists in the table at that point in the flow.</strong> In this example, docq_total_words is produced by the upstream doc_quality operator. The framework validates this at flow-definition time.</p><h4>Referencing a specific branch output</h4><p>Once you define branches, downstream operators consume specific branch outputs using dot notation: &quot;&lt;operator_name&gt;.&lt;branch_key&gt;&quot;.</p><pre>{<br>  &quot;name&quot;: &quot;ml_enrichment_long&quot;,<br>  &quot;type&quot;: &quot;ml_enrichment&quot;,<br>  &quot;depends_on&quot;: [&quot;quality_branching.long_docs_branch&quot;]<br>},<br>{<br>  &quot;name&quot;: &quot;noop_short&quot;,<br>  &quot;type&quot;: &quot;noop&quot;,<br>  &quot;depends_on&quot;: [&quot;quality_branching.short_docs_branch&quot;]<br>}</pre><h4>Meet MergeOperator</h4><p>After parallel branches have done their work, you often need to bring the results back together. That is what the MergeOperator (short name: merge) does. It takes two or more input tables and combines them using one of two strategies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Z6HfcnQQD-4sWuMqvXCSQ.png" /></figure><h4>Strategy 1: Row merge (“rows”)</h4><p>The simplest strategy. The tables are stacked vertically — one after another — into a single table.</p><p><strong>Use row merge when:</strong></p><ul><li>Branches handle non-overlapping document sets (e.g., by word count ranges or language).</li><li>You want a single unified table to feed into embeddings or a vector store.</li><li>The same columns exist in all branches (schemas are compatible).</li></ul><p><em>Important:</em> Row merge performs duplicate detection before concatenating. If the same document ID appears in more than one branch, the merge will fail fast with an error.</p><h4>Strategy 2: Column merge (“columns”)</h4><p>The more powerful strategy. Tables are joined <em>horizontally</em> on the document id column. Each branch&#39;s columns are added side-by-side to produce a wider table.<br>Column merge has two sub-options:</p><ul><li><strong>inner_join</strong>: Only documents present in <em>all</em> branches appear in the output. Use this when every document must have results from all branches to be valid.</li><li><strong>full_outer</strong>: All documents appear; missing values from absent branches are null. Use this when some branches may not produce output for every document.</li></ul><p>How complex types are handled: PyArrow’s native join doesn’t support list or struct types (like embedding vectors). MergeOperator handles this transparently internally by splitting the table into primitive columns, performing the join, and then reattaching complex columns by matching on document IDs.</p><h4>Two Patterns Worth Knowing</h4><h4>Pattern 1: Conditional Routing with Row Merge</h4><p>Segment documents by a property, apply different processing to each segment, then recombine for unified embedding and storage.</p><ol><li><strong>Upstream Processing:</strong> Ingest → Extract → Lang Detect → Doc Quality → Readability</li><li><strong>Branching:</strong> Split by word count.</li></ol><ul><li><em>Branch A (Long Docs):</em> ML Enrichment</li><li><em>Branch B (Medium Docs):</em> SQL Filter</li><li><em>Branch C (Short Docs):</em> No-op</li></ul><p><strong>3. Merge &amp; Embed:</strong> Merge (rows) → Embed → VectorDB</p><h4>Pattern 2: Fan-out with Column Merge (Dual Embeddings)</h4><p>Send the same documents down two parallel paths — each generating a different embedding — then join the two embedding columns side-by-side before writing to storage.</p><ol><li><strong>Upstream Processing:</strong> Ingest → Extract → Chunk</li><li><strong>Unconditional Fan-Out:</strong></li></ol><ul><li><em>Branch A:</em> Embed (nomic-embed-text)</li><li><em>Branch B:</em> Embed (granite-embedding)</li></ul><ol><li><strong>Merge &amp; Store:</strong> Merge (columns, inner_join) → Document Set / VectorDB</li></ol><p>The merged table has all original columns plus <em>both</em> embedding vectors per document, stored under different column names.</p><p><strong>A real RAG scenario: language + quality routing</strong></p><p>Here’s how this plays out for the enterprise knowledge base described earlier. The corpus is multilingual, mixed-length, and mixed-quality. The flow scores every document first — language and word count — then branches on those scores.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQs5tbaBUJCg8idIvIA8Ng.png" /></figure><p>The criteria for the first branch — lang_name == &#39;en&#39; AND docq_total_words &gt;= 500 — routes long English documents into the ML enrichment path. Short English documents get a lighter SQL filter pass. Documents that don&#39;t match either branch — non-English content, for example — simply don&#39;t appear in either branch output and never reach the merge.</p><p>Both lang_name and docq_total_words are columns produced by upstream quality operators in the same flow. No external classification service. No preprocessing step. The pipeline computes what it needs and branches on it — in one execution.</p><h4>Closing Thoughts: Why Dynamic DAGs Win in Production</h4><p>Linear document pipelines are great for quick prototypes, but in production, they force an inefficient compromise: either burning compute on simple files or under-processing complex ones.</p><p>By introducing conditional branching and merging into your RAG data pipelines with Docling Pipelines, you unlock three core production benefits:</p><ul><li><strong>Cost &amp; Latency Optimization:</strong> Stop wasting expensive LLM extraction passes and embedding calls on lightweight or low-priority documents.</li><li><strong>Maximized Retrieval Accuracy:</strong> Run deep enrichment and multi-model embedding strategies specifically where they matter most, improving context relevance downstream.</li><li><strong>Zero Infrastructure Overhead:</strong> Manage complex routing entirely in declarative JSON configs — no custom Python wrappers, no extra DAG orchestrators, and no unmaintainable if/else spaghetti code.</li></ul><p>The next time you build a RAG data pipeline, don’t ask <em>“How do I process all my documents?”</em> Ask <em>“How do my documents </em><strong><em>deserve</em></strong><em> to be processed?”</em></p><p><strong>Loved this post?</strong></p><ul><li>⭐ Star the <a href="https://github.com/IBM/docling-pipelines"><strong>Docling Pipelines repository on GitHub</strong></a> to support the project.</li><li>💬 Leave a comment below with the dynamic routing logic or pipeline edge cases you’re tackling in your current RAG stack!</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9eba77b438f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>