- Overview ℹ️
- Architecture Overview 📍
- Features ✨
- Technologies Used 🛠️
- Setup Instructions 🚀
- Demo Video 📹
- Screenshots 📷
- File Structure 📁
- Usage 📘
- Sample Questions 📝
InquireDB is an AI-powered SQL agent designed to facilitate Q&A interactions with an SQL database using natural language. It leverages GroqCloud API
, Llama3
(an open-source Large Language Model), and LangChain
framework to convert user queries into SQL commands, execute them against an SQLite database (using the Northwind
sample database), and present the results in natural language via a Streamlit-based user interface.
The inquireDB application follows a structured workflow to process user queries:
-
Input: User enters a natural language query via the Streamlit user interface.
-
Natural Language Understanding: The Llama3 model processes the query and generates a Domain Specific Language (DSL) query. This DSL query is passed to the LangChain SQL chain.
-
SQL Query Execution: The LangChain SQL chain executes the DSL query against the SQLite database.
-
Output: The query results are retrieved from the database. LangChain Chain then formats the results into human-readable text using its output parsing capabilities.
-
Natural Language Processing: Utilizes the Large Language Model (LLM)
Llama3
, to interpret and respond to user queries in natural language, converting them into DSL queries (specifically SQL/SQLite). -
SQL Execution: Dynamically generates SQL queries based on the user's natural language input and executes them against an SQLite database (using the
Northwind
sample database), demonstrating practical database interaction. -
User Interface: Features a user-friendly GUI built with Streamlit, allowing seamless input and output interactions for users.
-
Database Interaction: Establishes connection with a SQL database to efficiently retrieve query results, showcasing robust and practical database interaction capabilities.
-
Error Handling: Implements robust error handling mechanisms to manage output parsing errors and retries queries using LangChain's capabilities.
-
Conversation History: Maintains a comprehensive conversation history, enabling users to review previous interactions seamlessly.
-
Python-based: Entirely coded in Python, emphasizing best practices in software development with contemporary technologies.
-
GroqCloud API: Hardware/software platform for building GenAI applications. Used for natural language processing and DSL query generation.
-
Llama3: Open-source Large Language Model (LLM) used for understanding and generating SQL queries from user input.
-
LangChain: Framework for creating conversational agents, custom chains and handling complex interactions, including error handling and conversation history.
-
Streamlit: Python library for building interactive web applications. Used for creating the user interface of InquireDB.
-
SQLite: Lightweight, embedded database used for storing and querying data in the Northwind sample database.
-
Python 3: Programming language used for implementing the application logic and integration with external libraries.
-
Install SQLite: Download and install SQLite from the official SQLite website (SQLite Downloads).
-
Download Northwind Sample Database: Obtain the Microsoft Northwind Sample Database. You can download it from here.
-
Setup Python Environment:
pip install -r requirements.txt
-
Clone the Repository:
git clone https://github.com/harmeetsingh11/inquireDB cd inquireDB
-
Setup Environment Variables:
- Create a
.env
file in the root directory with the following content:GROQ_API_KEY=your_groq_api_key_here
- Create a
-
Initialize the System:
- Run
main.py
using Streamlit:streamlit run main.py
- Run
-
Interact with inquireDB:
- Open your web browser and navigate to the Streamlit application URL (default: http://localhost:8501).
- Ask questions in plain English related to the Northwind database and observe the responses generated by inquireDB.
app_demo.mp4
The project's directory structure is organized to facilitate modular development and ease of maintenance:
-
main.py
: Entry point for the Streamlit application and backend logic, including initialization of environment variables, database, model, agent, and query execution. -
config/
: Directory containing configuration files and setup scripts.config.py
: Loads environment variables and configures application settings.
-
utils/
: Utilities directory containing helper functions.utils.py
: Utility functions for common tasks.
-
handlers/
: Handlers for managing chat history and interaction.chat_handler.py
: Manages chat history, user inputs, and AI responses.
-
database/
: Handles database initialization and interaction.database.py
: Initializes and connects to the SQLite database (northwind.db
).
-
chain/
: Handles the SQL chain processing and interaction.sql_chain.py
: Defines the SQL chain for processing user queries and generating responses.
-
prompts/
: Contains prompt templates for guiding user interactions.prompts.py
: Provides templates for generating prompts used in chat interactions.
-
Databases/
: Directory containing the SQLite database file.northwind.db
: Sample SQLite database used for demonstrating inquireDB functionalities.
- Upon running
main.py
, the Streamlit interface launches. - Users can input questions in natural language regarding the
Northwind
database. - inquireDB converts these questions into SQL queries, executes them, and displays results in plain English.
You can interact with inquireDB by asking questions related to the Northwind
database. Here are some examples:
-
List all the Product Names which have been discontinued.
-
How many Employees are there?
-
List all the Territories which have Region ID 3.
-
How many total Orders are placed by Customer ID HANAR?
-
List last 5 orders placed.
-
How many orders are shipped to USA?
-
List names of first 5 employees.