Database Setup
Configure your Supabase database with vector search capabilities. This section is crucial for a working installation.
Cloud vs Self-Hosted
Create Supabase Project
- Visit supabase.com and create a new project
- Choose a region close to your users for optimal performance
- Wait for the project to initialize (~2 minutes)
Configure Database Schema
ChatRAG includes a complete database setup file that creates all required tables, indexes, and security policies.
Follow these steps:
- Open SQL Editor in your Supabase dashboard
- Copy the entire contents of
supabase/complete_setup.sqlfrom your repository - Paste and execute the SQL in the editor
Run Once Per Project
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
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>Security Warning
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 interfaceVerification 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
HNSW Vector Search Performance
The HNSW (Hierarchical Navigable Small World) indexes provide 15-28x faster search compared to traditional IVFFlat indexes.
- Query time: <50ms for semantic search
- Index parameters: m=64, ef_construction=200
- Supports 1536-dimensional vectors (OpenAI embeddings)