Skip to content

This project enables users to connect to any database, input queries in natural human language, and retrieve relevant data by converting these queries into SQL. The project implements two different approaches to achieve this: one using pre-defined retrievers and query engines, and another using a Query Pipeline (DAG).

Notifications You must be signed in to change notification settings

Nipunkhattri/Text-To-SQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text to SQL Query Engine

This project enables users to connect to any database, input queries in natural human language, and retrieve relevant data by converting these queries into SQL. The project implements two different approaches to achieve this: one using pre-defined retrievers and query engines, and another using a Query Pipeline (DAG).

Features

  • Natural Language Querying: Input queries in plain human language and retrieve relevant data from a connected database.
  • SQL Conversion: Automatically convert natural language queries into SQL statements.
  • Multiple Approaches:
    • Pre-defined Retrievers and Query Engines: Quick and straightforward implementation using LlamaIndex components.
    • Query Pipeline (DAG): A more advanced and flexible approach, allowing for complex workflows and data processing steps.

Tech Stack

  • LlamaIndex: Used for building the natural language processing (NLP) components and managing the retrievers and query engines.
  • Flask: Lightweight web framework used to build the API endpoints and handle incoming requests.
  • Gemini: Leveraged for handling complex data processing and managing the execution of the query pipeline (DAG).

Installation

  1. Clone the repository:
    git clone https://github.com/your-username/text-to-sql.git
    cd text-to-sql
    
  2. Create and activate a virtual environment:
    python3.10 -m venv venv
    
  3. Activate Virtual environment
    source venv/bin/activate
    
  4. Install the required dependencies:
    pip install -r requirements.txt
    
  5. Start The Server
    python main.py
    

Run the Request and Get the Response using Postman

POST Request

URL: http://localhost:5000/database/connect-and-query

Method: POST

Request Body

{
    "connection_string": "postgresql://postgres:postgres@localhost:5432/texttosql",
    "query": "Tell all the emails in users table?"
}
{
    "data": "\"assistant: Nipun@gmail.com, Anurag@gmail.com, Abc@gmail.com, Xyz@gmail.com\"",
    "message": "Success"
}

About

This project enables users to connect to any database, input queries in natural human language, and retrieve relevant data by converting these queries into SQL. The project implements two different approaches to achieve this: one using pre-defined retrievers and query engines, and another using a Query Pipeline (DAG).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages