Skip to main content
NISHORGO Engineering portfolio
work production

Production Business Query RAG

A production text-to-SQL system for business questions, grounded in semantic layer models, business definitions, and a data dictionary.

fig. 00 · workflow at a glance system structure

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

fig. 01 · grounded question to cited answer
Business query RAG: source indexing and answer path Semantic models, business definitions, and dictionary entries feed a versioned hybrid index. A business question is access scoped, retrieved using text and vector search, reranked, assembled with original definitions, drafted into SQL, checked, executed with read limits, and returned with the SQL and citations. Weak evidence or invalid SQL leads to another retrieval attempt or abstention. 01 / VERSIONED SOURCE CONTEXT 02 / ACCESS-SCOPED ANSWER PATH GROUNDING SOURCES semantic models business definitions data dictionary entries hybrid index text + vectors version + access tags original entries retained for citation businessquestion access scoperequester permissions retrieve+ rerankhybrid search sourcecontextfetch originals draft SQLsemantic layer SQL checksmeaning + scope bounded readcost + result size cited answerresult · SQL · sources retry retrieval / abstain weak evidence or invalid SQL

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 index supplies access-scoped source context for SQL generation. The execution path checks the query before a bounded read and returns the result with SQL and citations; weak evidence or an invalid query takes the retry or abstain path.

The architecture joins curated source material to text and vector search:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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?