Skip to content

Repository files navigation

Text2VectorSQL Demo

A prototype demonstrating the Text2VectorSQL concept - translating natural language queries into hybrid SQL + Vector search queries.

Based on the research paper: Text2VectorSQL: Bridging Text-to-SQL and Vector Search

Features

  • 🔍 Natural Language to VectorSQL - Translate plain English queries to hybrid SQL
  • 🧠 Chain of Thought Reasoning - See how the query is analyzed and translated
  • 📊 Live Query Execution - Run generated queries on real data
  • 🎯 Semantic Search - Find products based on meaning, not just keywords

Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Configure Environment

Edit .env file with your credentials:

OPENAI_API_KEY=your_openai_api_key_here
OPENAI_MODEL=gpt-4.1
DATABASE_URL=postgresql://user:password@host:port/dbname

3. Ingest Data

python ingest_data.py

This will:

  • Load first 5,000 rows from Amazon reviews CSV
  • Generate embeddings for text columns
  • Store data with vectors in PostgreSQL

4. Run Demo

streamlit run app.py

Project Structure

text2vectorsql_demo/
├── .env                    # Configuration (you fill in)
├── .env.example            # Configuration template
├── requirements.txt        # Python dependencies
├── config.py              # Configuration loader
├── database.py            # PostgreSQL + pgvector operations
├── embeddings.py          # OpenAI embedding generation
├── ingest_data.py         # Data loading script
├── vectorsql_generator.py # LLM-powered query translator
├── app.py                 # Streamlit demo UI
└── README.md              # This file

Example Queries

Try these in the demo:

  1. "Find pet products that reviewers describe as durable and long-lasting"

    • Uses vector search on review text + category filter
  2. "Show me highly-rated office supplies with positive customer feedback"

    • Combines semantic search with rating filter
  3. "Find products similar to Blue Buffalo dog food with good reviews"

    • Product similarity + sentiment analysis

How It Works

User Query → LLM Analysis → VectorSQL Generation → Execution
     ↓              ↓                ↓               ↓
  "Find..."    Identify         Generate        Query DB
               semantic +       hybrid SQL      with pgvector
               structured       + VECTOR_SEARCH
               components

Tech Stack

  • PostgreSQL + pgvector - Vector database
  • OpenAI GPT-4.1 - Query translation
  • OpenAI Embeddings - text-embedding-3-small
  • Streamlit - Interactive UI
  • Python - Backend logic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages