Multimodal RAG Ingestion: Vectorizing Images and Tables
This article explains how to build a multimodal ingestion pipeline for Retrieval-Augmented Generation (RAG), focusing on why naive parsing loses semantics and how to preserve them. It covers a five-layer architecture, table structure recognition and linearization, handling informational versus decorative images, chunking and metadata design, source traceability, evaluation by question type, and common pitfalls with practical fixes. Readers will learn how to align text, table, and image semantics in a shared vector space for more reliable retrieval.
1. The Real Problem: Not That Images Can’t Be Vectorized, but That Semantics Get Lost
During the ingestion stage of RAG, most engineering failures happen on the parsing and chunking side, not on the generation side. Traditional text embedding models only accept token sequences, yet the images, flowcharts, bar charts, and parameter comparison tables in a document often carry the highest information density in the entire text. Skipping them throws away the most valuable semantics; crudely converting them to plain text with OCR destroys the original spatial and logical relationships, causing retrieval to produce “literal matches with semantic mismatches.”
The correct goal, therefore, is not to “turn images into text” but to build a multimodal fusion pipeline: one where the structural semantics of tables, the visual semantics of images, and the textual semantics of the body content all land in the same comparable vector space.
2. Overall Architecture: A Five-Layer Pipeline
- Layout parsing layer: distinguish titles, body text, headers and footers, figure captions, table captions, and footnotes, and output a reading-order sequence with coordinates.
- Structure reconstruction layer: restore tables to row-and-column structure, and classify image regions as “informational charts” or “decorative illustrations.”
- Semantic enrichment layer: generate descriptive text (caption / structured summary) for each non-text block.
- Representation layer: text goes through text embedding, images go through joint vision-language representation, and both are projected into a unified space.
- Indexing and governance layer: vector index + metadata filtering + source回溯定位 (source traceback and localization).
A schematic parsing result structure (pseudocode, expressing data shape only):
block = {"type": "table", # text / image / table / chart"page": 12,"bbox": [88, 240, 520, 610],"caption": "Table 3-2 Comparison of Three Caching Strategies","text": "Strategy|Hit Rate|Consistency|Ops Cost ...", # linearized table result"struct": {"header": [...], "rows": [[...]]},"modality": "structured","children": [] # merged result for tables continued across pages}
3. Tables: Compressing a Two-Dimensional Structure into One-Dimensional Semantics
Table processing hinges on three things: structure recognition, linearized expression, and context binding.
Structure recognition must handle merged cells, tables continued across pages, and multi-level headers. In engineering practice, this usually means first performing cell detection and relationship判定 (relationship determination), then outputting a row-and-column coordinate matrix; for borderless tables, it also relies on text alignment and column-spacing inference.
Linearized expression determines retrieval quality. Compared with row-by-row concatenation, a more robust approach is “header injection + one sentence per row,” so that each row carries its own column names and remains semantically self-contained even when a single row is chunked out:
[Table 3-2 Comparison of Three Caching Strategies]Strategy=LRU, Hit Rate=Medium, Consistency=Weak, Ops Cost=LowStrategy=TTL, Hit Rate=High, Consistency=Strong, Ops Cost=Medium
Context binding requires writing the table caption, the paragraph above it, and footnotes into the block’s text payload, and storing a whole-table summary as a separate “parent block,” with row-level blocks as “child blocks.” When retrieval hits a child block, trace back to the parent block and hand it to the model, balancing precision and completeness.
4. Images: Distinguishing Informational from Decorative
Images cannot be treated uniformly. Decorative illustrations can be discarded outright or kept only as placeholders; informational charts must be semanticized.
For flowcharts and architecture diagrams, generate ordered descriptions by combining layout position with arrow relationships; for bar charts and line charts, restore the axes, units, extrema, and trend conclusions as much as possible; for screenshot-type images, after OCR you still need to preserve contextual notes such as “this is an interface / error / configuration example.” The generated descriptive text and the original image vectors can be ingested via dual paths, with weighted fusion at retrieval time.
There are two approaches to unified alignment: one is a shared embedding space, so image and text vectors can be compared directly; the other is text占位 (text placeholder), using high-quality descriptive text in place of the image for retrieval, which has lower engineering cost and better interpretability. In practice, the second is usually primary and the first secondary.
5. Chunking, Metadata, and Traceback
Chunking principle: split on semantic boundaries rather than a fixed word count, and keep non-text blocks intact without mixing them into body-text chunks.
Metadata should include at least: document identifier, page number, block type, coordinates, heading path, version, and effective time, to support filtering and traceability.
The traceback chain must be closed-loop: vector hit → locate block → fetch original text/image → assemble context. Without this step, the model easily “makes things up by looking at the picture.”
6. Evaluation and Common Pitfalls
Evaluation should report recall by type: build separate evaluation sets for pure-text questions, table-value questions, and chart-trend questions, so that overall metrics don’t mask weak spots.
Common pitfalls include: cross-page tables being truncated, figure captions separated from figures, OCR noise polluting vectors, multimodal descriptions hallucinating numeric values, and duplicate blocks causing redundant recall. Corresponding measures are structure validation, coordinate-proximity merging, confidence-threshold filtering, secondary numeric verification, and deduplication.
7. Implementation Recommendations
If in-house development is too costly, you can use Baidu AI Cloud’s document parsing capabilities to reconstruct layout and table structure, then connect object storage to keep the original files, a message queue to decouple parsing tasks, and a container platform to host parsing and embedding services. Use logging services and monitoring alerts to observe parsing failure rates and retrieval quality, forming a sustainable, iterable ingestion pipeline.
