<?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 Nipun Bayas on Medium]]></title>
        <description><![CDATA[Stories by Nipun Bayas on Medium]]></description>
        <link>https://medium.com/@nbayas?source=rss-0a176fb2a44c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Nipun Bayas on Medium</title>
            <link>https://medium.com/@nbayas?source=rss-0a176fb2a44c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 04:04:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nbayas/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[How to Build an Intelligent Invoice Processing Pipeline using docling-pipelines]]></title>
            <link>https://medium.com/@nbayas/how-to-build-an-intelligent-invoice-processing-pipeline-using-docling-pipelines-39332f8d2b1e?source=rss-0a176fb2a44c------2</link>
            <guid isPermaLink="false">https://medium.com/p/39332f8d2b1e</guid>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[docling]]></category>
            <category><![CDATA[unstructured-data]]></category>
            <category><![CDATA[agentic-rag]]></category>
            <category><![CDATA[data-pipeline]]></category>
            <dc:creator><![CDATA[Nipun Bayas]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 18:22:03 GMT</pubDate>
            <atom:updated>2026-09-08T18:22:03.045Z</atom:updated>
            <content:encoded><![CDATA[<h4>Extract structured data from PDFs, classify documents with a local LLM, and index everything in a searchable vector store -running entirely on your laptop with docling-pipelines.</h4><p>Every team that handles invoices at scale eventually writes the same code. A PDF parser. A regex for the vendor name. Another regex for the total. A third for the date, which breaks whenever a vendor switches from “Dec 12, 2024” to “12/12/2024”. A special case for the vendor who sends scanned images instead of digital PDFs. And so on, until the codebase is a collection of brittle edge cases that nobody wants to touch.</p><p>The modern answer is LLM-based extraction — and it is genuinely more robust. But by itself it does not tell you how to run it at scale, how to confirm a document <em>is</em> an invoice before spending tokens on it, or how to make the output queryable once it exists. “Find invoices from Acme Corp with a total over $5,000” is a reasonable thing to want to ask. Getting there requires more than a model call.</p><p>This post walks through a complete, runnable invoice processing pipeline using <a href="https://github.com/IBM/docling-pipelines">docling-pipelines</a>, an open-source document curation framework we built at IBM. The whole thing runs locally, costs nothing to try, and is defined entirely in JSON — no Python glue code required.</p><h3>What the pipeline actually does</h3><p>Here is the concrete outcome: you point the pipeline at a folder of PDF invoices, run one command, and end up with a searchable OpenSearch index where every chunk of every invoice has:</p><ul><li>its full text as markdown,</li><li>structured fields like vendor name, invoice number, and total extracted from the document,</li><li>a vector embedding you can use for semantic search,</li><li>and enough metadata to filter by amount, vendor, or date.</li></ul><p>Once that index exists, you can ask questions like <em>“find invoices from construction vendors with totals over $50k”</em> and get back ranked, relevant results that combine semantic meaning with structured filters.</p><p>The pipeline that gets you there has six steps:</p><ol><li><strong>Ingest</strong> PDF files from a local folder.</li><li><strong>Classify</strong> each document with a local LLM to confirm it is an invoice — not a receipt, contract, or something else.</li><li><strong>Extract</strong> both the full markdown text and structured invoice fields using Docling.</li><li><strong>Chunk</strong> the extracted text into retrieval-ready segments.</li><li><strong>Embed</strong> the chunks locally with Ollama.</li><li><strong>Index</strong> everything into OpenSearch with vectors and metadata together.</li></ol><p>The classify-before-extract order is a deliberate design choice. Entity extraction is the most expensive step. Running it on every document in a mixed corpus wastes time and money. By classifying first, you can route only confirmed invoices through the extraction stage — and skip everything else.</p><blockquote><em>Classifying first is not just about accuracy. It is about not spending compute on documents that do not need it.</em></blockquote><h3>Get running in one command</h3><p>The repo includes a setup script that handles everything — Ollama, OpenSearch, the models, and the Python environment — so you do not have to install or configure each piece separately:</p><pre>git clone https://github.com/IBM/docling-pipelines.git<br>cd docling-pipelines<br>chmod +x scripts/setup_docling_pipelines_environment.sh<br>./scripts/setup_docling_pipelines_environment.sh --models llama3.2,nomic-embed-text</pre><p>Then set these environment variables before running the flow:</p><pre>export OLLAMA_API_KEY=ollama<br>export OPENSEARCH_USERNAME=admin<br>export OPENSEARCH_PASSWORD=password</pre><p>If you prefer to set things up manually, you need Python 3.12, Ollama, and an OpenSearch instance (Docker or Podman works fine). See the <a href="https://github.com/IBM/docling-pipelines/blob/main/USER_GUIDE_PIPELINE_SETUP.md">setup guide</a> for step-by-step instructions.</p><p>If you want to run in the cloud instead — OpenAI, watsonx.ai, Anthropic — you swap two config values. The flow structure does not change.</p><h3>The flow file</h3><p>The complete flow is in the repo at <a href="https://github.com/IBM/docling-pipelines/blob/main/sample_flows/use_cases/invoice_processing.json">sample_flows/use_cases/invoice_processing.json</a>. Here is what each operator does and why the order matters.</p><p>ingest_source reads PDFs from a folder and produces one row per document with source metadata and a binary payload. It supports filesystem, S3, IBM COS, SharePoint, OneDrive, and Google Drive — same operator, different provider config.</p><p>document_classifier works directly from the binary payload — no separate extraction step needed first. It sends content to a local LLM via Ollama&#39;s OpenAI-compatible endpoint and adds three columns to every row: document_type, document_type_confidence, and document_type_reasoning. A confidence_threshold of 7.0 means low-confidence results get flagged rather than silently misclassified. temperature: 0.0 keeps the output deterministic — classification is not a creative task.</p><p>extract_operator does two things in one step: Docling converts each PDF into clean markdown, and the entity extraction step pulls out specific fields. The key config here is worth seeing:</p><pre>&quot;entity_extraction&quot;: {<br>  &quot;provider&quot;: &quot;docling&quot;,<br>  &quot;expand_extracted_data&quot;: true,<br>  &quot;custom_schema&quot;: {<br>    &quot;invoice_number&quot;: &quot;string&quot;,<br>    &quot;invoice_date&quot;: &quot;string&quot;,<br>    &quot;vendor_name&quot;: &quot;string&quot;,<br>    &quot;grand_total&quot;: &quot;float&quot;<br>  }<br>}</pre><p>expand_extracted_data: true means those fields become individual columns on the table, not a raw JSON blob. That matters for what comes later: you can only filter on a metadata field in OpenSearch if you actually indexed it as a field. Three entity extraction modes are available — docling (template-based, no LLM call needed), litellm (any LLM provider), and watsonx (IBM Cloud). For a structured schema like invoices, docling is the simplest starting point.</p><p>chunker splits the extracted markdown using hybrid mode, which respects document structure and will not break a table mid-row.</p><p>embeddings generates 768-dimensional vectors locally using nomic-embed-text via Ollama.</p><p>vectordb indexes everything into OpenSearch. One thing worth knowing: feature_mappings defines what the fields are called <em>in OpenSearch</em>. When you query later, use those mapped names — not the upstream column names.</p><h3>Run it</h3><pre>docling-pipelines --flow-file invoice_pipeline.json</pre><p>You’ll see output like this:</p><pre>================================================================================<br> FLOW: invoice-processing-pipeline<br> Operators: 6 | Started: 2025-07-15 10:30:00<br>================================================================================</pre><pre> ingest   (COMPLETED)  0.4s  | Documents: 12 processed, 0 failed<br> classify (COMPLETED)  8.2s  | Documents: 12 classified<br> extract  (COMPLETED)  14.1s | Documents: 12 extracted<br> chunk    (COMPLETED)  1.2s  | 47 chunks produced<br> embed    (COMPLETED)  3.8s  | 47 embeddings generated<br> store    (COMPLETED)  1.1s  | 47 documents indexed</pre><pre>Status: COMPLETED | Total: 28.8s<br>====================================================================</pre><p>Each operator stage runs in sequence. When it finishes, your OpenSearch index exists and is ready to query.</p><h3>What you can do with the result</h3><p>Because the extracted fields are stored as OpenSearch metadata, you can combine semantic vector search with structured filters. Here’s a query that asks for “invoices mentioning support services” — but only from Acme Corp with totals over $5,000:</p><pre>curl -u admin:password &quot;http://localhost:9200/invoices/_search&quot; \<br>  -H &#39;Content-Type: application/json&#39; -d &#39;{<br>    &quot;query&quot;: {<br>      &quot;bool&quot;: {<br>        &quot;must&quot;: {<br>          &quot;knn&quot;: {<br>            &quot;vector_embeddings&quot;: {<br>              &quot;vector&quot;: [/* your query embedding */],<br>              &quot;k&quot;: 5<br>            }<br>          }<br>        },<br>        &quot;filter&quot;: [<br>          { &quot;term&quot;:  { &quot;vendor_name&quot;: &quot;Acme Corp&quot; } },<br>          { &quot;range&quot;: { &quot;grand_total&quot;: { &quot;gt&quot;: 5000 } } }<br>        ]<br>      }<br>    }<br>  }&#39;</pre><p>This is where the classify-then-extract pattern pays off at query time. You’re not just doing semantic search — you’re doing semantic search over a structured, enriched index where every chunk carries validated metadata extracted from the original document.</p><h3>Moving to production</h3><p>The pipeline above runs entirely locally with Ollama. To switch to watsonx.ai — for example, in a regulated environment where you can’t run models locally — update four configuration value:</p><ul><li>Change classifier provider from litellm to watsonx.</li><li>Change classifier model_id from openai/llama3.2 to ibm/granite-3-8b-instruct.</li><li>Change embeddings provider from litellm to watsonx.</li><li>Change embeddings model_id from openai/nomic-embed-text to ibm/slate-125m-english-rtrvr-v2.</li></ul><p>Everything else — the DAG structure, the entity extraction schema, the OpenSearch config — stays identical. Provider portability is a first-class design goal of docling-pipelines.</p><p>The same pipeline pattern generalises beyond invoices: purchase orders, contracts, claims documents, compliance records, medical forms. Anywhere you have a mixed document corpus and need both semantic retrieval and structured metadata, the classify-then-extract approach applies.</p><h3>What you can build from here</h3><p>The invoice pipeline is a template. The same pattern applies to any document type where you need to:</p><ul><li><strong>Classify first</strong> — legal contracts vs. amendments vs. exhibits; purchase orders vs. invoices vs. receipts; technical specs vs. user manuals</li><li><strong>Extract structured entities</strong> — party names and penalty clauses from contracts; part numbers from purchase orders; expiration dates from compliance certificates</li><li><strong>Store for hybrid search</strong> — semantic similarity plus structured metadata filters for complex retrieval requirements</li></ul><p>The repository includes sample flows for <a href="https://github.com/IBM/docling-pipelines/blob/main/sample_flows/advanced/multi_stage_enrichment.json">multi-stage enrichment</a>, <a href="https://github.com/IBM/docling-pipelines/blob/main/sample_flows/advanced/branching_quality_routing.json">quality-based routing</a>, <a href="https://github.com/IBM/docling-pipelines/blob/main/sample_flows/use_cases/audio_video_extraction.json">audio and video transcription</a>, and more. And if you need something the framework doesn’t ship, custom operators load via a pip package or environment variable without any changes to core code.</p><p>What I’d build first is an internal knowledge base that actually works — one that ingests from all the places enterprise knowledge actually lives (Confluence, SharePoint, Google Drive, email archives) and lets employees ask real questions across all of it. The technology to do this well has been there for a while. The missing piece was always a reliable, production-grade data pipeline to feed it. That’s what docling-pipelines is.</p><h3>Try it</h3><pre>pip install docling-pipelines<br>git clone https://github.com/IBM/docling-pipelines<br>cd docling-pipelines<br>export OLLAMA_API_KEY=ollama<br>export OPENSEARCH_USERNAME=admin<br>export OPENSEARCH_PASSWORD=&lt;YOUR_OPENSEARCH_PASSWORD&gt;<br>docling-pipelines --flow-file sample_flows/use_cases/invoice_processing.json</pre><p>The repo includes PDF invoice fixtures so you can run end-to-end without any data prep.</p><ul><li>📖 <strong>Full documentation:</strong> <a href="https://github.com/IBM/docling-pipelines">github.com/IBM/docling-pipelines</a></li><li>🐛 <strong>Issues &amp; feature requests:</strong> <a href="https://github.com/IBM/docling-pipelines/issues">GitHub Issues</a></li><li>📧 <strong>Team:</strong> docling_pipeline_team-dg@ibm.com</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39332f8d2b1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Architecting a Multi-Tier RAG Pipeline: Quality-Aware Document Routing with docling-pipelines]]></title>
            <link>https://medium.com/@nbayas/architecting-a-multi-tier-rag-pipeline-quality-aware-document-routing-with-docling-pipelines-7c62a5089ae1?source=rss-0a176fb2a44c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c62a5089ae1</guid>
            <category><![CDATA[vector-database]]></category>
            <category><![CDATA[data-pipeline]]></category>
            <category><![CDATA[agentic-rag]]></category>
            <category><![CDATA[docling]]></category>
            <category><![CDATA[unstructured-data]]></category>
            <dc:creator><![CDATA[Nipun Bayas]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 18:17:07 GMT</pubDate>
            <atom:updated>2026-09-08T18:17:07.498Z</atom:updated>
            <content:encoded><![CDATA[<h4>Use CPU-based quality scoring, readability metrics, and declarative JSON branching to route unstructured documents into OpenSearch indexes.</h4><p>When migrating a multi-format customer support knowledge base to an AI-powered search system, a common issue is treating every document identically. A typical ingestion corpus contains a heterogeneous mix: clean FAQs, structured product guides, highly complex developer manuals, duplicate legal terms, and corrupted files containing no readable text.</p><p>Feeding this raw mix into a single conversational Retrieval-Augmented Generation (RAG) system degrades retrieval quality. End-users seeking straightforward guides receive dense fragments of developer manuals. Furthermore, sending low-quality text or system logs to expensive AI models for summaries or translations is a waste of compute and money.</p><p>To solve these issues, production RAG systems require a quality-aware document routing architecture. We can design a multi-tier search system that analyzes each document, drops empty pages, evaluates readability, and splits the ingestion corpus:</p><ol><li><strong>Tier 1 (Consumer Search)</strong>: High-readability documents are enriched with structural metadata (such as word counts) to assist with customer-facing conversational search.</li><li><strong>Tier 2 (Developer &amp; Reference Search)</strong>: Dense, highly technical documentation is routed to a specialized index for advanced technical queries.</li></ol><p><a href="https://github.com/IBM/docling-pipelines">docling-pipelines</a> is an open-source, MIT-licensed, IBM-backed framework that compiles and executes document-processing DAGs directly from JSON configurations. It removes custom Python glue code, passing documents between modular operators as in-memory Apache Arrow tables. This architecture ensures that intermediate transformations and routing checks introduce negligible CPU and memory overhead.</p><h3>What this pipeline does</h3><p>The quality-aware pipeline processes documents in a directed acyclic graph (DAG) defined entirely in a single JSON flow file:</p><ol><li><strong>Ingest (</strong>ingest<strong>)</strong>: Reads documents like PDF, TXT, DOCX, and HTML from the filesystem.</li><li><strong>Extraction (</strong>extract<strong>)</strong>: Uses the Docling library to extract structured text.</li><li><strong>Language Detection (</strong>detect_language<strong>)</strong>: Detects the document language.</li><li><strong>Deduplication (</strong>dedup<strong>)</strong>: Uses content hashes to drop duplicate rows.</li><li><strong>Document Quality Scoring (</strong>doc_quality<strong>)</strong>: Computes structural metrics like total word counts.</li><li><strong>Readability Analysis (</strong>readability<strong>)</strong>: Computes text complexity scores.</li><li><strong>Quality-Based Branching (</strong>quality_branching<strong>)</strong>: Routes documents using the Flesch Reading Ease score. Scores above 60 route to the high-quality branch; scores of 60 or less route to the low-quality branch.</li><li><strong>High-Quality Path (</strong>ml_enrichment_high_quality<strong>, </strong>embeddings_high_quality<strong>, </strong>vectordb_high_quality<strong>)</strong>: Computes machine learning-based linguistic enrichments, generates vector embeddings, and writes to a high_quality_docs index.</li><li><strong>Low-Quality Path (</strong>sql_filter_low_quality<strong>, </strong>embeddings_low_quality<strong>, </strong>vectordb_low_quality<strong>)</strong>: Filters out empty rows, generates vector embeddings, and writes to a low_quality_docs index.</li></ol><h3>Before the branch: scoring every document</h3><p>To determine the correct processing path, each document must first be profiled. We represent our pipeline as a directed acyclic graph (DAG) of modular operators. The pipeline starts by executing the <strong>Ingest</strong> operator to read document payloads, followed by the <strong>Extract</strong> operator to parse the raw layout into text.</p><p>Once extraction is complete, every subsequent operator acts as a transformer. They analyze the document table and append new features directly as columns in our in-memory Apache Arrow table. Before routing documents, we run fast, CPU-based checks to detect the language, drop duplicate files, and measure text complexity.</p><h4>1. Language Detection (detect_language)</h4><p>Downstream machine learning models and readability formulas require language context. Language detection is the first analytical step.</p><pre>{<br>      &quot;name&quot;: &quot;detect_language&quot;,<br>      &quot;type&quot;: &quot;lang_detect&quot;,<br>      &quot;config&quot;: {<br>        &quot;doc_column&quot;: &quot;content&quot;<br>      },<br>      &quot;depends_on&quot;: [<br>        &quot;extract&quot;<br>      ]<br>    }</pre><p>The language detection operator evaluates text in the content column and appends lang_name (ISO 639-1 language code) and lang_score columns to the Apache Arrow table. Placing this operator immediately after extraction ensures that downstream, language-sensitive steps can consume its output.</p><h4>2. Deduplication (dedup)</h4><p>Ingesting duplicate documents wastes embedding compute and skews search results.</p><pre>{<br>      &quot;name&quot;: &quot;dedup&quot;,<br>      &quot;type&quot;: &quot;ededup&quot;,<br>      &quot;config&quot;: {<br>        &quot;doc_column&quot;: &quot;content&quot;,<br>        &quot;doc_id_column&quot;: &quot;doc_id_hash&quot;<br>      },<br>      &quot;depends_on&quot;: [<br>        &quot;detect_language&quot;<br>      ]<br>    }</pre><p>This operator references the document content hash in doc_id_hash and the raw text in the content column. It drops duplicate rows from the Arrow table. Computing deduplication early avoids unnecessary CPU work in subsequent operations.</p><h4>3. Document Quality (doc_quality)</h4><p>We analyze basic structural characteristics to detect empty pages or layout anomalies.</p><pre>{<br>      &quot;name&quot;: &quot;doc_quality&quot;,<br>      &quot;type&quot;: &quot;doc_quality&quot;,<br>      &quot;config&quot;: {<br>        &quot;doc_column&quot;: &quot;content&quot;,<br>        &quot;doc_content_column&quot;: &quot;content&quot;,<br>        &quot;text_lang&quot;: &quot;en&quot;<br>      },<br>      &quot;depends_on&quot;: [<br>        &quot;dedup&quot;<br>      ]<br>    }</pre><p>This operator appends 11 structural quality columns prefixed with docq_ to the Arrow table. The key metric generated here is docq_total_words, which captures the total word count of the document.</p><h4>4. Readability Analysis (readability)</h4><p>Readability formulas measure the difficulty of a text based on word lengths, syllable patterns, and sentence structures.</p><pre>{<br>      &quot;name&quot;: &quot;readability&quot;,<br>      &quot;type&quot;: &quot;readability&quot;,<br>      &quot;config&quot;: {<br>        &quot;doc_column&quot;: &quot;content&quot;,<br>        &quot;readability_score_list&quot;: [<br>          &quot;flesch_reading_ease&quot;,<br>          &quot;flesch_kincaid_grade&quot;,<br>          &quot;gunning_fog&quot;,<br>          &quot;difficult_words&quot;,<br>          &quot;dale_chall_readability_score&quot;<br>        ]<br>      },<br>      &quot;depends_on&quot;: [<br>        &quot;doc_quality&quot;<br>      ]<br>    }</pre><p>The readability_score_list array configures the operator to calculate specific metrics, appending them as new columns to the table. The primary metric used for our routing decision is the Flesch Reading Ease score, which evaluates text on a scale from 0 to 100:</p><ul><li><strong>Scores above 60</strong> indicate standard, accessible language suited for a general Help Center interface.</li><li><strong>Scores of 60 or below</strong> represent dense, technical prose requiring specialized background knowledge.</li></ul><h3>The branch</h3><p>The branching operator splits the Apache Arrow dataset into independent processing paths.</p><pre>{<br>      &quot;name&quot;: &quot;quality_branching&quot;,<br>      &quot;type&quot;: &quot;branching&quot;,<br>      &quot;config&quot;: {<br>        &quot;branches&quot;: {<br>          &quot;high_quality_branch&quot;: {<br>            &quot;link_name&quot;: &quot;High Quality Documents&quot;,<br>            &quot;criteria_json&quot;: {<br>              &quot;criteria_list&quot;: [<br>                {<br>                  &quot;variable&quot;: &quot;flesch_reading_ease&quot;,<br>                  &quot;operator&quot;: &quot;&gt;&quot;,<br>                  &quot;value&quot;: 60<br>                }<br>              ],<br>              &quot;logical_operator&quot;: &quot;AND&quot;<br>            }<br>          },<br>          &quot;low_quality_branch&quot;: {<br>            &quot;link_name&quot;: &quot;Low Quality Documents&quot;,<br>            &quot;criteria_json&quot;: {<br>              &quot;criteria_list&quot;: [<br>                {<br>                  &quot;variable&quot;: &quot;flesch_reading_ease&quot;,<br>                  &quot;operator&quot;: &quot;&lt;=&quot;,<br>                  &quot;value&quot;: 60<br>                }<br>              ],<br>              &quot;logical_operator&quot;: &quot;AND&quot;<br>            }<br>          }<br>        }<br>      },<br>      &quot;depends_on&quot;: [<br>        &quot;readability&quot;<br>      ]<br>    }</pre><p>The branches dictionary defines the routing identifiers: high_quality_branch and low_quality_branch. Downstream nodes subscribe to these branches using dot-notation: quality_branching.high_quality_branch or quality_branching.low_quality_branch.</p><p>The routing is controlled by a declarative criteria_json structure:</p><ul><li>variable identifies the target column in our table (e.g., flesch_reading_ease).</li><li>operator specifies the comparison type (such as &gt; or &lt;=).</li><li>value defines the threshold value (such as 60).</li><li>logical_operator combines multiple items in the list using boolean logic (such as AND or OR).</li></ul><p>Using the threshold flesch_reading_ease &gt; 60 partitions the documents. The docling-pipelines engine evaluates these conditions natively, splitting the in-memory Arrow table and executing the respective downstream branches.</p><h3>High-quality path: enrich, embed, index</h3><p>Documents routed to the high_quality_branch undergo linguistic machine learning enrichment.</p><pre>{<br>      &quot;name&quot;: &quot;ml_enrichment_high_quality&quot;,<br>      &quot;type&quot;: &quot;ml_enrichment&quot;,<br>      &quot;config&quot;: {<br>        &quot;doc_column&quot;: &quot;content&quot;,<br>        &quot;lang_column&quot;: &quot;lang_name&quot;,<br>        &quot;output_column_prefix&quot;: &quot;ml_&quot;,<br>        &quot;error_column_name&quot;: &quot;enrichment_error&quot;<br>      },<br>      &quot;depends_on&quot;: [<br>        &quot;quality_branching.high_quality_branch&quot;<br>      ]<br>    }</pre><p>The ml_enrichment operator parses raw text using language-aware machine learning models to generate structured metadata (such as sentence counts, syllable properties, and noun lists) to optimize retrieval. It requires the lang_name output from the upstream language detection step. We apply this CPU-intensive operation only to high-readability texts to optimize system resource consumption. The output_column_prefix configuration appends output columns prefixed with ml_, including ml_num_words.</p><p>The text is then converted into 2560-dimensional vector embeddings using the openai/granite4:latest model through a local Ollama server and LiteLLM:</p><pre>{<br>      &quot;name&quot;: &quot;embeddings_high_quality&quot;,<br>      &quot;type&quot;: &quot;embeddings&quot;,<br>      &quot;config&quot;: {<br>        &quot;embeddings_column&quot;: &quot;embeddings&quot;,<br>        &quot;overlap_ratio&quot;: 0.2,<br>        &quot;doc_column&quot;: &quot;content&quot;,<br>        &quot;provider_config&quot;: {<br>          &quot;api_base&quot;: &quot;http://localhost:11434/v1&quot;,<br>          &quot;api_key&quot;: &quot;${OLLAMA_API_KEY}&quot;,<br>          &quot;model_id&quot;: &quot;openai/granite4:latest&quot;<br>        },<br>        &quot;provider&quot;: &quot;litellm&quot;<br>      },<br>      &quot;depends_on&quot;: [<br>        &quot;ml_enrichment_high_quality&quot;<br>      ]<br>    }</pre><p>Finally, the documents are indexed into OpenSearch. The config uses feature_mappings to map the Apache Arrow columns to OpenSearch fields:</p><pre>{<br>      &quot;name&quot;: &quot;vectordb_high_quality&quot;,<br>      &quot;type&quot;: &quot;vectordb&quot;,<br>      &quot;config&quot;: {<br>        &quot;provider&quot;: &quot;opensearch&quot;,<br>        &quot;doc_id_column&quot;: &quot;doc_id_hash&quot;,<br>        &quot;embeddings_column&quot;: &quot;embeddings&quot;,<br>        &quot;vector_dimension&quot;: 2560,<br>        &quot;create_index&quot;: &quot;true&quot;,<br>        &quot;provider_config&quot;: {<br>          &quot;index_name&quot;: &quot;high_quality_docs&quot;,<br>          &quot;host&quot;: &quot;localhost&quot;,<br>          &quot;port&quot;: 9200,<br>          &quot;username&quot;: &quot;${OPENSEARCH_USERNAME}&quot;,<br>          &quot;password&quot;: &quot;${OPENSEARCH_PASSWORD}&quot;,<br>          &quot;use_ssl&quot;: false,<br>          &quot;verify_certs&quot;: false,<br>          &quot;batch_size&quot;: 100,<br>          &quot;engine&quot;: &quot;faiss&quot;,<br>          &quot;algorithm&quot;: &quot;hnsw&quot;,<br>          &quot;space_type&quot;: &quot;l2&quot;<br>        },<br>        &quot;feature_mappings&quot;: [<br>          {&quot;feature_name&quot;: &quot;doc_id_hash&quot;, &quot;mapped_column_name&quot;: &quot;pk&quot;},<br>          {&quot;feature_name&quot;: &quot;name&quot;, &quot;mapped_column_name&quot;: &quot;doc_name&quot;},<br>          {&quot;feature_name&quot;: &quot;content&quot;, &quot;mapped_column_name&quot;: &quot;text&quot;},<br>          {&quot;feature_name&quot;: &quot;embeddings&quot;, &quot;mapped_column_name&quot;: &quot;vector_embeddings&quot;},<br>          {&quot;feature_name&quot;: &quot;lang_name&quot;, &quot;mapped_column_name&quot;: &quot;language&quot;},<br>          {&quot;feature_name&quot;: &quot;flesch_reading_ease&quot;, &quot;mapped_column_name&quot;: &quot;readability_score&quot;},<br>          {&quot;feature_name&quot;: &quot;ml_num_words&quot;, &quot;mapped_column_name&quot;: &quot;word_count&quot;}<br>        ]<br>      },<br>      &quot;depends_on&quot;: [<br>        &quot;embeddings_high_quality&quot;<br>      ]<br>    }</pre><h3>Low-quality path: filter, embed, index</h3><p>Documents routed to the low_quality_branch bypass the expensive ml_enrichment step. However, some documents may contain zero readable words after extraction (such as corrupted files or blank scan pages). Embedding empty text creates vector noise. We apply a filter to drop these documents:</p><pre>{<br>      &quot;name&quot;: &quot;sql_filter_low_quality&quot;,<br>      &quot;type&quot;: &quot;sql_filter&quot;,<br>      &quot;config&quot;: {<br>        &quot;criteria_json&quot;: {<br>          &quot;criteria_list&quot;: [<br>            {<br>              &quot;variable&quot;: &quot;docq_total_words&quot;,<br>              &quot;operator&quot;: &quot;&gt;&quot;,<br>              &quot;value&quot;: 0<br>            }<br>          ],<br>          &quot;logical_operator&quot;: &quot;AND&quot;<br>        }<br>      },<br>      &quot;depends_on&quot;: [<br>        &quot;quality_branching.low_quality_branch&quot;<br>      ]<br>    }</pre><p>This operator evaluates the docq_total_words column computed by doc_quality. Any document containing zero words is dropped.</p><p>Surviving technical documents are embedded using the same openai/granite4:latest model, then uploaded to a separate OpenSearch index:</p><pre>{<br>      &quot;name&quot;: &quot;vectordb_low_quality&quot;,<br>      &quot;type&quot;: &quot;vectordb&quot;,<br>      &quot;config&quot;: {<br>        &quot;provider&quot;: &quot;opensearch&quot;,<br>        &quot;doc_id_column&quot;: &quot;doc_id_hash&quot;,<br>        &quot;embeddings_column&quot;: &quot;embeddings&quot;,<br>        &quot;vector_dimension&quot;: 2560,<br>        &quot;create_index&quot;: &quot;true&quot;,<br>        &quot;provider_config&quot;: {<br>          &quot;index_name&quot;: &quot;low_quality_docs&quot;,<br>          &quot;host&quot;: &quot;localhost&quot;,<br>          &quot;port&quot;: 9200,<br>          &quot;username&quot;: &quot;${OPENSEARCH_USERNAME}&quot;,<br>          &quot;password&quot;: &quot;${OPENSEARCH_PASSWORD}&quot;,<br>          &quot;use_ssl&quot;: false,<br>          &quot;verify_certs&quot;: false,<br>          &quot;batch_size&quot;: 100,<br>          &quot;engine&quot;: &quot;faiss&quot;,<br>          &quot;algorithm&quot;: &quot;hnsw&quot;,<br>          &quot;space_type&quot;: &quot;l2&quot;<br>        },<br>        &quot;feature_mappings&quot;: [<br>          {&quot;feature_name&quot;: &quot;doc_id_hash&quot;, &quot;mapped_column_name&quot;: &quot;pk&quot;},<br>          {&quot;feature_name&quot;: &quot;name&quot;, &quot;mapped_column_name&quot;: &quot;doc_name&quot;},<br>          {&quot;feature_name&quot;: &quot;content&quot;, &quot;mapped_column_name&quot;: &quot;text&quot;},<br>          {&quot;feature_name&quot;: &quot;embeddings&quot;, &quot;mapped_column_name&quot;: &quot;vector_embeddings&quot;},<br>          {&quot;feature_name&quot;: &quot;lang_name&quot;, &quot;mapped_column_name&quot;: &quot;language&quot;},<br>          {&quot;feature_name&quot;: &quot;flesch_reading_ease&quot;, &quot;mapped_column_name&quot;: &quot;readability_score&quot;},<br>          {&quot;feature_name&quot;: &quot;difficult_words&quot;, &quot;mapped_column_name&quot;: &quot;difficult_words&quot;}<br>        ]<br>      },<br>      &quot;depends_on&quot;: [<br>        &quot;embeddings_low_quality&quot;<br>      ]<br>    }</pre><p>Because this path bypassed enrichment, word_count is absent. However, we map the computed count of difficult_words to help target technical search queries.</p><h3>Two indexes, two query patterns</h3><p>Splitting documents into separate indexes by readability tier enables tailored downstream query patterns. You target searches depending on the user group and target retrieval criteria.</p><h4>Query 1: Help Center customer search</h4><p>When serving end-users, we target the high_quality_docs index, filtering for highly readable guides (readability_score &gt; 60) that contain substantive content (word_count &gt; 100):</p><pre>curl -XGET &quot;http://localhost:9200/high_quality_docs/_search&quot; \<br>  -H &#39;Content-Type: application/json&#39; -d&#39;<br>{<br>  &quot;query&quot;: {<br>    &quot;bool&quot;: {<br>      &quot;must&quot;: [<br>        {<br>          &quot;knn&quot;: {<br>            &quot;vector_embeddings&quot;: {<br>              &quot;vector&quot;: [0.015, -0.023, 0.004],<br>              &quot;k&quot;: 10<br>            }<br>          }<br>        }<br>      ],<br>      &quot;filter&quot;: [<br>        {<br>          &quot;range&quot;: {<br>            &quot;readability_score&quot;: {<br>              &quot;gt&quot;: 60<br>            }<br>          }<br>        },<br>        {<br>          &quot;range&quot;: {<br>            &quot;word_count&quot;: {<br>              &quot;gt&quot;: 100<br>            }<br>          }<br>        }<br>      ]<br>    }<br>  }<br>}&#39;</pre><h4>Query 2: Developer technical reference search</h4><p>When an expert user searches for technical specifications, we query the low_quality_docs index. We search across complex documents, filtering for segments containing a high count of difficult technical terms (difficult_words &gt; 5):</p><pre>curl -XGET &quot;http://localhost:9200/low_quality_docs/_search&quot; \<br>  -H &#39;Content-Type: application/json&#39; -d&#39;<br>{<br>  &quot;query&quot;: {<br>    &quot;bool&quot;: {<br>      &quot;must&quot;: [<br>        {<br>          &quot;knn&quot;: {<br>            &quot;vector_embeddings&quot;: {<br>              &quot;vector&quot;: [0.015, -0.023, 0.004],<br>              &quot;k&quot;: 10<br>            }<br>          }<br>        }<br>      ],<br>      &quot;filter&quot;: [<br>        {<br>          &quot;range&quot;: {<br>            &quot;difficult_words&quot;: {<br>              &quot;gt&quot;: 5<br>            }<br>          }<br>        }<br>      ]<br>    }<br>  }<br>}&#39;</pre><h3>Run it</h3><p>The easiest way to prepare your local infrastructure is by using the setup script included in the codebase. This script manages your virtual environment, registers dependencies, launches local OpenSearch container services, and registers Ollama models.</p><h4>Step 1: Environment Setup</h4><p>Clone the repository and run the setup script:</p><pre>git clone https://github.com/IBM/docling-pipelines.git<br>cd docling-pipelines<br>./scripts/setup_docling_pipelines_environment.sh</pre><p>Alternatively, you can install the package directly from PyPI:</p><pre>pip install docling-pipelines</pre><h4>Step 2: Configure Environment Variables</h4><pre>export OLLAMA_API_KEY=ollama<br>export OPENSEARCH_USERNAME=admin<br>export OPENSEARCH_PASSWORD=&lt;your-password&gt;</pre><h4>Step 3: Run the Pipeline</h4><p>Execute the pipeline using the command-line interface:</p><pre>docling-pipelines --flow-file sample_flows/advanced/branching_quality_routing.json</pre><h3>Pipeline Execution Output</h3><p>Running the pipeline displays the execution flow, logging the data transformations and document routing decisions:</p><pre>$ docling-pipelines --flow-file sample_flows/advanced/branching_quality_routing.json<br>[INFO] [ingest] Loading files from tests/fixtures/customer_support_docs/<br>[INFO] [ingest] Ingested 12 files.<br>[INFO] [extract] Running extract_operator using docling_library...<br>[INFO] [extract] Extracted text from 12 documents.<br>[INFO] [detect_language] Running lang_detect...<br>[INFO] [detect_language] Complete. lang_name assigned.<br>[INFO] [dedup] Running ededup...<br>[INFO] [dedup] Removed 2 duplicate documents. 10 documents remaining.<br>[INFO] [doc_quality] Running doc_quality...<br>[INFO] [doc_quality] Computed docq_* features for 10 documents.<br>[INFO] [readability] Running readability...<br>[INFO] [readability] Computed readability features for 10 documents.<br>[INFO] [quality_branching] Branching 10 documents...<br>[INFO] [quality_branching] Routed 6 documents to link &#39;High Quality Documents&#39; (flesch_reading_ease &gt; 60).<br>[INFO] [quality_branching] Routed 4 documents to link &#39;Low Quality Documents&#39; (flesch_reading_ease &lt;= 60).<br>[INFO] [ml_enrichment_high_quality] Running ml_enrichment on 6 documents...<br>[INFO] [embeddings_high_quality] Generating embeddings with model &#39;openai/granite4:latest&#39;...<br>[INFO] [vectordb_high_quality] Uploaded 6 documents to OpenSearch index &#39;high_quality_docs&#39;.<br>[INFO] [sql_filter_low_quality] Running sql_filter on 4 documents...<br>[INFO] [sql_filter_low_quality] Filtered out 0 empty documents. 4 documents remaining.<br>[INFO] [embeddings_low_quality] Generating embeddings with model &#39;openai/granite4:latest&#39;...<br>[INFO] [vectordb_low_quality] Uploaded 4 documents to OpenSearch index &#39;low_quality_docs&#39;.<br>[INFO] Flow execution finished successfully in 4.23s.</pre><p>By moving quality metrics and routing logic out of custom Python code and directly into a declarative configuration file, you build an ingestion pipeline that is highly performant and easy to maintain. Your document processing cost scales directly with document value, and your downstream RAG application receives clean, structured, and tailored indexes matching your target search audiences.</p><p>This branching design works with any metric computed upstream. You can route documents based on language, PII risk scores, or custom classifier labels by changing the routing criteria. This declarative architecture decouples pipeline logic from orchestration code, allowing engineering teams to scale pipeline complexity without increasing maintenance overhead.</p><h3>Try it Yourself</h3><p>docling-pipelines is an active open-source project. If you find edge cases, want to suggest new operators, or want to contribute optimizations to the execution engine, we welcome your feedback and pull requests.</p><ul><li>📖 <strong>Full Documentation &amp; Source</strong>: <a href="https://github.com/IBM/docling-pipelines">github.com/IBM/docling-pipelines</a></li><li>🐛 <strong>Issues &amp; Feature Requests</strong>: <a href="https://github.com/IBM/docling-pipelines/issues">GitHub Issues</a></li><li>📧 <strong>Get in Touch</strong>: <a href="/service/mailto:docling_pipeline_team-dg@ibm.com">docling_pipeline_team-dg@ibm.com</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c62a5089ae1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>