Skip to main content
Supabase is an open-source Firebase alternative that provides a PostgreSQL database with pgvector extension for vector similarity search. It offers a powerful and scalable solution for storing and querying vector embeddings. Create a Supabase account and project, then get your connection string from Project Settings > Database. See the docs for details.

Usage

SQL Migrations for TypeScript Implementation

The following SQL migrations are required to enable the vector extension and create the memories table:
Go to Supabase and run the above SQL migrations in the SQL Editor.

Config

Here are the parameters available for configuring Supabase:

Index Methods

The following index methods are supported:
  • auto: Automatically selects the best available index method
  • hnsw: Hierarchical Navigable Small World graph index (faster search, more memory usage)
  • ivfflat: Inverted File Flat index (good balance of speed and memory)

Distance Measures

Available distance measures for similarity search:
  • cosine_distance: Cosine similarity (recommended for most embedding models)
  • l2_distance: Euclidean distance
  • l1_distance: Manhattan distance
  • max_inner_product: Maximum inner product similarity

Best Practices

  1. Index Method Selection:
    • Use hnsw for fastest search performance when memory is not a constraint
    • Use ivfflat for a good balance of search speed and memory usage
    • Use auto if unsure, it will select the best method based on your data
  2. Distance Measure Selection:
    • Use cosine_distance for most embedding models (OpenAI, Hugging Face, etc.)
    • Use max_inner_product if your vectors are normalized
    • Use l2_distance or l1_distance if working with raw feature vectors
  3. Connection String:
    • Always use environment variables for sensitive information in the connection string
    • Format: postgresql://user:password@host:port/database