Skip to main content

Overview

The Supabase provider stores chat history, metrics, and feedback in your Supabase database.

Features

  • Chat History - Automatic conversation storage
  • Metrics Tracking - Request performance data
  • Feedback Collection - User feedback storage
  • Auto Setup - Tables created automatically

Basic Usage

from langchat.database import Supabase

db = Supabase(
    url="https://xxxxx.supabase.co",
    key="eyJhbGc..."
)

Configuration

db = Supabase(
    url="https://xxxxx.supabase.co",  # Required
    key="eyJhbGc..."  # Required (anon or service role key)
)
LangChat automatically creates database tables on first run if they don’t exist.

Using with LangChat

from langchat import LangChat
from langchat.llm import OpenAI
from langchat.vector_db import Pinecone
from langchat.database import Supabase

llm = OpenAI(api_key="sk-...", model="gpt-4o-mini")
vector_db = Pinecone(api_key="...", index_name="...")
db = Supabase(url="https://...", key="...")

ai = LangChat(llm=llm, vector_db=vector_db, db=db)

Database Tables

LangChat uses these tables:
  • chat_history - User conversation history
  • request_metrics - Request performance metrics
  • feedback - User feedback on responses

Table Setup

Tables are created automatically. You can also get the SQL:
db = Supabase(url="...", key="...")
sql = db.get_create_tables_sql()
print(sql)  # SQL to create tables manually

Best Practices

1. Use Service Role Key for Setup

For initial setup, use service role key:
# Setup (service role key)
db = Supabase(url="...", key="service_role_key")
db.create_tables_if_not_exist()

# Runtime (anon key)
db = Supabase(url="...", key="anon_key")

2. Monitor Database

Check table status:
# Tables are checked automatically
# You can verify in Supabase dashboard

Troubleshooting

Tables Not Created

Solution: Run create_tables_if_not_exist() or use the SQL from get_create_tables_sql().

Permission Errors

Solution: Ensure your key has proper permissions. Use service role key for setup.

Next Steps


Built with ❤️ by NeuroBrain