How to calculate amount of RAM required for serving X N-dimensional vectors with pgvector (HNSW)?

331 views Asked by At

I'm trying to determine a function f(x, n) where x is the number of vectors and n is the number of vector dimensions such that for any x, n, f(x, n) is greater that the required amount of RAM to serve these vectors via a pgvector database with HNSW index.

I did some googling, but

  1. I can't find a formula for index size.
  2. I see that some databases (like Qdrant) can use memory-mapped files for both vectors and indices to reduce RAM consumption, but I don't see such options for pgvector. Does it require to store the whole HNSW index in memory? If not, how to determine the required amount of memory?

This article says:

The third trade-off for HNSW indexes is that they are sizable — the index for 1M rows of AI embeddings can be 8GB or larger. For performance reasons, you’ll want all of this index in memory.

although in this article Qdrant that uses the same HNSW indexing algorithm is said to only require ~1GB RAM for serving 1 million vectors (without memory mapping). Why such difference?

0

There are 0 answers