Transform the existing AI SQL Assistant into a production-ready Multilingual RAG-powered SQL Analytics Assistant capable of understanding user questions in multiple languages while maintaining accurate SQL generation and execution.
The enhancement must preserve the existing architecture and functionality while introducing a Retrieval-Augmented Generation (RAG) layer for schema-aware and business-aware query generation.
Current System:
Natural Language Question → LangChain Agent → NVIDIA NIM (Mistral Large 3) → SQL Generation → PostgreSQL Execution → Results
Target System:
User Question (Any Language) → Multilingual Embedding Generation → Vector Retrieval → Schema & Business Context Retrieval → LangChain SQL Agent → NVIDIA NIM (Mistral Large 3) → SQL Generation → PostgreSQL Execution → Results
Current Limitations
- Entire schema is injected into prompts.
- Performance decreases as schema size grows.
- No business glossary support.
- No multilingual understanding.
- Increased token consumption.
- Limited scalability.
RAG Benefits
- Retrieve only relevant schema information.
- Support multiple languages.
- Improve SQL accuracy.
- Reduce prompt size.
- Scale to large enterprise databases.
- Support business definitions and KPI documentation.
Users should be able to ask database questions in different languages and receive the same SQL output.
Example:
English
Show top 10 customers by revenue
Hindi
राजस्व के अनुसार शीर्ष 10 ग्राहक दिखाओ
French
Montrez les 10 meilleurs clients par revenus
Spanish
Mostrar los 10 principales clientes por ingresos
All should retrieve the same schema context and generate equivalent SQL.
Provider: NVIDIA NIM
Model:
mistralai/mistral-large-3-675b-instruct-2512
Purpose:
- SQL generation
- Query reasoning
- Join inference
- Aggregation logic
- Response explanation
Reason:
Currently integrated into the project and provides strong SQL reasoning performance.
Provider: NVIDIA NIM
Model:
BAAI/bge-m3
Purpose:
- Multilingual embeddings
- Cross-lingual semantic search
- Schema retrieval
- Business glossary retrieval
Reason:
- Supports 100+ languages
- Excellent retrieval quality
- Optimized for multilingual RAG
- Maps semantically equivalent questions into the same vector space
Primary:
ChromaDB
Reason:
- Open source
- Local deployment
- Lightweight
- Easy LangChain integration
Future Options:
- Pinecone
- Weaviate
- Qdrant
Primary Database:
PostgreSQL
PostgreSQL support must never be removed.
- LangChain
- Streamlit
- SQLAlchemy
- psycopg2
- ChromaDB
User Query ↓ Language Detection ↓ BGE-M3 Embeddings ↓ ChromaDB Vector Search ↓ Retrieve Schema Context ↓ Retrieve Business Definitions ↓ Context Assembly ↓ LangChain SQL Agent ↓ Mistral Large 3 ↓ Generate SQL ↓ SQL Validation ↓ PostgreSQL Execution ↓ Results
Current Structure
app.py db.py chain.py prompts.py
New Structure
app.py db.py chain.py prompts.py
rag/ │ ├── embeddings.py ├── retriever.py ├── vector_store.py ├── indexing.py ├── language_detector.py ├── context_builder.py └── sql_guardrails.py
knowledge/ │ ├── schema_docs/ ├── business_rules/ ├── glossary/ └── kpi_definitions/
vector_db/
The RAG system should index the following information.
Example
Table: customers
Description: Stores customer information.
Columns: customer_id name email created_at
Example
orders.customer_id → customers.customer_id
Example
Revenue
Definition: Total value of completed orders.
Example
Monthly Active Users
Definition: Distinct users active within a calendar month.
Business terms should be searchable.
Examples
Customer Revenue Sales Profit Retention Churn
Goal
Build retrieval infrastructure.
Tasks
- Install ChromaDB
- Configure BGE-M3 embeddings
- Create indexing pipeline
- Create retrieval layer
- Store schema metadata
Deliverables
- Functional vector database
- Successful retrieval pipeline
Success Criteria
Questions retrieve relevant schema information.
Goal
Enable language-independent retrieval.
Tasks
- Integrate BGE-M3 embedding model
- Add language detection
- Test retrieval across languages
Example
Hindi Query
राजस्व के अनुसार शीर्ष ग्राहक
Should retrieve:
customers table orders table revenue definition
Success Criteria
Identical retrieval quality across supported languages.
Current State
Entire schema injected into prompt.
New State
Only relevant schema sections retrieved.
Prompt Structure
System Prompt
Retrieved Schema Context
Business Definitions
User Question
Benefits
- Lower token usage
- Faster responses
- Better SQL quality
Goal
Improve SQL correctness.
Retrieved Context Should Include
- Relevant tables
- Relevant columns
- Foreign key relationships
- Business definitions
- KPI definitions
Expected Results
- Better joins
- Fewer hallucinations
- More accurate aggregations
Goal
Increase transparency.
Output Should Include
Generated SQL
Explanation
Tables Used
Columns Used
Retrieved Context
Example
SQL Generated
SELECT customer_name, SUM(order_amount) FROM orders GROUP BY customer_name
Explanation
This query calculates total revenue generated by each customer.
Goal
Transform assistant into analytics platform.
Features
Automatic Chart Suggestions
Examples
Revenue Trends Sales Forecasts Customer Growth Top Products
Suggested Libraries
- Plotly
- Altair
All generated SQL must pass validation.
Block
DROP
DELETE
TRUNCATE
ALTER
UPDATE
unless explicitly enabled.
Allow
SELECT
WITH
Aggregate Queries
Analytical Queries
Read-only operations
Embedding Model
BAAI/bge-m3
Search Type
Vector Similarity Search
Similarity Metric
Cosine Similarity
Top K Retrieval
5
Future Enhancement
Hybrid Search
Vector Search + Keyword Search
Chunk Size
300-500 Tokens
Overlap
50-100 Tokens
Chunk Metadata
Source Type
Schema
Business Rule
Glossary
KPI
Table Name
Column Name
Relationship Information
Retrieval Time
Less than 500 ms
SQL Generation
Less than 5 seconds
Embedding Generation
Less than 1 second
Overall Response Time
Less than 8 seconds
The existing AI SQL Assistant must remain fully operational throughout development.
The following features must never break:
- PostgreSQL connectivity
- SQL generation
- SQL execution
- Streamlit UI
- Existing prompts
- NVIDIA NIM integration
The RAG layer must enhance the system, not replace its core functionality.
Potential Phase 2 Features
- Query history
- Conversational memory
- Multi-database support
- Dashboard generation
- Automated insights
- LangGraph agents
- Query optimization
- Fine-tuned SQL models
The project will be considered successful when:
- Users can query databases in multiple languages.
- Relevant schema information is retrieved automatically.
- SQL accuracy improves significantly.
- Token consumption decreases.
- Existing functionality remains intact.
- PostgreSQL integration remains stable.
- The assistant scales to enterprise-sized schemas.
The RAG implementation must augment and strengthen the existing AI SQL Assistant without introducing breaking changes to the current workflow.