RAG Knowledge Extraction from Mixed Text and Image Documents: An Engineering Guide

    Building RAG systems for documents that combine text, tables, and images requires more than text extraction. This article outlines an engineering workflow covering layout analysis, multimodal knowledge extraction, structure-aware chunking, hybrid retrieval, evidence-grounded generation, and evaluation. It also explains how provenance, access controls, versioning, and pipeline management support reliable, traceable answers.

    RAG Knowledge Extraction from Mixed Text and Image Documents: An Engineering Guide

    Enterprise knowledge bases, technical manuals, research reports, and contract attachments often combine multiple content types on a single page: body text, heading hierarchies, tables, flowcharts, photographs, captions, headers, and footers.

    Extracting these documents as plain text loses layout relationships, table structure, image semantics, and links between visuals and the text that references them. These losses can weaken retrieval, leave generated answers without adequate evidence, and make citations difficult to trace.

    For retrieval-augmented generation (RAG), the goal is therefore not simply to convert documents into text. It is to transform multimodal page content into knowledge units that can be retrieved, cited, and verified.

    1. Core Challenges and Design Principles

    Knowledge extraction from mixed text and image documents typically faces five challenges:

    1. Complex layouts: Multiple columns, tables spanning pages, sidebars, and captions can disrupt reading order.
    2. Missing multimodal semantics: Images and tables represented only by filenames or placeholders cannot support meaningful semantic retrieval.
    3. Difficult chunk sizing: Small chunks lose context, while large chunks introduce retrieval noise.
    4. Weak evidence constraints: Without clear boundaries between retrieval and generation, models may answer beyond the available evidence.
    5. Insufficient evaluation: Errors are difficult to locate across parsing, retrieval, reranking, and generation without a feedback loop.

    Four principles should guide implementation:

    • Structure before content: Recover reading order and relationships between page regions before extracting text.
    • Extraction before indexing: Convert text, tables, and image descriptions into a consistent knowledge-unit representation before building indexes.
    • Traceability: Preserve page numbers, coordinates, parent–child relationships, and source versions for every knowledge unit.
    • Measurability: Establish separate metrics and labeled datasets for parsing, retrieval, and generation.

    2. Document Parsing and Layout Understanding

    The parsing layer provides the foundation for every downstream stage. Normalize input documents into a consistent representation, then organize them around pages, regions, blocks, and relationships.

    • Pages retain their original dimensions and page numbers.
    • Regions identify content types such as headings, paragraphs, lists, tables, captions, headers, footers, formulas, and stamps.
    • Blocks store text, images, table cells, and coordinates.
    • Relationships capture heading paths, image–caption associations, table merges across pages, and references from body text.

    Key processing steps include:

    • Recovering reading order so that two-column documents are not read horizontally across both columns.
    • Removing repeated headers and footers.
    • Identifying and flagging low-confidence optical character recognition (OCR) results.
    • Associating captions with their corresponding images.
    • Merging tables across pages using their headers and column structure.

    The intermediate representation can be modeled as follows:

    1. Document
    2. └─ Page(page_no, width, height)
    3. └─ Region(region_id, type, bbox, reading_order)
    4. └─ Block(block_id, modality, text, cells, image_ref, parent_id)

    The bbox, reading_order, and parent_id fields are essential for citation handling and context assembly. Without coordinates and hierarchy, validating citations during generation becomes much harder.

    3. Multimodal Knowledge Extraction

    Text

    Preserve heading paths and paragraph boundaries. Keep the hierarchy of list items rather than flattening multiple semantic units into one paragraph.

    Tables

    Table extraction should retain more than flattened text. Preserve headers, row and column relationships, units, footnotes, and merged-cell information.

    A table can have two complementary representations:

    • A structured table for precise question answering.
    • A natural-language summary for semantic retrieval.

    Images

    Classify image regions before extracting their meaning. Distinguish flowcharts, architecture diagrams, charts, photographs, formulas, and other visual types.

    For each image, generate a searchable description, a caption summary, and key entities. Retain the original image reference so that answers can link back to the visual evidence.

    Cross-Modal Relationships

    Connecting modalities is central to extraction from mixed-content documents. References such as “as shown in the figure” or “see the table below” should point to the corresponding image or table block.

    Captions and table titles should provide context within the same knowledge unit. Table units and footnotes must remain attached to the table.

    At a minimum, each knowledge unit should contain:

    • Content.
    • Modality type.
    • Metadata.
    • Source fragment.
    • Heading path.
    • Entities.
    • Access-control labels.

    4. Cleaning, Chunking, and Knowledge-Unit Design

    Use structure-aware chunking rather than fixed character boundaries.

    Keep the heading path with each chunk. Tables should generally remain intact or be split into row groups. Images should be grouped with their captions and the paragraphs that reference them. Content whose meaning spans multiple paragraphs can be organized into parent and child chunks.

    A common pattern is child-chunk retrieval with parent-chunk generation. Smaller child chunks support targeted retrieval, while parent chunks supply the complete context needed to generate an answer.

    Metadata should include the document identifier, version, page number, region coordinates, access permissions, time information, source type, and parsing confidence.

    1. def build_units(document):
    2. units = []
    3. for region in document.regions:
    4. if region.type in ["title", "paragraph", "list"]:
    5. units.append(make_text_unit(region))
    6. elif region.type == "table":
    7. units.append(make_table_unit(region))
    8. elif region.type == "image":
    9. units.append(make_image_unit(region, bind_caption(region)))
    10. return merge_by_parent_path(filter_low_quality(units))

    During cleaning, filter out empty blocks, garbled text, repeated headers and footers, and low-confidence recognition results. Redact sensitive information where required.

    Tune chunking parameters against an evaluation dataset rather than fixing them solely through intuition.

    5. Indexing and Hybrid Retrieval

    The indexing layer should support multiple representations:

    • Keyword indexes for exact matches on entities, identifiers, and technical terms.
    • Vector indexes for semantic retrieval.
    • Structured fields for filtering by time, document type, and access permissions.
    • Image descriptions and table summaries included in the semantic index.

    The retrieval workflow consists of query understanding, retrieval across multiple paths, result fusion, deduplication, reranking, and context assembly.

    Apply permission filtering as early as possible to prevent unauthorized content from entering the candidate set.

    When assembling context, preserve reading order and parent–child relationships, stay within the token budget, and retain citation anchors. For questions about table values or conclusions from images, prioritize structured table blocks and image-description blocks, and give them greater weight during reranking.

    1. def retrieve(query, user_scope):
    2. q = understand(query)
    3. candidates = []
    4. candidates += keyword_recall(q, user_scope)
    5. candidates += vector_recall(q, user_scope)
    6. candidates += structured_filter(q, user_scope)
    7. merged = fuse_and_deduplicate(candidates)
    8. ranked = rerank(q, merged)
    9. return assemble_context(ranked, token_budget)

    6. Generation Constraints and Citation Validation

    Generation should follow explicit evidence rules:

    • Answer only from retrieved evidence.
    • Attach knowledge-unit citations to each key conclusion.
    • State “This cannot be confirmed from the available materials” when evidence is insufficient.
    • Include units with values taken from tables.
    • Cite the caption or image description for conclusions drawn from images.
    • Present conflicting evidence side by side rather than concealing the conflict.

    The output can include an answer, a citation list, confidence information, and a description of missing information.

    Post-processing should verify that cited source fragments exist, numerical values match the evidence, and units are consistent. These checks help reduce hallucinations and incorrect citations.

    7. Evaluation, Iteration, and Engineering Governance

    Offline and Online Evaluation

    Offline evaluation should cover:

    • Parsing accuracy.
    • Region recall.
    • Table-structure accuracy.
    • Retrieval Recall@k.
    • Mean reciprocal rank.
    • Generation faithfulness.
    • Citation accuracy.
    • Answer coverage.

    The labeled dataset should include questions involving text, tables, images, content spanning pages, and multi-hop reasoning.

    Online signals can include clicks, follow-up questions, no-answer rates, and human feedback.

    Error analysis should distinguish between information lost during parsing, context split by chunking, retrieval failures, reranking errors, and generation that exceeds the evidence. This stage-level diagnosis creates an actionable iteration loop.

    Pipeline Operations

    Connect ingestion, parsing, extraction, indexing, retrieval, generation, and feedback through an asynchronous pipeline. The workflow should support retries, idempotency, version management, and incremental updates.

    Store original documents and intermediate artifacts in object storage, and manage indexes and metadata separately. Message queues can support task scheduling, while logging, monitoring, and alerts track operational status.

    To control costs, cache image descriptions and table summaries, and reparse only the necessary content when documents change.

    Security controls should cover permission filtering, sensitive-data redaction, auditing, and citation version management.

    Conclusion

    RAG knowledge extraction from mixed text and image documents is a systems-engineering task, not a capability delivered by a single model. It combines document-structure understanding, multimodal extraction, hybrid retrieval, evidence-constrained generation, and evaluation.

    Start with a small labeled evaluation dataset. Use structure-aware chunking and hybrid retrieval, preserve source coordinates and versions, and strengthen citation validation. Then use stage-level error analysis to guide continuous improvement.