Skip to content

This tool uses an SQL Agent from LangChain and ChatGPT-3.5 to translate natural language queries into SQL commands. Users can modify queries, visualize data, or export it, simplifying database interactions.

Notifications You must be signed in to change notification settings

Awos99/Query-SQL-Databases-with-Natural-Language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Query SQL Databases with Natural Language

Demo GIF

Overview

This repository hosts the prototype of an innovative tool designed to leverage the capabilities of an SQL Agent from LangChain to facilitate querying databases using natural language. This project harnesses the power of large language models (LLMs) to interpret and translate user queries into executable SQL commands.

How It Works

The application workflow is intuitive and efficient, making it accessible for users without deep technical expertise in SQL:

  1. User Input: The user poses a question to the application.
  2. Description Generation: A descriptive message about the database is generated by providing an LLM (specifically ChatGPT-3.5) with the first three rows from all tables within the database.
  3. Query Generation and Execution:
    • The SQL Agent crafts an SQL query based on the input.
    • This query is retrieved via a callback handler and executed against the database to fetch the necessary information.
  4. Response Generation: The application uses the retrieved data and the original user question to generate a comprehensive answer.
  5. Query Modification: Users have the flexibility to modify the auto-generated SQL query and rerun it, allowing for customization and refinement of results.
  6. Data Visualization and Export: The retrieved data can be visualized through bar, line, or scatter plots, or downloaded as a CSV file for further analysis.

Enhanced Capabilities with LLMs

Integrating LLMs like ChatGPT-3.5 significantly enhances the application's functionality. These models bring a deep understanding of natural language, enabling the system to handle a wide range of queries and generate precise SQL commands. This integration points to a future where natural language can serve as a powerful interface for complex database interactions, making data more accessible to non-specialist users.

Challenges Encountered

The development of this application presented several unique challenges:

  • SQL Query Retrieval: Extracting the dynamically generated SQL query from the SQL Agent was particularly challenging, given that the agent's definitions are managed externally by the LangChain library.
  • Widget Management: The sequential loading behavior of widgets in Streamlit necessitated careful planning of the user interface layout to ensure a logical and user-friendly order of operations.

Please, try the app here:

Streamlit App

About

This tool uses an SQL Agent from LangChain and ChatGPT-3.5 to translate natural language queries into SQL commands. Users can modify queries, visualize data, or export it, simplifying database interactions.

Topics

Resources

Stars

Watchers

Forks

Languages