From: jkatz (@jkatz) <noreply+jkatz@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #678: Iterative index scans
Date: Fri, 04 Oct 2024 00:49:36 +0000
Message-ID: <gh-pgvector-pgvector-678-c2392576311@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-678@github.com>
References: <gh-pgvector-pgvector-678@github.com>
It turned out I didn't enable streaming correctly on the above tests, but that's OK because streaming wouldn't have taken effect; I reran a few and had very similar results. So as mentioned somewhere, this is due to all the other performance and memory improvements targeted for v0.8 (thanks @ankane!)
That said, I did run some tests that did leverage streaming today. Specifically, I used the dataset in here https://github.com/pgvector/pgvector/issues/678#issuecomment-2381458610 along with VectorDBBench to test the impact of streaming on the following query:
```sql
SELECT i.id
FROM (
SELECT id, embedding <=> $2 AS distance
FROM table_name
ORDER BY binary_quantize(embedding)::bit(1536) <~> binary_quantize($2)
LIMIT $3) i
ORDER BY i.distance LIMIT $1"
```
where:
- `$1` - equivalent of `k`
- `$2` - equivalent of the query vector
- `$3` - I call this the "inner limit" but I would vary this to see the effects of streaming. Streaming takes effect when $3 > `hnsw.ef_search`
I tested the above query with a variety of different configurations for streaming mode, and am posting the most interesting results here. For this test with binary quantization (BQ), I wanted to see the behavior targeted a recall of 90% (+/- 0.005 in the BQ portions) and see the impact of iterative scans, attempting to find the ideal configuration. The results are below. I include the size of the index in the results. The configurations are the same as https://github.com/pgvector/pgvector/issues/678#issuecomment-2381458610, though I'll specifically call out the pgvector config:
### pgvector
- Index type: HNSW (vector_cosine_ops)
- `m`: `16`
- `ef_construction`: `256`
- `k` (`$1`): 10
- `hnsw.streaming`: `on` (strict)
In the below results, `$3` is the value of `hnsw.ef_search` unless explicitly stated in the `inner limit` column:
Here's the Markdown table:
| version | config | ef_search | inner limit | recall | QPS (singe client) | QPS (max) | single client p99 (ms) | Max QPS p99 (ms) | Index size (GiB) |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 0.7.4 | flat | 40 | - | 0.934 | 473 | 19,538 | 7.0 | 5.3 | 38.15 |
| 0.8.0 (1a1221f) | flat | 40 | - | 0.928 | 503 | 22,235 | 6.9 | 4.7 | 38.15 |
| 0.7.4 | halfvec | 40 | - | 0.927 | 465 | 21,108 | 7.0 | 5.7 | 19.07 |
| 0.8.0 (8b9333d) | halfvec | 40 | - | 0.925 | 501 | 23,661 | 6.4 | 4.4 | 19.07 |
| 0.7.4 | bq-rerank | 80 | - | 0.901 | 326 | 15,017 | 7.8 | 12.5 | 2.34 |
| 0.8.0 (8b9333d) | bq-rerank | 80 | - | 0.899 | 328 | 16,321 | 8.5 | 8.4 | 2.34 |
| 0.8.0 (8b9333d) | bq-rerank | 10 | 80 | 0.895 | 295 | 14,633 | 8.9 | 9.3 | 2.34 |
| 0.8.0 (8b9333d) | bq-rerank | 40 | 80 | 0.898 | 299 | 14,841 | 9.0 | 9.3 | 2.34 |
| 0.8.0 (8b9333d) | bq-rerank | 60 | 70 | 0.901 | 232 | 11,169 | 11.0 | 12.3 | 2.34 |
## Analysis
Hooray for the performance bump in a heads up comparison without streaming :smile: In my other tests, I did see ~10% boost at equivalent recalls.
The streaming results are interesting -- particularly because I can set a low value for `hnsw.ef_search` and still get comparable (though lower) performance across the board at equivalent recall. I do think the better tests would be with filters, but this at least provides a notion that even for BQ for this dataset/embedding model, it makes more sense to tweak `hnsw.ef_search` to find your target recall at peak performance instead of leaving `hnsw.ef_search` to a low value and increasing the inner limit.