pgvector /pgvector
Open-source vector similarity search for Postgres
★ 23,850⑂ 1,415👁 139⑃ 202● 874▤ 0
+9
Daily
+90
Weekly
23,850
stars
1,415
forks
139
watchers
202
prs
874
issues
0
releases
README
pgvector
Open-source vector similarity search for Postgres
Store your vectors with the rest of your data. Supports:
- exact and approximate nearest neighbor search
- single-precision, half-precision, binary, and sparse vectors
- L2 distance, inner product, cosine distance, L1 distance, Hamming distance, and Jaccard distance
- any language with a Postgres client
Plus ACID compliance, point-in-time recovery, JOINs, and all of the other great features of Postgres
Have a lot of vectors? Use quantization to scale
Installation
Linux and Mac
Compile and install the extension (supports Postgres 13+)
sh
cd /tmp
git clone --branch v0.8.7 https://github.com/pgvector/pgvector.git
cd pgvector
make
make install may need sudo
See the installation notes if you run into issues
You can also install it with Docker, Homebrew, PGXN, APT, Yum, pkg, APK, or conda-forge, and it comes preinstalled with Postgres.app and many hosted providers. There are also instructions for GitHub Actions.
Windows
Ensure C++ support in Visual Studio is installed and run x64 Native Tools Command Prompt for VS [version] as administrator. Then use nmake to build:
cmd
set "PGROOT=C:\Program Files\PostgreSQL\19"
cd %TEMP%
git clone --branch v0.8.7 https://github.com/pgvector/pgvector.git
cd pgvector
nmake /F Makefile.win
nmake /F Makefile.win install
See the installation notes if you run into issues
You can also install it with Docker or conda-forge.
Getting Started
Enable the extension (do this once in each database where you want to use it)
tsql
CREATE EXTENSION vector;
Create a vector column with 3 dimensions
sql
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
Insert vectors
sql
INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
Get the nearest neighbors by L2 distance
sql
SELECT FROM items ORDER BY embedding '[3,1,2]' LIMIT 5;
Also supports inner product (), cosine distance (), and L1 distance ()
Note: returns the negative inner product since Postgres only supports ASC order index scans on operators
Storing
Create a new table with a vector column
sql
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
Or add a vector column to an existing table
sql
ALTER TABLE items ADD COLUMN embedding vector(3);
Also supports half-precision, binary, and sparse vectors
Insert vectors
sql
INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
Or load vectors in bulk using COPY (example)
sql
COPY items (embedding) FROM STDIN WITH (FORMAT BINARY);
Upsert vectors
sql
INSERT INTO items (id, embedding) VALUES (1, '[1,2,3]'), (2, '[4,5,6]')
ON CONFLICT (id) DO UPDATE SET embedding = EXCLUDED.embedding;
Update vectors
sql
UPDATE items SET embedding = '[1,2,3]' WHERE id = 1;
Delete vectors
sql
DELETE FROM items WHERE id = 1;
Querying
Get the nearest neighbors to a vector
sql
SELECT FROM items ORDER BY embedding '[3,1,2]' LIMIT 5;
Supported distance functions are:
- - L2 distance
Top issues
#521Are either int8 or fp8 vectors planned?23 comments · 2024-04-17#761Enhancement: multicolumn vector index design17 comments · 2025-01-20#1003Support RabitQ in pgvector11 comments · 2026-07-28#235RFC: Setting search defaults as an index option8 comments · 2023-08-22#846Unexpected use of Index Scan in ANN query without LIMIT or enable_indexscan7 comments · 2025-05-26#749Enhancement: Increase 1,000 non-zero elements limit to 1,200 for sparsevec when creating HNSW index5 comments · 2025-01-04#1043bit Jaccard distance returns 1.0 for identical all-zero bit vectors3 comments · 2026-10-20#1065Support for Advanced K-means Acceleration Techniques in IVFFlat Index Construction3 comments · 2026-11-16