pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
32+ messages / 5 participants
[nested] [flat]

* [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-03-22 23:23 "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
  0 siblings, 0 replies; 32+ messages in thread

From: iamsabhoho (@iamsabhoho) @ 2024-03-22 23:23 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hello, 

I'm Sabrina, a data scientist at GSI Technology. I've been working on a pgvector benchmarking project on deep-1B dataset. 

The documentation states that I can improve index build time by changing the parameters **max_parallel_maintenance_workers** and **max_parallel_workers**. 

Unfortunately, if I increase the values of the parameters beyond 10, I do not see an improvement. We tested with 1M records of deep-1B and here are some results: 
| number of workers | index build time in seconds |
| ----------- | ----------- |
| default | 4041 |
| 10 | 2043 |
| 20 | 2090 |

I am using the following hardware:
- Intel(R) Xeon(R) Gold
- 104 cores

Here are the loaded extensions:
| Name   | Version |   Schema   |                     Description                   |   
| ----------- | ----------- |  ----------- | ----------- |
| plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language | 
| vector  | 0.6.1   | public     | vector data type and ivfflat and hnsw access methods |

Should I expect to see better performance as I increase the value of workers? Thank you!

I am happy to provide my code or any additional machine information needed. 

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-03-22 23:45 ` "ankane (@ankane)" <noreply+ankane@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: ankane (@ankane) @ 2024-03-22 23:45 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @iamsabhoho, pgvector 0.6.2 reduces lock contention for HNSW builds with a large number of parallel workers, so I'd recommend trying that. Also, the build times look very slow compared to previous benchmarks (https://github.com/pgvector/pgvector/issues/409), so I'd double check that `maintenance_work_mem` ([docs](https://github.com/pgvector/pgvector?tab=readme-ov-file#index-build-time)) and other settings like `shared_buffers` ([docs](https://github.com/pgvector/pgvector?tab=readme-ov-file#tuning)) are set correctly. With only 1M records, it's possible you won't see much difference with more than 10 workers.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-03-23 00:23 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: iamsabhoho (@iamsabhoho) @ 2024-03-23 00:23 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @ankane, 
Thanks for the fast response! I couldn't find `shared_buffers` with the link provided. Could you recommend a setting for me to try it out? Thanks again! 

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-03-23 00:35 ` "ankane (@ankane)" <noreply+ankane@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: ankane (@ankane) @ 2024-03-23 00:35 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

`shared_buffers` should typically be 25% of your memory.

Edit: Also, be sure the restart the Postgres server after updating.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-03-25 21:22 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: iamsabhoho (@iamsabhoho) @ 2024-03-25 21:22 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane thanks for the tips! We re-ran the experiments based on your suggestions. The build time matches your 1M benchmark closely. As you mentioned, adding more workers does not improve the time linearly. 

![Screenshot 2024-03-25 at 2 18 38 PM](https://github.com/pgvector/pgvector/assets/19927448/71649e85-7196-411a-aee8-dae808e215f4)

How do you suggest we increase the worker memory as we build indexes up to 1B records? Thank you! 

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-03-25 21:43 ` "ankane (@ankane)" <noreply+ankane@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: ankane (@ankane) @ 2024-03-25 21:43 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

If you set `maintenance_work_mem` to a lower value like 100MB, there will be a notice that shows how many tuples fit into that much memory.

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

From that, you can extrapolate roughly how much memory it would take to fit the entire graph (and set `maintenance_work_mem` above that if possible).

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-03-25 23:15 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: iamsabhoho (@iamsabhoho) @ 2024-03-25 23:15 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

We are using Python library to interact with PostgreSQL, is there any way to get those messages mentioned above? thanks! 

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-03-25 23:23 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: jkatz (@jkatz) @ 2024-03-25 23:23 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@iamsabhoho Those messages will be in the server logs.

FWIW, I've done and worked with folks who have done builds of 1B indexes with pgvector (particularly with 0.6.2) with a HNSW index. I've used datasets with 128 dimensions, and the build time would be somewhere in the 2-3 day range.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-03-25 23:29 ` "ankane (@ankane)" <noreply+ankane@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: ankane (@ankane) @ 2024-03-25 23:29 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Getting messages on the client will depend on the library. For psycopg 3, you can use:

```python
def log_notice(diag):
    print(f"{diag.severity}:  {diag.message_primary}")

conn.add_notice_handler(log_notice)
```

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-03-26 23:25 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: iamsabhoho (@iamsabhoho) @ 2024-03-26 23:25 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Thanks for the help! We will update on the benchmarking results as we get them in the next few days. 

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-04-03 23:41 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: iamsabhoho (@iamsabhoho) @ 2024-04-03 23:41 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @ankane @jkatz, 

I've finished the benchmarks up to 100M now. Here are the results: 

![pgvector_hnswlib_gxl_index_build_time_total](https://github.com/pgvector/pgvector/assets/19927448/a7d08474-f242-4162-b3b7-6d4c6c62f2e7)

I will continue benchmarking till 1B and share the results here! 

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-04-04 06:01 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: jkatz (@jkatz) @ 2024-04-04 06:01 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@iamsabhoho Thanks! That seems a bit slow to me; I'm able to build a m=16, ef_construction=256 index for 1B 128-dim vectors in about 60 hours with 64 cores. Which version of pgvector are you using? Also, for the `hnswlib` and `gxl` tests (can you please share a reference to gxl?), do those tests also flush the data to disk? Thanks!

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-04-04 06:09 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: jkatz (@jkatz) @ 2024-04-04 06:09 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Just for a quick comparison, I'm running the DEEP1B test from ANN Benchmark (~10MM 96-dim vectors) from d7354a86a8 -- with m=16, ef_construction=128 on a r7gd.16xl (64 vCPU) and writing to the local NVMe, the index build in about 5 minutes. Using a linear extrapolation (which at least at this scale is not too far off), this would take about 50min to run in the 100MM case.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-04-04 21:04 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: iamsabhoho (@iamsabhoho) @ 2024-04-04 21:04 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @jkatz , 

It looks like a significant portion of time is spent inserting the vectors into the table, 20-30%.  

![pgvector_insert_index_build](https://github.com/pgvector/pgvector/assets/19927448/cd828ea0-9007-4061-992f-b24dee6a26f9)

Is there a way to optimize that?  Also, can you share your pgvector parameters for your experiment?  As for GXL, it's an algorithm my company works on.  We'll have a blog on it in the near future. Thank you! 

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-04-04 21:21 ` "ankane (@ankane)" <noreply+ankane@github.com>
  30 siblings, 0 replies; 32+ messages in thread

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

Hi @iamsabhoho, check out [this example](https://github.com/pgvector/pgvector-python/blob/master/examples/bulk_loading.py) for bulk loading. The build times still seem pretty slow, so I don't think the setup is optimized.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-04-04 22:05 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: iamsabhoho (@iamsabhoho) @ 2024-04-04 22:05 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@jkatz we will rerun on a machine with an NVMe drive and report back here. Thanks! 

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-04-04 22:13 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: jkatz (@jkatz) @ 2024-04-04 22:13 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

To be pedantic - the example that @ankane references using the binary mode with COPY - this should significantly speed up the load as you won't have to convert from binary to text to binary.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-04-12 17:45 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: iamsabhoho (@iamsabhoho) @ 2024-04-12 17:45 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @jkatz @ankane,

![pgvector_index_build_only](https://github.com/pgvector/pgvector/assets/19927448/ce629c30-4bd8-4d0a-afe1-96f190550ce4)

We've integrated all the optimizations suggested, please see the subtitle above. The plot is only index build time, we will update the plot to include the bulk insert of vectors later. This plot uses the latest 0.6.2 pgvector extension, which speeds up the index build time significantly. We've also tried running in a psql console and the pgvector message helped with the worker memory optimization. 

If there is any other optimizations I can try it out that would also be great! Thanks again! 


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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-04-15 23:57 ` "phobrain (@phobrain)" <noreply+phobrain@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: phobrain (@phobrain) @ 2024-04-15 23:57 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Could the write speeds of the NVMe vary enough to be worth reporting? Could writing dump files and loading them add speed? It benchmarked better than inserts for me in pre-pgvector days on lesser hardware for an O(N^2) load that pgvector has made vestigial. It still seems better with a 20-thread i9 and nvme.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-04-16 00:52 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: jkatz (@jkatz) @ 2024-04-16 00:52 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@iamsabhoho Glad the results are improving. A few more thoughts:

* I looked up your process and it supports 26 cores / 52 threads. I don't know how busy the machien is, but you can set `max_parallel_maintenance_workers` higher (e.g. 32)
* The unreleased pgvector 0.7.0 is adding support for casting to a 2-byte float -- however for the DEEP1B dataset, I don't believe you'll see much gains (at least based on the [SIFT128 test](https://jkatz05.com/post/postgres/pgvector-scalar-binary-quantization/))

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-05-01 22:02 ` "ankane (@ankane)" <noreply+ankane@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: ankane (@ankane) @ 2024-05-01 22:02 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-05-01 22:02 ` "ankane (@ankane)" <noreply+ankane@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: ankane (@ankane) @ 2024-05-01 22:02 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Cleaning up issues, but feel free to share if there are more results.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-09-24 06:03 ` "schuemie (@schuemie)" <noreply+schuemie@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: schuemie (@schuemie) @ 2024-09-24 06:03 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Just wanted to leave these results somewhere: I have 37 million vectors (PubMed), each of 768 dimensions (Snowflake Arctic M 1.5). I've loaded them as `halfvec`.  I know from my development environment that I need 80GB of RAM to build the HSNW index. However, I don't have that amount of memory in a second environment (and no way to copy the index). There, I'm restricted to roughly 8GB of RAM, which I provide to a single worker:
```sql
SET maintenance_work_mem = '8GB'
SET max_parallel_maintenance_workers = 0
CREATE INDEX ON public.vectors_snowflake_arctic_m USING hnsw (embedding halfvec_cosine_ops)
```
I've plotted progress over time:

![pgVectorIndexing](https://github.com/user-attachments/assets/fa574fcd-99ad-464f-a2c8-ea995650f90a)

As you can see, after you run out of memory ('*NOTICE:  hnsw graph no longer fits into maintenance_work_mem after 3707009 tuples*`), which is at 10%, progress slows down significantly. Not only that, it progressively becomes slower over time, meaning it will likely never finish. I'll switch to IVFFlat, but that is slow to search and has lower accuracy. 

It would be great if there was some way to create HSNW indices without the large memory requirements. Maybe split the index into *n* parts that fit in memory, and then when searching under the hood perform *n* searches and combine them (so for me that would be 10x slower searches but equal accuracy)?

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-09-24 07:02 ` "phobrain (@phobrain)" <noreply+phobrain@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: phobrain (@phobrain) @ 2024-09-24 07:02 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Could you use memory mapping on a file? 

Bill

--

Phobrain.com 

On 2024-09-23 23:04, Martijn Schuemie wrote:

> Just wanted to leave these results somewhere: I have 37 million vectors (PubMed), each of 768 dimensions (Snowflake Arctic M 1.5). I've loaded them as halfvec. I know from my development environment that I need 80GB of RAM to build the HSNW index. However, I don't have that amount of memory in a second environment (and no way to copy the index). There, I'm restricted to roughly 8GB of RAM, which I provide to a single worker:
> 
> SET maintenance_work_mem = '8GB'
> SET max_parallel_maintenance_workers = 0
> CREATE INDEX ON public.vectors_snowflake_arctic_m USING hnsw (embedding halfvec_cosine_ops)
> 
> I've plotted progress over time: 
> 
> pgVectorIndexing.png (view on web) [1] 
> 
> As you can see, after you run out of memory ('_NOTICE: hnsw graph no longer fits into maintenance_work_mem after 3707009 tuples_`), which is at 10%, progress slows down significantly. Not only that, it progressively becomes slower over time, meaning it will likely never finish. I'll switch to IVFFlat, but that is slow to search and has lower accuracy. 
> 
> It would be great if there was some way to create HSNW indices without the large memory requirements. Maybe split the index into _n_ parts that fit in memory, and then when searching under the hood perform _n_ searches and combine them (so for me that would be 10x slower searches but equal accuracy)? 
> 
> --
> Reply to this email directly, view it on GitHub [2], or unsubscribe [3].
> You are receiving this because you commented.Message ID: ***@***.***>
 

Links:
------
[1]
https://github.com/user-attachments/assets/fa574fcd-99ad-464f-a2c8-ea995650f90a
[2]
https://github.com/pgvector/pgvector/issues/500#issuecomment-2370265830
[3]
https://github.com/notifications/unsubscribe-auth/AEVHVGLGWSUBWKHLYKUBK3TZYD6FRAVCNFSM6AAAAABFED2OXS...

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-09-24 07:48 ` "ankane (@ankane)" <noreply+ankane@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: ankane (@ankane) @ 2024-09-24 07:48 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @schuemie, if you partition the table, it'll create a separate index for each partition. Also, if you increase `max_parallel_maintenance_workers`, you'll likely see faster build times.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-09-24 11:14 ` "schuemie (@schuemie)" <noreply+schuemie@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: schuemie (@schuemie) @ 2024-09-24 11:14 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Thanks @ankane! It sounds like table partitioning is what I was looking for, I'll give it a try.

I don't think I can increase `max_parallel_maintenance_workers`, because each will require its own RAM. My current strategy is to allocate all available memory to 1 worker, which as far as I can see is more performant than splitting the memory over multiple workers (obviously only when memory constrained).

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-09-24 12:20 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: jkatz (@jkatz) @ 2024-09-24 12:20 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

> I don't think I can increase max_parallel_maintenance_workers, because each will require its own RAM.

The parallel workers are sharing memory available in the `maintenance_work_mem` pool. Using more workers on index build can significantly improve index build time (sharing a slide from one more my talks on this):

<img width="1025" alt="Screenshot 2024-09-24 at 8 20 05 AM" src="https://github.com/user-attachments/assets/57f7ca56-26a8-401a-9a34-adecd07dc16f";

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-09-24 12:34 ` "schuemie (@schuemie)" <noreply+schuemie@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: schuemie (@schuemie) @ 2024-09-24 12:34 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Thanks @jkatz ! I totally misunderstood. I think together with partitioning, using parallel workers should bring an HSNW index within my reach.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-09-24 14:03 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: jkatz (@jkatz) @ 2024-09-24 14:03 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@schuemie FWIW I've used it on billion-size datasets. For speed, you do need to ensure you have enough `maintenance_work_mem` for the in-memory build, otherwise it will spill to disk and slow down.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-09-24 14:11 ` "schuemie (@schuemie)" <noreply+schuemie@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: schuemie (@schuemie) @ 2024-09-24 14:11 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@jkatz : Would you mind sharing how much memory you used? I'm having a hard time thinking of what a reasonable amount of memory is. I'm using cloud computing, so I could ask to scale the server up, but I would need some guidance on what to ask for.

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-09-24 14:26 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: jkatz (@jkatz) @ 2024-09-24 14:26 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@schuemie It depends on the dataset, and if you're indexing the full vectors (no quantization), you'll need roughly 1.3x the size of the dataset of memory. So using the above dataset and very rough math (not accounting for page size here, which adds a bit more), you'd ~137GiB to hold the full set in memory:

```
SELECT (1.3 * (37000000::numeric * (768 * 4 + 8))) / 1024^3;
```

Thus, as Andrew suggests, partitioning the data would help reduce the overall amount of memory required. Given you need memory for other database operations and your shared buffers (I'll assume your shared buffers are set to `20GB`), let's say you set `maintenace_work_mem` to `20GB` - you can then build the dataset over 8 partitions while keeping the index in memory (again, rough math).

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

* Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
@ 2024-09-25 13:05 ` "schuemie (@schuemie)" <noreply+schuemie@github.com>
  30 siblings, 0 replies; 32+ messages in thread

From: schuemie (@schuemie) @ 2024-09-25 13:05 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Just reporting back: I ended up using 8 partitions, 10GB of `maintenance_work_mem`, and 4 `max_parallel_maintenance_workers`. With that setup, it took only 6 hours to create the index. Thanks all for your help!

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


end of thread, other threads:[~2024-09-25 13:05 UTC | newest]

Thread overview: 32+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22 23:23 [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers" "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
2024-03-22 23:45 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-03-23 00:23 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
2024-03-23 00:35 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-03-25 21:22 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
2024-03-25 21:43 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-03-25 23:15 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
2024-03-25 23:23 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-03-25 23:29 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-03-26 23:25 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
2024-04-03 23:41 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
2024-04-04 06:01 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-04-04 06:09 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-04-04 21:04 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
2024-04-04 21:21 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-04-04 22:05 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
2024-04-04 22:13 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-04-12 17:45 ` "iamsabhoho (@iamsabhoho)" <noreply+iamsabhoho@github.com>
2024-04-15 23:57 ` "phobrain (@phobrain)" <noreply+phobrain@github.com>
2024-04-16 00:52 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-05-01 22:02 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-05-01 22:02 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-09-24 06:03 ` "schuemie (@schuemie)" <noreply+schuemie@github.com>
2024-09-24 07:02 ` "phobrain (@phobrain)" <noreply+phobrain@github.com>
2024-09-24 07:48 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-09-24 11:14 ` "schuemie (@schuemie)" <noreply+schuemie@github.com>
2024-09-24 12:20 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-09-24 12:34 ` "schuemie (@schuemie)" <noreply+schuemie@github.com>
2024-09-24 14:03 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-09-24 14:11 ` "schuemie (@schuemie)" <noreply+schuemie@github.com>
2024-09-24 14:26 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2024-09-25 13:05 ` "schuemie (@schuemie)" <noreply+schuemie@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