A utility that converts natural language into SQL queries and runs them in an interactive interface

AI-Database-Query-Assistant: A Streamlit-based system that combines OpenAI GPT-3.5 and ChromaDB vector database to convert text to SQL queries. It can be used as a self-built reference framework.

Open source project maintained by Paulisure (Paul Loupe) on GitHub AI-Database-Query-Assistant。This is a utility that demonstrates how to convert natural language into SQL queries and run them through an interactive interface.

overview of items

The project aims to build a Natural Language → SQL Query System, and integrates the following technical components:

  • using OpenAI’s GPT-3.5 The model converts a user’s natural language request into SQL query statements.
  • use ChromaDB As a vector database, it is used for similarity retrieval of historical queries.
  • Front-end interface adopts Streamlit Framework for users to interact through web pages.

Main functional highlights

  1. natural language query processing: Users enter ordinary English questions, such as “Who are the top 5 customers by total purchase amount?”, The system will automatically generate the corresponding SQL query.
  2. vector similarity retrieval: With ChromaDB, the system can find historical queries similar to the current input statement, improving the accuracy and consistency of generated results.
  3. Interactive web display: The interface built using Streamlit makes user operations more intuitive, supporting entering questions, viewing results, and even automatically generating chart visualizations.
  4. automatic visual: Query results can be displayed in real-time charts through Plotly Express, making the experience more friendly.
  5. Sample query library: Include examples such as “Which genre generates the most revenue” and “Calculate the average invoice amount by country” to help users get started quickly.

Technology stack and usage

technologyuse
GPT-3.5Convert natural language to SQL
ChromaDBVector database that supports similar query retrieval
StreamlitUsed to build web interactive interfaces
Plotly ExpressUsed to generate data visualization charts
SQLite (Chinook database)As a back-end database, the architecture includes common table structures such as customers, artists, albums, audio tracks, and invoices, which are used to query presentations.

Brief steps to use

  • After cloning the warehouse, create a virtual environment locally and install dependencies (requirements.txt defined in).
  • Configure the OpenAI API key by .streamlit/secrets.toml File preservation.
  • Launch the application:streamlit run streamlit_app.py, access the local address in the browser: such as http://localhost:8501You can use the system. You can use the system.

summary

AI-Database-Query-Assistant It is a lightweight tool that allows users to interact with databases through natural language. It integrates GPT-3.5 generated SQL, ChromaDB semantic retrieval and Streamlit front-end display, and combines Plotly to achieve intuitive charts. The project structure is clear and suitable as a learning reference for understanding the principles of natural language interface database query.

Github:https://github.com/Paulisure/AI-Database-Query-Assistant

Oil tubing:

Scroll to Top