Database Setup

Configure your Supabase database with vector search capabilities. This section is crucial for a working installation.

1

Create Supabase Project

  1. Visit supabase.com and create a new project
  2. Choose a region close to your users for optimal performance
  3. Wait for the project to initialize (~2 minutes)
2

Configure Database Schema

ChatRAG includes a complete database setup file that creates all required tables, indexes, and security policies.

Follow these steps:

  1. Open SQL Editor in your Supabase dashboard
  2. Copy the entire contents of supabase/complete_setup.sql from your repository
  3. Paste and execute the SQL in the editor

What This Creates:

  • 14 production tables with Row Level Security (RLS) for multi-tenant isolation
  • HNSW vector indexes (15-28x faster than traditional RAG)
  • Storage buckets for images, videos, and 3D models
  • Database functions for semantic search operations
  • Security policies for secure multi-tenant data access
3

Get Supabase Credentials

From your Supabase project settings, retrieve the following credentials:

Project Settings → API

NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=<YOUR_SUPABASE_ANON_KEY>

Project Settings → API → Service Role

# Keep this secret - server-side only!
SUPABASE_SERVICE_ROLE_KEY=<YOUR_SUPABASE_SERVICE_ROLE_KEY>
4

Verify Database Setup

Test your database connection to ensure everything is configured correctly:

# 1. Add Supabase credentials to your config
npm run config
# Paste your credentials and save

# 2. Start the development server
npm run dev

# 3. Check browser console for any database errors
# 4. Verify at http://localhost:3000 - you should see the chat interface

Verification Checklist:

  • Chat interface loads without errors
  • No database connection errors in browser console
  • User authentication is working (sign up/login)
  • Tables visible in Supabase Table Editor

Database Tables Reference

The setup script creates the following core tables:

documents

Stores uploaded document metadata

document_chunks

Vector embeddings for RAG (1536 dimensions)

chats

Chat conversations and history

folders

Chat organization and categorization

subscriptions

Payment and subscription management

admin_settings

Global configuration and settings

whatsapp_sessions

WhatsApp connection data

whatsapp_conversations

WhatsApp chat history