Why pgvector’s Default ivfflat Settings Quietly Return the Wrong Nearest Neighbors

A rack of servers, representing the database infrastructure behind vector search and nearest-neighbor indexes

pgvector’s ivfflat index returns incomplete nearest-neighbor results by default because its query-time parameter, probes, defaults to 1 — meaning a search only checks one of however many list partitions the index was built with, even if the true nearest neighbor sits in a different list entirely. Nothing errors when this happens; the query just returns a confident, plausible-looking, and sometimes wrong answer. If your RAG pipeline is quietly retrieving the second- or third-best chunk instead of the best one, this default is the first thing to check.

What “probes” actually controls

ivfflat works by clustering your vectors into a number of lists at index-build time, then, at query time, searching only the probes number of lists closest to your query vector. With the default probes = 1, pgvector checks exactly one list and returns the best match found inside it — not the best match in the whole table. If the true nearest neighbor happens to live in list #47 and your query vector’s centroid distance puts list #12 first, you get list #12’s best result and never see list #47 at all. The index isn’t broken and the query doesn’t fail; it’s doing exactly what an approximate index is supposed to do, which is trade recall for speed. The problem is that pgvector’s own documentation doesn’t suggest a lists value by default, and plenty of setup guides copy a round number like 100 without ever mentioning that probes needs to scale with it.

ivfflat vs. HNSW, from pgvector’s own documentation

ivfflatHNSW
StructureVectors divided into lists; query searches the closest listsMultilayer graph
Needs existing data to build?Yes — training step requires data already in the tableNo — can be created on an empty table
Build-time parameterslists (no stated default; common guidance: rows/1000 up to 1M rows, sqrt(rows) above that)m = 16, ef_construction = 64
Query-time parameter and defaultivfflat.probes = 1hnsw.ef_search = 40
Build time / memoryFaster, less memorySlower, more memory
Speed-recall tradeoffLower query performance for a given recall targetBetter
Common cause of bad resultsIndex built before enough data existed, or probes left at 1 with many listsResults capped by ef_search; dead tuples or filters can reduce results further

The defaults reveal the design intent: pgvector ships ivfflat tuned for raw speed out of the box, not recall, and trusts you to raise probes once you know your data. HNSW ships closer to a reasonable recall/speed balance by default, which is a real reason it’s become the more commonly recommended choice for new projects — not because ivfflat is deprecated or worse in general, but because its default is the one more likely to surprise you in production.

A worked example of how bad this gets

Say you have 200,000 embedded chunks and followed the rows / 1000 guidance to set lists = 200. With probes left at its default of 1, each query searches exactly 1 of those 200 lists — 0.5% of your clustered data — and returns the best match found inside whichever single list the query vector happened to land closest to. If the true best match sits in a neighboring list whose centroid is only slightly farther from the query than the chosen list’s centroid, which is a common and unremarkable situation with real embeddings, it’s invisible to the search. Raising probes to sqrt(200) (about 14) means checking 7% of the lists instead of 0.5% — a 28x larger search space for a query that’s still fast, because you’re still skipping 93% of the data. The gap between “technically working” and “actually finding the right answer most of the time” in this example is a one-line configuration change, not a re-architecture, which is exactly why it’s worth checking before assuming the problem is somewhere else in the pipeline.

How this shows up in a RAG pipeline

The failure mode is rarely “the index returns nothing.” It’s that a RAG system built on top of a vector database retrieves a chunk that’s plausible but not the best available match, and the generation step — which has no way to know a better chunk existed — writes a fluent, confident answer built on the second-best source. Nothing in the logs says “recall was low here.” The symptom users actually notice is a model that seems to “forget” a detail that’s clearly present somewhere in the knowledge base, which gets misdiagnosed as a chunking problem or a prompt problem far more often than it gets correctly traced back to an index parameter. If you’ve already gone through chunking strategy options and the retrieved chunks still feel oddly inconsistent — right most of the time, wrong in a way that seems almost random — checking probes against lists is worth doing before you re-chunk anything.

The fix for ivfflat

  • Build the index after loading your data, not before. pgvector’s own guidance says building ivfflat with too little data relative to the chosen lists value produces bad clusters; if you built it on an empty or near-empty table, drop and rebuild it now that real data exists.
  • Pick lists based on table size, roughly rows / 1000 up to a million rows, and sqrt(rows) beyond that — not a fixed number copied from a tutorial written for a different dataset size.
  • Set probes to roughly sqrt(lists) as a starting point, and increase it if recall still looks low in testing. Setting probes equal to lists gives you exact search — useful as a one-time baseline to measure how much recall you’re giving up at a lower setting, even if it’s too slow to run that way permanently.
  • Measure recall against a known-answer set, not against “the results look reasonable.” Take a handful of queries where you know which chunk should come back first, run them at a few different probes values, and check whether the expected result is actually in the top-k — eyeballing plausible-sounding retrieved text won’t catch a quiet drop from 95% to 70% recall.

Switching to HNSW isn’t a free fix either

HNSW’s default ef_search of 40 still caps how many candidates a query considers, and pgvector’s documentation notes that dead tuples or a WHERE filter applied alongside the vector search can reduce the effective result count further — a filtered query can come back with fewer rows than your LIMIT asked for, which looks like a bug but is the index behaving as documented. The practical difference from ivfflat is that HNSW’s default is tuned to a reasonable recall level out of the box, so the quiet-failure risk from an untouched default is lower, not zero. If you’re choosing between pgvector and a different approach entirely for a new project, that choice sits one level up from this one — our comparison of fine-tuning, prompting, and RAG and our plain-English walkthrough of how RAG works end to end are both useful before you’ve committed to a specific vector index at all.

Spotting it before it reaches production

The reliable way to catch this isn’t reading query plans — EXPLAIN ANALYZE will happily show you an index scan completing quickly and tell you nothing about whether it found the right answer, because “fast” and “correct” are measured completely separately here. What actually catches it is a small evaluation set: take 20 to 50 queries where you already know, by some other means, which chunk or row is the true best match — pulled from support tickets that got resolved by a specific document, or from a prior manual audit — and run them through your retrieval step at whatever probes value you’re currently using. Count how often the known-correct result appears in the top-k you actually use downstream, not just in the full result set. This is the same discipline as unit testing a function: you need known inputs with known correct outputs, not a vibe check on whether the output text looks plausible. Teams that skip this step typically only find the problem when a user complains that the model “should have known” something that was in the knowledge base the whole time, which is a much more expensive way to discover a misconfigured default than running the eval set once during setup.

FAQ

How do I check what my current probes and lists values actually are?

SHOW ivfflat.probes; returns the session’s current setting (it resets to 1 per session unless you set it explicitly), and the lists value used at build time isn’t stored as a queryable setting — check the CREATE INDEX statement you ran, or your migration history, since it isn’t visible from a later session otherwise.

Is HNSW strictly better, so should I just always use it?

Not universally — HNSW takes longer to build and uses more memory, which matters at large scale or on constrained hardware, and ivfflat with properly tuned probes can hit comparable recall for less resource cost on some workloads. The real issue this post covers isn’t “ivfflat is bad,” it’s that its default is tuned for speed over recall and silently stays that way unless you change it.

Sources: pgvector’s official documentation and README; EnterpriseDB’s pgvector usage guide.

Image: “Servers in a Rack” by Abigor, CC BY-SA 3.0, via Wikimedia Commons.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top