pgvector logo

pgvector

pgvector is an open-source extension that adds vector similarity search to Postgres.

It lets developers store embeddings in an ordinary table column, then find the nearest neighbors with a SQL query using L2, inner product, cosine, L1, Hamming or Jaccard distance. Both exact and approximate search are…

pgvector screenshot

pgvector is an open-source extension that adds vector similarity search to Postgres. It lets developers store embeddings in an ordinary table column, then find the nearest neighbors with a SQL query using L2, inner product, cosine, L1, Hamming or Jaccard distance. Both exact and approximate search are supported, with HNSW and IVFFlat indexes for speed, and vectors can be single-precision, half-precision, binary or sparse. The extension is free, and it supports Postgres 13 and newer.

Backend engineers, data scientists and machine learning developers who already run Postgres are the natural audience. Instead of adding a separate vector database, they keep embeddings next to the rest of their data and get ACID compliance, point-in-time recovery and JOINs. Any language with a Postgres client can talk to it, so Python, Ruby, Go, Node and Java teams all qualify. Small teams like the lower operational overhead, and larger ones can use quantization once the number of vectors grows.

Common uses include semantic search over documents, product recommendations, deduplication, and retrieval for LLM applications where relevant passages are fetched before generation. A typical setup creates a table with a vector column, inserts embeddings produced by a model, builds an HNSW index, and queries with ORDER BY embedding distance LIMIT. Filtering and multitenancy patterns let one table serve many customers, and iterative index scans help when a WHERE clause removes many candidates. It installs by compiling from source or through Docker, Homebrew, PGXN, APT, Yum and conda-forge, and many hosted Postgres providers include it.

pgvector alternatives

See all →

Frequently asked

6 questions
What does pgvector do inside Postgres?
It adds a vector data type and similarity search operators so embeddings can be stored and queried like any other column. Exact and approximate nearest neighbor search are both supported.
Who should use pgvector?
Developers who already use Postgres and want vector search without running another database. Teams building semantic search, recommendations or retrieval for AI applications are typical users.
How would pgvector be used for retrieval in an AI app?
Embeddings from a model are inserted into a vector column, an HNSW or IVFFlat index is built, and a query orders rows by distance to a query embedding. The nearest rows are then returned as context.
Is pgvector free?
The extension is open source and free to install. Costs depend on where Postgres runs, whether self-hosted or at a hosted provider that includes the extension.
What distance metrics and vector types are supported?
Distances include L2, inner product, cosine, L1, Hamming and Jaccard. Vector types include single-precision, half-precision, binary and sparse.
How do I install pgvector?
Compile and install it on Linux or Mac, or build it on Windows with nmake. Docker, Homebrew, PGXN, APT, Yum, pkg, APK and conda-forge packages exist, and it comes preinstalled with Postgres.app and many hosted providers.

Reviews (0)

Write review

No reviews yet. Be the first to share your experience.