pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #912: Question about hnsw result set size
6+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #912: Question about hnsw result set size
@ 2025-10-16 20:02 "chmaurer (@chmaurer)" <noreply+chmaurer@github.com>
  0 siblings, 0 replies; 6+ messages in thread

From: chmaurer (@chmaurer) @ 2025-10-16 20:02 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

I have been playing around a few days and I cannot wrap my head around that issue. I already found the issue/section in the README about iterative scans (https://github.com/pgvector/pgvector/issues/776) as well as feature requests to have more than 1000 results on hsnw's ef_search paramter (https://github.com/pgvector/pgvector/issues/865). Anyhow, I still don't know how to proceed on this:

- I have an application which strictly requires us to deliver back 25.000 rows from the database. Reasons are involved, but we need to do a cosine search and return 25k candidates.
- I tried with hnsw but ran into the limitation that ef_search can only return 1000 rows. 
- I tried with ivfflat, but playing with the lists of the index (currently 1000, because I have 1.3 mio rows), the ivfflat.probes (currently 100), and ivfflat.max_probes (150) did not change a lot. I always seem to get a "random" number of results.

The query I try to execute is `SELECT id, vector, payload
                FROM boardid_data
                ORDER BY (vector <=> %s) ASC
                    LIMIT %s;`

where I pass in a vector as string and the limit parameter (25000 obviously). The index performs nicely (if it is not used, retrieval is above 1 minute, with the index <= 3 sec), but the number of candidates varies. 

I have also tried to `SET ivfflat.iterative_scan = relaxed_order;`, but this didn't help either. Also, I have created the index when 1.3 mio rows were filled. Is there any way to constantly get ivfflat index to return 25k candidates?

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [pgvector/pgvector] issue #912: Question about hnsw result set size
@ 2025-10-16 20:57 ` "ankane (@ankane)" <noreply+ankane@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: ankane (@ankane) @ 2025-10-16 20:57 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @chmaurer, I'd expect an IVFFlat index to always return 25k rows with those settings (even without iterative scanning).

1. What's the output of `EXPLAIN (ANALYZE)`?
2. Does recreating the index fix it?

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [pgvector/pgvector] issue #912: Question about hnsw result set size
@ 2025-10-16 21:04 ` "ankane (@ankane)" <noreply+ankane@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: ankane (@ankane) @ 2025-10-16 21:04 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

You should also be able to get HNSW to return 25k rows by tweaking a few settings (even without changing `hnsw.ef_search`):

```sql
SET hnsw.iterative_scan = relaxed_order;
SET hnsw.max_scan_tuples = 30000;
SET hnsw.scan_mem_multiplier = 2; -- set higher if needed
```

Feel free to share the output of `EXPLAIN (ANALYZE, SETTINGS)` if that's not the case.

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [pgvector/pgvector] issue #912: Question about hnsw result set size
@ 2025-10-18 10:57 ` "chmaurer (@chmaurer)" <noreply+chmaurer@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: chmaurer (@chmaurer) @ 2025-10-18 10:57 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @ankane, many thanks for your response, sorry I am just getting back to you today. 

Well, I think we found the issue an you're right - we now manage to return 25k rows constantly. I am pretty new to PostgreSQL as such and I needed a hint from a colleague, because I misread the documentation (https://github.com/pgvector/pgvector?tab=readme-ov-file#query-options). I thought that setting the parameters mentioned by you and me above is *always* on the database level and if `LOCAL` is used, it's on the transaction level. I now have learned that the parameters are always set on the session level, hence my query was run without the intended settings (I did the settings with my database query window, ran the performance tests from my IDE).

We now (for our tests) issue the set commands before the query, that fixed the issue. Many thanks for your help - I think we can close the issue.

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [pgvector/pgvector] issue #912: Question about hnsw result set size
@ 2025-10-18 10:58 ` "chmaurer (@chmaurer)" <noreply+chmaurer@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: chmaurer (@chmaurer) @ 2025-10-18 10:58 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@chmaurer closed this.

^ permalink  raw  [nested|flat] 6+ messages in thread

* Re: [pgvector/pgvector] issue #912: Question about hnsw result set size
@ 2025-10-18 17:24 ` "ankane (@ankane)" <noreply+ankane@github.com>
  4 siblings, 0 replies; 6+ messages in thread

From: ankane (@ankane) @ 2025-10-18 17:24 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Great, thanks for following up.

^ permalink  raw  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2025-10-18 17:24 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-10-16 20:02 [pgvector/pgvector] issue #912: Question about hnsw result set size "chmaurer (@chmaurer)" <noreply+chmaurer@github.com>
2025-10-16 20:57 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-10-16 21:04 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-10-18 10:57 ` "chmaurer (@chmaurer)" <noreply+chmaurer@github.com>
2025-10-18 10:58 ` "chmaurer (@chmaurer)" <noreply+chmaurer@github.com>
2025-10-18 17:24 ` "ankane (@ankane)" <noreply+ankane@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox