Multimodal Ingestion for RAG: Vectorizing Images and Tables
This article explains why non-text content breaks retrieval in RAG systems and presents a reusable five-stage multimodal ingestion pipeline. You will learn how to restore table structure into searchable semantics, convert images into joint visual-language representations, align text, tables, and images in a shared vector space, and apply metadata filtering and reranking. It also includes a practical engineering checklist and common pitfalls.
1. The Problem: Why Non-Text Content Breaks RAG Retrieval
Most RAG (Retrieval-Augmented Generation) implementations assume documents are plain text streams: chunk, embed, write to a vector store, and retrieve by similarity. But real documents—technical manuals, financial reports, research reports, contracts, and product documentation—carry high-value information in images and tables that ordinary text embedding models cannot directly represent. As a result, user queries fail to hit key evidence, and the model falls back on parametric memory, producing a “retrieval gap.”
This gap has three root causes:
- Missing representation: Text embedding models only accept token sequences. Images are pixel matrices, and tables are two-dimensional or multi-dimensional structures. Discarding them means discarding evidence.
- Lost structure: A table’s row/column semantics, merged cells, and continued tables across pages are destroyed once flattened into a string. The row-column correspondence breaks, and retrieval can no longer locate the semantics of a specific cell.
- Misalignment: Even if vectors are generated separately for images and tables, if they do not live in the same semantic space as text vectors, similarity scores are not comparable during hybrid retrieval, and ranking becomes distorted.
2. Overall Approach: A Reusable Multimodal Ingestion Pipeline
Break ingestion into five stages to form an observable, traceable pipeline:
- Parsing and layout restoration: Detect headings, paragraphs, lists, tables, images, captions, headers, and footers while preserving reading order and coordinate information.
- Modality routing: Route each block by type to a table parser, an image understanding module, or a text chunker.
- Semantic enrichment: Generate structured summaries and row/column descriptions for tables; generate joint visual-language representations and textual descriptions (including captions and OCR text) for images.
- Unified embedding: Map text, table summaries, and image descriptions into the same vector space; optionally keep multiple vectors (original text vector plus summary vector).
- Metadata and filtering: Store page numbers, coordinates, type, heading path, permission labels, and more, to support hybrid retrieval and reranking.
Illustrative code (flow only, not a specific API):
def ingest(doc):blocks = parse_layout(doc) # Layout parsing; outputs blocks with coordinatesfor b in blocks:if b.type == "table":t = parse_table(b) # Restore rows, columns, and merged cellsb.text = table_to_semantic(t) # Structured summary + key row descriptionsb.vec = embed(b.text)elif b.type == "image":cap = caption_and_ocr(b) # Visual description + text inside the imageb.text = capb.vec = embed_image_text(cap) # Joint visual-language representationelse:b.vec = embed(b.text)b.meta = { "page": b.page, "bbox": b.bbox, "type": b.type }upsert_to_vector_store(blocks)
3. Tables: From “Strings” to Searchable Structured Semantics
The key to table handling is not converting content into text, but preserving and expressing structure. Recommended practices:
- Structure restoration: Identify headers, body rows, merged cells, and continued tables across pages, and build row/column indexes.
- Semantic rewriting: Turn each row into a natural-language sentence of “subject + metric + value + unit + qualifier,” or combine headers and cells into key-value descriptions so the embedding model can capture metric semantics.
- Hierarchical chunking: Split large tables into chunks of “header + several rows” so each chunk carries its own context; additionally generate a global summary vector for the whole table to support “locate the table first, then the row.”
- Metadata enrichment: Record the table title, section, units, and dimensions. These can serve as filters during retrieval to reduce confusion between identically named metrics.
Example (header + row to semantic sentence):
Table: Quarterly revenue by region (unit: 10k CNY)Row -> region=East China, quarter=Q2, revenue=1280Semantic sentence: East China generated 12.8 million CNY in revenue in Q2.
4. Images: Joint Visual-Language Representations and Searchable Text
Images cannot be consumed directly by text embedding models and must be “translated” into searchable semantics:
- Bind captions and context: Prefer using the figure title, caption, and surrounding paragraphs from the document as strong priors to generate descriptions that better fit the context.
- Extract text inside images: For screenshots, flowcharts, and dashboards containing text, extract the text and fuse it with the visual description to form a composite “visuals + text” representation.
- Joint representation: Use joint visual-language modeling to map an image and its description into the same space; at ingestion time, store both the image vector and the description text vector to support dual-path retrieval.
- Typed labels: Distinguish diagrams, trend charts, architecture diagrams, photos, and so on, and write them into metadata to enable filtering by query intent (for example, architecture-diagram questions prioritize architecture diagrams).
5. Unified Alignment: Making Three Modalities Comparable in One Space
Alignment is the make-or-break factor. Engineering can adopt and combine three strategies:
- Shared embedding space: Use the same multimodal embedding model for text, table summaries, and image descriptions to keep similarity comparable.
- Dual-vector retrieval: The original text vector handles fine granularity, while the summary/description vector handles semantic generalization; fuse and rerank after retrieval.
- Reranking and filtering: Apply hard filtering with metadata (type, page, section), then use a cross-encoder for precise reranking to mitigate scoring-scale differences across modalities.
6. Engineering Checklist and Common Pitfalls
- Parsing first: The ceiling on ingestion quality is set by layout parsing. Always preserve coordinates and reading order.
- Chunk with context: Tables by “header + rows,” images by “caption + paragraph.” Avoid isolated blocks.
- Traceability: Keep the source page and coordinates on every vector so answers can cite the original location.
- Evaluation loop: Build an evaluation set covering table QA and image QA, and monitor retrieval hit rate and answer accuracy.
- Permissions and security: Apply permission labels at ingestion and enforce access control at retrieval to prevent unauthorized recall.
- Cost and latency: Precompute image descriptions and joint representations asynchronously; index very large tables hierarchically, coarse first then fine.
7. Conclusion
Non-text information is not a “side note” for RAG but a primary carrier of high-value evidence. Structuring tables, verbalizing images, mapping multimodal content into a unified vector space, and combining metadata filtering with reranking are what fundamentally eliminate the retrieval gap. With the general capabilities of Baidu AI Cloud in document parsing and multimodal vectorization, teams can build a stable, observable, and scalable multimodal ingestion pipeline more quickly, so RAG can truly “see images and understand tables.”
