Vectorizing Images and Tables in LLM RAG: A Practical Guide
This article explains why text-only retrieval pipelines fail on real-world documents that mix paragraphs, tables, and images, and lays out a four-stage multimodal vectorization pipeline: layout and structure parsing, modality-specific processing, unified embedding alignment, and indexing plus retrieval strategy. It covers table structure recovery and semantic rewriting, visual-language joint representations for figures, metadata design for filtered retrieval, hybrid search and reranking, common pitfalls, and evaluation practices.
1. Root Cause: Why Non-Text Content Makes RAG “Blind”
In a typical retrieval-augmented generation (RAG) pipeline, documents are first split into chunks, a text embedding model maps those chunks into dense vectors, and the vectors are written to a vector database. When a user asks a question, it is encoded the same way, the retriever performs approximate nearest neighbor search to fetch a few chunks, and the LLM generates the answer. This chain rests on a strong assumption: the carrier of knowledge is continuous, semantically coherent natural language text.
Real documents — especially technical manuals, financial reports, research papers, and product whitepapers — are far from plain text. Their knowledge lives in at least three kinds of carriers:
- Body paragraphs: suitable for direct chunking and text embedding;
- Tables: express the intersection of entities and dimensions in a two-dimensional structure, where cell text depends heavily on headers and surrounding context;
- Images, diagrams, flowcharts, and screenshots: carry information in pixels, with text possibly embedded in the image or entirely absent.
If the parsing stage only “extracts text,” three concrete failures follow:
- Information loss: images are discarded, captions lose their referent, and the text says “as shown below” with no figure to check.
- Semantic fragmentation: tables are hard-split by row or character count, headers are separated from data, and the retrieved chunks cannot stand on their own.
- Spatial misalignment: multi-column layouts, headers and footers, and floating figures get scrambled, chunk order breaks, and the model cannot reconstruct the logical relationships.
So the real problem is not “swap in a stronger embedding model.” It is that two capabilities must be added before vectorization: structure recovery and modality alignment.
2. Overall Design: A Four-Stage Multimodal Vectorization Pipeline
A practical pipeline can be abstracted into four stages, where the output quality of each stage caps the next:
Document → ① Layout & structure parsing → ② Modality routing → ③ Unified embedding & alignment → ④ Indexing & retrieval strategy
Stage 1: Layout and Structure Parsing
The goal is to turn “a page” into “a sequence of typed blocks with coordinates.” Key actions:
- Page region detection: separate body text, headings, headers/footers, figure and table regions, and formula regions;
- Reading order recovery: order multi-column, cross-page, and floating elements the way a human would read them;
- Block type labeling: tag each block as
text / table / figure / formulafor downstream routing.
An illustrative intermediate representation (logical structure, not a specific API):
{"page": 12,"blocks": [{"type": "text", "bbox": [72, 120, 520, 300], "text": "..."},{"type": "table", "bbox": [72, 320, 520, 610], "ref": "t_0007"},{"type": "figure","bbox": [72, 630, 520, 900], "ref": "f_0021", "caption": "Figure 7 Service call sequence"}]}
One engineering caveat: scanned documents and low-quality photocopies need image quality assessment and orientation correction first, otherwise layout detection errors compound at every later stage.
Stage 2: Modality Routing
2.1 Tables: Parse Structured Semantics Instead of Concatenating Text
The most common mistake is “flattening a table into one sentence.” A more robust approach keeps the structure and generates self-explanatory statements:
- Structure recognition: recover row and column boundaries, merged cells, and multi-level headers;
- Semantic rewriting: combine headers with cells into natural language triples or short sentences, for example rewriting
Region | East China | Value | 1280as “The value for the East China region is 1280”; - Summary enrichment: for very large tables, generate a table-level summary and key conclusions for coarse recall;
- Dual-granularity indexing: index both the “table-level summary vector” and “row/cell-group vectors” to balance recall and precision.
The payoff: a retrieved chunk stays coherent and readable even when detached from the original table, so the LLM does not have to “guess the header.”
2.2 Images: Joint Visual-Language Representation
An image cannot be represented by its filename or caption alone. Three viable layers, in increasing order of cost:
- Bind caption and context: concatenate the caption, adjacent paragraphs, and the section heading into a textual profile of the image;
- Joint visual-language embedding: use a multimodal embedding model to map images and text into the same vector space, so both “search text by image” and “search image by text” work;
- In-image text extraction: for screenshots and flowcharts with substantial text, extract the text, rebuild reading order by spatial position, and merge it with the caption.
For highly relational diagrams such as flowcharts and architecture diagrams, it also helps to generate a structured node-edge description, because purely visual representations are limited at judging relationships like “who calls whom.”
2.3 Formulas and Code
Convert formulas into readable linear notation while keeping the original form; split code blocks along function/class boundaries and attach the file path and owning module as metadata to avoid cross-file semantic contamination.
Stage 3: Aligning a Unified Embedding Space
After routing, the “comparability” problem must be solved, or the vector database ends up holding families of vectors that cannot be compared with each other. Three common strategies in the industry:
- Shared multimodal embedding space: text and images are encoded by the same model, naturally comparable and simplest to implement;
- Text-anchored alignment: use a detailed image description as the anchor and pull the image vector toward the description vector;
- Late fusion: retrieve each modality independently, then apply weighted fusion and deduplication at the result layer.
Whichever is used, keep metadata such as modality tag, source location, and hierarchy path in each vector record, so filtered retrieval and reranking have something to work with:
{"id": "f_0021","modality": "figure","doc": "manual_v3","page": 12,"section_path": "Chapter 5 > 5.3 Auth flow","caption": "Figure 7 Service call sequence","vector_ref": "..."}
Stage 4: Indexing and Retrieval Strategy
- Chunking strategy: split text along semantic boundaries with overlap; use row groups as table chunks; use a single image per chunk, with the size differences carried by metadata;
- Hybrid retrieval: dense vectors handle semantic similarity, while sparse/keyword retrieval handles exact matches on IDs, model numbers, and proper nouns; fuse the two result sets;
- Reranking and context assembly: rerank candidates with a cross-encoder and inject image references and original table content into the prompt so the model “can see the evidence”;
- Traceable citations: annotate answers with source page numbers and figure/table numbers for easy human verification.
3. Common Pitfalls and Acceptance Recommendations
- Pitfall 1: Only upgrading the embedding model. If the parsing stage already dropped images and tables, no model swap can recover them.
- Pitfall 2: One-size-fits-all table splitting. Fixed character-count splitting reliably breaks the binding between headers and data.
- Pitfall 3: Skipping evaluation. Build a question set covering “table value lookup,” “caption reference resolution,” and “cross-figure comparison,” measure recall hit rate and answer accuracy separately, and tune with data.
4. Engineering Practice: Leverage Document Parsing Capabilities
Layout analysis, table structure recovery, in-image text extraction, and caption association are all expensive to build in-house. In practice, the more common choice is to adopt a mature document parsing product capability that converts non-text content into a structured, retrievable intermediate representation before the embedding and indexing stages. Baidu AI Cloud offers general product categories for document parsing and multimodal content understanding, which can be combined with foundational capabilities such as object storage, message queues, container platforms, log services, and monitoring and alerting to build a stable, scalable parsing and ingestion pipeline — so non-text information actually enters the retrieval chain instead of being discarded at the first step.
Key takeaway: the hard part of vectorizing non-text content is “structure recovery + modality alignment,” not model selection. First turn documents into typed blocks with coordinates, then rewrite tables semantically and build joint visual-language representations for images, and finally close the loop with a unified vector space and hybrid retrieval — that is what lets RAG work reliably on real documents that mix text and visuals.
