Building a RAG Vector Store for Non-Text Data: A Practical Guide
This article explains why non-text content such as tables, charts, and diagrams breaks retrieval in RAG systems, and how to fix it with a multimodal ingestion pipeline. It covers parsing documents into a unified Markdown-style format, restoring layout and reading order, converting tables into structured semantic records, choosing separate embedding strategies for text, tables, and images, aligning modalities in a shared vector space, and combining metadata filtering, multi-channel recall, and citation enforcement at query time. It also lists common pitfalls and a small acceptance test set for regression evaluation.
Building a RAG Vector Store for Non-Text Data: A Practical Guide
1. The Problem: Why Non-Text Content Breaks Retrieval
The first step of ingesting knowledge into a Retrieval-Augmented Generation (RAG) system is chunking documents and converting them into vectors. Most implementations silently assume the knowledge carrier is plain natural language. Real documents are never plain text: tables in financial reports, diagrams in manuals, and line charts in research papers are often where the actual answer lives.
Once this content is dropped during parsing or flattened into a meaningless string of characters, three typical failures appear downstream:
- Information gaps: The question asks about “the change in Q3 gross margin,” but that fact exists only inside table cells. Plain-text embeddings cannot express row and column semantics, so recall comes back empty or badly off target.
- Semantic drift: Images are skipped, leaving the model to guess from surrounding context and produce answers that sound plausible but have no grounding.
- Unverifiable citations: The answer cannot point back to a specific chart or table location, so the business side has no way to audit it.
Non-text handling is therefore not a nice-to-have optimization. It is foundational engineering that sets the quality floor of a RAG knowledge base.
2. Overall Approach: Unify the Representation First, Then the Vector Space
The solution can be abstracted as a multimodal fusion pipeline with four layers:
- Parsing layer: Restore heterogeneous layouts into a structured intermediate representation with semantic labels.
- Representation layer: Text goes through text embeddings, tables through structured semantic encoding, and images through joint visual-language representation.
- Alignment layer: Map different modalities into the same vector space so similarity scores are comparable.
- Governance layer: Preserve metadata such as position, source, and permissions to support filtered retrieval and traceability.
The key judgment: do not start by trying to solve everything with one end-to-end multimodal model. The more robust engineering path is “structure first, split by modality, then align spaces” — restore tables into real structures first, then decide which content actually needs visual representation.
3. Parsing Layer: Turning Layout into Structure
3.1 A Unified Intermediate Format
Converting common formats such as PDF, scanned documents, presentations, and email into a Markdown-like intermediate format is the highest-value step. Markdown has two advantages at once: native syntax for tables (pipe tables) and explicit slots for images (placeholder plus number plus caption). That makes chunking easy and makes it easy to later swap in multimodal nodes.
A typical intermediate representation:
## 3.2 Quarterly Operating Data| Quarter | Revenue (100M CNY) | Gross Margin || ------- | ------------------ | ------------ || Q2 | 12.4 | 38.1% || Q3 | 13.1 | 35.6% |
Two design points matter: keep the heading and surrounding context paragraphs around each table, and keep the figure number and caption for images instead of a bare link.
3.2 Layout Cleanup and Reading Order
The hard parts of real documents are two-column layouts, headers and footers, tables spanning pages, and footnotes. Parsing should at minimum:
- Strip headers, footers, and page numbers to avoid noisy chunks.
- Reconstruct reading order so left and right columns do not interleave and scramble meaning.
- Merge tables that span pages, so one table is not split in half with its header lost.
- Restore merged cells, expanding multi-level headers into complete column names.
The quality of this step caps everything downstream, so it deserves the bulk of the effort.
3.3 Structured Semantic Parsing of Tables
Do not treat a table as concatenated text lines. The recommended approach is to convert it into “header path plus row records” and then generate a natural-language description:
def table_to_records(header, rows):records = []for row in rows:kv = "; ".join(f"{h} is {v}" for h, v in zip(header, row))records.append(kv)return records# "Quarter is Q3; Revenue (100M CNY) is 13.1; Gross margin is 35.6%"
After this transformation, “gross margin” and “35.6%” are bound inside the same semantic unit, so vector search can match numeric questions. For very large tables, chunk by row groups and carry the header redundantly so every chunk is self-explanatory.
4. Representation Layer: Three Content Types, Three Encoding Strategies
- Text chunks: A standard text embedding model, with chunk size kept to a few hundred tokens and a small overlap to preserve contextual continuity.
- Tables: Prefer “structured serialization plus text embedding.” For scenarios requiring exact comparison, add a column-level index and use metadata filtering to narrow the candidate set.
- Images: Use joint visual-language representation, encoding the image together with its caption and surrounding body text. If there are many scanned pages, apply page-level visual encoding first, then send recognized text through the text channel, forming dual-channel recall.
A common engineering pattern is constructing “image-text pairs”: concatenate the caption, key points inside the figure, and the context paragraph into a description text, store it alongside the image vector, and return the same node when either channel matches at retrieval time.
5. Alignment Layer: Making Similarity Comparable
There are usually two routes to a unified vector space:
- Shared embedding space: Encode text and images with the same multimodal representation model, making them comparable by construction.
- Projection alignment: Encode each modality independently, then use a linear projection or lightweight mapping layer to land in the same dimensional space, fine-tuned with a small amount of paired data.
Either way, run a consistency check: sample a batch of “question to correct chart” pairs and verify that recall rankings are stable. If text chunks consistently outrank chart chunks, apply a slight score boost to non-text nodes or run an independent recall channel and fuse the results.
6. Retrieval and Generation: Chunking, Filtering, and Traceability
- Metadata filtering: Pre-filter by document type, section, page number, and modality type before computing similarity, balancing speed and precision.
- Multi-channel recall fusion: Run the text channel and the visual channel in parallel, then deduplicate and rerank the results.
- Context assembly: When a table is hit, inject its header into the prompt; when an image is hit, provide the caption and adjacent paragraphs as well.
- Enforced citations: Require generated output to label the source chunk number so humans can verify it.
Example prompt assembly:
Reference [1] (table, page 12): Quarter is Q3; Gross margin is 35.6%Reference [2] (image, Figure 1 Quarterly gross margin trend): {image description}Answer only based on the references above and label the citation numbers.
7. Common Pitfalls and an Acceptance Checklist
- Extracting tables as plain text, which loses row and column relationships.
- Storing only image links without semantics, so retrieval can never match them.
- Chunks that are too large, mixing several tables into one chunk and diluting the vector semantics.
- Missing modality-type metadata, which makes targeted recall impossible.
- Skipping regression evaluation, so accuracy actually drops after a parsing strategy change.
Build a small acceptance set covering three question types — plain text questions, table numeric questions, and chart trend questions — and track recall hit rate and citation accuracy for each as a baseline for pipeline iteration.
8. Implementation Advice
For most teams, the pragmatic order is: unify document parsing and cleanup first, structure tables while preserving chart placeholders and captions, then gradually introduce visual representation and space alignment. Baidu AI Cloud offers general-category support for document parsing and multimodal retrieval capabilities; combined with foundational components such as object storage, message queues, log services, and monitoring and alerting, parsing, ingestion, and evaluation can be chained into an observable pipeline that steadily improves the precision and usefulness of the knowledge base.
