pgvector
pgvector:
vector search, built into PostgreSQL.
Store embeddings and search by similarity in PostgreSQL. Use pgvector with the SQL, filters, and joins you already know.
CREATE EXTENSION vector;
ALTER TABLE docs ADD COLUMN embedding vector(1536);
CREATE INDEXON docs USING hnsw (embedding vector_cosine_ops);
SELECT title
FROM docs
ORDER BY embedding <=> $1
LIMIT 10;_
Keep vectors beside your data and search with SQL.
what is pgvector
A vector type, distance operators, and ANN indexes, all inside Postgres.
A vector type and operators
Store embeddings in a vector column and rank rows with PostgreSQL distance operators.
ANN indexes: HNSW & IVFFlat
Use HNSW or IVFFlat to trade a little recall for faster searches.
Just PostgreSQL underneath
Keep your SQL joins, filters, transactions, and backups. Your vectors live beside your data.
HNSW vs IVFFlat
The two pgvector index types, and when to use each.
using pgvector in three steps
01
Enable the extension
CREATE EXTENSION vector; on Rivestack it is already enabled, so this is a no-op. Add a column: ALTER TABLE docs ADD COLUMN embedding vector(1536);
02
Insert embeddings
Generate vectors with OpenAI, Cohere, or your own model and INSERT them like any other column, in the same transaction as the content they describe.
03
Index and query
CREATE INDEX ON docs USING hnsw (embedding vector_cosine_ops); then SELECT ... ORDER BY embedding <=> $1 LIMIT 10, combined with normal WHERE filters and joins.
where to run pgvector
Rivestack includes pgvector, local NVMe, backups, and monitoring. Choose a node size that fits your index.
pgvector FAQ
Common questions about vector search in PostgreSQL.
pgvector is an open source PostgreSQL extension for storing embeddings and finding similar vectors. HNSW and IVFFlat indexes speed up searches.
RAG, semantic search, recommendations, deduplication, and image or audio similarity. Combine similarity with ordinary SQL filters.
HNSW usually offers faster queries at the cost of memory and build time. IVFFlat is lighter to build and suits more static datasets, but needs tuning. Benchmark both against your recall target.
Install the extension and run CREATE EXTENSION vector. Rivestack includes pgvector 0.8.x, already enabled.
The vector type supports up to 16,000 dimensions; standard vector indexes support up to 2,000. Match your column to the embedding model.
Yes, with suitable hardware and index settings. Memory, storage latency, and recall targets determine capacity. See the benchmarks and test your dataset.
Often. Postgres keeps vectors, filters, and joins in one system. Dedicated vector databases may suit very large datasets or workloads without relational data.
Run it wherever PostgreSQL supports the extension. Compare storage, memory, supported versions, and tuning. Rivestack includes pgvector on local NVMe with backups and monitoring.
pgvector guides
Go deeper on setup, tuning, and trade-offs.
Getting started with pgvector
Enable the extension, create an HNSW index, and run your first similarity query.
Read the guide →
pgvector HNSW tuning
Choosing m, ef_construction, and ef_search for recall and latency on managed Postgres.
Read the guide →
pgvector vs Pinecone
When Postgres is the right home for vectors, and when a dedicated store wins.
Read the guide →
Related: PostgreSQL for AI · managed PostgreSQL · managed pgvector