RAG Vector Database Construction: Handling Non-Text Data in Practice

    This article explains why non-text content such as images and tables becomes a bottleneck when building vector databases for Retrieval-Augmented Generation (RAG) systems, and presents a practical four-layer framework to address it. It covers layout parsing, semantic conversion, indexing, and retrieval, with specific strategies for tables (structured serialization, summaries, row-level chunking), images (multimodal descriptions and image vectors), metadata for traceability and permission filtering, and multi-path retrieval with reranking to reduce hallucination. It also lists engineering pitfalls around parsing quality, incremental updates, observability, and cost control. Readers will learn how to convert heterogeneous content into a unified representation before indexing so that RAG can retrieve evidence rather than plain text.

    When building a vector database for a large language model RAG (Retrieval-Augmented Generation) system, non-text information in documents—such as images and tables—often becomes the critical bottleneck. Traditional text embedding models cannot process this heterogeneous data directly, creating gaps in the retrieval stage. Users do not distinguish between “body text” and “illustrations” when asking questions. If a key conclusion exists only in a flowchart or a data table, plain text chunking will fail entirely during recall. This article presents a practical processing framework based on engineering experience.

    1. The Real Problem: The Gap Is in the Representation Layer, Not the Storage Layer

    Many teams first assume the vector database lacks capacity or write throughput, but the actual break point is inconsistent representation. Text can naturally be tokenized and mapped into dense vectors, while an image is a pixel matrix and a table is a two-dimensional set of cell relationships. Neither shares the same semantic space as text vectors. Ignoring them means deliberately discarding information from the knowledge base; crudely converting an image into “this is an image” loses every detail inside it.

    The core goal of the processing strategy is therefore singular: convert heterogeneous objects into a “representation that the same retrieval system can understand,” while preserving enough contextual cues so that recall results can be matched by both vector retrieval and keyword retrieval.

    2. Overall Architecture: Decoupling Parsing, Conversion, Indexing, and Retrieval

    Split the pipeline into four layers so that parsing logic and retrieval logic do not contaminate each other:

    1. Layout parsing layer: identify titles, paragraphs, lists, tables, images, formula regions, and their reading order in the document;
    2. Semantic conversion layer: convert tables into structured text, and images into descriptive text or image vectors;
    3. Indexing layer: write to the vector index while also writing structured metadata and pointers to the original text positions;
    4. Retrieval layer: run vector retrieval, keyword retrieval, and metadata filtering in parallel, then apply unified reranking.

    A skeletal pipeline is shown below (pseudocode, expressing stage division only):

    1. blocks = layout_parse(file) # output a sequence of blocks with type and coordinates
    2. for b in blocks:
    3. if b.type == "table":
    4. payload = table_to_markdown(b) # structured text conversion
    5. elif b.type == "image":
    6. payload = image_to_caption(b) # multimodal description
    7. else:
    8. payload = b.text
    9. records.append(build_record(payload, meta=b.meta))
    10. index.upsert(records)

    3. Table Processing: Structure First, with Summaries and Query Rewriting

    The key for tables is not “concatenating cells into a line of text” but preserving row and column semantics. Three recommended approaches can be combined:

    • Serialize into structured text: use Markdown tables or “field name: value” key-value pairs so that headers are bound to data and columns do not shift;
    • Generate a natural language summary: produce an overview of the entire table for coarse recall;
    • Row-level chunking: split large tables by row or logical group, repeating the header in each chunk to prevent semantic loss across chunks.

    Tables should also be enriched with metadata: table title, containing section, units, time range, and metric definitions. These fields are extremely valuable in the filtering stage. For example, when a user restricts the query to “2024” or “East China region,” filtering first and then running vector retrieval significantly reduces noise.

    4. Image Processing: Dual Track of Multimodal Descriptions and Image Vectors

    Images fall into three categories, each with a different strategy:

    • Informational charts (line charts, bar charts, architecture diagrams): prioritize multimodal descriptions that output text covering axes, trends, key values, and natural language conclusions; when necessary, add recognition results for text inside the image;
    • Decorative images: keep only position and caption to reduce index noise;
    • Scanned pages or full-page screenshots: first apply orientation correction and layout segmentation, then run text recognition, and finally establish a mapping to the coordinates of the original page.

    Beyond text descriptions, image vectors can be introduced to form a dual-track representation: text descriptions serve semantic question answering, while image vectors serve visual retrieval needs such as “find similar images.” The two paths are fused at the retrieval layer.

    5. Chunking and Metadata: Making Non-Text Blocks Locatable

    Non-text blocks must carry traceable information; otherwise the model cannot produce trustworthy citations. The minimum metadata set should include: document identifier, page number or coordinate range, block type, section path, update time, and permission labels. When chunking, apply an “do not split” principle for tables and images; split overly long tables by row groups rather than hard-cutting by characters.

    Permission labels are especially important: in enterprise scenarios, charts often contain sensitive business data, and metadata filtering should take effect before vector retrieval rather than being patched at the generation stage.

    6. Retrieval and Reranking: Multi-Path Complementarity to Suppress Hallucination

    Single-path vector recall is not friendly to numeric table questions. A more robust combination is: dense vector recall + exact keyword matching (hitting metric names, IDs, and proprietary abbreviations) + metadata filtering, followed by a reranking model that scores the candidate set so that only high-scoring fragments are passed to the generation stage. On the generation side, the model must answer strictly based on the retrieved content and explicitly state when nothing was found, rather than freely filling gaps.

    7. Engineering Implementation Points and Common Pitfalls

    • Parsing quality sets the ceiling: layout analysis errors waste all downstream work, so always validate with manual sampling;
    • Idempotency and incremental updates: after a document is revised, update by block fingerprints to avoid stale tables causing conflicting answers;
    • Observability: log the block type distribution of each recall; if table-related questions recall only text blocks, the conversion stage has failed;
    • Cost control: multimodal descriptions and reranking both consume compute, so process documents by value tier;
    • If using general cloud capabilities, use object storage for original files, a container platform for parsing tasks, a message queue for peak shaving, and logging and monitoring services to track pipeline quality.

    Conclusion

    The key to handling non-text information is to complete the “heterogeneous to unified representation” conversion before indexing, and to retain structured filtering and multi-path recall at retrieval time. Structure the tables, semanticize the images, and complete the metadata, and RAG can evolve from “retrieving text” to “retrieving evidence.”