Skip to main content
Supabase provides comprehensive AI and vector capabilities through pgvector, specialized storage buckets, and integration with popular AI frameworks. Store embeddings, perform similarity search, and build AI-powered applications at scale.

What are Vectors?

Vectors are arrays of numbers that represent the “meaning” or “features” of data. In AI applications, vectors (embeddings) capture semantic relationships:

Vector Similarity

Vectors enable semantic search by measuring similarity:

Architecture

Supabase offers multiple ways to work with vectors:

1. pgvector Extension

Store vectors in Postgres tables with full SQL support:

2. Vector Buckets

Specialized Storage buckets optimized for vector operations:

3. Analytics Buckets

Store large-scale vector datasets using Apache Iceberg:

Working with pgvector

Enable the Extension

  1. Go to Database → Extensions
  2. Search for “vector”
  3. Enable the extension

Create a Vector Table

Generating Embeddings

Use popular embedding models:

Storing Vectors

Find similar documents using vector operators:
Call from your application:

Distance Metrics

pgvector supports three distance metrics:

Cosine Distance (most common)

Measures angle between vectors (0 = identical, 2 = opposite):

Euclidean Distance

Measures straight-line distance:

Inner Product

Measures dot product (use with normalized vectors):

Indexing Strategies

HNSW (Hierarchical Navigable Small World)

Best for most use cases - fast and accurate:

IVFFlat (Inverted File Flat)

Better for very large datasets:
No index - exact results but slow:

RAG (Retrieval Augmented Generation)

Build AI applications that combine search with LLMs:
Combine vector similarity with traditional filters:

Metadata Filtering

Filter by metadata before similarity search:

Vector Buckets

For specialized vector storage:

Performance Optimization

Choose the Right Dimensions

Batch Operations

Partial Indexes

AI Frameworks Integration

LangChain

LlamaIndex

Best Practices

Normalize Vectors

Normalize embeddings when using inner product or cosine similarity.

Index Strategy

Use HNSW for most cases; IVFFlat for 1M+ vectors.

Batch Processing

Generate and store embeddings in batches for better performance.

Monitor Quality

Track similarity thresholds and adjust based on results.

Next Steps

Vector Columns

Learn about storing vectors in Postgres

Vector Indexes

Optimize similarity search with indexes

Python Clients

Use Python for AI applications

Examples

Explore AI example applications