====== Supabase Vector ====== **Supabase Vector** leverages PostgreSQL with the [[pgvector|pgvector]] extension to enable efficient storage, indexing, and similarity search of high-dimensional vector embeddings within the Supabase platform. It combines vector search with Supabase's authentication, row-level security, Edge Functions, and real-time capabilities.((source [[https://supabase.com/features/vector-database|Supabase Vector Database]])) ===== pgvector Integration ===== Supabase integrates pgvector as a PostgreSQL extension, allowing vectors to be stored alongside relational data in the same schema:((source [[https://sparkco.ai/blog/mastering-supabase-vector-storage-a-2025-deep-dive|Supabase Vector Storage Deep Dive - Sparkco]])) * Enable with ''CREATE EXTENSION IF NOT EXISTS vector WITH SCHEMA extensions;'' * Store embeddings in dedicated ''VECTOR'' columns * Support for HNSW and IVFFlat indexing * Hybrid semantic and keyword queries by combining embeddings with text columns * Standard SQL operations (joins, filters, aggregations) alongside vector search ===== Edge Functions ===== Supabase Edge Functions (serverless TypeScript/Deno functions) handle embedding generation and processing:((source [[https://supabase.com/docs/guides/ai|Supabase AI Documentation]])) * Process incoming data and generate embeddings in real-time * Integrate with OpenAI, Hugging Face, Cohere, and other embedding APIs * Upsert embeddings into pgvector tables * Deployable as database webhooks triggered on row changes * No external infrastructure required ===== Built-in Embedding Model ===== Since Supabase Edge Runtime v1.36.0, the **gte-small** model (384 dimensions) runs natively within Edge Functions:((source [[https://supabase.com/docs/guides/functions/examples/semantic-search|Supabase Semantic Search Example]])) * No external API calls required for embedding generation * ''const model = new Supabase.ai.Session('gte-small')'' * Suitable for lightweight semantic search applications * Reduces latency and external dependencies ===== Similarity Search ===== Supabase exposes vector search through RPC functions callable via client SDKs:((source [[https://supabase.com/features/vector-database|Supabase Vector Database]])) * Create PostgreSQL functions using pgvector operators (''<=>'', ''<->'', ''<#>'') * Call via Supabase JS/Python SDKs using ''supabase.rpc()'' * Support for top-k retrieval with distance metrics * Combinable with metadata filters and row-level security policies **Vector Buckets** (launched 2026) provide S3-backed vector storage for larger-scale workloads:((source [[https://supabase.com/blog/vector-buckets|Supabase Vector Buckets]])) * Up to 50 million vectors per index * Queryable via JavaScript SDK and Postgres Foreign Data Wrappers * Multi-index buckets for multi-tenant applications ===== RAG Patterns ===== Supabase facilitates retrieval-augmented generation workflows:((source [[https://www.echoalgoridata.no/en/blog/rag-systems-supabase-guide|Building RAG Systems with Supabase - Echo Algori Data]])) * Store document chunks with their embeddings in pgvector tables * Retrieve top-k similar chunks via RPC similarity search * Feed retrieved context to LLMs (OpenAI, Anthropic, etc.) for generation * Hybrid RAG combining semantic search with keyword filtering * Edge Functions orchestrate the full embed-search-generate pipeline ===== Row-Level Security ===== Row-level security (RLS) applies to vector tables like any PostgreSQL relation:((source [[https://supabase.com/features/vector-database|Supabase Vector Database]])) * Enforce policies on SELECT, INSERT, UPDATE operations involving embeddings * Filter similarity searches by user ID or organization * GDPR-compliant data isolation for multi-tenant applications * No custom application-level access control needed ===== Automatic Embeddings Pipeline ===== Supabase provides an automated embedding generation pipeline:((source [[https://supabase.com/docs/guides/ai/automatic-embeddings|Supabase Automatic Embeddings]])) * **Triggers** -- detect content changes and enqueue embedding requests * **pgmq** -- queue embedding generation for processing and retries * **pg_net** -- asynchronous HTTP requests to Edge Functions from Postgres * **pg_cron** -- scheduled processing and retry of failed embeddings * Generic and reusable across multiple tables and content types ===== Supabase Vector vs Alternatives ===== ^ Aspect ^ Supabase Vector ^ Standalone pgvector ^ Pinecone ^ | Setup | Instant with Supabase project | Self-managed PostgreSQL | Managed SaaS | | Auth/RLS | Built-in with Supabase Auth | Manual implementation | API key-based | | Scale | Millions (pgvector) + 50M (Vector Buckets) | Depends on PostgreSQL tuning | Billions with auto-sharding | | Cost | Included in Supabase pricing | Free extension | Usage-based subscription | | Best For | AI apps needing auth, real-time, and relational data | Custom PostgreSQL deployments | Pure vector workloads at scale | Supabase Vector excels in applications requiring unified relational and vector data with built-in authentication and security.((source [[https://sparkco.ai/blog/mastering-supabase-vector-storage-a-2025-deep-dive|Supabase Vector Storage Deep Dive - Sparkco]])) ===== See Also ===== * [[pgvector|pgvector]] * [[pinecone|Pinecone]] * [[hugging_face|Hugging Face]] ===== References =====