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.

query.sql

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.

HNSW
IVFFlat
Structure
Navigable small-world graph
Inverted lists (k-means clusters)
Build time
Slower, more memory
Fast, low memory
Query speed
Fastest, best recall/latency
Good, depends on probes
Updates
Handles inserts well
Best on static data; re-train lists
Key params
m, ef_construction, ef_search
lists, probes
Use when
Most production workloads
Static dataset, low build cost

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.

Related: PostgreSQL for AI · managed PostgreSQL · managed pgvector

Make room for your next idea.

Send us your current setup and we'll tell you in 48 hours whether Rivestack is cheaper, faster, and a good production fit. New customers can also test their own data on Solo free for 7 days.

For new customers. Card required; cancel before the trial ends and you pay nothing.