top of page
Chandan Kumar

Deploy your own SQL AI Agent in Minutes with Huggingface TGI on Denvr Cloud


In today's data-driven world, accessing and analyzing data efficiently is crucial for decision-making. However, interacting with databases often requires knowledge of complex query languages like SQL, creating a barrier for non-technical users. To bridge this gap, we developed an AI-powered tool that enables users to interact with their databases using natural language.


This blog outlines our journey of creating and refining this tool, highlighting its features, technical challenges, and the innovations that make it unique.


The Problem: Complexity of Database Queries


Traditional database interfaces are built for technical users who understand SQL or similar query languages. For non-technical users, extracting insights involves:

  • Relaying requirements to technical teams.

  • Waiting for queries to be written, executed, and results shared.

This process is inefficient and prone to miscommunication. We wanted to simplify this interaction by allowing users to ask questions in plain English and receive immediate, actionable results.


The Solution: Natural Language to SQL


Our AI tool leverages large language models (LLMs) to convert natural language queries into SQL commands. These SQL commands are then executed on the user’s database, returning precise results in real-time.


Key Features


  1. Natural Language Input: Users can type queries like, "Show me the top 5 customers by sales" or "List orders placed in the last week." The tool translates these into SQL statements.

  2. Database Compatibility: The tool supports multiple databases, including PostgreSQL, MySQL, and SQLite, ensuring flexibility for various use cases.

  3. Chat History: Users can view their query history, enabling easy revisits to previous analyses.

  4. Seamless Execution: SQL queries are executed instantly, and results are displayed in a clean, user-friendly interface.

  5. Persistence: Chat and query histories are saved, so users can resume their work after a session ends.



Technology Stack


  • Web Application framework - Python Streamlit

  • LLM specialized for SQL - defog/llama-3-sqlcoder-8b

  • Cloud Provider - Denvr Dataworks VM solution

  • GPU Platform - Nvidia A100 SXM



SQL AI Agent Architecture
SQL AI Agent Architecture


Prerequisite


  • Denvr Cloud Account to deploy open source model

  • Hugging face account -To download and inference the model

  • Basic familiarity with command line interface


Step by Step guide to deploy the solution


Launch your VM

In today's data-driven world, accessing and analyzing data efficiently is crucial for decision-making. However, interacting with databases often requires knowledge of complex query languages like SQL, creating a barrier for non-technical users. To bridge this gap, we developed an AI-powered tool that enables users to interact with their databases using natural language.

Configure the Instance in our single page view


VM Selection Screen
VM Selection Screen



VM Selection Screen
VM Selection Screen

Once VM has been deployed, ensure it is detecting NVIDIA card


 

Export the Huggingface token


ubuntu@db-agent-example:~$ export HF_TOKEN=<YOUR TOKEN>

Clone and build the application


Launch the Application


docker compose -f docker-compose.demo.yml up -d

Check the logs to ensure that TGI has started inferencing the LLM, look for following log in the console messages


docker compose -f docker-compose.demo.yml logs -f

The Streamlit application endpoint you can see at



Once login to browser, please ensure the DB credentials are like below ( use default user postgres ) and



Now you are ready to fire DB queries using natural language, play around with more queries to test the limit of the LLM


Conclusion


The DB-Agent is more than just a tool for simplifying database interactions—it’s a testament to the flexibility and power of modern AI-driven solutions. Built to run seamlessly on Denvr Cloud’s virtual machines, it allows you to leverage cutting-edge NVIDIA GPUs for accelerated performance. This capability not only enhances query processing speed but also ensures you can deploy and scale your AI-powered applications with ease.


Denvr Cloud’s virtual machine solution provides unmatched flexibility, enabling rapid setup and deployment of AI workloads without the complexity. With support for the latest NVIDIA GPUs, you can reduce time-to-market for your AI products, ensuring faster insights and superior user experiences.


We invite developers, businesses, and AI enthusiasts to explore the DB-Agent and see how Denvr Cloud’s infrastructure can amplify the potential of your AI solutions. Whether you're building a prototype or scaling to production, our platform is designed to meet your needs efficiently. Let’s transform the way we interact with data and deliver impactful AI products to the market—faster than ever before.

2 views0 comments

Comments


bottom of page