Integrating Structured Data into RAG: Architecture and Practices

    This article explains why document-style RAG falls short for structured data and how to design a reliable pipeline around it. It covers a four-layer architecture, table and chart parsing techniques, hybrid retrieval with vector, keyword, and metadata paths, query generation for calculations, workflow orchestration, layered evaluation, and common pitfalls. The goal is to preserve structural semantics while enabling accurate value lookup and computation.

    1. Why Structured Data Breaks Document-Style RAG

    Mainstream Retrieval-Augmented Generation (RAG) was originally designed for unstructured text: documents are split into semantic chunks, vectorized, stored in a vector index, and passed to a large language model for answer generation once a match is found. But real enterprise data is far more than long text. A large amount of critical information lives in well-organized spreadsheets, charts, and business objects expressed as key-value structures. This kind of data has three notable characteristics:

    1. Semantics depend heavily on structure: a cell’s meaning is determined jointly by its row and column headers; a single value viewed without the header is nearly meaningless.
    2. It can be computed precisely: operations such as summation, year-over-year comparison, and range filtering are extremely unreliable when “mentally calculated” by a generative model and should be handled by a query engine.
    3. Many-to-many relationships: a wide table often carries dimensions, metrics, and hierarchies at the same time, and splitting it simply by rows breaks semantic integrity.

    So the core of integrating structured data into RAG is not “whether it can be stuffed in,” but how to let the model retrieve the correct value and perform the correct calculation without breaking structural semantics. This means we need multiple paths beyond pure vector recall, including keyword retrieval, metadata filtering, and query generation.

    2. Overall Architecture: Four Layers of Responsibility

    A robust solution can be split into four layers, decoupled through clear contracts:

    • Ingestion layer: handles multi-source extraction and format normalization, unifying Excel files, two-dimensional tables, chart descriptions, and nested objects into an internal intermediate representation.
    • Understanding layer: handles structure recognition, type inference, header semantic completion, and generation of textual descriptions.
    • Indexing layer: maintains a vector index, an inverted index, and a structured metadata index at the same time to support hybrid recall.
    • Orchestration layer: the so-called “workflow,” responsible for intent detection, routing, tool invocation, result validation, and citation backfilling.

    The orchestration layer is the most underestimated part in practice. A common mistake is sending every question down the same vector retrieval chain. A more reasonable approach is to perform intent classification first, determining whether the question is “value lookup,” “calculation,” “trend explanation,” or “definition,” and then route it to the appropriate tool.

    3. Structured Parsing: Turning Tables into Model-Readable Objects

    3.1 Table Normalization

    Raw tables often contain merged cells, multi-level headers, mixed units, and blank-row separators. Normalization is recommended first: split merged cells and fill downward, flatten multi-level headers into a “parent.child” form, extract units into separate fields, and unify date and numeric types. After normalization, the table should ensure that every row is a semantically self-contained record.

    3.2 Row-Level Textualization and Chunk Design

    For each row, you can generate a natural-language description that concatenates column names as context into the values, for example:

    1. [Region] East China [Channel] Online [Month] 2025-03
    2. [Sales] 12.8 million CNY [YoY] +12.4% [Orders] 8642

    This “row-to-sentence” approach lets vector recall hit while preserving field names and avoiding numeric ambiguity. For chunk granularity, a small table can be a single chunk with a summary attached; for a large table, chunk by row and inject the header and a table-level summary as a shared prefix into every chunk, forming a combination of “local chunk + global context.”

    3.3 Handling Charts

    Charts themselves are not readable and need to be converted into two kinds of retrievable assets: first, a structured sequence of data points; second, a caption-style text description (including axis meanings, units, time range, extrema, and trend conclusions). Storing only the image with no retrievable text is the main reason chart question answering fails.

    3.4 Semi-Structured Objects

    For nested key-value structures, path expansion is recommended: flatten nested fields into dot-separated paths while preserving the original structure for precise value retrieval. When indexing, use the combination of path and value as the text unit; when querying, you can filter by path or recall semantically.

    4. Indexing and Recall: Hybrid Retrieval Is a Must

    The typical weakness of single-path vector recall in structured scenarios is poor exact matching for numbers, IDs, and proper nouns. In engineering, three-path fusion is commonly used:

    • Vector recall: handles synonymous expressions and fuzzy semantics, such as “revenue” mapping to “sales.”
    • Keyword recall: handles exact matching of IDs, names, and units.
    • Metadata filtering: applies hard filters by fields such as time, region, and version first, then ranks, significantly shrinking the candidate set.

    Fusion ranking can use weighted summation or a reranking model for secondary scoring. In practice, filter first, then recall is often more stable than “recall first, then filter,” because the latter can easily end up with a candidate set that does not contain the target row at all.

    An illustrative retrieval flow:

    1. def retrieve(query, filters):
    2. candidates = []
    3. if need_exact(query):
    4. candidates += keyword_search(query, filters)
    5. candidates += vector_search(query, filters)
    6. candidates = dedup(candidates)
    7. return rerank(query, candidates)[:top_k]

    5. Calculation Questions: From “Generating Answers” to “Generating Queries”

    For questions involving aggregation, comparison, and trends, the model should output a structured query rather than answer directly. The common approach is to define read-only query templates and have the model fill in only the parameters:

    1. SELECT region, SUM(amount)
    2. FROM sales
    3. WHERE month BETWEEN :start AND :end
    4. GROUP BY region
    5. ORDER BY 2 DESC
    6. LIMIT :n

    There are three key constraints: the query must be read-only; parameters must be validated for type and range; and the execution result must be backfilled as “data evidence” and handed to the model to organize the language. This avoids numeric hallucination and makes citations traceable to specific rows.

    6. Workflow Orchestration Essentials

    1. Intent routing: after classification, split traffic to the retrieval chain, query chain, or direct question-answering chain; when confidence is low, run multiple chains in parallel and pick the best.
    2. Context budget: allocate fixed quotas for retrieval results, header descriptions, and conversation history, truncating by relevance when limits are exceeded.
    3. Citation backfilling: annotate the source table name, row identifier, or chart number in the answer for easy manual verification.
    4. Failure fallback: when recall is empty or a query errors out, clearly state the data scope and do not generate speculative conclusions.
    5. Observability: record recall hits, latency, and failure reasons at each step to provide a basis for tuning.

    7. Evaluation and Tuning

    Evaluation should be layered: the parsing layer looks at field completeness and type correctness; the recall layer looks at hit rate and first-screen relevance; the generation layer looks at numeric accuracy and citation correctness. It is recommended to maintain a regression set covering four question types—value lookup, calculation, trend, and definition—and rerun it after each change to chunking strategy or fusion weights, avoiding tuning by feel. If the enterprise has general infrastructure such as a container platform, object storage, and log monitoring, index construction and evaluation can be made into scheduled jobs for versioned iteration.

    8. Common Pitfalls Checklist

    • Missing headers cause loss of numeric semantics;
    • Inconsistent units cause magnitude errors;
    • Hard-splitting a large table at a fixed length cuts the same record apart;
    • Vector recall only, with zero hit rate for ID-type queries;
    • Letting the model calculate directly, producing plausible-looking wrong values;
    • No citation backfilling, making results unauditable.

    9. Conclusion

    The key to integrating structured data into RAG is to treat “structure” itself as a first-class citizen: preserve structure at the parsing stage, keep multiple paths at the indexing stage, route by intent at the orchestration stage, and replace generation with queries at the calculation stage. Once this chain is solid, both self-hosted inference and retrieval components and deployment forms carried by general capabilities on Baidu AI Cloud—such as a container platform, object storage, and monitoring and alerting—can achieve consistent, verifiable question-answering results.