Every Retrieval-Augmented Generation (RAG) tutorial makes spinning up a dedicated vector database look trivial. In production, however, adding a separate vector store introduces a second operational failure domain: you now have to synchronize document deletes, enforce tenant access controls across two engines, manage eventual consistency lags, and pay for duplicate memory footprints.
That operational friction explains why so many engineering teams evaluate pgvector inside their existing PostgreSQL cluster before adopting a standalone vector engine. In this technical comparison, we examine what pgvector 0.8 and pgvectorscale bring to production RAG, how to combine semantic similarity with PostgreSQL Full Text Search, and where dedicated vector databases retain a genuine architectural edge.
Why Teams Consolidate AI Embeddings Inside PostgreSQL
Most RAG applications do not search raw vectors in isolation. A user asks a question, and your backend needs to filter chunks by organization_id, document permissions, publication date, or active subscription status before ranking semantic matches. In a dedicated vector store, relational metadata lives in PostgreSQL while vectors live elsewhere, forcing teams to maintain brittle CDC pipelines or dual-write code paths.
By storing embeddings directly inside PostgreSQL, you keep relational records and vector columns under the same ACID transaction boundary. When a document is updated or soft-deleted, its chunks and permissions update atomically in a single commit. If you are already weighing relational database choices as discussed in PostgreSQL vs SQLite vs MySQL: Which Database for Your Web App?, PostgreSQL’s extension ecosystem turns it into a multi-model engine without sacrificing SQL JOINs or point-in-time recovery.
Keep vectors next to your source-of-truth permissions and relational metadata until scale, multi-billion-vector sharding, or specialized SLA requirements genuinely force separation.
Vector Types and Distance Operators in pgvector 0.8
As documented in the official pgvector repository, pgvector (v0.8.7) runs on PostgreSQL 13 and newer and supports both exact and approximate nearest neighbor search. Importantly for memory budgeting, pgvector is no longer restricted to 32-bit floats: it provides four distinct vector storage types alongside six distance metrics.
vector(single-precision): Standard 4-byte float dimensions for maximum precision when RAM is abundant.halfvec(half-precision): 2-byte float dimensions that cut vector storage and index memory roughly in half with minimal recall trade-offs.bit(binary quantization): Compact bit-packed vectors queried with Hamming or Jaccard distance for fast coarse filtering followed by re-ranking.sparsevec(sparse vectors): Efficiently stores learned sparse retrieval weights (such as SPLADE) where most dimensions are zero.
For distance scoring, pgvector natively implements L2 (<->), negative inner product (<#>), cosine distance (<=>), L1 (<+>), Hamming (<~>), and Jaccard (<%>) operators. Choosing halfvec with cosine distance on normalized embeddings is one of the fastest ways to shrink index RAM requirements without leaving standard SQL.
HNSW vs IVFFlat vs pgvectorscale StreamingDiskANN
Exact sequential scans give 100% recall on small tables, but as chunk counts grow into the hundreds of thousands or tens of millions, approximate nearest neighbor (ANN) indexes become essential. Selecting the right index type determines build time, memory footprint, and filtered-query recall.
| Index Strategy | Primary Strength | Memory Profile | Best Use Case |
|---|---|---|---|
| pgvector IVFFlat | Fast index build, low build memory | Moderate; requires training list centroids | Static datasets rebuilt periodically |
| pgvector HNSW | High recall and fast query speed without training step | Higher RAM usage to hold graph in memory | Dynamic RAG tables with frequent inserts |
| pgvectorscale StreamingDiskANN | Disk-backed graph with Statistical Binary Quantization | Significantly lower RAM per million vectors | Large datasets exceeding available RAM |
| Dedicated Vector DB | Distributed sharding and managed multi-tenant scaling | Horizontally scaled cluster memory | Massive multi-region corpora and dedicated ML infra |
When datasets outgrow single-node RAM, pgvectorscale extends pgvector with a StreamingDiskANN index inspired by Microsoft DiskANN and Statistical Binary Quantization (SBQ) compression. Because StreamingDiskANN keeps compressed graph structures efficiently paged from SSDs rather than demanding the entire uncompressed graph stay pinned in shared buffers, teams can push PostgreSQL vector workloads much further before needing distributed sharding.

Building Hybrid Semantic and Full-Text Search in SQL
Pure dense vector search famously struggles with exact product SKUs, error codes, function names, and acronyms. Combining dense embeddings with PostgreSQL Full Text Search—which indexes tsvector documents with GIN indexes and scores tsquery matches—lets you solve both semantic intent and exact lexical matching inside one query. For broader architectural context on ranking strategies, see How to Solve Complex Search Problems: Strategies and Real-World Applications.
A clean, deterministic pattern is Reciprocal Rank Fusion (RRF) across two CTEs: one fetching top lexical candidates via GIN, and one fetching top semantic candidates via HNSW, joined by document chunk ID.
sql-- Schema with halfvec embeddings and generated tsvector column
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE doc_chunks (
id BIGSERIAL PRIMARY KEY,
tenant_id UUID NOT NULL,
content TEXT NOT NULL,
embedding halfvec(1536) NOT NULL,
tsv tsvector GENERATED ALWAYS AS (to_tsvector('english', content)) STORED
);
CREATE INDEX idx_doc_chunks_tsv ON doc_chunks USING GIN (tsv);
CREATE INDEX idx_doc_chunks_hnsw ON doc_chunks USING hnsw (embedding halfvec_cosine_ops);
-- Hybrid search using Reciprocal Rank Fusion (RRF)
WITH semantic AS (
SELECT id, ROW_NUMBER() OVER (ORDER BY embedding <=> $1::halfvec) AS rank
FROM doc_chunks
WHERE tenant_id = $2
ORDER BY embedding <=> $1::halfvec
LIMIT 40
),
lexical AS (
SELECT id, ROW_NUMBER() OVER (ORDER BY ts_rank_cd(tsv, websearch_to_tsquery('english', $3)) DESC) AS rank
FROM doc_chunks
WHERE tenant_id = $2
AND tsv @@ websearch_to_tsquery('english', $3)
ORDER BY ts_rank_cd(tsv, websearch_to_tsquery('english', $3)) DESC
LIMIT 40
)
SELECT
c.id,
c.content,
COALESCE(1.0 / (60 + s.rank), 0.0) + COALESCE(1.0 / (60 + l.rank), 0.0) AS rrf_score
FROM doc_chunks c
LEFT JOIN semantic s ON s.id = c.id
LEFT JOIN lexical l ON l.id = c.id
WHERE s.id IS NOT NULL OR l.id IS NOT NULL
ORDER BY rrf_score DESC
LIMIT 10;
Note the WHERE tenant_id = $2 predicate inside both CTEs. With pgvector 0.8’s iterative index scanning, filtered HNSW queries automatically scan deeper into the graph if strict tenant filters discard initial candidates, preventing the classic empty-result bug when a single tenant owns only a small slice of the table.
When a Dedicated Vector Database Still Makes Sense
PostgreSQL plus pgvector and pgvectorscale covers the vast majority of SaaS RAG applications gracefully, yet dedicated vector databases (such as Qdrant, Milvus, or Pinecone) remain the better tool in specific scenarios:
- Horizontal sharding at massive scale: If you store hundreds of millions or billions of high-dimensional vectors with strict sub-50ms tail latency across distributed shards, purpose-built distributed vector engines handle automatic shard rebalancing natively.
- Workload isolation from OLTP transactions: Heavy vector index builds or bursty batch re-embedding jobs can compete for CPU, IOPS, and shared buffers on a primary transactional PostgreSQL node unless isolated onto a read replica or separate cluster.
- Managed serverless scaling to zero: If your AI retrieval workload is spiky and independent from your transactional store, a serverless vector API avoids provisioning large PostgreSQL RAM instances just to hold HNSW graphs.
Start with PostgreSQL, halfvec, and hybrid RRF unless you have already hit multi-node sharding limits. You get ACID deletes, permission JOINs, full-text search, and one fewer database to wake you up at 3 a.m.
Featured image credit: MediaWiki 1.10 database schema by Nick Jenkins and contributors (CC BY-SA 3.0), via Wikimedia Commons.