VercelLogotypeVercelLogotype
LoginSign Up

Natural Language Postgres

An Next.js application that allows you to query a PostgreSQL database with natural language.

DeployView Demo

Natural Language PostgreSQL

This project is a Next.js application that allows users to query a PostgreSQL database using natural language and visualize the results. It's powered by the AI SDK by Vercel and uses OpenAI's GPT-4o model to translate natural language queries into SQL.

Features

  • Natural Language to SQL: Users can input queries in plain English, which are then converted to SQL using AI.
  • Data Visualization: Results are displayed in both table and chart formats, with the chart type automatically selected based on the data.
  • Query Explanation: Users can view the full SQL query and get an AI-generated explanation of each part of the query.

Technology Stack

  • Next.js for the frontend and API routes
  • AI SDK by Vercel for AI integration
  • OpenAI's GPT-4o for natural language processing
  • PostgreSQL for data storage
  • Vercel Postgres for database hosting
  • Framer Motion for animations
  • ShadowUI for UI components
  • Tailwind CSS for styling
  • Recharts for data visualization

How It Works

  1. The user enters a natural language query about unicorn companies.
  2. The application uses GPT-4 to generate an appropriate SQL query.
  3. The SQL query is executed against the PostgreSQL database.
  4. Results are displayed in a table format.
  5. An AI-generated chart configuration is created based on the data.
  6. The results are visualized using the generated chart configuration.
  7. Users can toggle between table and chart views.
  8. Users can request an explanation of the SQL query, which is also generated by AI.

Data

The database contains information about unicorn companies, including:

  • Company name
  • Valuation
  • Date joined (unicorn status)
  • Country
  • City
  • Industry
  • Select investors

This data is based on CB Insights' list of unicorn companies.

Getting Started

To get the project up and running, follow these steps:

  1. Install dependencies:

    pnpm install
  2. Copy the example environment file:

    cp .env.example .env
  3. Add your OpenAI API key and PostgreSQL connection string to the .env file:

    OPENAI_API_KEY=your_api_key_here
    POSTGRES_URL="..."
    POSTGRES_PRISMA_URL="..."
    POSTGRES_URL_NO_SSL="..."
    POSTGRES_URL_NON_POOLING="..."
    POSTGRES_USER="..."
    POSTGRES_HOST="..."
    POSTGRES_PASSWORD="..."
    POSTGRES_DATABASE="..."
  4. Download the dataset:

  • Go to https://www.cbinsights.com/research-unicorn-companies
  • Download the unicorn companies dataset
  • Save the file as unicorns.csv in the root of your project
  1. Seed the database:

    pnpm run seed
  2. Start the development server:

    pnpm run dev

Your project should now be running on http://localhost:3000.

Deployment

The project is set up for easy deployment on Vercel. Use the "Deploy with Vercel" button in the repository to create your own instance of the application.

Learn More

To learn more about the technologies used in this project, check out the following resources:

  • Next.js Documentation
  • AI SDK
  • OpenAI
  • Vercel Postgres powered by Neon
  • Framer Motion
  • ShadcnUI
  • Tailwind CSS
  • Recharts
GitHub Repovercel-labs/natural-language-postgres
Use Cases
AI
Stack
Next.js
Tailwind
Radix UI
Database
Postgres

Related Templates

Chatbot

A full-featured, hackable Next.js AI chatbot built by Vercel
Chatbot thumbnail

Upstash Vector + Vercel AI SDK Starter

A RAG chatbot starter for expert answers on university degrees. Built using Vercel AI SDK, LangChain, Upstash Vector, and OpenAI.
Upstash Vector + Vercel AI SDK Starter thumbnail

Get Started

  • Templates
  • Supported frameworks
  • Marketplace
  • Domains

Build

  • Next.js on Vercel
  • Turborepo
  • v0

Scale

  • Content delivery network
  • Fluid compute
  • CI/CD
  • Observability
  • AI GatewayNew
  • Vercel AgentNew

Secure

  • Platform security
  • Web Application Firewall
  • Bot management
  • BotID
  • SandboxNew

