pg_gpt  by cloudquery

Postgres extension for natural language queries

created 2 years ago
456 stars

Top 67.5% on sourcepulse

GitHubView on GitHub
Project Summary

This experimental PostgreSQL extension enables natural language querying by integrating with OpenAI's GPT API. It's designed for users who want to interact with their databases using plain English, translating natural language requests into SQL queries.

How It Works

The extension sends a subset of the database schema (table names and columns, not data) to the OpenAI GPT API. It then prompts the model to generate a SQL query based on the provided schema and the user's natural language input. This approach allows for intuitive database interaction without requiring users to know SQL syntax.

Quick Start & Requirements

  • Installation: Requires pgx (Postgres Extension Framework). Install pgx via cargo install --locked cargo-pgx and cargo pgx init. Then, clone the repository, set OPENAI_KEY, and run cargo pgx run.
  • Prerequisites: Rust, cargo-pgx, PostgreSQL, and an OpenAI API key.
  • Usage: After installation, run create extension pg_gpt; and set openai.key = '<YOUR OPENAPI API KEY HERE>';. Use the gpt() function, e.g., select gpt('show me all open aws s3 buckets');.
  • Documentation: Demo available at https://user-images.githubusercontent.com/1121616/228234378-40c796d3-0a38-465a-92da-9370fb21b93b.mp4.

Highlighted Details

  • Translates natural language to SQL queries using OpenAI GPT.
  • Supports gpt(text) for full schema queries and gpt_tables(table_pattern, text) to limit schema context.
  • Requires an OpenAI API key for functionality.

Maintenance & Community

  • This is an experimental plugin and not officially supported by CloudQuery.

Licensing & Compatibility

  • License not specified in the README.

Limitations & Caveats

The extension uses gpt-3.5-turbo, which has a token limit of 4096, potentially impacting performance with very large schemas. It is explicitly not recommended for production databases due to its experimental nature and the transmission of schema information to a third-party API.

Health Check
Last commit

2 years ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
1 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.