⇄ConnectorData & ETLFree
pgvector
Open-source vector similarity search for PostgreSQL — store and query embeddings directly in your Postgres DB.
Installs310k
Rating★ 4.8
Reviews103
pgvector
pgvector is an open-source PostgreSQL extension for vector similarity search. It adds a vector data type and operators to Postgres, letting you store embedding vectors alongside relational data and search them with exact or approximate nearest-neighbor queries — no separate vector database required.
Key Features
- Native Postgres: use SQL, JOIN with relational data, leverage existing Postgres tooling
- Exact and approximate search: exact KNN and IVFFlat/HNSW approximate indexes
- Distance metrics: L2, inner product, cosine, L1, Hamming, Jaccard
- Sparse vector support (svector) for BM25-style retrieval
- Half-precision vectors (halfvec) to cut storage by 2×
- Works with any ORM that supports Postgres: SQLAlchemy, Django, ActiveRecord
Quick Start
CREATE EXTENSION vector;
CREATE TABLE embeddings (
id SERIAL PRIMARY KEY,
content TEXT,
embedding vector(1536)
);
CREATE INDEX ON embeddings USING hnsw (embedding vector_cosine_ops);
-- Nearest neighbor search
SELECT content, 1 - (embedding <=> '[0.1,0.2,...]') AS similarity
FROM embeddings
ORDER BY embedding <=> '[0.1,0.2,...]'
LIMIT 5;
from pgvector.sqlalchemy import Vector
# Works with SQLAlchemy, Django, and psycopg2/psycopg3
Install via ai-supply
npx ai-supply add pgvector-postgres-embeddings
Curated mirror of the open-source pgvector (PostgreSQL License). Get it from the source.