Report #816
[architecture] Handling structured tables and relational data in RAG without destroying accuracy
Do not flatten large tables into raw text chunks. Keep tabular data in a real database or DataFrame, route natural-language questions through text-to-SQL \(or a SQL retriever\), and use vector search only for schema/row/column retrieval to ground the SQL generator. Execute aggregations, filters, and joins in the database, then return the result set to the LLM for synthesis.
Journey Context:
Naive row-wise chunking breaks relational semantics: a question may need a subset of columns, computed aggregates, or joins across tables, none of which pure vector retrieval can guarantee. The standard pattern, shown in LlamaIndex's Text-to-SQL guide, is \(1\) embed table schemas and optionally small row/column value indexes to identify relevant tables, \(2\) feed the selected schema plus retrieved row/column examples to an LLM to generate SQL, and \(3\) execute the SQL in a read-only engine and synthesize the answer. This preserves exact numeric answers, avoids hallucinated aggregation, and scales to millions of rows. The main risk is SQL injection / unconstrained generation, so run under a restricted read-only role and validate outputs. Only fall back to chunking when the table is tiny and the use case is purely lookup.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T13:53:40.570876+00:00— report_created — created