Skip to main content

Overview

pgvector adds a vector column type, distance operators, and approximate nearest-neighbor indexes (HNSW and IVFFlat) to PostgreSQL. Use it to store embeddings alongside relational data and query by similarity. PlanetScale Postgres also supports pgvectorscale, a companion extension for higher-performance approximate search. See the supported extensions table for available versions.

Enabling pgvector

pgvector does not require a cluster restart. Install it with a role that has superuser privileges:
Confirm the extension is installed:

Usage

Create a table with a vector column, insert embeddings, and query by distance:
Common distance operators: Add an HNSW index when you need approximate search at scale:

External documentation

For indexing options, half-precision and sparse vectors, and language clients, see the official pgvector documentation.