Skip to content

Latest commit

 

History

History
164 lines (100 loc) · 7.41 KB

README.md

File metadata and controls

164 lines (100 loc) · 7.41 KB

InquireDB - Transforming Database Interactions into Seamless Conversations! 👩‍💻

Table of Contents 📃

Overview ℹ️

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.

Architecture Overview 📍

Excalidraw

The inquireDB application follows a structured workflow to process user queries:

  1. Input: User enters a natural language query via the Streamlit user interface.

  2. 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.

  3. SQL Query Execution: The LangChain SQL chain executes the DSL query against the SQLite database.

  4. Output: The query results are retrieved from the database. LangChain Chain then formats the results into human-readable text using its output parsing capabilities.

Features ✨

  • 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.

Technologies Used 🛠️

  • 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.

Setup Instructions 🚀

Prerequisites

  1. Install SQLite: Download and install SQLite from the official SQLite website (SQLite Downloads).

  2. Download Northwind Sample Database: Obtain the Microsoft Northwind Sample Database. You can download it from here.

  3. Setup Python Environment:

    pip install -r requirements.txt

Running the Application ▶️

  1. Clone the Repository:

    git clone https://github.com/harmeetsingh11/inquireDB
    cd inquireDB
  2. Setup Environment Variables:

    • Create a .env file in the root directory with the following content:
      GROQ_API_KEY=your_groq_api_key_here
      
  3. Initialize the System:

    • Run main.py using Streamlit:
      streamlit run main.py
  4. 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.

Demo Video 📹

app_demo.mp4

Screenshots 📷

ss1

ss2

File Structure 📁

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.

Usage 📘

  • 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.

Sample Questions 📝

You can interact with inquireDB by asking questions related to the Northwind database. Here are some examples:

  1. List all the Product Names which have been discontinued.

  2. How many Employees are there?

  3. List all the Territories which have Region ID 3.

  4. How many total Orders are placed by Customer ID HANAR?

  5. List last 5 orders placed.

  6. How many orders are shipped to USA?

  7. List names of first 5 employees.