Installing the pgvector Extension
TOC
OverviewPrerequisitesProcedure1. Verify the extension is available2. Create the extension3. Smoke testIndexing for approximate nearest-neighbor searchIVFFlatHNSWUpgrading the extensionVerificationOverview
pgvector adds a vector data type and
nearest-neighbor search to PostgreSQL, which is commonly used for embedding /
similarity-search workloads. The extension is pre-bundled in the Spilo image
shipped with the PostgreSQL Operator, so no image rebuild is required — you only
need to create the extension inside the target database.
Prerequisites
- A running PostgreSQL cluster managed by the PostgreSQL Operator.
- A database user with privileges to create extensions (the
postgressuperuser, used below).
Procedure
1. Verify the extension is available
Expected output (version may differ depending on the operand release):
2. Create the extension
3. Smoke test
The distance operators are:
Indexing for approximate nearest-neighbor search
By default pgvector performs an exact search (perfect recall). For larger datasets you can add an approximate index, trading some recall for speed.
IVFFlat
Build the index after the table contains data. A good starting point for
the number of lists is rows / 1000 (up to 1M rows) or sqrt(rows) beyond
that.
HNSW
HNSW has slower build time and higher memory usage than IVFFlat but better query performance, and can be created on an empty table.
Use vector_ip_ops (inner product) or vector_cosine_ops (cosine) instead of
vector_l2_ops to index the corresponding distance function.