Parsing and Indexing Images and Tables for LLM RAG
Images and tables require more than text extraction to support reliable retrieval-augmented generation. This article explains how to preserve source evidence, reconstruct document layouts and table structures, create searchable representations, and combine text, keyword, and multimodal indexes. It also covers structured computation, evidence-aware answer generation, quality evaluation, and a phased implementation approach. The central principle is to use vectors to discover evidence, structured data to support accurate interpretation and calculation, and original assets for verification and traceability.
1. The Core Challenge: Preserving Retrievable Evidence
In a large language model (LLM) retrieval-augmented generation (RAG) system, a typical pipeline parses documents, splits text into chunks, generates embeddings, builds indexes, retrieves relevant passages, and generates answers. This works well for continuous prose, but images, tables, scanned pages, and complex layouts can lose important information along the way.
A troubleshooting flowchart, for example, represents relationships between decision conditions and corrective actions. Extracting its text alone does not recover the branching logic. A value such as “12.6” in a business table is meaningful only when paired with its row label, column header, unit, and reporting period. A line chart may show a trend that the surrounding text never describes.
Processing non-text content therefore has three distinct goals:
- Preserve source evidence: Store original images and tables, along with their document locations, so results can be traced back to their sources.
- Create retrieval representations: Convert content into forms suitable for text search, vector search, or multimodal retrieval.
- Preserve analytical structure: Retain machine-processable data for calculation, filtering, and comparison rather than relying solely on natural-language summaries.
A vector database stores and retrieves vector representations. It does not replace document parsing, structured storage, or source-file management. A complete solution typically needs these capabilities to work together.
2. Parse Documents Before Generating Embeddings
2.1 Choose the Processing Path by Input Type
Document parsing should reflect the characteristics of the input rather than applying optical character recognition (OCR) to every page.
For documents with an extractable text layer, first read the text and its positions, then reconstruct the layout. For scanned pages, use OCR to extract text and identify text, image, and table regions. For mixed documents, select the processing path at the page or even region level.
This reduces unnecessary recognition costs and avoids introducing OCR errors into text that was already readable. However, an extractable text layer is not automatically high-quality input: encoding problems and incorrect reading order still require validation.
2.2 Reconstruct Reading Order and Context
Complex documents often contain multiple columns, headers, footers, side notes, captions, and content spanning several pages. Sorting text solely by character coordinates can join paragraphs from different columns or insert a footer into the body text.
Parsing should preserve the following relationships wherever possible:
- Headings and their associated sections.
- The reading order of body paragraphs.
- Images and their captions.
- Tables, titles, and notes.
- Continuity between parts of a table spanning multiple pages.
- The mapping between page regions and original coordinates.
These relationships affect both chunking and retrieval. An image might refer to “Option 2,” while the definition appears in the preceding paragraph. If the image loses that connection, even an accurate image description may not support an answer about which option to choose.
2.3 Keep a Machine-Readable Intermediate Representation
Lightweight markup is useful for reading and conventional text chunking, but it cannot fully represent every complex structure. Merged cells, multilevel headers, coordinates, and image references are better preserved alongside structured records.
Each content block can include a document ID, block ID, content type, page number, bounding box, section path, parent block ID, source-asset reference, and parser version.
Source-asset references are intended for internal lookup and should not be exposed directly as public URLs. In enterprise knowledge bases, retrieved results and original files must follow the same access-control rules.
3. Tables: Support Both Understanding and Accurate Calculation
3.1 Recover the Table Structure First
Table parsing involves more than recognizing text. It must also recover rows, columns, and relationships between cells. Common challenges include borderless tables, merged cells, multilevel headers, tables spanning multiple pages, line breaks within cells, and values separated from their units.
Check the following carefully:
- Which row labels and column headers apply to each data cell.
- The ranges covered by merged cells.
- Whether a unit applies to the entire table, a column, or an individual cell.
- Whether content on different pages belongs to the same table.
- Whether notes below the table change the interpretation of values.
- Whether blank cells mean missing data, inherited values, or “not applicable.”
Do not convert blank values to zero by default. Likewise, percentage signs, parentheses, and footnote markers should not all be discarded as irrelevant characters. Cleaning rules must preserve business meaning.
3.2 Maintain Multiple Table Representations
A single table can be stored in three complementary forms.
Original structured representation
Preserve cells, row and column indexes, header hierarchies, merged-cell relationships, and data types. This representation supports verification, filtering, and calculation.
Semantic text representation
Convert each row into a description with complete context. For example:
Reporting period: Q2; Business region: Eastern region; Metric: Revenue; Value: 1,260; Unit: RMB 10,000.
This is more suitable for text embeddings than an isolated pair such as “Eastern region, 1,260.”
Table-level summary
Describe the table’s subject, time range, dimensions, and metrics so the system can determine whether it is relevant to a query. A summary helps locate the table; it should not be the sole source of exact values.
3.3 Chunk Tables According to Size and Query Patterns
Small tables can be indexed as complete retrieval chunks. Large tables usually need to be split by row, row group, or business dimension. Each chunk should include the table name, relevant headers, units, and necessary notes.
If users frequently compare several metrics for the same business entity, keep that entity’s data together where possible. If queries primarily target time ranges, organize chunks around time intervals.
Do not merge tables across pages simply because one appears at the bottom of a page and another at the top of the next. Also compare column structure, table titles, repeated headers, and content continuity.
3.4 Use Structured Execution for Exact Calculations
Questions such as “Which region grew fastest?” or “What was the annual total?” should not depend entirely on a generative model calculating from retrieved text.
A more reliable approach is to retrieve the relevant tables, perform filtering, sorting, aggregation, and calculation on structured data, and then provide the results and sources to the model for answer composition.
Before execution, validate numeric types, units, and reporting definitions. Values using different currencies, reporting periods, or tax treatments should not be added or compared directly.
4. Images: Text Extraction, Visual Description, and Relationship Extraction
4.1 Classify Images Before Selecting a Parsing Strategy
Different images carry different kinds of information and require different processing strategies.
- Text screenshots: Extract text while preserving paragraph or interface-region relationships.
- Statistical charts: Identify titles, axes, legends, units, and major trends.
- Flowcharts and architecture diagrams: Extract nodes, connection directions, conditions, and hierarchical relationships.
- Photographs: Describe observable objects, conditions, and scenes.
- Decorative images: These generally do not need to enter the retrieval index.
Classification reduces unnecessary indexing and prevents logos, backgrounds, and repeated icons from crowding retrieval results.
4.2 Generate Searchable Semantic Descriptions
Vision-language models can describe images in text, but those descriptions should stay grounded in observable content rather than introduce unsupported interpretations.
For flowcharts, descriptions should cover the starting point, steps, decision conditions, branches, and endpoints. For statistical charts, they should explain the metrics, axis meanings, legends, and overall trends. For architecture diagrams, they should focus on component responsibilities, connections, and data-flow directions.
Record uncertainty when text is too small, lines are blurred, or scale markings cannot be read. Approximate values inferred visually must not be presented as exact source data.
4.3 Combine Images with Their Context
An image may not contain enough information to stand alone. Its description, recognized text, caption, section heading, and nearby explanatory paragraphs can be combined into retrieval text. Keep those fields separately as well so their origins remain traceable.
Do not expand the surrounding text without limits, as this can dilute the image’s topic. Determine the context boundary using caption relationships, paragraph references, and layout position.
4.4 Decide Whether Multimodal Embeddings Are Needed
If the main requirement is answering text questions, start by converting images into semantic text and generating text embeddings. This approach integrates relatively easily with an existing text-based RAG pipeline, although its effectiveness depends on description quality.
If users need to find images by visual characteristics or submit image queries, a multimodal embedding index may be useful.
Vectors produced by different models generally cannot be compared directly. Text-to-image similarity is meaningful only when the embedding model explicitly supports a compatible cross-modal representation space. Otherwise, retrieve from separate indexes and fuse the ranked results.
5. Index Design: Use Multiple Representations Rather Than Forcing a Single Vector Space
A robust design builds several searchable representations around the same underlying evidence:
- Text embeddings for body-text chunks.
- Table summaries for locating relevant tables.
- Table-row descriptions for matching specific business records.
- Image descriptions for matching the semantics of visual content.
- Image-vector indexes where needed.
- Keyword indexes for specialized terms, identifiers, and metric names.
- Evidence IDs linking original images, table structures, and complete context.
Multiple representations of the same image or table should share a source identifier. After retrieval, results can be grouped by source so that the same evidence does not occupy the answer context repeatedly in different forms.
Vector similarity is useful for finding semantically related content. Keyword search is better suited to exact identifiers, rare terms, and fixed names. Combining them is generally more robust than relying on either alone.
When scores from different indexes are not comparable, fuse results using their rankings rather than directly adding raw scores.
6. Answer Generation: Match Evidence to the Question
Retrieving content does not automatically make it reliable or sufficient for an answer. The system must also determine what the user is asking.
For conceptual explanations, body text and image descriptions may be appropriate. For workflow decisions, include node relationships and the original diagram. For numerical calculations, provide structured execution results. For questions about layout or visual details, the relevant image may need another review by a model with image-understanding capabilities.
The answer context should contain sufficient evidence metadata, including source documents, page numbers, table names, figure names, units, and notes—not just isolated fragments.
It should also distinguish among three kinds of information:
- Content explicitly stated in the source.
- Descriptions generated by a model from an image.
- Results calculated by the system from structured data.
These have different evidentiary foundations. Answers involving critical numbers or business conclusions should cite original evidence wherever possible and explain limitations when the evidence is insufficient.
Document content must also be treated as data to analyze, not as system instructions. Text in images, tables, or body paragraphs that asks the model to change its behavior must not override the system’s established rules.
7. Quality Evaluation: Test More Than Whether an Answer Is Generated
Non-text RAG quality should be evaluated at several layers.
Parsing quality
Check reading order, table structure, cell values, and image-caption associations. Sample documents should include multicolumn layouts, low-resolution scans, multipage tables, multilevel headers, and complex charts.
Retrieval quality
Check whether the target image or table appears among the candidates and whether retrieved chunks include the headers, units, and notes needed to answer the question. Retrieving content on a similar topic is not the same as retrieving the correct evidence.
Answer quality
Evaluate factual accuracy, calculation correctness, citation completeness, and uncertainty handling. Pay particular attention to answers that appear plausible but are not supported by the evidence.
Engineering quality
Track processing time, update costs, duplicate-content rates, retry handling, and version consistency.
When parsing rules or embedding models change, record the versions and assess whether affected indexes need to be rebuilt. Mixing versions can change retrieval behavior. Updating files alone is not enough if vectors and structured data remain out of sync.
8. Implementation: Complete the End-to-End Pipeline Before Adding Complexity
An existing text knowledge base can be extended in stages.
Stage 1: Improve parsing and source traceability
Add layout parsing and source-location tracking. Integrate image descriptions and semantic table text into the existing retrieval pipeline, then verify whether this reduces information loss.
Stage 2: Add structured table processing
Preserve complete table structures, introduce controlled structured queries and calculations, and establish spot checks for critical data.
Stage 3: Add capabilities based on demonstrated needs
Introduce multimodal indexes, query routing, and visual evidence verification where real usage justifies them. Avoid starting with expensive capabilities that users rarely need.
The guiding principle is simple: Use vectors to discover relevant evidence, structure to preserve meaning and calculation accuracy, and original assets for verification and traceability.
Effective image and table handling is not about converting everything into text. It is about retaining the information that retrieval and generation actually need to answer the question.
