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 desk5 min

How to Troubleshoot Slow pgvector Similarity Searches

Use the query plan first, then test index compatibility, approximate-search settings, filter selectivity, memory use, and maintenance—measuring recall as well as speed.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start with EXPLAIN (ANALYZE, BUFFERS) on the slow query as it actually runs. Then check whether its SQL shape can use the vector index, whether the plan chose an appropriate exact or approximate search, and whether filters, memory use, or maintenance explain the result. Measure latency and result quality together: HNSW and IVFFlat can be faster than exact search, but they trade away perfect recall.

1. Capture the plan for the slow query

Run the query with representative parameters and data, adding EXPLAIN (ANALYZE, BUFFERS). PostgreSQL executes the statement when ANALYZE is included, so choose an appropriate environment and be mindful of any side effects. The pgvector project README recommends this plan format for diagnosing performance.

As an Amazon Associate I earn from qualifying purchases.

Read the plan for actual execution time, buffer activity, row counts, and whether PostgreSQL used the expected index. A sequential scan is not automatically a problem: for a small table, scanning the table may be cheaper than using an index. If the plan differs between test and production, compare the data volume, query parameters, filters, and settings rather than assuming the index itself is broken.

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

2. Check that the query matches the indexable form

For pgvector’s documented nearest-neighbor index pattern, order by a distance operator in ascending order and apply a LIMIT. For example:

SELECT *
FROM items
ORDER BY embedding <-> '[3,1,2]'
LIMIT 5;

A reformulation such as ORDER BY 1 - (embedding <=> query) DESC may express a similar ranking to a reader, but it does not match the documented indexable pattern. Keep the distance operator in the ascending ORDER BY when testing whether the vector index can serve the query.

As a diagnostic experiment, the project suggests temporarily setting enable_seqscan = off inside a transaction to encourage an index plan. Use it to determine whether the query shape can use an index; it is not a general production fix. If forcing the index changes the plan, compare execution costs and results rather than treating index use as proof of improvement.

3. Establish whether the bottleneck is exact or approximate search

pgvector performs exact nearest-neighbor search by default. Exact search returns the true nearest neighbors for the distance metric, so it provides perfect recall, but the work can grow with the dataset. HNSW and IVFFlat are approximate indexes: they can reduce query cost while returning a different set of neighbors. Benchmark both latency and recall against exact results on a representative sample.

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

To obtain an exact-search comparison for an indexed query, the README describes locally disabling index scans with enable_indexscan = off. Keep that comparison scoped to diagnosis; do not assume one approximate configuration is suitable for every query or workload.

When an exact scan is slow

  • For an exact scan without a vector index, the project suggests increasing max_parallel_workers_per_gather. Treat this as a tuning experiment and check the plan and workload impact.
  • If all vectors are normalized to unit length, pgvector notes that inner product can perform better. This is conditional on normalization; validate that the stored vectors and query vectors meet that requirement and compare results for your application.
  • For selective filters, first test whether an ordinary index on the filter column makes exact search efficient within the matching rows.

4. Tune the approximate index your plan actually uses

Do not adjust HNSW and IVFFlat controls interchangeably. Identify the index in the plan, change one relevant setting at a time, and record latency and recall against your exact-search baseline.

Index What to tune Trade-off and starting point
HNSW hnsw.ef_search, plus iterative-scan settings for filtered queries The README gives a default hnsw.ef_search of 40. Broader search can improve recall but usually costs more time. Validate against your workload.
IVFFlat Number of lists at index creation and ivfflat.probes at search time The project’s starting heuristic is approximately rows divided by 1,000 for datasets up to one million rows, and the square root of row count above one million. It suggests beginning probes near the square root of the list count. More probes can improve recall at a speed cost.

HNSW breadth and iterative scans

Increasing hnsw.ef_search broadens the candidate search and can improve recall, but it can also increase latency. Tune it against the result quality your application needs rather than maximizing it by default.

For filtered queries that return too few matches, the README documents hnsw.iterative_scan = strict_order and hnsw.iterative_scan = relaxed_order. Iterative scans can continue searching for matches, subject to hnsw.max_scan_tuples and available scan memory. Strict ordering preserves exact distance order; relaxed ordering can improve recall while permitting slight deviations in distance order. Check whether the application depends on strict ranking before choosing relaxed ordering.

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

IVFFlat lists and probes

The list-count values above are project heuristics, not universal optima. Measure them on the actual corpus. An IVFFlat index built with too few rows for its number of lists may return fewer results; the README advises creating the index after the table has data. Increasing probes expands the search and can improve recall, at the expense of speed.

5. Diagnose filters and tenant layout

With approximate indexes, filtering is applied after the vector index scan. That can leave too few results even when the query returns quickly. As an illustration—not a performance benchmark—the project README estimates that if a filter matches 10% of rows and HNSW uses its documented default search breadth of 40, roughly four matching rows may be found on average. Actual counts vary with the data and query.

Choose the next experiment based on filter selectivity and how many distinct filter values you have:

  • Highly selective filter: try an ordinary index on the filter column and exact nearest-neighbor search over the matching rows.
  • Approximate search with too few filtered matches: try iterative scans, then measure returned-row counts, latency, and recall.
  • A few distinct filter values: consider a partial vector index for each relevant value.
  • Many filter values or tenant isolation needs: consider partitioning. The project warns that tenants sharing one approximate index can affect one another’s recall and speed; list partitioning or separate tables are named isolation approaches.

6. Reduce the working set carefully

If memory footprint is a constraint, the README points to halfvec and binary quantization with reranking as ways to reduce the working set at scale. These options can change numerical precision or search behavior. Compare their recall and output quality with the current representation before adopting them; a smaller index is not useful if it misses application-critical neighbors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

7. Include index maintenance in the diagnosis

When HNSW vacuuming is slow

For slow HNSW vacuuming, the project suggests running REINDEX INDEX CONCURRENTLY before VACUUM. Confirm the index name and operational suitability for your PostgreSQL deployment before running maintenance commands.

When index creation is slow

PostgreSQL’s pg_stat_progress_create_index view exposes index-build progress. The pgvector README includes separate progress queries for HNSW and IVFFlat, which help identify the build phase rather than leaving index creation opaque.

8. Compare changes on the workload that matters

For each candidate change, use the same representative queries and data, and compare these outcomes:

  • Query latency and buffer reads.
  • Recall or application-relevant result quality against exact search.
  • How many rows survive each filter.
  • Index memory footprint, build time, and maintenance cost.
  • Whether one tenant’s workload or filter distribution affects another’s results.

The documented defaults and feature set can vary by installed pgvector release. The guidance here reflects the project README on its moving master branch as accessed October 4, 2026; check the documentation for the release installed in your deployment before relying on a version-specific setting.

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

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.

Leave a Reply

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

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.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.