Production Business Query RAG
A production text-to-SQL system for business questions, grounded in semantic layer models, business definitions, and a data dictionary.
01 / grounding
3
semantic models, business definitions, data dictionary
02 / retrieval
2
text and vector search, followed by reranking
03 / controls
3
access scope, SQL checks, bounded read
04 / output
1
answer with query, result, and cited definitions
Status
This business query RAG system is built in production. The summary maps its sources, retrieval methods, controls, and output.
Problem
A business question often depends on definitions that a database schema alone cannot explain: which metric to use, how a dimension is defined, which tables may be joined, and what the requester may access. A text-to-SQL system needs to retrieve those definitions before it writes a query and show the basis for its answer.
Architecture
01 · Versioned sources. Index entries keep access tags and a path back to original definitions.
02 · Scope first. Retrieval and SQL must stay within the requester’s access.
03 · Inspectable result. Checked SQL returns a bounded result with cited definitions, or the system retries or abstains.
The architecture joins curated source material to text and vector search:
- Index the source of meaning. Chunk semantic layer models, business definitions, and data dictionary entries. Attach source versions and access tags, build a hybrid text and vector index, and retain the original entries for citation.
- Scope a business question. Resolve the requester’s access scope before search. Hybrid search finds relevant metrics, dimensions, entities, and definitions; reranking selects the strongest matches and fetches their originals.
- Build context and SQL. Assemble the retrieved definitions and approved semantic model references. The model drafts SQL against the semantic layer and identifies the definitions it used.
- Check before execution. Verify the SQL against the retrieved definitions, available semantic models, and access scope. The execution path should bound read access, query cost, and result size. Unsupported or ambiguous requests trigger another retrieval attempt or an abstention.
- Answer with provenance. Present the query result with the SQL and citations to the business definitions and dictionary entries that shaped it. A person can inspect both the query and the cited sources.
Evaluation, traces, and audit records need to cover retrieval, SQL generation, validation, execution, and the final answer. Source updates and access changes must invalidate stale indexed entries.
Operational questions
- How quickly do changed metric definitions and permissions reach the index?
- Which semantic models and SQL operations are allowed for each requester?
- How are query cost, timeouts, and result size bounded?
- How often does retrieval select the correct metric and grain, and how often does the resulting SQL return the intended answer?
- When should an ambiguous business term cause clarification or abstention?