Skip to content

Getting Started

Install pgvector on PostgreSQL 14–18 and run your first vector similarity queries.

Installation

Pigsty provides prebuilt native pgvector packages (v0.8.2) for PostgreSQL 14–18 across Debian, Ubuntu, and RHEL/Rocky/AlmaLinux (x86_64 and ARM64):

pig repo add pgdg pigsty -u
pig ext install pgvector

If you also want disk-friendly RaBitQ vector indexes and BM25 ranking, install the full Vchord suite together:

pig ext install pgvector vchord vchord_bm25 pg_tokenizer

Docker

Run the official pgvector container image:

docker run -d \
  --name pgvector-demo \
  -e POSTGRES_PASSWORD=postgres \
  -p 5432:5432 \
  pgvector/pgvector:pg18

Or use the all-in-one Vchord Suite image, which bundles pgvector, vchord, vchord_bm25, and pg_tokenizer:

docker run -d \
  --name vchord-suite \
  -e POSTGRES_PASSWORD=postgres \
  -p 5432:5432 \
  tensorchord/vchord-suite:pg18-latest

Linux (PGDG APT / YUM)

macOS (Homebrew)

brew install pgvector

Build from Source (Linux / macOS)

Ensure PostgreSQL development headers (postgresql-server-dev-* or postgresql*-devel), make, and a C compiler are installed:

cd /tmp
git clone --branch v0.8.2 https://github.com/pgvector/pgvector.git
cd pgvector
make
sudo make install
Host-Specific SIMD Optimization

To compile with -march=native for maximum SIMD performance on the current machine, pass OPTFLAGS="" only if needed for portability; by default pgvector’s Makefile adds -march=native when supported by the compiler. If building a portable binary for multiple CPU generations, run make OPTFLAGS="".


Enable the Extension

Connect to your target database and enable vector (this must be done once per database where you want to use it):

CREATE EXTENSION IF NOT EXISTS vector;

Check the installed version:

SELECT extversion FROM pg_extension WHERE extname = 'vector';

Upgrading pgvector

After installing a newer binary package on the server, upgrade the SQL catalog definitions inside each database:

ALTER EXTENSION vector UPDATE;

Quick Start

1. Create a Table with a vector Column

Create a table storing 3-dimensional single-precision (float32) vectors:

CREATE TABLE items (
    id bigserial PRIMARY KEY,
    embedding vector(3)
);

You can also add a vector column to an existing table:

ALTER TABLE items ADD COLUMN embedding vector(3);

2. Insert, Upsert, Update, and Delete Vectors

Insert vectors using the string literal format '[x1,x2,x3]':

INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');

Upsert vectors with ON CONFLICT:

INSERT INTO items (id, embedding) VALUES (1, '[1,2,3]'), (2, '[4,5,6]')
ON CONFLICT (id) DO UPDATE SET embedding = EXCLUDED.embedding;

Update and delete rows with standard SQL:

UPDATE items SET embedding = '[1,2,3]' WHERE id = 1;
DELETE FROM items WHERE id = 1;

3. Bulk Loading with COPY

For large datasets (millions of vectors), always prefer COPY over row-by-row INSERT:

COPY items (embedding) FROM STDIN WITH (FORMAT BINARY);

4. Query Nearest Neighbors

Find the 5 closest vectors by L2 (Euclidean) distance:

SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;

Next, read Querying & Filtering for all distance metrics and filtering patterns, or HNSW & IVFFlat Indexing to accelerate queries over large tables.