Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

SQLRAG

Project Logo

SQLRAG allows users to query databases using natural language and receive results as SQL code and beautiful visualizations. Powered by Large Language Models (LLMs), SQLRAG supports both OpenAI models and open-source alternatives from GPT4All. Additionally, Redis caching is employed for optimized performance, and users can choose between CPU and GPU processing for open-source models.

Table of Contents

Description

SQLRAG is a Python package that lets users query their databases using simple natural language prompts. SQLRAG translates these prompts into SQL, executes the queries, and returns results as SQL code, data, and visualizations using either Matplotlib or Chart.js. It supports both open-source LLMs from GPT4All and paid models like OpenAI, giving users flexibility in model choice.

Redis caching is used to speed up responses for repeated queries, and users can opt for GPU processing with open-source models for faster execution.

Features

  • Natural Language Queries: Input your queries in plain language, and SQLRAG will convert them into SQL statements.
  • Data Visualization: Generate charts using Python's Matplotlib or JavaScript's Chart.js.
  • Model Flexibility: Supports both OpenAI models and open-source alternatives like GPT4All.
  • Redis Caching: Improves response times for repeated queries by caching previous results.
  • Supports CPU and GPU: Open-source models can run on both CPU and GPU, providing performance flexibility.

Getting Started

Prerequisites

  • Python 3.10 or higher
  • A compatible database (PostgreSQL, MySQL, SQLite, etc.)
  • Redis for caching (optional but recommended)
  • An OpenAI API key (if using OpenAI models)

Installation

SQLRAG is distributed as a Python package and can be installed via pip.

  1. Install the package:

    pip install sqlrag
    
  2. Set environment variables (if using OpenAI):

    export OPENAI_API_KEY=your_openai_key
    

That's it! Now you’re ready to use SQLRAG.

Usage

For Open-Source Models

You can use open-source models from GPT4All with SQLRAG. Here's how:

from sqlrag.open_sql_rag import OpenSQLRAG

# Initialize SQLRAG with your database and model
sql_rag = OpenSQLRAG("sqlite:///mydb.db", model_name="Meta-Llama-3-8B-Instruct.Q4_0.gguf", is_openai=False)

# Generate SQL code and a chart
data = sql_rag.generate_code_and_sql({"chart_type": "chart.js", "query": "List out all customers"})

# Output the generated SQL code and data
print(data)

# Check available open-source models and supported GPUs
print(sql_rag.get_open_source_models())
print(sql_rag.get_gpus_list())

For OpenAI Models

If you have an OpenAI API key, you can use OpenAI models with SQLRAG as follows:

from sqlrag.open_sql_rag import OpenSQLRAG

# Initialize SQLRAG with your database (OpenAI by default)
sql_rag = OpenSQLRAG("sqlite:///mydb.db")

# Generate SQL code and a chart
data = sql_rag.generate_code_and_sql({"chart_type": "chart.js", "query": "List out all customers"})

# Output the generated SQL code and data
print(data)

Redis Caching

SQLRAG automatically uses Redis to cache results of frequently used queries, speeding up the response time for repeated requests.

API Hosting

While SQLRAG is primarily a Python package, you can also expose it as an API if desired. However, it’s primarily designed for use as a Python library for direct database querying and data visualization.

Contributing

We welcome contributions to SQLRAG! Whether it's reporting bugs, submitting features, or writing documentation, feel free to open a pull request or issue. See CONTRIBUTING.md for more details.

License

SQLRAG is licensed under the MIT License. See LICENSE.md for further information.

Acknowledgments

Special thanks to the developers of GPT4All, OpenAI, and Redis for their open-source contributions. Their work has made this project possible.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlrag-0.1.dev33.tar.gz (601.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlrag-0.1.dev33-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file sqlrag-0.1.dev33.tar.gz.

File metadata

  • Download URL: sqlrag-0.1.dev33.tar.gz
  • Upload date:
  • Size: 601.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for sqlrag-0.1.dev33.tar.gz
Algorithm Hash digest
SHA256 d3e25bae8f75e4efda93da02d20b8f88a47bde424256553cb63e461cd8b8add0
MD5 c5e51aaf3cbd6cbbb058c6dfbd3f093e
BLAKE2b-256 817af455a7a026255e521f7ede8c9cb9b8325730318b2aef2ff2056382dc3ed6

See more details on using hashes here.

File details

Details for the file sqlrag-0.1.dev33-py3-none-any.whl.

File metadata

  • Download URL: sqlrag-0.1.dev33-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for sqlrag-0.1.dev33-py3-none-any.whl
Algorithm Hash digest
SHA256 5eada9971cb5680ff0c18cc14442b34989f6ebea2f64ea2c7c4786dc9a1204c5
MD5 9f13e8642ed640ac56dc22c31f26bdf1
BLAKE2b-256 9ab06f69a415d4430d76487fbbfd8436c8f9da225ef94fa70b42da16a6255492

See more details on using hashes here.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page