October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Choose Between pgvector HNSW and IVFFlat Indexes

HNSW prioritizes a stronger speed-recall tradeoff at higher memory and build cost; IVFFlat is lighter and faster to build but needs data-trained lists. Benchmark both against your real queries.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose HNSW when query speed and recall matter more than index-build time and memory; choose IVFFlat when a lighter, quicker-building index suits your workload and you can train it on representative table data. Neither option is universally faster in a particular deployment: both are approximate, and the right choice depends on measured recall, latency, filtering, and available resources.

What differs between HNSW and IVFFlat?

pgvector uses exact nearest-neighbor search by default. HNSW and IVFFlat are approximate indexes: they can make queries faster, but may not return the same nearest results as exact search. The pgvector project describes HNSW as having better query performance in the speed-recall tradeoff, with slower builds and greater memory use than IVFFlat. IVFFlat generally builds faster and uses less memory, but its query-performance tradeoff is lower. These are project-level comparisons, not a promise for every dataset or server. See the pgvector README.

As an Amazon Associate I earn from qualifying purchases.

Decision factor HNSW IVFFlat
Query speed and recall Project documentation describes a better speed-recall tradeoff. Project documentation describes a lower speed-recall tradeoff.
Build time and memory Slower to build and uses more memory. Faster to build and uses less memory.
Data needed at index creation No training step; can be created before data is loaded. Needs trained lists based on table data; create it after loading data.
Primary controls m, ef_construction, and query-time ef_search. lists and query-time probes.

For a production decision, benchmark both with your data and query patterns rather than treating the qualitative comparison as a universal result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When should you choose HNSW?

Start with HNSW if query performance is the priority and your system can accommodate greater index memory and slower creation. HNSW builds a multilayer graph. It does not require IVFFlat’s data-based training step, so you can create the index before loading rows.

HNSW settings

  • m controls the maximum number of connections per layer; its documented default is 16.
  • ef_construction controls the candidate list used during index construction; the documented default is 64. Raising it can improve recall, but increases build time and slows inserts.
  • ef_search controls the candidate list considered at query time; the documented default is 40. Raising it can improve recall while making queries slower.

The pgvector README advises keeping the defaults unless recall is too low. HNSW builds faster when its graph fits in maintenance_work_mem, but do not raise that setting so far that it exhausts server memory.

Create an HNSW index

CREATE INDEX ON items USING hnsw (embedding vector_cosine_ops);

This example uses cosine distance. The operator class must match the distance operator used in the query; consult the README for the supported operators, vector types, dimensional limits, and requirements for your installed pgvector version.

When should you choose IVFFlat?

Choose IVFFlat when lower memory use and quicker index creation are useful and you can build after representative data is present. IVFFlat groups vectors into lists and searches a subset of those lists near the query vector. Because the lists are trained from table data, creating the index before the table has data is a poor fit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Starting values for lists and probes

The README gives these as starting heuristics, not measured performance guarantees:

  • For up to 1 million rows, start with lists = rows / 1000.
  • Above 1 million rows, start with lists = sqrt(rows).
  • Start with probes around sqrt(lists).

Increasing probes searches more lists and can improve recall at a query-speed cost. If probes equals the number of lists, the search is exact and the planner will not use the IVFFlat index.

Create an IVFFlat index

CREATE INDEX ON items USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);

Here, 100 is an example value, not a recommendation for every table. Choose the list count for your row count, then test it and the probe count against the workload.

How do filters affect index choice?

With approximate indexes, filtering happens after the index scan. A selective condition can therefore leave fewer rows than the requested result limit: the scan may not have visited enough qualifying vectors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Starting with pgvector 0.8.0, iterative index scans can keep scanning until enough rows are found or a configured limit is reached. Strict ordering preserves exact distance order; relaxed ordering can improve recall while allowing slight deviations in distance order. Check the installed extension version before relying on these options.

  • For a small number of distinct filter values, consider a partial index.
  • For many filter values, consider partitioning.
  • In a multitenant application, a shared approximate index can let one tenant’s vectors affect another tenant’s recall and speed. The pgvector documentation suggests list partitioning or separate tables for tenant isolation.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How should you benchmark and validate the choice?

  1. Measure exact results as a baseline. The pgvector README demonstrates disabling index scans within a transaction to compare approximate results with exact search. Use the same query and representative data for both.
  2. Compare recall and query speed. Test the actual distance operator, requested result count, filters, and workload mix. Adjust HNSW ef_search or IVFFlat probes and observe the recall-versus-speed tradeoff.
  3. Inspect query execution. Run EXPLAIN (ANALYZE, BUFFERS) to see how the query behaves and what resources it uses.
  4. Track index creation. Monitor progress with pg_stat_progress_create_index, particularly when comparing build behavior.

The pgvector README does not establish a universal latency or recall benchmark, so results from one deployment should not be presented as a general ranking.

Check version and operator compatibility

The pgvector README was accessed on October 4, 2026, and its search result showed a v0.8.6 release reference. The README also identifies iterative scans as a feature introduced in v0.8.0. Confirm the extension version actually deployed before using version-sensitive settings or examples. Confirm that the index operator class and query distance operator match, and verify supported types and dimension limits in the current README.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.