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).
- 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.
- Pre-defined Retrievers and Query Engines: Quick and straightforward implementation using
- 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).
- Clone the repository:
git clone https://github.com/your-username/text-to-sql.git cd text-to-sql
- Create and activate a virtual environment:
python3.10 -m venv venv
- Activate Virtual environment
source venv/bin/activate
- Install the required dependencies:
pip install -r requirements.txt
- Start The Server
python main.py
URL: http://localhost:5000/database/connect-and-query
Method: POST
{
"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"
}