From: schuemie (@schuemie) <noreply+schuemie@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #500: Index Build Time Does Not Improve as Expected When Changing "Workers"
Date: Tue, 24 Sep 2024 06:03:47 +0000
Message-ID: <gh-pgvector-pgvector-500-c2370265830@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-500@github.com>
References: <gh-pgvector-pgvector-500@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:

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)?