From: bantmen (@bantmen) <noreply+bantmen@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #661: IVFFLAT QPS too low
Date: Mon, 26 Aug 2024 06:13:46 +0000
Message-ID: <gh-pgvector-pgvector-661@github.com> (raw)
I am using IVFFLAT for 1200 dimensional embeddings of vector type. I have 20 million rows.
The query that is slow takes a user provided vector and finds the top 100 matching vectors. There are 4200 lists and 10 probes. The query **takes 30 seconds** when it's cold and 100ms if it's a repeat query. I confirmed with EXPLAIN that the index is being used.
The issue is very slow IO. All of the query time is spent reading in the blocks that are buffer misses during the `Index Scan` operation. The throughput is about 6 mb/s. The hardware configuration is r5.2xlarge from AWS RDS.
Here is an example `EXPLAIN (ANALYZE, BUFFERS)` result:
```
Limit (cost=106671.48..106680.48 rows=800 width=57) (actual time=11957.952..13229.665 rows=800 loops=1)
Buffers: shared hit=17539 read=16834
I/O Timings: shared/local read=13154.684
-> Index Scan using table_name_idx on table_name
Buffers: shared hit=17539 read=16834
I/O Timings: shared/local read=13154.684
Planning:
Buffers: shared hit=104
Planning Time: 1.011 ms
Execution Time: 13230.135 ms
```
Given that the IO should be on SSD, I am puzzled at the extremely low throughput.
What am I doing wrong? Should I be using HNSW? Is it a huge performacne issue that most of my rows are stored as TOAST?