How abhinavvikram333/nl_to_sql_rag works
Purpose and Entry Point
This repository is a natural-language-to-SQL prototype for an expense-oriented dimensional data warehouse. The executable workflow is concentrated in the notebook NL_TO_SQL_PROJECT_API/FINAL_CODE.ipynb; no standalone application server or README-defined CLI/API entry point is present.
Warehouse Schema
The SQL schema defines a star-style model used as the target for generated queries:
• Fact table: NL_TO_SQL_PROJECT_API/SCHEMA/FACT_EXP.sql
• Dimensions: NL_TO_SQL_PROJECT_API/SCHEMA/DIM_DATE.sql, NL_TO_SQL_PROJECT_API/SCHEMA/DIM_EMPLOYEE.sql, NL_TO_SQL_PROJECT_API/SCHEMA/DIM_CATEGORY.sql
• Database/table setup and seed-oriented creation script: NL_TO_SQL_PROJECT_API/SCHEMA/TABLE DATA BASE CREATION.sql
Natural-language requests should be translated against this schema, with joins and aggregations centered on expense facts and date, employee, and category attributes.
RAG Knowledge Layer
Retrieval-augmented generation grounds SQL creation in domain documentation rather than relying only on model knowledge:
• Schema semantics: NL_TO_SQL_PROJECT_API/rag_data/SCHEMA_DESCRIPTION.txt
• Business constraints and interpretation rules: NL_TO_SQL_PROJECT_API/rag_data/BUSINESS RULES.txt
• SQL patterns/examples: NL_TO_SQL_PROJECT_API/rag_data/SQL_EXAMPLES.txt
These documents form the authoritative prompt context for interpreting user intent, selecting tables/columns, and applying business logic.
Vector Retrieval Storage
A persisted Chroma-style vector database stores embeddings of the RAG corpus:
• Metadata/database: NL_TO_SQL_PROJECT_API/vector_db/chroma.sqlite3
• Vector index segment: NL_TO_SQL_PROJECT_API/vector_db/3745870e-ab02-4fd5-bb7c-337d74122f92/data_level0.bin
• Graph/index links: NL_TO_SQL_PROJECT_API/vector_db/3745870e-ab02-4fd5-bb7c-337d74122f92/link_lists.bin
The notebook likely opens this local store, retrieves relevant schema/rule/example chunks for an incoming question, and incorporates them into the SQL-generation context. The committed binary index is an operational dependency unless the notebook includes re-ingestion/re-embedding logic.
Primary Control Flow
1. Establish access to the expense warehouse schema and local vector store.
2. Receive or define a natural-language analytical question in NL_TO_SQL_PROJECT_API/FINAL_CODE.ipynb.
3. Embed/query the question against the persisted vector database.
4. Combine retrieved documentation with the question in an LLM prompt.
5. Generate SQL targeting the fact/dimension model.
6. Potentially execute, inspect, or refine the SQL in the notebook workflow.
The key boundary is between untrusted/generated SQL and the target database: generated statements should be validated and restricted before execution, especially if this prototype is promoted into an API.
Runtime and External Dependencies
Python notebook dependencies are declared in NL_TO_SQL_PROJECT_API/requirements.txt. Material runtime services are an LLM/embedding provider (not identifiable from the tree), a local Chroma-compatible vector database, and the relational database hosting the scripts in NL_TO_SQL_PROJECT_API/SCHEMA/. Credentials, deployment configuration, and a production request-serving layer are not represented in the repository tree.
Main entry points: FINAL_CODE.ipynb NL-to-SQL workflow · chroma.sqlite3 Persisted vector store · FACT_EXP.sql Expense fact · SCHEMA_DESCRIPTION.txt Schema semantics
Components 18
Notebook workflow
- NL-to-SQL workflow · Primary executable entry point.
NL_TO_SQL_PROJECT_API/FINAL_CODE.ipynb - Analytical question
- Context retrieval · Embeds the question and retrieves grounding context.
NL_TO_SQL_PROJECT_API/FINAL_CODE.ipynb - SQL generation · Combines question and retrieved context into warehouse SQL.
NL_TO_SQL_PROJECT_API/FINAL_CODE.ipynb - SQL inspection or execution · Generated SQL may be reviewed, run, or refined.
NL_TO_SQL_PROJECT_API/FINAL_CODE.ipynb
RAG knowledge
- Schema semantics
NL_TO_SQL_PROJECT_API/rag_data/SCHEMA_DESCRIPTION.txt - Business rules
NL_TO_SQL_PROJECT_API/rag_data/BUSINESS RULES.txt - SQL examples
NL_TO_SQL_PROJECT_API/rag_data/SQL_EXAMPLES.txt - Persisted vector store · Local embeddings and retrieval index for the RAG corpus.
NL_TO_SQL_PROJECT_API/vector_db/chroma.sqlite3 - Vector index segment
NL_TO_SQL_PROJECT_API/vector_db/3745870e-ab02-4fd5-bb7c-337d74122f92/data_level0.bin
Expense warehouse
- Expense fact · Central expense measures and dimensional keys.
NL_TO_SQL_PROJECT_API/SCHEMA/FACT_EXP.sql - Date dimension
NL_TO_SQL_PROJECT_API/SCHEMA/DIM_DATE.sql - Employee dimension
NL_TO_SQL_PROJECT_API/SCHEMA/DIM_EMPLOYEE.sql - Category dimension
NL_TO_SQL_PROJECT_API/SCHEMA/DIM_CATEGORY.sql - Warehouse setup · Creates and seeds the warehouse tables.
NL_TO_SQL_PROJECT_API/SCHEMA/TABLE DATA BASE CREATION.sql - Expense warehouse database · Target database for generated SQL.
Runtime dependencies
- LLM and embedding provider
- Notebook dependencies
NL_TO_SQL_PROJECT_API/requirements.txt
Connections 20
- Analytical question → NL-to-SQL workflow: defined in
- NL-to-SQL workflow → Context retrieval: orchestrates
- NL-to-SQL workflow → SQL generation: orchestrates
- NL-to-SQL workflow → SQL inspection or execution: orchestrates
- Context retrieval → LLM and embedding provider: embeds/query
- Context retrieval → Persisted vector store: searches
- Persisted vector store → Vector index segment: uses
- Schema semantics → Persisted vector store: indexed as context
- Business rules → Persisted vector store: indexed as context
- SQL examples → Persisted vector store: indexed as context
- Context retrieval → SQL generation: retrieved context
- SQL generation → LLM and embedding provider: generates with
- SQL generation → SQL inspection or execution: generated SQL
- SQL inspection or execution → Expense warehouse database: untrusted SQL boundary · Validate and restrict generated statements before execution.
- Expense fact → Expense warehouse database: defined in
- Date dimension → Expense fact: joins by date key
- Employee dimension → Expense fact: joins by employee key
- Category dimension → Expense fact: joins by category key
- Warehouse setup → Expense warehouse database: creates and seeds
- Notebook dependencies → NL-to-SQL workflow: supports runtime