Files
supabase-vercel-tedd[bot] 36e370aa5c docs(ai): explain how hnsw.ef_search caps HNSW results and how to set it (#53997)
## Problem

The HNSW tuning section said only that a higher `ef_search` gives better
accuracy and slower queries. A reader whose query uses a `limit` above
`ef_search` gets fewer rows back. The docs didn't explain why, what the
range is, or how to change the setting.

Related to
[FDBKIN-12895](https://linear.app/supabase/issue/FDBKIN-12895/document-performance-trade-offs-of-pgvectors-hnsw-ef-search-parameter)
Closes
[DOCS-1800](https://linear.app/supabase/issue/DOCS-1800/explain-that-hnswef-search-caps-hnsw-results-and-how-to-set-it)

## Solution

The `ef_search` bullet on the "Going to production" guide now names the
`hnsw.ef_search` setting, its default, and its valid range. Plain
paragraphs after the list explain how it caps the rows an HNSW scan
returns and how to set it. They cover a session, one transaction, a
transaction-mode pooler, and a database function called through the Data
API. They also point to iterative index scans for returning more rows,
and don't repeat that explanation. The filtering section of the HNSW
indexes page now names `hnsw.ef_search` as the limit, so the two pages
agree.

## How to verify

1. Open
https://docs-git-tedd-docs-1800-supabase.vercel.app/docs/guides/ai/going-to-prod#hnsw-understanding-efconstruction--efsearch--and-m
and
https://docs-git-tedd-docs-1800-supabase.vercel.app/docs/guides/ai/vector-indexes/hnsw-indexes#filtering-with-hnsw-indexes.
2. The `ef_search` bullet states the `hnsw.ef_search` default (40) and
range (1 to 1,000), and stays one paragraph like the `m` and
`ef_construction` bullets.
3. A paragraph after the list says that without iterative index scans,
an HNSW index scan returns at most `ef_search` rows, even when the
query's `limit` is larger.
4. A SQL block shows a `set` statement and a `set local` statement
inside `begin` / `commit`. A second SQL block shows a database function
with a `set hnsw.ef_search = 100` clause.
5. The paragraph about setting the value links to "Transaction mode
limitations" and to "Querying a vector / embedding", and both links land
on those sections.
6. A paragraph links to "Filtering with HNSW indexes", and the link
lands on that section.
7. In "Filtering with HNSW indexes", the sentence about selective
filters names `hnsw.ef_search` as the limit on rows a scan returns, and
its link lands on the going-to-prod HNSW section.

## Checks

Ran `pnpm turbo run typecheck`, `pnpm turbo run lint`, and `pnpm exec
oxfmt --check` on the changed docs. Ran both SQL blocks in page order on
Postgres 18 with pgvector 0.8.1, against 20k random vectors with an HNSW
`vector_l2_ops` index and `vector` installed in the `extensions` schema.
At the default, `limit 100` returned 40 rows. With `set` or `set local
hnsw.ef_search = 100`, it returned 100 rows. The `set local` value reset
after `commit`, and `1001` was rejected as outside 1..1000. The function
with `set hnsw.ef_search = 100` returned 100 rows for `limit 200`, and
the session value stayed at 40. At `ef_search = 1000`, `limit 1500`
returned 1000 rows, and 1500 after `set hnsw.iterative_scan =
relaxed_order`. Docs tests skipped: they need Docker.

## Checklist

- [x] I have read the [Contributing
Guidelines](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] I have checked that the change works in the preview deployment

## Feedback for Tedd

To ask Tedd for a change to this PR, reply in Tedd's session on
[DOCS-1800](https://linear.app/supabase/issue/DOCS-1800/explain-that-hnswef-search-caps-hnsw-results-and-how-to-set-it).
Tedd doesn't read comments on this PR.

---------

Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com>
2026-11-24 20:02:50 -07:00
..