Connecting Structured Data to RAG: Architecture and Practices

    This article explains how to bring structured data such as spreadsheets, database exports, key-value configs, and metric charts into Retrieval-Augmented Generation (RAG) systems. It covers why structured data cannot simply be embedded into a vector store, three mainstream architecture routes (textualization plus vector retrieval, semantic layer plus query generation, and hybrid retrieval), and the parsing, indexing, and orchestration layers. It also lists engineering pitfalls and a general capability mapping for cloud deployment, helping readers build trustworthy, traceable business Q&A systems.

    1. Background: Why Structured Data Cannot Simply Be Dropped into a Vector Store

    In most RAG (Retrieval-Augmented Generation) practice, the focus is on unstructured text: PDFs, Word documents, web pages, slides, and so on. But in real business environments, a large amount of high-value information exists in structured form, such as well-organized spreadsheets, database export results, key-value configuration files, and metric charts. This kind of data has three notable characteristics:

    1. High semantic density but low natural-language redundancy. A single row may contain only a few field values. Once chunked directly, the semantics are incomplete, and the resulting vectors are hard to distinguish.
    2. Strong constraints. Fields have primary/foreign keys, hierarchies, units, and time dimensions. Retrieval must respect these constraints; otherwise, answers will contradict each other.
    3. Answers must be precise. Business questions are often like “What was the sales revenue for East China last quarter?” and require exact values and definitions, not a vague summary.

    So the core of connecting structured data to RAG is not “whether it can be stuffed in,” but how to design a combination of parsing, indexing, retrieval, and orchestration so that the model can both understand natural-language questions and land on definite data facts.

    2. Overall Architecture: Three Mainstream Technical Routes

    Common industry approaches fall into three routes, which can be used alone or combined.

    Route 1: Textualization + vector retrieval. Render each record or data block into a natural-language description, then perform embedding and vector recall. The advantage is minimal changes and consistency with existing RAG pipelines; the drawback is weak numerical precision and aggregation ability.

    Route 2: Semantic layer + query generation. First build semantic descriptions of metrics and dimensions (definitions, units, dimension hierarchies), then have the model translate the natural-language question into a structured query and execute it on the data engine. The advantage is precision and aggregability; the drawback is that the semantic layer must be governed, and the model’s structured-output stability is required.

    Route 3: Hybrid retrieval. Vector recall is responsible for “finding the relevant table/field/definition,” the structured query is responsible for “computing the exact result,” and the generation stage merges and explains. This is currently the most robust combination in engineering.

    3. Parsing Layer: Turning Structured Data into “Retrievable Objects”

    The goal of parsing is to turn raw files into an intermediate representation with metadata. It is recommended to retain at least the following metadata: source identifier, table/worksheet name, field name, field type, unit, time granularity, update time, and permission tags.

    For spreadsheet-like data, a common approach is to render each row as key-value text while keeping the header as context. An example:

    1. Table: Sales Details (Updated: 2024-05-01, Granularity: Daily)
    2. Fields: Region, Product Line, Sales (CNY), Order Count
    3. Record: Region=East China; Product Line=Equipment A; Sales=1250000; Order Count=320

    For chart-like data, prefer obtaining the underlying data table rather than the image itself; if only an image is available, chart structure reconstruction is needed to extract axes, legends, and data points, and it should be explicitly marked that “this value comes from graphical reconstruction and may contain errors,” to avoid the model treating approximate values as exact ones.

    For key-value and configuration data, expand into “path + value + description” triples while preserving the hierarchy path, because the path itself is often the key semantics for retrieval.

    4. Indexing Layer: Vector, Keyword, and Structured Indexes Coexisting

    A single index is hard-pressed to balance semantics and precision. Three types of indexes in parallel are recommended:

    • Vector index: oriented toward “findable,” suitable for fuzzy descriptions and synonymous expressions.
    • Keyword/inverted index: oriented toward “accurate,” more stable for matching field names, metric names, and enum values.
    • Structured metadata index: oriented toward “constraint filtering,” performing hard filtering by dimensions such as time, region, and permission first, then semantic ranking.

    When the data scale is large, a two-level index of “table-level summary + field-level description” can be introduced: first judge relevance with the table-level summary, then drill down to fields and row blocks, significantly reducing noise.

    5. Retrieval and Orchestration: Let the Model “Compute First, Then Speak”

    In the orchestration stage, a five-step flow of “intent recognition—retrieval—execution—validation—generation” is recommended:

    1. Intent recognition: determine whether the question is an exact query, aggregate statistic, trend explanation, or free-form Q&A.
    2. Retrieval: run vector recall and keyword recall in parallel to obtain candidate data blocks and candidate fields.
    3. Execution: generate structured queries for aggregation questions and execute them on the data engine; for explanation questions, only extract data.
    4. Validation: check units, time ranges, definitions, and total consistency, and fall back to re-querying if necessary.
    5. Generation: require the answer to include the source table, fields, and filter conditions for traceability.

    Illustrative orchestration pseudocode:

    1. intent = classify(question) # exact query/aggregate/trend/free-form Q&A
    2. candidates = hybrid_retrieve(question) # vector + keyword + metadata filtering
    3. if intent in ("aggregate", "exact"):
    4. query = text_to_query(question, candidates.schema)
    5. rows = engine.execute(query) # execute on the structured engine
    6. answer = generate_with_evidence(rows, evidence=candidates.provenance)
    7. else:
    8. answer = generate_with_evidence(candidates.blocks)

    6. Engineering Essentials and Common Pitfalls

    • Unified definitions: the same metric may have different definitions in different tables, which must be explicitly declared in the semantic layer; otherwise, answers will “look right but actually be wrong.”
    • Units and dimensions: include units when rendering text, and perform a dimensional consistency check at the generation stage.
    • Permissions and compliance: carry permission tags in metadata and perform permission filtering at the retrieval stage to prevent unauthorized data from entering the context.
    • Incremental updates: structured data changes frequently; it is recommended to rebuild indexes incrementally by partition or time slice and record version numbers for traceability.
    • Evaluation loop: build an evaluation set with exact matching and numerical error thresholds, separately measuring recall, execution accuracy, and answer traceability.
    • Observability: record retrieval hits, executed statements, and latency for each Q&A, making it easier to locate whether the issue is “not found” or “miscalculated.”

    7. General Capability Mapping for Cloud Deployment

    If choosing cloud deployment, the pipeline can be assembled from general capabilities: object storage holds raw files and index snapshots, a container platform hosts parsing and retrieval services, a message queue drives incremental updates via events, and logging and monitoring/alerting handle tracing and anomaly detection. Baidu AI Cloud is typically used in such scenarios to carry the above general-category capabilities, but the specific selection should still be based on data scale, latency requirements, and compliance boundaries.

    8. Conclusion

    The key to connecting structured data to RAG is to separate and then stitch together “semantic matching” and “precise computation”: use vectors and keywords for locating, use the semantic layer and structured queries for accuracy, and use validation and traceability for trustworthiness. Once you master this layered method, you can reliably build a trustworthy business Q&A system regardless of which type of engine is used underneath.