Inspired by Ashpreet Bedi's Dash, rebuilt from scratch with an enhanced multi-node architecture on top of the TPC-DS 100TB benchmark dataset.
Dash answers natural language questions about retail data by generating, validating, executing, and interpreting SQL β and learns from every interaction.
- Natural Language to SQL: Converts complex business questions into optimized Snowflake SQL.
- Self-Learning: Captures and reuses successful query patterns and error corrections.
- Cost Protection: 4 layers of credit protection to prevent expensive Snowflake queries.
- Multi-Agent Architecture: 9 specialized nodes orchestrated by LangGraph.
User βββΊ Intent Classifier (gpt-4o-mini)
β
βββ data_question / infra_request βββΊ Context Retrieval
β β
β βββββββββββββββΌββββββββββββββ
β βΌ βΌ β
β Analyst Engineer β
β β β β
β SQL Validator β β
β β β β β
β Executor ββretry β β
β β β β β
β Interpreter β β β
β β β β β
β Learning Evaluatorβ β β
β β β β β
βββ general / feedback βββΊ Leader β β β
β β β β β
βΌ βΌ βΌ βΌ β
END βββββββββββββββββββββββββ΄ββββββ΄ββββββββ β
β
βββββββββββββββββββββββββββββββββββ
βΌ
validation_failed / execution_failed βββΊ END
9 specialized nodes + 3 helper nodes (retry, validation_failed, execution_failed) connected via conditional edges with a max 3-retry loop.
| Component | Technology | Description |
|---|---|---|
| πΌ Orchestration | LangGraph | StateGraph for routing and flow control |
| π§ LLM | Azure OpenAI | gpt-4o (analyst, engineer, interpreter) + gpt-4o-mini (intent, leader) |
| π€ Embeddings | Azure OpenAI | text-embedding-3-small |
| ποΈ Vector Store | Qdrant | Persistent storage for knowledge & learnings (supports both local memory and Cloud) |
| βοΈ Database | Snowflake | SNOWFLAKE_SAMPLE_DATA.TPCDS_SF100TCL (100TB) |
| π¨ Frontend | Streamlit | Interactive chat UI |
A 100TB retail benchmark featuring:
- π 7 Fact Tables:
STORE_SALES(~300B rows),CATALOG_SALES,WEB_SALES,STORE_RETURNS,CATALOG_RETURNS,WEB_RETURNS,INVENTORY. - ποΈ 17 Dimension Tables:
CUSTOMER(~100M rows),ITEM(~500K rows),DATE_DIM,STORE,CUSTOMER_ADDRESS, etc. - π Scope: 1998β2002 across 3 sales channels (Store, Catalog, Web).
Click to expand
Dash-LangGraph/
βββ app.py # Streamlit UI
βββ config.py # Central configuration (env vars)
βββ requirements.txt # Python dependencies
β
βββ db/
β βββ __init__.py # Snowflake connection factory (read + write engines)
β βββ schema_cache.py # INFORMATION_SCHEMA β local JSON cache
β
βββ graph/
β βββ state.py # DashState TypedDict (shared graph state)
β βββ edges.py # 4 conditional routing functions
β βββ builder.py # Graph assembly (nodes + edges + compile)
β βββ graph_view.py # Export compiled graph as PNG
β βββ nodes/
β βββ intent_classifier.py # Classifies intent (gpt-4o-mini)
β βββ context_retrieval.py # Fetches knowledge + learnings + schema
β βββ analyst.py # Generates read-only SQL (gpt-4o)
β βββ sql_validator.py # Validates SQL (regex, no LLM)
β βββ executor.py # Runs SQL on Snowflake
β βββ interpreter.py # Converts results to insights (gpt-4o)
β βββ learning_evaluator.py # Saves learnings from interactions
β βββ leader.py # Handles general/greeting messages
β βββ engineer.py # Creates views in DASH schema (gpt-4o)
β
βββ vectorstore/
β βββ __init__.py # Qdrant wrapper (knowledge + learnings)
β
βββ knowledge/
β βββ tables/ # 24 table metadata JSONs (all TPC-DS tables)
β βββ queries/ # 8 validated SQL patterns
β βββ business/
β βββ rules.json # Metrics, gotchas, join patterns
β
βββ scripts/
β βββ snowflake_setup.sql # Snowflake setup (warehouse, roles, grants)
β βββ cache_schema.py # One-time schema fetch β JSON
β βββ load_knowledge.py # Embed knowledge into Qdrant
β
βββ .env.example # Environment variable template
βββ .gitignore
git clone <repo-url>
cd Dash-LangGraph
python -m venv venv
# Windows
.\venv\Scripts\activate
# macOS/Linux
source venv/bin/activatepip install -r requirements.txtcp .env.example .envUpdate .env with your credentials. (See Environment Variables Reference below).
Run scripts/snowflake_setup.sql in a Snowflake worksheet as ACCOUNTADMIN. This creates:
COMPUTE_WHβ XSMALL warehouse (auto-suspend 60s)DASH_DB.DASHβ Schema for Engineer-created views- Required Roles:
DASH_ANALYST(read-only) &DASH_ENGINEER(read/write to DASH schema) - Resource monitor capping at 10 credits/month
Cache the schema to avoid expensive queries, and load knowledge into ChromaDB:
python scripts/cache_schema.py
python scripts/load_knowledge.py --recreatestreamlit run app.py(Optional) Visualize the graph structure:
python graph/graph_view.pyRunning on a 100TB dataset requires aggressive cost controls:
| Layer | Mechanism | How it Works |
|---|---|---|
| 1. Knowledge-first | Skip SQL generation | Pre-validated queries matched via semantic search. |
| 2. SQL Validator | Prevent expensive scans | Auto-injects LIMIT, warns on missing date filters, blocks DML. |
| 3. Schema Cache | Avoid info queries | Fetched once, stored as local JSON, kept in memory. |
| 4. Vector Store | Zero Snowflake cost | Qdrant stores pre-calculated vectors. Fallbacks to in-memory for testing, saving I/O. |
Performance Gains: Connection pooling, LLM singletons, and memory caching reduce per-request overhead, bringing response times down to ~18-20s after an initial warmup.
The Learning Evaluator node captures two types of data:
- π Error Corrections: When a SQL error is fixed after a retry, the
error β fixpattern is saved. - π― Successful Patterns: When a query runs successfully, it's saved as a reusable pattern.
These are stored in Qdrant and retrieved by the Context node for future queries.
Try these out in the Streamlit app:
"What is the total revenue by sales channel for 2001?"
"Show me the top 10 product categories by sales amount"
"What's the return rate comparison across store, catalog, and web?"
"Rank all stores by revenue for year 2000"
"How does customer spending vary by education level?"
"Create a view that shows monthly revenue trends by channel"
| Variable | Description | Default |
|---|---|---|
AZURE_OPENAI_API_KEY |
Azure OpenAI API key | Required |
AZURE_OPENAI_ENDPOINT |
Azure OpenAI endpoint URL | Required |
AZURE_OPENAI_CHAT_DEPLOYMENT |
GPT-4o deployment name | gpt-4o |
AZURE_OPENAI_MINI_DEPLOYMENT |
GPT-4o-mini deployment name | gpt-4o-mini |
AZURE_OPENAI_EMBEDDING_DEPLOYMENT |
Embedding model deployment | text-embedding-3-small |
AZURE_OPENAI_API_VERSION |
Azure API version | 2024-12-01-preview |
SNOWFLAKE_ACCOUNT |
Snowflake account identifier | Required |
SNOWFLAKE_USER |
Snowflake username | Required |
SNOWFLAKE_PASSWORD |
Snowflake password | Required |
SNOWFLAKE_DATABASE |
Database name | SNOWFLAKE_SAMPLE_DATA |
SNOWFLAKE_SCHEMA |
Schema name | TPCDS_SF100TCL |
SNOWFLAKE_WAREHOUSE |
Warehouse name | COMPUTE_WH |
SNOWFLAKE_ROLE |
Default role | SYSADMIN |
QDRANT_URL |
Qdrant Cluster URL | Optional (defaults to memory) |
QDRANT_API_KEY |
Qdrant API Key | Optional |
