Overview
pgvector is an open-source extension that adds a vector data type and similarity search to PostgreSQL. It lets you store embeddings in the same database as the rest of your application data and query them with regular SQL, so you don't need to run a separate vector store alongside Postgres.
It is aimed at developers who already use Postgres and want to add semantic search, recommendations, or retrieval for AI applications. Because vectors live in normal tables, you keep JOINs, transactions, ACID guarantees, point-in-time recovery, and the rest of Postgres on top of your similarity search.
As a vector database option, pgvector supports both exact and approximate nearest neighbor search, single-precision, half-precision, binary, and sparse vectors, and several distance functions including L2, inner product, cosine, L1, Hamming, and Jaccard. It works from any language that has a Postgres client.
What it does
- Adds a native vector column type to Postgres tables, alongside halfvec, bit (binary), and sparsevec types
- Exact nearest neighbor search for perfect recall, plus approximate search via HNSW and IVFFlat indexes
- Distance operators for L2 (<->), inner product (<#>), cosine (<=>), L1 (<+>), Hamming (<~>), and Jaccard (<%>)
- Full Postgres feature set: ACID compliance, JOINs, point-in-time recovery, and standard SQL queries
- Works with any language that has a Postgres client; supports Postgres 13 and later
- Available via Docker, Homebrew, APT, Yum, conda-forge, and many hosted Postgres providers
Getting started
Install the extension into a Postgres 13+ instance, enable it once per database, then create a vector column and run a nearest-neighbor query.
Compile and install (Linux/Mac)
Clone the extension and build it with make. You may need sudo for the install step. Docker, Homebrew, APT, Yum, and conda-forge packages are also available.
cd /tmp
git clone --branch v0.8.2 https://github.com/pgvector/pgvector.git
cd pgvector
make
make install # may need sudoEnable the extension
Run this once in each database where you want to use vectors.
CREATE EXTENSION vector;Create a table and insert vectors
Add a vector column with a fixed number of dimensions, then insert your embeddings.
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');Query the nearest neighbors
Order by a distance operator and limit the results. This example uses L2 distance; <#> (inner product), <=> (cosine), and <+> (L1) are also supported.
SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Add semantic search or retrieval (RAG) to an app that already runs on Postgres, without standing up a separate vector database
- Store text or image embeddings next to their source rows so you can filter, JOIN, and rank in a single SQL query
- Build recommendation or similar-item features by finding the nearest vectors to a given row
- Scale to large vector sets using HNSW or IVFFlat indexes for fast approximate nearest neighbor search
How pgvector compares
pgvector alongside other open-source vector databases tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| Supabase | ★ 105k | Managed Postgres backend whose Vector toolkit (pgvector) stores, indexes, and queries embeddings next to transactional data. |
| Redis Cloud | ★ 75k | Fully-managed Redis with built-in vector search, offering low-latency similarity and hybrid queries over any embeddings. |
| Milvus | ★ 44.9k | A distributed vector database for storing and searching billions of embeddings at scale, with multiple index types and Kubernetes-native deployment. |
| FAISS | ★ 40.4k | A library from Meta for efficient similarity search and clustering of dense vectors, with both exact and approximate indexes. |
| Qdrant | ★ 32.5k | A Rust-based vector search engine that stores embeddings with rich payload filtering for semantic search and recommendation systems. |
| Chroma | ★ 28.5k | A developer-focused vector database designed for quickly building retrieval and RAG features with a simple Python and JavaScript API. |
| pgvector | ★ 21.8k | Open-source vector similarity search for Postgres |
| Weaviate | ★ 16.4k | A vector database with built-in hybrid search and LLM-provider integrations for building semantic search and retrieval applications. |