Vector Plus quickstart v0

Before you start, install Vector Plus and enable the extension. The following quickstart then creates a table with vector embeddings, builds an ivfplus index over it, and runs an approximate nearest-neighbor query end to end:

CREATE EXTENSION IF NOT EXISTS edb_vectorplus CASCADE; -- pulls in pgvector

CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(768));
COPY items (embedding) FROM '/path/to/embeddings.csv'; -- load BEFORE indexing

CREATE INDEX items_embedding_idx ON items
USING ivfplus (embedding vector_l2_ops); -- lists and probes are chosen automatically

SELECT id FROM items ORDER BY embedding <-> '[...]' LIMIT 10;

SELECT * FROM check_ivfplus_index_health('items_embedding_idx');

Create the index without options. The build sizes lists from the table and reports the value in a NOTICE, and each query picks probes from the index's lists, so you don't need to set either.

Three settings control most of an index's behavior:

OptionSet withDefaultRecommended starting point
listsWITH (...) at buildAutomatic when omitted (see Tuning and sizing)Leave automatic. Set it only if the table will grow far past its build-time size.
probesSET ivfplus.probesAutomatic when unset (see Tuning and sizing)Leave automatic for about 0.95 recall@10. Raise it for higher recall or a larger LIMIT.
OpclassCREATE INDEX ... USING ivfplus (col <opclass>)vector_l2_opsMatch your distance metric.

Review the following before you build an index:

  • Automatic lists is resolved from the rows present at build time, and again at each REINDEX. An explicit lists isn't derived from table size: set to 100, it stays 100 whether the table has a thousand rows or a billion. See Tuning and sizing.
  • Index at a dimensionality that's a multiple of 4, and at most 1780. Only those get the packed fast-scan layout; anything else falls back to a slower scan for the life of the index, and CREATE INDEX emits a NOTICE when it happens. See Limits and fixed constants.
  • Load data before CREATE INDEX. The build clusters the rows that already exist at build time.
  • This is an approximate index. Work through Measuring recall before relying on it in production.
  • CREATE INDEX blocks writes on the table. Use CREATE INDEX CONCURRENTLY in production.
  • Centroids are fixed for the life of the index. Clustering happens once, at build time. A table that keeps changing drifts away from its centroids over time — new rows land in a slower append region until the index is rebuilt. check_ivfplus_index_health() reports this drift and recommends a REINDEX CONCURRENTLY when needed. See Writes, VACUUM, and REINDEX.