Resources

  • Pricing
  • Customers
  • Enterprise
  • Articles
  • Startups
  • Solution partners

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Community

Frameworks

  • Next.js
  • Nuxt
  • Svelte
  • Nitro
  • Turbo

SDKs

  • AI SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDK
  • Streamdown AINew

Use Cases

  • Composable commerce
  • Multi-tenant platforms
  • Web apps
  • Marketing sites
  • Platform engineers
  • Design engineers

Company

  • About
  • Careers
  • Help
  • Press
  • Legal
  • Privacy Policy

Community

  • Open source program
  • Events
  • Shipped on Vercel
  • GitHub
  • LinkedIn
  • X
  • YouTube

Loading status…

Select a display theme:
    • AI Cloud
      • AI Gateway

        One endpoint, all your models

      • Sandbox

        Isolated, safe code execution

      • Vercel Agent

        An agent that knows your stack

      • AI SDK

        The AI Toolkit for TypeScript

      • v0

        Build applications with AI

    • Core Platform
      • CI/CD

        Helping teams ship 6× faster

      • Content Delivery

        Fast, scalable, and reliable

      • Fluid Compute

        Servers, in serverless form

      • Workflow

        Long-running workflows at scale

      • Observability

        Trace every step

    • Security
      • Bot Management

        Scalable bot protection

      • BotID

        Invisible CAPTCHA

      • Platform Security

        DDoS Protection, Firewall

      • Web Application Firewall

        Granular, custom protection

    • Company
      • Customers

        Trusted by the best teams

      • Blog

        The latest posts and changes

      • Changelog

        See what shipped

      • Press

        Read the latest news

      • Events

        Join us at an event

    • Learn
      • Docs

        Vercel documentation

      • Academy

        Linear courses to level up

      • Knowledge Base

        Find help quickly

      • Community

        Join the conversation

    • Open Source
      • Next.js

        The native Next.js platform

      • Nuxt

        The progressive web framework

      • Svelte

        The web’s efficient UI framework

      • Turborepo

        Speed with Enterprise scale

    • Use Cases
      • AI Apps

        Deploy at the speed of AI

      • Composable Commerce

        Power storefronts that convert

      • Marketing Sites

        Launch campaigns fast

      • Multi-tenant Platforms

        Scale apps with one codebase

      • Web Apps

        Ship features, not infrastructure

    • Tools
      • Marketplace

        Extend and automate workflows

      • Templates

        Jumpstart app development

      • Partner Finder

        Get help from solution partners

    • Users
      • Platform Engineers

        Automate away repetition

      • Design Engineers

        Deploy for every idea

  • Enterprise
  • Pricing
Log InContact
Sign Up
Sign Up
DeployView Demo
AI Gateway

One endpoint, all your models

Sandbox

Isolated, safe code execution

Vercel Agent

An agent that knows your stack

AI SDK

The AI Toolkit for TypeScript

v0

Build applications with AI

CI/CD

Helping teams ship 6× faster

Content Delivery

Fast, scalable, and reliable

Fluid Compute

Servers, in serverless form

Workflow

Long-running workflows at scale

Observability

Trace every step

Bot Management

Scalable bot protection

BotID

Invisible CAPTCHA

Platform Security

DDoS Protection, Firewall

Web Application Firewall

Granular, custom protection

Customers

Trusted by the best teams

Blog

The latest posts and changes

Changelog

See what shipped

Press

Read the latest news

Events

Join us at an event

Docs

Vercel documentation

Academy

Linear courses to level up

Knowledge Base

Find help quickly

Community

Join the conversation

Next.js

The native Next.js platform

Nuxt

The progressive web framework

Svelte

The web’s efficient UI framework

Turborepo

Speed with Enterprise scale

AI Apps

Deploy at the speed of AI

Composable Commerce

Power storefronts that convert

Marketing Sites

Launch campaigns fast

Multi-tenant Platforms

Scale apps with one codebase

Web Apps

Ship features, not infrastructure

Marketplace

Extend and automate workflows

Templates

Jumpstart app development

Partner Finder

Get help from solution partners

Platform Engineers

Automate away repetition

Design Engineers

Deploy for every idea