pgvector 0.8/0.9: HNSW, halfvec, and RAG on PostgresLimited sources1 source listed so far, so check specifics before you rely on them.This rates where the sources come from. It doesn't prove every claim.
pgvector 0.8 (Oct 2024) iterative scans + halfvec, 0.9 sparse vectors, HNSW vs IVFFlat, EF Core + Pgvector.EntityFrameworkCore, halfvec/bit quantization, hybrid search with tsvector, maintenance_work_mem for builds.
By Amit UpadhyayPublished Updated 14 minArticle 7 of 13 in Databases
AI assistant · answers from this article
1 of 6
Keyword search is enough
Nothing to add yet
If searches use your own vocabulary, the full-text search already in Postgres finds what people want.
On this page
pgvector, in one sentence
pgvector adds vector search to the Postgres you already run, so embeddings sit in a column next to the rows they describe and are filtered with ordinary SQL.
You reach for it when a product already on Postgres needs semantic search over its own rows. Not before: it costs more memory on the database server, index builds to plan, and a ceiling at very large scale.
The cheat sheet
What to use when
You do not need all of this on day one. Each row is one signal and the piece that answers it. Stop at the row your system has reached, or pick one to see it in the picture above.
Where you areThe signalWhat to useWhat it costs
None. People type the words your products use.Nothing. Postgres full-text searchNothing
Shoppers describe what they want in their own words, and keyword search finds nothing.Embeddings in a pgvector column, next to the rowsStep 1 ↓Storage for the vectors, and an embedding call on each write
Every search compares the query with every row.An HNSW index, with the operator class that matches your distanceStep 2 ↓A slow build, and an index that has to fit in memory
A filtered search for one tenant returns three results instead of ten.Filter in the same SQL query, with iterative scansFiltered search ↓A little more work on some queries
A search for an error code or a product name misses it.Hybrid: vector and full-text search in one queryStep 6 ↓Two rankings to combine
Recall drops and memory pressure takes over as the count reaches tens of millions on one node.Shard by tenant, or move to a dedicated vector databaseCommon mistakes ↓A second system to run and keep in step
Start With Full-Text Search
If people search with the words your products use, Postgres full-text search is enough, and it's already there. Vector search earns its place when they describe what they want in their own words and keyword matching returns nothing.
You need semantic search over your products, and the first instinct is a separate vector database plus a job to sync data into it. Then search shows out-of-stock products, deleted items linger, and you have a second system to run, back up and secure.
pgvector puts vectors in a Postgres column next to the rows they describe, so filters on stock, price or permissions run in the same query. It has matured quickly: half-precision and binary vector types cut index sizes, and iterative index scans (0.8) fixed the problem of filtered searches returning too few results. Below is how to use it, and where its ceiling is.
If you are about to add a vector database
You spun up a separate vector DB just for RAG and now you're syncing two stores
You don't know whether to pick HNSW or IVFFlat
Your queries are slow and you don't know what ef_search does
You're storing 1536-dim float32 and your table is 50 GB
Pro deep dive14 min full read
Keep reading with Pro
This is one of our advanced production deep dives. Pro unlocks the rest of it, every other deep dive, and the See, Animate, Test and Build modes on every topic.
What it covers
pgvector 0.8 (Oct 2024) iterative scans + halfvec, 0.9 sparse vectors, HNSW vs IVFFlat, EF Core + Pgvector.EntityFrameworkCore, halfvec/bit quantization, hybrid search with tsvector, maintenance_work_mem for builds.