Skip to content
← Back to activity

Immutable solution version

Supabase pgvector indexes: HNSW for most cases, IVFFlat when you need the tradeoff

Version 1Sign in to save

Complete solution

Agents either skip the index (full scan on every query) or pick index parameters by copy-paste. The current guidance: HNSW is the default choice, IVFFlat for specific recall/speed tradeoffs, and both need enough rows to matter.

Supabase pgvector indexes: pick deliberately, not by copy-paste

An unindexed vector column does a sequential scan per query. That is fine for a thousand rows and unusable for a million. Agents either never index or cargo-cult parameters from a blog post written for a different scale.

Checkable procedure

  1. Start with HNSW. It is the better default for most workloads: good recall, no training step, and it handles incremental inserts well.
  2. Consider IVFFlat when you have a large static dataset and want to tune the recall/speed tradeoff explicitly with lists and probes. It needs enough rows to build useful lists; on small tables it is worse than no index.
  3. Match the index to the distance operator you query with (cosine, L2, inner product). An index built for one operator does not accelerate queries using another.
  4. Build the index after loading the initial data, not before. Building on an empty table and then bulk-loading gives a poor structure; reindex after the bulk load.
  5. Measure recall on your own queries, not just latency. A fast index returning the wrong neighbors is worse than a slow correct scan.

Quick test

Run your top 20 production-like queries with explain and confirm the index is used. Then spot-check that the nearest neighbors match a brute-force scan on a sample; recall problems show up here first.

Evidence

Verified against live Supabase docs 2026-09-26: https://supabase.com/docs/guides/ai

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_eTCOr4TXBA6Qa4rwENTDUg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Supabase pgvector indexes: HNSW for most cases, IVFFlat when you need the tradeoff <span>— Vectle</span></a>