Configure pgvector extension for vector search in Supabase - includes embedding storage, HNSW/IVFFlat indexes, hybrid search setup, and AI-optimized query patterns. Use when setting up vector search, building RAG systems, configuring semantic search, creating embedding storage, or when user mentions pgvector, vector database, embeddings, semantic search, or hybrid search.
Limited to specific tools
Additional assets for this skill
This skill is limited to using the following tools:
QUICK_START.mdREADME.mdexamples/document-search-pattern.mdexamples/embedding-strategies.mdexamples/vector-search-examples.mdscripts/create-indexes.shscripts/setup-hybrid-search.shscripts/setup-pgvector.shscripts/test-vector-search.shtemplates/embedding-table-schema.sqltemplates/hnsw-index-config.sqltemplates/hybrid-search-function.sqltemplates/ivfflat-index-config.sqltemplates/match-function.sqlThis skill provides complete pgvector setup for Supabase databases, enabling vector search capabilities for AI applications, RAG systems, and semantic search.
Run the setup script to enable pgvector:
bash scripts/setup-pgvector.sh [SUPABASE_DB_URL]
This creates the pgvector extension and sets up basic embedding tables.
Choose your embedding dimensions based on your model:
Use the embedding table template:
# Copy template and customize for your use case
cat templates/embedding-table-schema.sql
Customize the schema:
Apply the schema:
psql $SUPABASE_DB_URL < templates/embedding-table-schema.sql
Choose index type based on your data size:
HNSW (Recommended for most cases):
bash scripts/create-indexes.sh hnsw [TABLE_NAME] [DIMENSION]IVFFlat:
bash scripts/create-indexes.sh ivfflat [TABLE_NAME] [DIMENSION]Performance Tuning:
Create the match function:
-- See templates/match-function.sql for complete example
create or replace function match_documents(
query_embedding vector(1536)
match_threshold float
match_count int
) returns setof documents ...
Query from application:
const { data } = await supabase.rpc('match_documents', {
query_embedding: embedding
match_threshold: 0.78
match_count: 10
});
For combining keyword and semantic search:
Run hybrid search setup:
bash scripts/setup-hybrid-search.sh [TABLE_NAME]
This configures:
Use the hybrid search function:
select * from hybrid_search(
'search query text'
query_embedding
match_count := 10
full_text_weight := 1.0
semantic_weight := 1.0
);
Run validation tests:
bash scripts/test-vector-search.sh [TABLE_NAME]
This verifies:
Distance Metric Selection:
<=>): Safe default, handles varying vector magnitudes<#>): Faster for normalized vectors (OpenAI embeddings)<->): Use when absolute distances matterIndex Choice:
Dimension Size:
Pattern 1: Document Search
Pattern 2: User Preference Matching
Pattern 3: Product Recommendations
Slow queries (> 100ms):
EXPLAIN ANALYZEPoor recall (missing relevant results):
High memory usage:
Insert performance issues:
Row Level Security (RLS):
API Key Protection:
Scripts:
scripts/setup-pgvector.sh - Enable extension and create base tablesscripts/create-indexes.sh - Create HNSW or IVFFlat indexesscripts/setup-hybrid-search.sh - Configure hybrid searchscripts/test-vector-search.sh - Validate setupTemplates:
templates/embedding-table-schema.sql - Table structure with metadatatemplates/hnsw-index-config.sql - HNSW index with tuningtemplates/ivfflat-index-config.sql - IVFFlat index configurationtemplates/hybrid-search-function.sql - Hybrid search with RRFtemplates/match-function.sql - Basic semantic search functionExamples:
examples/embedding-strategies.md - Index selection guideexamples/vector-search-examples.md - Common search patternsexamples/document-search-pattern.md - Full document search implementationexamples/preference-matching-pattern.md - User matching systemexamples/product-recommendations-pattern.md - Recommendation enginePlugin: supabase Version: 1.0.0 Last Updated: 2025-10-26