pgvector/pgvector
Open-source vector similarity search for Postgres
What it solves
pgvector adds vector similarity search directly inside Postgres, so you can store vectors (lists of numbers that represent things like text or images) in the same database as your regular data. Instead of running a separate vector database, you get search-by-similarity — finding the closest vectors to a query — alongside normal SQL features like JOINs, transactions, and backups. It supports both exact search (perfect results, slower) and approximate search (very fast, slightly less accurate) via two index types.
How it works
You install it as a Postgres extension and enable it with CREATE EXTENSION vector. Then you add a vector column to a table, insert vectors, and query for nearest neighbors using special operators: <-> for L2 distance, <#> for inner product, <=> for cosine distance, <+> for L1 distance, <~> for Hamming distance, and <%> for Jaccard distance.
For speed on large datasets, you can build an approximate index. HNSW builds a multilayer graph for fast search with good accuracy but slower builds and more memory. IVFFlat divides vectors into lists and searches only the closest lists; it builds faster and uses less memory but has lower query performance. Both support tuning parameters (like ef_search for HNSW and probes for IVFFlat) to trade speed for recall.
It also supports half-precision vectors (halfvec) to save memory, binary vectors (bit) for Hamming/Jaccard distance, binary quantization to shrink indexes, sparse vectors for high-dimensional data with mostly zeros, and hybrid search combining vector similarity with Postgres full-text search.
Who it's for
Developers building applications that need similarity search — for example, recommendation systems, image or text matching, or any app that works with embeddings — and who already use Postgres and want to avoid running a separate vector database. It works with any language that has a Postgres client and supports Postgres 13+.
Highlights
- Exact and approximate nearest-neighbor search in one extension
- Multiple vector types: single-precision, half-precision, binary, and sparse
- Six distance metrics: L2, inner product, cosine, L1, Hamming, Jaccard
- Two index algorithms (HNSW and IVFFlat) with tunable speed/recall tradeoffs
- ACID compliance, point-in-time recovery, JOINs, and other standard Postgres features
- Binary quantization for smaller indexes and faster builds at scale
- Hybrid search combining vector similarity with Postgres full-text search
- Iterative index scans to improve filtered queries
- Works with any language that has a Postgres client
Related
- Project
- Project
- Project
- Project
- Project