Skip to main content
Supabase provides powerful AI capabilities through pgvector, vector storage, and integration with AI frameworks. Build semantic search, recommendation systems, and RAG applications at scale.

Key Features

Vector Embeddings

Store and query high-dimensional vectors for semantic search

Similarity Search

Find similar items using cosine, L2, or inner product distance

pgvector Extension

Native PostgreSQL extension with full SQL support

AI Integrations

Works with OpenAI, Anthropic, Hugging Face, and more

What are Vector Embeddings?

Vector embeddings are numerical representations of data that capture semantic meaning. Similar items have similar vectors.
// Text embeddings from OpenAI
const embedding = [0.123, -0.456, 0.789, ...] // 1536 dimensions

// Similar texts have similar vectors
const query = "cat chases mouse"
const similar = "kitten hunts rodent" // High similarity
const different = "weather forecast" // Low similarity

Use Cases

Recommend products, content, or users based on similarity to past interactions or preferences.
Build chatbots that answer questions using your own data by retrieving relevant context before generating responses.
Detect similar or duplicate content, classify images, or identify inappropriate material.

Architecture Options

Supabase offers three ways to work with vectors:
Store vectors directly in PostgreSQL tables with full SQL support.
create extension vector;

create table documents (
  id bigint primary key,
  content text,
  embedding vector(1536)
);
Best for: Transactional workloads, complex queries with SQL

Getting Started

1

Enable pgvector

Enable the vector extension in your database:
create extension vector;
2

Create a table

Create a table to store vectors:
create table documents (
  id bigserial primary key,
  content text,
  embedding vector(1536)
);
3

Generate embeddings

Use OpenAI or another provider to generate embeddings:
import OpenAI from 'openai'

const openai = new OpenAI()

const response = await openai.embeddings.create({
  model: 'text-embedding-3-small',
  input: 'Your text here'
})

const embedding = response.data[0].embedding
4

Store and search

Store embeddings and perform similarity search:
// Insert
await supabase
  .from('documents')
  .insert({ content: 'Your text', embedding })

// Search
const { data } = await supabase
  .rpc('match_documents', {
    query_embedding: embedding,
    match_count: 5
  })

Next Steps

Vector Embeddings

Learn how to generate and store embeddings

Similarity Search

Build semantic search functionality

pgvector Guide

Deep dive into the pgvector extension

AI Examples

Explore complete AI application examples