Features
- Vector search as a PostgreSQL extension
- HNSW and IVFFlat indexing algorithms
- Combine vector search with SQL queries
- Works with any PostgreSQL hosting provider
Pros
- No separate database to manage, just PostgreSQL
- Full SQL power alongside vector search
- Works with existing PostgreSQL tooling and backups
Cons
- Performance lower than purpose-built vector databases
- Scaling requires PostgreSQL scaling expertise
- Limited vector-specific features compared to dedicated solutions
Overview
pgvector is a PostgreSQL extension that adds vector similarity search capabilities to the world’s most popular open-source relational database. Instead of managing a separate vector database, you can store embeddings alongside your relational data in the same PostgreSQL instance.
The extension supports multiple index types: HNSW (Hierarchical Navigable Small World) for high-recall approximate search, and IVFFlat for memory-efficient approximate search. It provides distance functions for L2, inner product, cosine, and L1 distance.
The key advantage of pgvector is operational simplicity. If you already run PostgreSQL, you already have a vector database. Your embeddings live alongside your application data, share the same backup strategy, and can be queried using familiar SQL with JOINs, filters, and aggregations.
When to Use
Choose pgvector when you already use PostgreSQL and want to add vector search without introducing a new database. It is ideal for applications where embeddings are a feature alongside relational data, not the primary data model.
Getting Started
CREATE EXTENSION vector;
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(1536));
CREATE INDEX ON items USING hnsw (embedding vector_cosine_ops);
INSERT INTO items (embedding) VALUES ('[0.1, 0.2, ...]');
SELECT * FROM items ORDER BY embedding <=> '[0.1, 0.2, ...]' LIMIT 5;