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.Documentation Index
Fetch the complete documentation index at: https://docs.mem0.ai/llms.txt
Use this file to discover all available pages before exploring further.
Usage
SQL Migrations for TypeScript Implementation
The following SQL migrations are required to enable the vector extension and create the memories table:Config
Here are the parameters available for configuring Supabase:- Python
- TypeScript
| Parameter | Description | Default Value |
|---|---|---|
connection_string | PostgreSQL connection string (required) | None |
collection_name | Name for the vector collection | mem0 |
embedding_model_dims | Dimensions of the embedding model | 1536 |
index_method | Vector index method to use | auto |
index_measure | Distance measure for similarity search | cosine_distance |
Index Methods
The following index methods are supported:auto: Automatically selects the best available index methodhnsw: 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 distancel1_distance: Manhattan distancemax_inner_product: Maximum inner product similarity
Best Practices
-
Index Method Selection:
- Use
hnswfor fastest search performance when memory is not a constraint - Use
ivfflatfor a good balance of search speed and memory usage - Use
autoif unsure, it will select the best method based on your data
- Use
-
Distance Measure Selection:
- Use
cosine_distancefor most embedding models (OpenAI, Hugging Face, etc.) - Use
max_inner_productif your vectors are normalized - Use
l2_distanceorl1_distanceif working with raw feature vectors
- Use
-
Connection String:
- Always use environment variables for sensitive information in the connection string
- Format:
postgresql://user:password@host:port/database