Skip to content

Retrieval for Structured Data

Answering questions over databases and spreadsheets with text-to-SQL and table retrieval instead of text chunks.

Editorial team 2 min read

Many questions are about numbers in tables — sales by region, open tickets this week — which text-chunk retrieval handles poorly.

Why Chunks Struggle

Aggregations, filters and calculations require the whole dataset, not a few retrieved rows. A model reading ten chunks of a table can't reliably sum a column of ten thousand rows.

Text-to-SQL

A language model translates the question into a SQL query, which runs against the database; the model then explains the result.

To make it reliable:

  • give the model the schema with clear table and column descriptions;
  • include example questions and correct queries;
  • restrict it to read-only access on specific tables or views;
  • validate queries before running them and limit result sizes;
  • show the query and result, so users can check.

Semantic Layers

Defining metrics and dimensions once ("revenue", "active customer") and having the model query that layer avoids inconsistent calculations.

Hybrid Questions

Some questions need both documents and data: "Why did churn rise in March?" may combine a churn query with retrieved release notes. Route or combine tools accordingly.

Evaluation

Build a set of questions with correct answers and check query results, not just query text — different SQL can be equally correct.

Security

Never let generated SQL run with write permissions or access to sensitive tables the user can't otherwise see.

More in RAG

All RAG guides →
RAG Guide · 1 min

RAG Architecture: The Components End to End

A map of a complete retrieval-augmented generation system, from ingestion to answer, and what each component is responsible for.

RAG 1 min read 6 Dec 2025

RAG Guide · 2 min

Document Parsing for RAG

Turning PDFs, slides, HTML and scans into clean, structured text — the unglamorous step that decides RAG quality.

RAG 2 min read 5 Dec 2025

RAG Guide · 2 min

Chunk Size and Overlap Tuning

How to choose chunk size and overlap for retrieval by testing against real questions rather than guessing.

RAG 2 min read 4 Dec 2025

RAG Guide · 2 min

Hybrid Search for RAG

Combining keyword and vector search so RAG finds both exact terms and paraphrased meaning.

RAG 2 min read 3 Dec 2025