pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #642: Search with IVF and HNSW indexes
5+ messages / 3 participants
[nested] [flat]

* [pgvector/pgvector] issue #642: Search with IVF and HNSW indexes
@ 2024-08-14 15:19  "xcu (@xcu)" <noreply+xcu@github.com>
  0 siblings, 0 replies; 5+ messages in thread

From: xcu (@xcu) @ 2024-08-14 15:19 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi folks,

if I have a table both with IVF and HNSW indexes created, which one will be used at query time? Is there a way to specify the planner which one we want to use?

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

* Re: [pgvector/pgvector] issue #642: Search with IVF and HNSW indexes
@ 2024-08-14 16:17  "jkatz (@jkatz)" <noreply+jkatz@github.com>
  3 siblings, 0 replies; 5+ messages in thread

From: jkatz (@jkatz) @ 2024-08-14 16:17 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@xcu It depends on what PostgreSQL determines is the cost of the scan, which involves many factors (dataset size, selectivity, index search parameters).

If you want to force a particular index to be scanned, you would either want to use a single index, or you can use an extension like [https://github.com/ossc-db/pg_hint_plan](https://github.com/ossc-db/pg_hint_plan) to provide hints.

What would be the use case to have both index types on the same table simultaneously?

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

* Re: [pgvector/pgvector] issue #642: Search with IVF and HNSW indexes
@ 2024-08-15 15:24  "xcu (@xcu)" <noreply+xcu@github.com>
  3 siblings, 0 replies; 5+ messages in thread

From: xcu (@xcu) @ 2024-08-15 15:24 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@jkatz I'm managing a fairly big postgres instance with +50M embeddings and IVF index. I will likely have to switch to HNSW in the near future, but I want to do the switch without downtime.
To maintain performance I need to keep the full index in memory, and having both IVF and HNSW at the same time is not an option due to high costs (the host already has 350GB of RAM just with IVF).
Since the table with the vectors is partitioned I'd like to switch to the new HNSW partition by partition to avoid downtime, as bringing just one partition index to memory is very fast. Partitions have 100k vectors each, so loading the index in one of them takes very little time.

Initially I thought it would be great if I could just create the HNSW index without using it, then switch from IVF to HNSW for each partition. But if I cannot control when the switch from IVF to HNSW is done in memory perhaps I should do something like this for each partitioned table?
1- create hnsw index.
2- remove IVF index.
3- switch to new partition.

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

* Re: [pgvector/pgvector] issue #642: Search with IVF and HNSW indexes
@ 2024-08-17 21:46  "ankane (@ankane)" <noreply+ankane@github.com>
  3 siblings, 0 replies; 5+ messages in thread

From: ankane (@ankane) @ 2024-08-17 21:46 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @xcu, I'd expect that approach to work as long as the IVFFlat index isn't on the parent table (otherwise, you won't be able to drop them independently). In any case, I'd test this with an offline instance first (also, if you're doing any filtering in the queries, note that you may see differences between HNSW and IVFFlat).

As @jkatz mentioned, you can use `pg_hint_plan` for more control over which index is used.

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

* Re: [pgvector/pgvector] issue #642: Search with IVF and HNSW indexes
@ 2024-08-17 21:46  "ankane (@ankane)" <noreply+ankane@github.com>
  3 siblings, 0 replies; 5+ messages in thread

From: ankane (@ankane) @ 2024-08-17 21:46 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

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


end of thread, other threads:[~2024-08-17 21:46 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-08-14 15:19 [pgvector/pgvector] issue #642: Search with IVF and HNSW indexes "xcu (@xcu)" <noreply+xcu@github.com>
2024-08-14 16:17 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-08-15 15:24 ` "xcu (@xcu)" <noreply+xcu@github.com>
2024-08-17 21:46 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-08-17 21:46 ` "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