pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries
9+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries
@ 2025-04-14 19:34  "vitonsky (@vitonsky)" <noreply+vitonsky@github.com>
  0 siblings, 0 replies; 9+ messages in thread

From: vitonsky (@vitonsky) @ 2025-04-14 19:34 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

It looks i have the similar problem to https://github.com/pgvector/pgvector/issues/689
I did not found answer there, so i file a new issue.

I have partitioned table, every partition contains about 40m rows.

I trying to create index concurrently with `USING hnsw ((embedding::vector(768)) vector_cosine_ops) WITH (m = 16, ef_construction = 200)`

I've set options

```
SET LOCAL maintenance_work_mem = '40GB';
SET LOCAL max_parallel_maintenance_workers = 11;
```

I've got warnings quickly in start of process

```
NOTICE:  hnsw graph no longer fits into maintenance_work_mem after 570905 tuples
DETAIL:  Building will take significantly more time.
HINT:  Increase maintenance_work_mem to speed up builds.
```

Now left about 19 hours and current progress `SELECT phase, round(100.0 * blocks_done / nullif(blocks_total, 0), 1) AS "%" FROM pg_stat_progress_create_index;` command draw is 29.2%

Progress is stuck here at least for 8 hours.

I've checked issues here to find some help, but nothing really useful yet.

I have next questions
- How i can check what's the problem? How to debug pgvector?
- What's your recommendations about indexing?
- Is a pgvector suitable to serve a hundreds of millions or even a billions rows? Or i should use another solution for that?

Third question looks reasonable for me, since my observation is pgvector build index really long time, have problem with long time for vacuum, so database may become unmaintainable if will have large data.

All benchmarks i've seen and blog posts operates over small vectors (128-512 dimensions) and small data samples (few millions) on powerful hardware (sometimes even few terabytes of RAM).

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

