A conversational AI agent that converts natural language questions into SQL queries, executes them, and provides AI-driven insights.
Built with LangChain, FAISS VectorDB, and Gradio for the Codecademy GenAI & Agents Bootcamp Contest.
- Natural Language to SQL - Ask questions in plain English, get accurate SQL queries
- RAG-Powered - Uses vector database to semantically search table schemas
- SQL Explanations - Beginner-friendly explanations of what each query does
- AI Insights - Analyzes query results and provides business insights
- Conversation Memory - Remembers context for follow-up questions
- Clean Chat Interface - Interactive Gradio UI for easy interaction
| Component | Technology |
|---|---|
| AI Framework | LangChain |
| LLM | OpenAI GPT-3.5 |
| Vector Database | FAISS |
| Embeddings | OpenAI Embeddings |
| Database | SQLite |
| Frontend | Gradio |
| Language | Python 3.13 |
git clone https://github.com/yourusername/sql-query-buddy.git
cd sql-query-buddypython -m venv .venv
source .venv/bin/activate # Mac/Linux
# OR
.venv\Scripts\activate # Windowspip install langchain langchain-openai langchain-community python-dotenv sqlalchemy faiss-cpu gradioCreate a .env file in the project root:
OPENAI_API_KEY=your_openai_api_key_here
cd database
python setup_database.py
cd ..python app.pyThis will launch the Gradio interface in your browser.
- "Show me all customers from California"
- "What are the top 3 customers by total spending?"
- "Which product category generates the most revenue?"
- "Show total sales per region for 2025"
- "How many unique products were sold in January?"
- "Show the trend of monthly revenue over time"
- "Find the average order value for returning customers"
The project uses a retail commerce database with 4 tables:
customers - Customer information (name, email, region, signup date)
products - Product catalog (name, category, price)
orders - Order records (customer, date, total amount)
order_items - Line items (links orders to products with quantity)
-
User asks a question in natural language
-
Vector search finds relevant table schemas from FAISS database
-
LLM generates SQL using the retrieved schema context
-
Query executes against the SQLite database
-
AI analyzes results and provides insights
-
Conversation saved to memory for follow-up questions
create_schema_documents()- Creates searchable documents for each tablecreate_vector_store()- Embeds schemas in FAISS vector databaseget_relevant_schemas()- Retrieves relevant tables based on questionask_question()- Main RAG pipeline: retrieve → generate → execute → insight
- Gradio chat interface
- Integrates with sql_agent functions
- Displays SQL, results, and insights
Rubin - Software Engineer Codecademy GenAI & Agents Bootcamp Participant
#CodecademyGenAIBootcamp #RAG #LangChain #VectorDB #SQL #AI #Gradio