Close Menu
    Trending
    • Optimizing Data Transfer in Distributed AI/ML Training Workloads
    • Achieving 5x Agentic Coding Performance with Few-Shot Prompting
    • Why the Sophistication of Your Prompt Correlates Almost Perfectly with the Sophistication of the Response, as Research by Anthropic Found
    • From Transactions to Trends: Predict When a Customer Is About to Stop Buying
    • America’s coming war over AI regulation
    • “Dr. Google” had its issues. Can ChatGPT Health do better?
    • Evaluating Multi-Step LLM-Generated Content: Why Customer Journeys Require Structural Metrics
    • Why SaaS Product Management Is the Best Domain for Data-Driven Professionals in 2026
    ProfitlyAI
    • Home
    • Latest News
    • AI Technology
    • Latest AI Innovations
    • AI Tools & Technologies
    • Artificial Intelligence
    ProfitlyAI
    Home » Building a Multimodal RAG That Responds with Text, Images, and Tables from Sources
    Artificial Intelligence

    Building a Multimodal RAG That Responds with Text, Images, and Tables from Sources

    ProfitlyAIBy ProfitlyAINovember 3, 2025No Comments12 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Era (RAG) has been one of many earliest and most profitable functions of Generative AI. But, few chatbots return photos, tables, and figures from supply paperwork alongside textual solutions.

    On this put up, I discover why it’s troublesome to construct a dependable, really multimodal RAG system, particularly for advanced paperwork similar to analysis papers and company studies — which frequently embrace dense textual content, formulae, tables, and graphs.

    Additionally, right here I current an strategy for an improved multimodal RAG pipeline that delivers constant, high-quality multimodal outcomes throughout these doc varieties.

    Dataset and Setup

    As an example, I constructed a small multimodal information base utilizing the next paperwork:

    1. Fully Fine-tuned CLIP Models are Efficient Few-Shot Learners
    2. VectorPainter: Advanced Stylized Vector Graphics Synthesis Using Stroke-Style Priors
    3. Marketing Strategy for Financial Services: Financing Farming & Processing the Cassava, Maize and Plantain Value Chains in Côte d’Ivoire

    The language mannequin used is GPT-4o, and for embeddings I used text-embedding-3-small.

    The Normal Multimodal RAG Structure

    In idea, a multimodal RAG bot ought to:

    • Settle for textual content and picture queries.
    • Return textual content and picture responses.
    • Retrieve context from each textual content and picture sources.

    A typical pipeline appears like this:

    1. Ingestion
    • Parsing & chunking: Break up paperwork into textual content segments and extract photos.
    • Picture summarization: Use an LLM to generate captions or summaries for every picture.
    • Multi-vector embeddings: Create embeddings for textual content chunks, picture summaries, and optionally for the uncooked picture options (e.g., utilizing CLIP).

    2. Indexing

    • Retailer embeddings and metadata in a vector database.

    3. Retrieval

    • For a consumer question, carry out similarity search on:
    • Textual content embeddings (for textual matches)
    • Picture abstract embeddings (for picture relevance)

    4. Era

    • Use a multimodal LLM to synthesize the ultimate response utilizing each retrieved textual content and pictures.

    The Inherent Assumption

    This strategy assumes that the caption or abstract of a picture generated from its content material, at all times comprises sufficient context concerning the textual content or themes that seem within the doc, for which this picture can be an acceptable response.

    In real-world paperwork, this typically isn’t true.

    Instance: Context Loss in Company Stories

    Take the “Advertising and marketing Technique for Monetary Providers (#3 in dataset)” report within the dataset. In its Government Abstract, there are two similar-looking tables exhibiting Working Capital necessities — one for major producers (farmers) and one for processors. They’re the next:

    Working Capital Desk for Major Producers
    Working Capital Desk for Processors

    GPT-4o generates the next for the primary desk:

    “The desk outlines varied forms of working capital financing choices for agricultural companies, together with their functions and availability throughout completely different conditions”

    And the next for the second desk:

    “The desk supplies an outline of working capital financing choices, detailing their functions and potential applicability in several eventualities for companies, significantly exporters and inventory purchasers”

    Each appear high-quality individually — however neither captures the context that distinguishes producers from processors.

    This implies they are going to be retrieved incorrectly for queries particularly asking about producers or processors solely. There are different tables similar to CAPEX, Funding alternatives the place the identical problem will be seen.

    For the VectorPainter paper, the place Fig 3 within the paper exhibits the VectorPainter pipeline, GPT-4o generates the caption as “Overview of the proposed framework for stroke-based model extraction and stylized SVG synthesis with stroke-level constraints,” lacking the truth that it represents the core theme of the paper, named “VectorPainter” by the authors.

    And for the Imaginative and prescient Language similarity distillation loss method outlined in Sec 3.3 of the CLIP finetuning paper, the caption generated is “Equation representing the Variational Logit Distribution (VLD) loss, outlined because the sum of Kullback–Leibler (KL) divergences between predicted and goal logit distributions over a batch of inputs.”, the place the context of imaginative and prescient and language correlation is absent.

    Additionally it is to be famous that within the analysis papers, the figures and tables have a writer supplied caption, nevertheless, throughout the extraction course of, that is extracted not as a part of the picture, however as a part of the textual content. And likewise the positioning of the caption is typically above and at different occasions under the determine. As for the Advertising and marketing Technique studies, the embedded tables and different photos don’t even have an connected caption describing the determine.

    What the above has illustrated is that the real-world paperwork don’t observe any commonplace format of textual content, photos, tables and captions, thereby making the method of associating context to the figures troublesome.

    The New and Improved Multimodal RAG pipeline

    To resolve this, I made two key adjustments.

    1. Context-Conscious Picture Summaries

    As a substitute of asking the LLM to summarize the picture, I extract the textual content instantly earlier than and after the determine — as much as 200 characters in every path.
     This fashion, the picture caption contains:

    • The author-provided caption (if any)
    • The surrounding narrative that offers it that means

    Even when the doc lacks a proper caption, this supplies a contextually correct abstract.

    2. Textual content Response Guided Picture Choice at Era Time

    Throughout retrieval, I don’t match the consumer question straight with picture captions. It’s because the consumer question typically is just too brief to supply ample context for picture retrieval (eg; What’s … ?)
     As a substitute:

    • First, generate the textual response utilizing the highest textual content chunks retrieved for context.
    • Then, choose one of the best two photos for the textual content response matched to the picture captions

    This ensures the ultimate photos are chosen in relation to the precise response, not the question alone.

    Here’s a diagram for the Extraction to Embedding pipeline:

    Extraction to Embedding Pipeline

    And the pipeline for Retrieval and Response Era is as follows:

    Retrieval and Response Era

    Implementation Particulars

    Step 1: Extract Textual content and Pictures

    Use Adobe PDF Extract API to parse PDFs into:

    • figures/ and tables/ folders with .png recordsdata
    • A structuredData.json file containing positions, textual content, and file paths

    I discovered this API to be way more dependable than libraries like PyMuPDF, particularly for extracting formulation and diagrams.

    Step 2: Create a Textual content File

    Concatenate all textual components from the JSON to create the uncooked textual content corpus:

    # Extract textual content, sorted by Web page and vertical order (Bounds[1])
    components = information.get("components", [])
    # Concatenate textual content
    all_text = []
    for el in components:
      if "Textual content" in el:
        all_text.append(el["Text"].strip())
        final_text = "n".be part of(all_text)

    Step 3: Construct Picture Captions: Stroll by way of every ingredient of `structuredData.json`, examine if the ingredient filepath ends in `.png` . Load the file from figures and tables folder of the doc, then use the LLM to carry out a top quality examine on the picture. That is wanted because the extraction course of will discover some illegible, small photos, header and footer, firm logos and so forth which must be excluded from any consumer responses.

    Word that we aren’t asking the LLM to interpret the photographs; simply remark whether it is clear and related sufficient to be included within the database. The immediate for the LLM can be like:

    Analyse the given picture for high quality, readability, measurement and so forth. Is it a superb high quality picture that can be utilized for additional processing ? The photographs that we contemplate good high quality are tables of information and figures, scientific photos, formulae, on a regular basis objects and scenes and so forth. Pictures of poor high quality can be any firm emblem or any picture that's illegible, small, faint and generally wouldn't look good in a response to a consumer question.
    Reply with a easy Good or Poor. Don't be verbose

    Subsequent we create the picture abstract. For this, within the `structuredData.json`, we take a look at the weather behind and forward of the `.png` ingredient, and gather as much as 200 characters in every path for a complete of 400 characters. This kinds the picture caption or abstract. The code snippet is as follows:

    # Accumulate earlier than
    j = i - 1
    whereas j >= 0 and len(text_before) < 200:
      if "Textual content" in components[j] and never ("Desk" in components[j]["Path"] or "Determine" in components[j]["Path"]):
        text_before = components[j]["Text"].strip() + " " + text_before
        j -= 1
        text_before = text_before[-200:]
    # Accumulate after
    ok = i + 1
    whereas ok < len(components) and len(text_after) < 200:
      if "Textual content" in components[k]:
        text_after += " " + components[k]["Text"].strip()
        ok += 1
        text_after = text_after[:200]

    We carry out this for every determine and desk for each doc in our database, and retailer the picture captions as metadata. In my case, I retailer as a `image_captions.json` file.

    This easy change makes a large distinction — the ensuing captions embrace significant context. As an illustration, the captions I get for the 2 Working Capital tables from the Advertising and marketing Technique report are as follows. Word how the contexts at the moment are clearly differentiated and embrace farmers and processors.

    "caption": "o farmers for his or her capital expenditure wants in addition to for his or her working capital wants. The desk under exhibits the completely different merchandise that might be related for the small, medium, and huge farmers. Working Capital Enter Financing For buy of farm inputs and labour Sure Sure Sure Contracted Crop Mortgage* For buy of inputs for farmers contracted by respected patrons Sure Sure Sure Structured Mortgage"
    "caption": "producers and their patrons b)t Potential Mortgage merchandise on the processing degree On the processing degree, the merchandise that might be related to the small scale and the medium_large processors embrace Working Capital Bill discounting_ Factoring Financing working capital necessities by use of accounts receivable as collateral for a mortgage Possibly Sure Warehouse receipt-financing Financing working ca"

    Step 4: Chunk Textual content and Generate Embeddings

    The textual content file of the doc is break up into chunks of 1000 characters, utilizing ` RecursiveCharacterTextSplitter` from `langchain` and saved. Embeddings created for the textual content chunks and picture captions, normalized and saved as `faiss` indexes

    Step 5: Context Retrieval and Response Era

    The consumer question is matched and the highest 5 textual content chunks are retrieved as context. Then we use these retrieved chunks and consumer question to get the textual content response utilizing the LLM.

    Within the subsequent step, we take the generated textual content response and discover the highest 2 closest picture matches (primarily based on caption embeddings) to the response. That is completely different from the normal manner of matching the consumer question to the picture embeddings and supplies a lot better outcomes.

    There may be one remaining step. Our picture captions had been primarily based on 400 characters across the picture within the doc, and will not kind a logical and concise caption for show. Subsequently, for the ultimate chosen 2 photos, we ask the LLM to take the picture captions together with the photographs and create a short caption prepared for show within the remaining response.

    Right here is the code for the above logic:

    # Retrieve context
    end result = retrieve_context_with_images_from_chunks(
    user_input,
    content_chunks_json_path,
    faiss_index_path,
    top_k=5,
    text_only_flag= True
    )
    text_results = end result.get("top_chunks", [])
    # Assemble prompts
    payload_1 = construct_prompt_text_only (user_input, text_results)
    # Accumulate responses (synchronously for device)
    assistant_text, caption_text = "", ""
    for chunk in call_gpt_stream(payload_1):
      assistant_text += chunk
      lst_final_images = retrieve_top_images (assistant_text, caption_faiss_index_path, captions_json_path, top_n=2)
    if len(lst_final_images) > 0:
      payload = construct_img_caption (lst_final_images)
    for chunk in call_gpt_stream(payload):
      caption_text += chunk
    response = {
    "reply": assistant_text + ("nn" + caption_text if caption_text else ""),
    "photos": [x['image_name'] for x in lst_final_images],
    }
    return response

    Take a look at Outcomes

    Let’s run the queries talked about at first of this weblog to see if the photographs retrieved are related to the consumer question. For simplicity, I’m printing solely the photographs and their captions displayed and never the textual content response.

    Question 1: What are the mortgage and dealing capital requirement of the first producer ?

    Determine 1: Overview of working capital financing choices for small, medium, and huge farmers.

    Determine 2: Capital expenditure financing choices for medium and huge farmers.

    Picture End result for Question 1

    Question 2: What are the mortgage and dealing capital requirement of the processors ?

    Determine 1: Overview of working capital mortgage merchandise for small-scale and medium-large processors.
     Determine 2: CAPEX mortgage merchandise for equipment buy and enterprise growth on the processing degree.

    Picture End result for Question 2

    Question 3: What’s imaginative and prescient language distillation ?

    Determine 1: Imaginative and prescient-language similarity distillation loss method for transferring modal consistency from pre-trained CLIP to fine-tuned fashions.

    Determine 2: Closing goal perform combining distillation loss, supervised contrastive loss, and vision-language similarity distillation loss with balancing hyperparameters.

    Formulation Retrieval for Question 3

    Question 4: What’s VectorPainter pipeline ?

    Determine 1: Overview of the stroke model extraction and SVG synthesis course of, highlighting stroke vectorization, style-preserving loss, and text-prompt-based technology.

    Determine 2: Comparability of varied strategies for model switch throughout raster and vector codecs, showcasing the effectiveness of the proposed strategy in sustaining stylistic consistency.

    Picture Retrieval for Question 4

    Conclusion

    This enhanced pipeline demonstrates how context-aware picture summarization and textual content response primarily based picture choice can dramatically enhance multimodal retrieval accuracy.

    The strategy produces wealthy, multimodal solutions that mix textual content and visuals in a coherent manner — important for analysis assistants, doc intelligence methods, and AI-powered information bots.

    Attempt it out… go away your feedback and join with me at www.linkedin.com/in/partha-sarkar-lets-talk-AI

    Sources

    1. Fully Fine-tuned CLIP Models are Efficient Few-Shot Learners: Mushui Liu, Bozheng Li, Yunlong Yu Zhejiang College

    2. VectorPainter: Advanced Stylized Vector Graphics Synthesis Using Stroke-Style Priors: Juncheng Hu, Ximing Xing, Jing Zhang, Qian Yu† Beihang College

    3. Marketing Strategy for Financial Services: Financing Farming & Processing the Cassava, Maize and Plantain Value Chains in Côte d’Ivoire from https://www.ifc.org



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleSamsungs släpper Internet för PC med Galaxy AI
    Next Article 3 Questions: How AI is helping us monitor and support vulnerable ecosystems | MIT News
    ProfitlyAI
    • Website

    Related Posts

    Artificial Intelligence

    Optimizing Data Transfer in Distributed AI/ML Training Workloads

    January 23, 2026
    Artificial Intelligence

    Achieving 5x Agentic Coding Performance with Few-Shot Prompting

    January 23, 2026
    Artificial Intelligence

    Why the Sophistication of Your Prompt Correlates Almost Perfectly with the Sophistication of the Response, as Research by Anthropic Found

    January 23, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    How I Would Learn To Code (If I Could Start Over)

    April 4, 2025

    Think Your Python Code Is Slow? Stop Guessing and Start Measuring

    December 26, 2025

    Graph RAG vs SQL RAG

    November 1, 2025

    AI-kompanjoner använder manipulativa taktiker för att förlänga konversationer

    October 16, 2025

    Retrieval Augmented Generation (RAG) — An Introduction

    April 22, 2025
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    Most Popular

    Business Insider’s Layoffs Signal a Harsh Truth: AI Efficiency Is Here

    June 10, 2025

    Trying to Stay Sane in the Age of AI

    June 10, 2025

    Cloudflare Accuses Perplexity of “Stealth Crawling” Blocked Sites

    August 12, 2025
    Our Picks

    Optimizing Data Transfer in Distributed AI/ML Training Workloads

    January 23, 2026

    Achieving 5x Agentic Coding Performance with Few-Shot Prompting

    January 23, 2026

    Why the Sophistication of Your Prompt Correlates Almost Perfectly with the Sophistication of the Response, as Research by Anthropic Found

    January 23, 2026
    Categories
    • AI Technology
    • AI Tools & Technologies
    • Artificial Intelligence
    • Latest AI Innovations
    • Latest News
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 ProfitlyAI All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.