From: developerayuva (@developerayuva) <noreply+developerayuva@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #844: Questions on HNSW graph memory usage and size estimation
Date: Sun, 25 May 2025 18:07:41 +0000
Message-ID: <gh-pgvector-pgvector-844-c2907981644@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-844@github.com>
References: <gh-pgvector-pgvector-844@github.com>
> I typically do sizeof(# vectors) * 1.3 - where the sizeof(vector) is 8 + dims * 4.
Thanks for the explanation!
I tried estimating the HNSW index size using the formula you shared
Here's my setup:
```
vector10m=> \d+ vector_items
Table "public.vector_items"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
-----------+-----------+-----------+----------+------------------------------------------+----------+-------------+--------------+-------------
id | integer | | not null | nextval('vector_items_id_seq'::regclass) | plain | | |
embedding | vector(5) | | | | external | | |
Indexes:
"vector_items_pkey" PRIMARY KEY, btree (id)
"vector_items_embedding_idx" hnsw (embedding vector_l2_ops) WITH (m='16', ef_construction='64')
Access method: heap
vector10m=> select count(*) from vector_items;
count
----------
10000000
(1 row)
vector10m=> SELECT pg_size_pretty(pg_relation_size('vector_items_embedding_idx'));
pg_size_pretty
----------------
3114 MB
(1 row)
vector10m=> show maintenance_work_mem ;
maintenance_work_mem
----------------------
4028MB
(1 row)
```
Based on the formula, I expected:
`10000000 * (8 + (5 * 4)) * 1.3 = 364000000 Bytes = 364 MB `
However, the actual index size is 3114 MB, which is much higher.
Am I missing some additional components or overhead in the index that contribute to this size?
> You have to call pg_relation_size on the name of the index.
So, is the final index size (from `pg_relation_size`) the same as the size of the HNSW graph built in memory during index creation?