pgvector logo

AI & Automation

Official site

pgvector

pgvector — vector similarity search inside PostgreSQL, keeping embeddings and relational data in one transactional store.

Overview

pgvector turns an existing PostgreSQL instance into a vector store with the HNSW and ivfflat indexes that power embedding-based similarity search. It avoids the operational cost of a separate vector database where relational ties matter.

I use it for RAG retrieval, semantic search, and deduplication across embeddings, alongside the relational data that describes those vectors. The payoff is transactional consistency and one query language for both.

Index choice and recall tuning are the practical craft — HNSW for precision, ivfflat for smaller datasets, and careful parameter selection against real recall requirements.

The main draw is co-location. Instead of a separate vector database, embeddings live in the same PostgreSQL engine as the relational data — one transaction, one backup, one operational surface.

Transactional consistency is a quiet but real win. Because the vectors and the rows they describe share an engine, updates are atomic and consistent rather than scattered across two systems that can drift apart.

One query language for both matters. A single SQL statement can filter on structured fields and rank by vector distance, so retrieval stays a query rather than a fragile orchestration between services.

Index choice is workload-dependent. HNSW gives strong precision for larger datasets and production recall; ivfflat is lighter for smaller sets — and I pick plus tune parameters against the actual recall requirement rather than a default.

It slots naturally into RAG. The embeddings that feed retrieval live beside the documents and metadata they describe, keeping the retrieval path grounded and inspectable.

pgvector is often the right call versus a dedicated vector platform when relational coupling and operational simplicity matter most. Where scale or isolation genuinely demands a managed vector service, I weigh, Pinecone and others honestly against it.

How I Work With pgvector

I keep embeddings and the relational data that describes them in one engine. Co-location means one transaction, one backup, and one operational surface.

Transactional consistency is the quiet win. Because the vectors and their rows share an engine, updates are atomic rather than scattered across two systems that drift.

One query language for both matters. A single SQL statement filters on structured fields and ranks by vector distance, so retrieval stays a query, not a fragile orchestration.

Index choice is workload-driven. HNSW gives strong precision at scale; ivfflat is lighter for smaller sets — picked and tuned against the actual recall requirement.

It slots naturally into RAG. The embeddings feeding retrieval live beside the documents and metadata they describe, keeping the path grounded and inspectable.

I keep the index refresh controlled and reproducible. Re-embedding is a documented, deterministic operation rather than an ad-hoc job.

Recall is measured, not assumed. A small eval set quantifies retrieval quality so a change to embedding or index is verified.

pgvector often beats a dedicated vector platform where relational coupling and operational simplicity matter most.

Where scale or isolation genuinely demands a managed vector service, I weigh Pinecone and others honestly against it rather than defending a default.

Key Capabilities

HNSW and ivfflat indexes for similarity search.
Embeddings and relational data in one PostgreSQL store.
RAG retrieval with transactional consistency.
One query path for structured and vector data.
Recall tuning against real dataset requirements.