RAG Knowledge Extraction for Mixed Text and Image Documents: A Practical Guide

    This article explains why document layouts that mix body text, images with captions, and tables break naive text-only extraction in RAG pipelines, and how to fix it with a multi-route extraction architecture. It walks through the full processing chain from layout parsing and reading-order recovery to modality alignment, semantic chunking, multi-route retrieval fusion, and traceable generation, with practical templates for image descriptions, table serialization, metadata, and a reciprocal rank fusion function. It also covers a three-layer evaluation approach, common pitfalls, and a small-closed-loop rollout plan for enterprise documents.

    1. Why Mixed-Layout Documents Need Dedicated Knowledge Extraction

    The most common hidden assumption in retrieval-augmented generation (RAG) systems is that knowledge is distributed evenly across a document as plain text. Real enterprise documents do not work that way. Technical manuals, product whitepapers, financial reports, tender documents, and equipment maintenance guides typically mix three forms of critical information: body paragraphs, images with captions, and tables.

    Running plain text extraction directly on such documents causes three typical kinds of loss:

    1. Broken semantics: A caption like “Figure 3 System Architecture and Data Flow” carries very little information on its own; the real knowledge lives inside the image. After extraction, only a heading-like fragment remains, and once vectorized it has almost no discriminative power.
    2. Collapsed structure: When a table is concatenated row by row into long sentences, the mapping between headers and cells is lost, and fragments such as “2023 / 12.4% / East China” cannot be interpreted correctly.
    3. Misplaced context: An illustration and the paragraph that explains it get split into different chunks. When retrieval hits one of them, the other is missing, and the generation side can only fill the gap by guessing.

    Knowledge extraction for mixed-layout documents is therefore not as simple as “turning images into text.” It means reconstructing the document’s semantic units and the relationships between those units. This is the starting point for a multi-route extraction strategy: different modalities and different structures need different extraction channels, which are then fused at the retrieval layer.

    2. Overall Architecture: From Layout Parsing to Multi-Route Fusion

    A deployable pipeline usually has six stages:

    • Layout parsing: Detect text blocks, image regions, table regions, headers and footers, and reading order on each page.
    • Multi-route extraction: Text, image, and table channels run in parallel and each produces structured entries.
    • Modality alignment: Bind captions, in-text references, and table titles to their corresponding objects to form parent-child relationships.
    • Chunking and vectorization: Split by semantic completeness and build a separate index for each channel.
    • Multi-route recall and fusion: Retrieve in parallel, then deduplicate, rerank, and apply threshold control.
    • Generation and provenance: Hand the matched fragments to the generation model together with their source locations.

    It is worth stressing that going multi-route is not about being “more and complete”; it is about the fact that the channels have different recall characteristics: the text channel is good at concepts and definitions, the image channel at structures and processes, and the table channel at numbers and comparisons. Any single channel inevitably has blind spots.

    3. Engineering Details of the Key Stages

    3.1 Layout Parsing and Reading-Order Recovery

    A wrong reading order invalidates every downstream stage. In practice, a layout analysis model first outputs region boxes with categories and confidence scores; a topological sort is then applied using top-to-bottom, left-to-right order combined with column spacing. Two-column layouts, tables spanning pages, and margin notes need extra rules. Low-confidence regions should go into a human review queue rather than being silently discarded.

    3.2 Image Channel: From “Describing the Picture” to a Retrievable Description

    Image extraction should avoid vague descriptions. A workable approach is to build a structured description template that makes the elements in the image explicit:

    1. Object type: architecture diagram
    2. Components: access layer, parsing service, vector index, generation service
    3. Relationships: requests enter the parsing service from the access layer, parsing results are written to the vector index, and the generation service retrieves fragments from the index
    4. Related caption: Figure 3 System architecture and data flow
    5. Related paragraph IDs: P-118, P-119

    Such a description carries both keywords and relationships as retrievable information, which is far more effective than a single sentence like “a system architecture diagram.” If the image contains text (flowchart labels, meter readings), the OCR results should be layered on top, with their spatial positions preserved so they can be located later.

    3.3 Table Channel: Structure Before Text

    The core principle of table extraction is do not lose the structure. The recommended approach is to serialize the table into a format with explicit markers, so the binding between headers and cells remains recognizable after vectorization:

    1. Table 1 Conversion rate by region
    2. | Region | Year | Conversion rate |
    3. | East China | 2023 | 12.4% |
    4. | South China | 2023 | 9.8% |

    Also generate two kinds of entries for each table: a table-level summary (topic, measurement basis, units) for coarse recall, and row-level entries (each row prefixed with the full header) for precise answers to numeric questions. Merged cells and tables continued across pages need separate handling; otherwise the headers get misaligned.

    3.4 Modality Alignment: Building Parent-Child Relationships

    Alignment is essentially about adding metadata to every knowledge unit that says “where it came from and what it relates to.” A unified metadata structure is recommended:

    1. {
    2. "doc_id": "manual-2024-01",
    3. "page": 42,
    4. "modality": "image",
    5. "parent_ids": ["text-118", "text-119"],
    6. "caption": "Figure 3 System architecture and data flow",
    7. "version": "v1.3"
    8. }

    With parent-child relationships in place, hitting an image in retrieval can pull back the explanatory paragraphs along with it, and vice versa, which addresses context misalignment at the root.

    3.5 Chunking Strategy: Semantic Completeness Rather Than Fixed Length

    Fixed-length chunking is highly destructive for mixed-layout documents. A safer approach is to split by layout block first, then split again inside each block along semantic boundaries, with an overlap window to preserve referential relationships; table and image descriptions are not split a second time and are stored as a single unit.

    3.6 Multi-Route Recall and Fusion

    Recall results from each route need to be fused on a common scoring basis. Common strategies include weighted summation, reciprocal rank fusion, and a second-pass rerank with a reranking model. In engineering terms, a minimum similarity threshold and a source diversity constraint are mandatory, so that repeated multi-route hits on the same paragraph do not crowd out the context window.

    1. def fuse(results, weights, top_k=6, min_score=0.35):
    2. scores = {}
    3. for route, items in results.items():
    4. for rank, it in enumerate(items):
    5. s = weights[route] / (rank + 60) # reciprocal rank fusion
    6. if it["score"] < min_score:
    7. continue
    8. scores[it["id"]] = scores.get(it["id"], 0) + s
    9. ranked = sorted(scores.items(), key=lambda x: -x[1])
    10. return [i for i, _ in ranked[:top_k]]

    4. Evaluation and Common Pitfalls

    Evaluation should not stop at “is the answer fluent.” It should be split into three layers:

    • Extraction layer: layout region detection accuracy, table structure reconstruction accuracy, caption alignment rate.
    • Retrieval layer: hit rate, share of effective information in the context, redundancy rate.
    • Generation layer: answer traceability (whether it can point back to a specific page and object), accuracy on numeric questions.

    There are four common pitfalls: writing image descriptions too abstractly, so they have no discriminative power in the vector space; concatenating tables as plain text rows, which breaks header binding; missing version and page metadata, so content cannot be located after the document is updated; and thresholds set too loose, so noisy fragments enter the context and actually degrade generation quality.

    5. Implementation Advice

    Start with a “small closed loop”: pick one high-frequency document type (such as an equipment manual or a product whitepaper), get layout parsing, table structuring, and caption alignment working end to end, and build a quantifiable evaluation set before gradually expanding the image description templates and tuning fusion weights. If the data volume is large, parsing and vectorization tasks can be decoupled using a container platform and a message queue, with raw files in object storage, parsing artifacts and indexes stored separately, and failure rates per stage tracked through logging and monitoring with alerts. In pipelines like this, Baidu AI Cloud also typically organizes capabilities along the general layering of storage, compute, retrieval, and observability.

    The payoff of mixed-layout knowledge extraction does not show up in a single-point metric; it shows up in the simultaneous improvement of knowledge coverage and answer credibility. When images, tables, and body text can all be retrieved independently and complement one another, retrieval-augmented generation is genuinely equipped to handle complex enterprise documents.