Vector indexes
A guide from Supabase
Apps on Plentiful run on Supabase's open-source database, sign-in, file storage and live updates, so most of this guide applies. The differences: your app reaches its database through its own server — not Supabase's data API (supabase.from(…)) — there are no Edge Functions (your app's server does that work), and scheduled work uses Jobs. Where it says "Supabase dashboard", use your app's Dashboard. Ask the builder when in doubt.
Once your vector table starts to grow, you will likely want to add an index to speed up queries. Without indexes, you'll be performing a sequential scan which can be a resource-intensive operation when you have many records.
Choosing an index#
Today pgvector supports two types of indexes:
In general we recommend using HNSW because of its performance and robustness against changing data.
Distance operators#
Indexes can be used to improve performance of nearest neighbor search using various distance measures. pgvector includes 3 distance operators:
| Operator | Description | Operator class |
|---|---|---|
<-> | Euclidean distance | vector_l2_ops |
<#> | negative inner product | vector_ip_ops |
<=> | cosine distance | vector_cosine_ops |
For pgvector versions 0.7.0 and above, it's possible to create indexes on vectors with the following maximum dimensions:
- vector: up to 2,000 dimensions
- halfvec: up to 4,000 dimensions
- bit: up to 64,000 dimensions
You can check your current pgvector version by running: SELECT * FROM pg_extension WHERE extname = 'vector'; or by navigating to the Extensions tab in your Supabase project dashboard.
If you are on an earlier version of pgvector, you should upgrade your project here.
Resources#
Read more about indexing on pgvector's GitHub page.