The Text-to-SQL Agent is an AI-powered tool built with Next.js that allows users to convert natural language queries into SQL commands and directly interact with a database. It utilizes LangChain, LangGraph, and Ollama to generate, execute, and refine SQL queries dynamically. The system can retrieve data from the database, enabling seamless interactions without requiring manual SQL writing.
- Natural Language to SQL Conversion: Converts user queries into SQL statements.
- Direct Database Interaction: Executes generated SQL queries and fetches results.
- Multi-Step Query Processing: Uses LangGraph for structured query generation.
- Supports SQLite: Works with SQLite databases for lightweight and fast execution.
- Extensible and Modular: Easily adaptable for other databases or additional AI capabilities.
- Next.js: Framework for building the frontend and backend.
- LangChain: For natural language processing and query generation.
- LangGraph: Enables structured decision-making for SQL refinement.
- Ollama: AI-powered model for query understanding.
- SQLite: Lightweight relational database engine.
- Node.js (Latest LTS version recommended)
- SQLite installed
- WatsonX API credentials
- Clone the repository:
git clone https://github.com/AlokTheDataGuy/text-to-sql-agent.git cd text-to-sql-agent
- Install dependencies:
npm install
- Set up environment variables in a
.env.local
file:WATSONX_AI_ENDPOINT=your_watsonx_endpoint WATSONX_AI_APIKEY=your_watsonx_apikey WATSONX_AI_PROJECT_ID=your_watsonx_project_id
- Run the development server:
npm run dev
- Open
http://localhost:3000
in your browser. - Enter a natural language query (e.g., "Show me all customers who made a purchase last month").
- The system will generate an SQL query and execute it on the database.
- Results will be displayed on the interface.
- Fork the repository.
- Create a new branch:
git checkout -b feature-branch-name
. - Commit your changes:
git commit -m "Add new feature"
. - Push to the branch:
git push origin feature-branch-name
. - Open a pull request.
This project is licensed under the MIT License.