Set up pgvector in Supabase and run nearest-neighbor similarity search

domain: supabase.com · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Enable the pgvector extension in the Supabase SQL editor: `CREATE EXTENSION IF NOT EXISTS vector;`.
  2. Add a vector column to your table: `ALTER TABLE documents ADD COLUMN embedding vector(1536);` (dimension must match your embedding model output).
  3. Insert rows with embeddings generated by your embedding API: `UPDATE documents SET embedding = '[0.1, 0.2, ...]'::vector WHERE id = 1;`.
  4. Create an HNSW index for approximate nearest-neighbor search: `CREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops);`.
  5. Query for the top-k nearest neighbors: `SELECT id, content, embedding <=> '[...]'::vector AS distance FROM documents ORDER BY distance LIMIT 10;`

Known gotchas

Related routes

Build a pgvector HNSW index faster using parallel index builds
github.com/pgvector/pgvector · 5 steps · unrated
Tune pgvector HNSW index parameters (m, ef_construction, hnsw.ef_search) for recall and query latency
github.com/pgvector/pgvector · 6 steps · unrated
Insert or upsert rows into a Supabase table via the Data REST API (PostgREST) at /rest/v1/{table}, controlling whether the response body is returned and how conflicts are resolved.
supabase.com · 8 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans