<?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 Ravi Srirangam on Medium]]></title>
        <description><![CDATA[Stories by Ravi Srirangam on Medium]]></description>
        <link>https://medium.com/@ravisrirangam?source=rss-96152d09b9de------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8pTO23pftWm-TwH7YIQPPg.png</url>
            <title>Stories by Ravi Srirangam on Medium</title>
            <link>https://medium.com/@ravisrirangam?source=rss-96152d09b9de------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 14:13:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ravisrirangam/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[From Concept to Code: Creating an Intuitive Text Extraction Framework — Part1]]></title>
            <link>https://medium.com/@ravisrirangam/from-concept-to-code-creating-an-intuitive-text-extraction-framework-part1-b78f56ad10d2?source=rss-96152d09b9de------2</link>
            <guid isPermaLink="false">https://medium.com/p/b78f56ad10d2</guid>
            <category><![CDATA[data-extraction]]></category>
            <category><![CDATA[watsonx-ai]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[generative-ai]]></category>
            <dc:creator><![CDATA[Ravi Srirangam]]></dc:creator>
            <pubDate>Thu, 26 Sep 2024 03:38:38 GMT</pubDate>
            <atom:updated>2024-09-26T03:38:38.509Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Concept to Code: Creating an Intuitive Text Extraction Framework — Part1</h3><p>This article is written in collaboration with <a href="https://medium.com/u/d633ab1bd7e4">Aishwarya Pradeep</a>, <a href="https://medium.com/u/435deb72ef46">Manoj Jahgirdar</a>, <a href="https://medium.com/u/d6a76a20f581">Suman P</a>, <a href="https://medium.com/u/4dceba8fd5ac">Surya Deep Singh</a></p><h3>Introduction</h3><p>In the age of data-driven decision-making, efficiently extracting text from various documents is critical. Documents often come in diverse layouts such as PDFs, Word files, excel and scanned images, which make data extraction difficult. Traditional extraction methods, such as rule-based systems and basic machine learning models, struggle with the variability of document structures, leading to errors or incomplete information. The quality of data used in AI applications can significantly impact their effectiveness. Recognizing this, a framework was developed to streamline text extraction, minimizing the complexity of handling diverse document formats. This tool simplifies the process, ensuring clean, ready-to-use text for applications, much like a pasta cutter effortlessly prepares penne. The framework focuses on simplifying the text extraction process, making it more adaptable and efficient.</p><p>The <a href="https://github.com/IBM/doc-fusion">Github repo</a> has the code, documentation and examples. Feel free to try it out before reading the rest of the article. The implementation used the Large Language Model (LLM) from the IBM watsonx.ai Foundation Model library.</p><h3>Framework Overview</h3><p>The framework had been designed and developed in a modular way with the following capabilities:</p><ul><li>Parse different data formats (pdf, docx, xlsx, csv) and also content from web pages</li><li>Handle complexities in data such as multi columnar, and tabular data</li><li>Leverage an Agentic approach, where the Agent would decide how each data format is handled</li><li>Extract metadata from the file — filename, page no., and in case of tables — table id, row id, column name</li><li>Provide a user-friendly configuration mechanism for chunking</li></ul><p>Data extraction is the first step in the Retrieval Augmented Generation (RAG) pipeline. DocFusion aims to simplify the process of data extraction and let users proceed to the next stages easily. The usual RAG pipeline with DocFusion framework is illustrated in the below picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZOHoUnDQ9W8Y__0RqX30cQ.png" /></figure><p>Scalability and extensibility are achieved by utilizing Agents to manage decisions regarding the appropriate module for processing a specific data format. This approach enables the framework to efficiently support new data formats as they arise.</p><p>The framework comprises of the following components:</p><ul><li>Agents — the framework is powered by the agents and these agents would decide the processing of each data format. There are two agents — <em>Configurator Agent</em> and <em>Orchestrator Agent</em></li><li>Loaders — these handle the data processing per the configuration. There are three loaders — <em>StructuredDataLoader</em> to handle the structured data such as Excel and CSV, <em>UnstructuredDataLoader</em> to process the PDF, DOCX, Markdown and text files, and <em>WebCrawlerLoader</em> to extract web page content</li><li>Splitters — simplifies the process of chunking the data and makes it ready to be used in the subsequent stages in the pipeline</li></ul><p>The execution flow is depicted in the below picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*_q0F29_GQKozMHzGOZi5Eg.png" /><figcaption>Execution Flow</figcaption></figure><h3>Setup and Usage</h3><p>Python version 3.11.9 or greater is recommended. The framework can be downloaded from the Github repo and combined with the application. The pip based installation is not preferred to avoid any conflicts with the already installed libraries. If any libraries are missing, use the <em>requirements.txt</em> to install them. The framework can be imported and used:</p><pre>from main import DocFusion</pre><h3>Components of the Framework</h3><p>This section details the working of each component with coding examples as appropriate.</p><h4>Agents</h4><p>Agents are driven by Large Language Model (LLM), the framework uses <em>Mixtral-8X7B-instruct-v01</em> from the <em>watsonx.ai </em>foundation models, to decide on the execution flow.</p><h4>Configurator Agent</h4><p>The <em>ConfiguratorAgent</em> uses a no code approach to create and save the config files in an intuitive way by asking the user a series of applicable questions. There is also a provision to create the config file manually and use it with the framework. The steps of configuration are as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*mtMTKHeQZqkUYpYMLhFIBA.png" /><figcaption>Configuration Process</figcaption></figure><p>The non-interactive way of creating a configuration involves giving inputs to the various configuration parameters, below code can be used as a starting point</p><pre>DocFusion.configure(<br>  input_data={<br>            &quot;agent_verbose&quot;: False,<br>            &quot;model_id&quot;: &quot;mistralai/mixtral-8x7b-instruct-v01&quot;,<br>            &quot;wx_project_id&quot;: &quot;****&quot;,<br>            &quot;wx_api_key&quot;: &quot;****&quot;,<br>            &quot;wx_endpoint&quot;: &quot;https://us-south.ml.cloud.ibm.com&quot;,<br>            &quot;chunk&quot;: True,<br>            &quot;chunk_table_rows&quot;: True,<br>            &quot;chunk_table_row_size&quot;: 3,<br>            &quot;chunk_table_row_overlap&quot;: 1,<br>            &quot;chunk_table_output_format&quot;: &quot;md&quot;,<br>            &quot;chunk_text_size&quot;: 512,<br>            &quot;chunk_text_overlap&quot;: 10<br>        }<br>)</pre><p>The interactive way of configuration can be initiated by</p><pre>DocFusion.configure() </pre><p>The set of questions and sample answers for configuration are shown below</p><pre>Enter watsonx.ai endpoint URL (https://us-south.ml.cloud.ibm.com):  https://us-south.ml.cloud.ibm.com <br><br>Enter watsonx.ai API Key:  ········ <br><br>Enter watsonx.ai project ID:  ········ <br><br>Enter LLM to use (mistralai/mixtral-8x7b-instruct-v01): mistralai/mixtral-8x7b-instruct-v01 <br><br>Do you want to see the LLM Agent reasoning process? (yes/no):  no  <br><br>What is the expected output? (docs/chunks):  chunks <br><br>How would you like to chunk the tables? (Row wise/ Full table):  row wise <br><br>How many rows in a table to consider for row wise table chunking?:  1 <br><br>What is the table output format you are expecting? (md/json):  json <br><br>What is the chunk size for text chunking?:  512 <br><br>What is the chunk text overlap?:  0 <br><br>Config data successfully written to config/data_config.json</pre><h4>Orchestrator Agent</h4><p>The <em>OrchestratorAgent</em> is responsible for identifying the data format and decide on the appropriate loader and splitter, and handle errors in case of invalid files or URLs. The functionality of <em>OrchestratorAgent</em> is depicted below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*GZnetXUPN90RyGuCEut0cg.png" /><figcaption>OrchestratorAgent</figcaption></figure><p>Code snippet to start the process of loading and splitting would begin by calling the <em>source()</em> method</p><pre># Load unstructured data<br>docs = DocFusion.source(<br>    input_data=&quot;Source this: docs/insurance.pdf&quot;<br>    )</pre><p>The invocation of the appropriate Loader and Splitter is handled seamlessly by the <em>OrchestratorAgent</em>. The Loader is invoked by the <em>OrchestratorAgent</em> based on the input type of the document. If the expected output in the configuration is document, then a LangChain Document is returned. <em>Splitter</em> would be called if the expected output in the configuration is chunks. The text chunks are at a fixed token count of 512. The table chunking is done per configuration and the current version of framework handles only simple tables.</p><p>Readers are encouraged to try out the end to end examples in the <a href="https://github.com/IBM/doc-fusion/tree/main">Github repo</a>.</p><h4>Full Code Example</h4><p>Here’s the full code example of extracting the text from a sample pdf. The file is located in the <em>examples/data</em> folder in the <a href="https://github.com/IBM/doc-fusion/tree/main/examples/data">Github repo</a></p><p>Sample configuration with table details</p><pre>{<br>  &quot;chunk&quot;: true,<br>  &quot;chunk_table_rows&quot;: true,<br>  &quot;chunk_table_row_size&quot;: 2,<br>  &quot;chunk_table_row_overlap&quot;: 0,<br>  &quot;chunk_table_output_format&quot;: &quot;json&quot;,<br>  &quot;chunk_text_size&quot;: 512,<br>  &quot;chunk_text_overlap&quot;: 20<br>}</pre><p>Python Code to parse the pdf and extract the text, note that the table data is also given as the LangChain Document</p><pre># Step 1: Import the necessary library<br>from main import DocFusion<br><br># Step 2: Configure the DocFusion library<br># This is required before using any extraction methods.<br>DocFusion.configure()<br><br># Step 3: Extract unstructured data from a PDF document<br># Provide the path to the document to be sourced.<br>input_data = &quot;Source this: docs/insurance.pdf&quot;<br><br># Use the DocFusion source method to extract document pages.<br>docs = DocFusion.source(input_data=input_data)<br><br># Step 4: Output the number of pages extracted<br>print(f&quot;{len(docs)} pages sourced.&quot;)<br><br># Step 5: Check the type of the docs object<br># It is an array of LangChain Document objects<br>print(type(docs))<br><br># Step 6: Iterate over the pages and print metadata and page content<br>for page in docs:<br>    print(&quot;Page Metadata:\n---&quot;)<br>    print(page.metadata, &quot;\n&quot;)<br>    print(&quot;Page Content:\n---&quot;)<br>    print(page.page_content, &quot;\n&quot;)<br><br># For pages with text, the output is as below<br><br># Page Metadata:<br># ---<br># {&#39;source&#39;: &#39;docs/insurance.pdf&#39;, &#39;page&#39;: 2, &#39;index&#39;: 2} <br><br># Page Content:<br># ---<br># It&#39;s essential to keep all necessary documents ready when making a claim to avoid delays.<br># 4. Service Level Agreement (SLA)<br># To ensure efficient processing of claims, insurance companies operate under a Service Level<br># Agreement (SLA). Below is a summary of the key service expectations:<br><br># For Tabular Data, the output is as below, notice that metadata is in JSON format<br># Notice the table number and row number in the metadata<br># Page Metadata:<br># ---<br># {&#39;json_format&#39;: {&#39;Insurance Type&#39;: &#39;Health Insurance&#39;, &#39;Coverage&#39;: &#39;Medical expenses,\nhospitalization,\nsurgeries&#39;, &#39;Key Benefits&#39;: &#39;Cashless treatments,\nmedical check-ups,\nno claim bonus&#39;, &#39;Premium Basis&#39;: &#39;Age, medical history,\npolicy tenure&#39;}, <br># &#39;source&#39;: &#39;docs/insurance.pdf&#39;, &#39;page&#39;: 1, &#39;table&#39;: 0, &#39;row&#39;: 1} <br><br># Page Content:<br># ---<br># Health Insurance | Medical expenses, hospitalization, surgeries | Cashless treatments, medical check-ups, no claim bonus | Age, medical history, policy tenure <br><br></pre><h3>Conclusion</h3><p>In this post, we looked at the concept of simplifying the text extraction from diverse document formats and the implementation details have been covered. In the next part, the design and working of the configuration, Loader and Splitter shall be covered.</p><h3>References</h3><ul><li><a href="https://github.com/IBM/data-prep-kit">IBM Data Prep Toolkit</a></li><li><a href="https://github.com/DS4SD/docling">IBM Deepsearch, Docling</a></li><li><a href="https://github.com/opendatalab/PDF-Extract-Kit">PDF Extract Kit</a></li><li><a href="https://medium.com/@krtarunsingh/ai-and-llm-for-document-extraction-simplifying-complex-formats-with-ease-b3261b5be58e">AI and LLM for Document Extraction</a></li><li><a href="https://pub.towardsai.net/demystifying-pdf-parsing-05-unifying-separate-tasks-into-a-small-model-d3739db021f7">Demystifying PDF Parsing Series</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b78f56ad10d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>