* Re: [pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries
@ 2025-04-14 20:01  "ankane (@ankane)" <noreply+ankane@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: ankane (@ankane) @ 2025-04-14 20:01 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @vitonsky,

1. The slow build time is due to `hnsw graph no longer fits into maintenance_work_mem`. Try removing `LOCAL` from the `SET` commands (`LOCAL` only sets it for the current transaction, and if you're creating the index concurrently, it will be outside of a transaction). You'll also need to increase `max_parallel_workers` if you want to use 11 workers.
2. Using the default `ef_construction` of 64 will build faster.
3. Yes, it's suitable. I'd recommend using the `halfvec` type or binary quantization with re-ranking to reduce the index size.

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

* Re: [pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries
@ 2025-04-14 20:01  "ankane (@ankane)" <noreply+ankane@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: ankane (@ankane) @ 2025-04-14 20:01 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

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

* Re: [pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries
@ 2025-04-14 20:19  "vitonsky (@vitonsky)" <noreply+vitonsky@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: vitonsky (@vitonsky) @ 2025-04-14 20:19 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Ok that's good catch about `LOCAL`, i will try again, thank you.

Is it possible to debug current state to better understand what problem we have? It's scary perspective to start use pgvector and be unable to understand the bottleneck and tune it in future.

Also interesting is there some public info about use pgvector for large data-sets?

Currently i looking for solution and a search performance with pgvector indexes looks good for me, but it takes really long time to build index and as i understood i will have this problem every time i will try to vacuum database. Maybe you may share some cases where pgvector is used for large data processing

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

* Re: [pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries
@ 2025-04-14 21:18  "ankane (@ankane)" <noreply+ankane@github.com>
  7 siblings, 0 replies; 9+ messages in thread

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

In this case, pgvector reported the specific issue and how to address it.

```text
NOTICE:  hnsw graph no longer fits into maintenance_work_mem after 570905 tuples
DETAIL:  Building will take significantly more time.
HINT:  Increase maintenance_work_mem to speed up builds.
```

In addition to looking at indexing progress, you can also check `pg_stat_activity` to see how many workers are being used.

Sentry has a [good write-up](https://blog.sentry.io/how-sentry-decreased-issue-noise-with-ai/) on their approach.

One trick to speed up vacuuming is [mentioned here](https://github.com/pgvector/pgvector?tab=readme-ov-file#vacuuming). You can also use partitioning to create smaller indexes that be vacuumed independently.

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

* Re: [pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries
@ 2025-04-15 09:55  "vitonsky (@vitonsky)" <noreply+vitonsky@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: vitonsky (@vitonsky) @ 2025-04-15 09:55 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane i tried with no `LOCAL`

```
SET maintenance_work_mem = '80GB';
SET max_parallel_maintenance_workers = 11;
```

and i faced with this problem again. Progress is stuck on `57.6`. Now is 6 hours since last update of this value. It looks a progress will not changes anymore.

Last notifications is

```
NOTICE:  hnsw graph no longer fits into maintenance_work_mem after 22880331 tuples
DETAIL:  Building will take significantly more time.
HINT:  Increase maintenance_work_mem to speed up builds.
```

I run this command on server with next config if it does matter

```
fsync = off
full_page_writes = off
```

I can't increase RAM anymore since it is out of RAM budged for current DB.

---

Why progress may stuck?

According to notice it is expected that `Building will take significantly more time` but not "Building will dead-locked"

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

* Re: [pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries
@ 2025-04-15 14:36  "ankane (@ankane)" <noreply+ankane@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: ankane (@ankane) @ 2025-04-15 14:36 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

If you remove the rounding, you should see it progressing slowly (once the index is flushed to disk). I'd recommend using half-precision indexing or binary quantization so the index build fits in memory. Please use other resources for additional help with this.

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

* Re: [pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries
@ 2025-04-15 14:54  "vitonsky (@vitonsky)" <noreply+vitonsky@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: vitonsky (@vitonsky) @ 2025-04-15 14:54 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane current behaviour looks like a bug. Progress is dead-locked and it is still not clear why.

I report a bug to issues and I trying to figure out whats the problem.
I explain context and add information about my use case.

I got back only irrelevant recommendations how to build reduced index and your "Please use other resources for additional help with this".

Is this how pgvector handle bugs and contact with community?

If so, it would be fair to update description
```diff
- Open-source vector similarity search for Postgres 
+ Source-available vector similarity search for Postgres (we don't like you if you don't pay us)
```

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

* Re: [pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries
@ 2025-04-15 18:59  "vitonsky (@vitonsky)" <noreply+vitonsky@github.com>
  7 siblings, 0 replies; 9+ messages in thread

From: vitonsky (@vitonsky) @ 2025-04-15 18:59 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane 
> If you remove the rounding, you should see it progressing slowly (once the index is flushed to disk)

Index query in run already 17 hours. In first 4 hours index were reach 57.6%, printed notice and started write data on disk.

Now progress is still 57.6%. I tried to check progress with no rounding with `SELECT phase, blocks_done FROM pg_stat_progress_create_index;` and result is accordingly stuck on `304523`. No difference for last 3 hours.

The assumption from your quote has not been confirmed.

It is reasonable to expect any progress, at least 0.1% for 13 hours on hardware that processed 57.6% for 4 hours.

But current state is progress in stuck for 13 hours. I tried to run `sync` - nothing changed.

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


end of thread, other threads:[~2025-04-15 18:59 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-04-14 19:34 [pgvector/pgvector] issue #822: HNSW index creation is stuck on dozens millions entries "vitonsky (@vitonsky)" <noreply+vitonsky@github.com>
2025-04-14 20:01 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-04-14 20:01 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-04-14 20:19 ` "vitonsky (@vitonsky)" <noreply+vitonsky@github.com>
2025-04-14 21:18 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-04-15 09:55 ` "vitonsky (@vitonsky)" <noreply+vitonsky@github.com>
2025-04-15 14:36 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-04-15 14:54 ` "vitonsky (@vitonsky)" <noreply+vitonsky@github.com>
2025-04-15 18:59 ` "vitonsky (@vitonsky)" <noreply+vitonsky@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