RAG Architecture for Structured Data: Design and Implementation
This article explains why structured data such as tables, chart data, JSON, and logs cannot be handled with document-style RAG alone, and presents a dual-path architecture that combines semantic retrieval with structured querying. It covers preprocessing strategies, hybrid retrieval and reranking, workflow orchestration, and layered evaluation, showing how to route each question type correctly so that lookups and aggregations stay accurate and traceable.
1. Why Structured Data Breaks Document-Style RAG
In most enterprises, only part of the knowledge base consists of readable unstructured documents. A large share of high-value information lives in tables, chart descriptions, semi-structured JSON, and log records. If this data is chunked and vectorized directly into a Retrieval-Augmented Generation (RAG) pipeline, three problems typically appear:
- Semantic dilution: a single table row, stripped of its header and context, produces a vector with almost no discriminative information, and recall quality drops sharply.
- Numeric distortion: chunking easily breaks numeric precision, units, and dimensions, so the model produces conclusions that look reasonable but cannot be recomputed.
- Aggregation failure: questions like “total across regions”, “year-over-year change”, or “top 10” require exact computation, which vector similarity search fundamentally cannot perform — it does not sum, sort, or group.
The core idea, therefore, is not to “turn tables into vectors” but to build a dual-path architecture in which semantic retrieval and structured querying coexist, with an orchestration layer that classifies the question, routes it, and merges both results before generation.
2. Overall Architecture: Dual Paths Plus an Orchestration Layer
A practical reference architecture has five layers:
- Ingestion layer: extracts data from multiple sources (file uploads, object storage, databases, message queue subscriptions) and performs format detection and schema probing.
- Preprocessing layer: type inference, unit normalization, primary/foreign key detection, and generation of textual descriptions.
- Indexing layer: maintains three index types at once — a full-text/keyword inverted index, a vector index, and structured metadata with a query engine.
- Retrieval and orchestration layer: intent recognition, query routing, hybrid recall, reranking, and result fusion.
- Generation and governance layer: prompt assembly, citation tracing, permission filtering, logging, and evaluation.
The key design principle: structured queries make the numbers exact, semantic retrieval makes the right data findable, and the orchestration layer makes the right choice of path.
3. Preprocessing: Where Structured Data Ingestion Succeeds or Fails
3.1 Tables
Do not chunk rows mechanically. The recommended approach is two-level modeling, at table level and row level:
- Generate a table-level description for each table (business topic, field meanings, time granularity, refresh frequency), vectorize it separately, and use it for coarse routing from question to table.
- Concatenate each row with its header to form natural-language text and vectorize that, while keeping a structured copy of the original fields for exact filtering.
Illustrative logic:
row_text = "Table: Regional Sales Monthly Report | month=2024-03 | region=East China | category=Home appliances | sales=1280000 | unit=CNY"
The structured fields are written alongside it: {month, region, category, amount, unit}.
3.2 Charts
A chart should become a triple of “image + data + text”: keep the original image for display, extract the underlying data points, and have the model generate an objective description of the data (trends, extremes, inflection points). The description must not contain inferences unsupported by the data.
3.3 JSON and Semi-Structured Data
Fix the schema first, promote frequently filtered fields to top-level index fields, and flatten deeply nested content into flat views on demand. Build a synonym dictionary for enumerated values to handle variations such as “East China” versus “East China region” versus “eastern region”.
4. Hybrid Retrieval and Reranking
No single recall strategy handles both exact and fuzzy matching. A more robust engineering combination is:
- Structured pre-filtering: narrow the candidate set with hard conditions such as time, region, and category.
- Keyword recall: guarantee exact hits on IDs, proper nouns, and metric names.
- Vector recall: handle synonymous phrasings and natural-language questions.
- Reranking: use a cross-encoder to fine-rank candidates and cap how many enter the context.
- Numeric verification: for answers involving computation, go back to the original structured copy and recompute instead of letting the model estimate.
Pseudocode:
def answer(query, user_ctx):plan = router.classify(query) # lookup / aggregate / trend / open_qaif plan.kind in ("lookup", "aggregate"):rows = structured_query(plan.filters, plan.metrics)evidence = table_schema_text(plan.tables) + serialize(rows)else:cands = bm25_search(query) + vector_search(query)evidence = rerank(cands, query)[:8]return llm_generate(query, evidence, citations=True)
5. Orchestration in a Workflow Platform
When implementing this in a low-code workflow platform, break the flow into an observable chain of nodes: document parsing → chunking and metadata tagging → dual index writes → intent classification → conditional branch (structured query / semantic retrieval) → result merging → reranking → generation → citation backfill. Branch conditions and thresholds should be externalized as configuration so parameters can be tuned without code changes. For permission-sensitive scenarios, filtering must take effect at the retrieval stage rather than trimming output after generation.
6. Evaluation and Tuning
Evaluation should be layered: the recall layer looks at hit rate and coverage, the retrieval layer at ranking metrics, and the generation layer at factual consistency, numeric accuracy, and citation verifiability. Maintain a regression set containing exact queries, aggregation queries, and fuzzy questions, and run it after every change to chunking strategy or prompt template. Common tuning measures include adjusting chunk size and overlap, adding business synonyms for fields, limiting the number of context items, and instructing the model in the prompt to refuse when no evidence is available.
7. Conclusion
Ingesting structured data into RAG is essentially a division of labor between semantic understanding and exact computation. Give “finding” to hybrid retrieval, “computing” to structured queries, and “deciding” to the orchestration layer, and you get stable answers that remain traceable. To reduce the cost of building and operating everything in-house, these components can run on general-purpose cloud capabilities such as container platforms, object storage, managed retrieval, and log monitoring, leaving the team to focus on data governance and evaluation.
