pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #967: `halfvec` table + index shows unexpected QPS degradation and slower index build vs `vector`/flat in HNSW
8+ messages / 3 participants
[nested] [flat]

* [pgvector/pgvector] issue #967: `halfvec` table + index shows unexpected QPS degradation and slower index build vs `vector`/flat in HNSW
@ 2026-03-09 10:08 "R3gardless (@R3gardless)" <noreply+R3gardless@github.com>
  0 siblings, 0 replies; 8+ messages in thread

From: R3gardless (@R3gardless) @ 2026-03-09 10:08 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

HI! I'm currently researching performance anaysis using [VectorDBBench](https://github.com/zilliztech/VectorDBBench).

**Environment**

- **Dataset** : Cohere-10M (10M vectors, 768 dim, COSINE)
- **CPU** : 48 cores
- **Memory** : 64 GB
- **HNSW params** : m = 16, ef_construction = 64
- **pgvector version** : 0.8.0
- **postgresql version** : 15.13

**Configuration Tested**

  | Config | Table Type | Index Type | Index Size |
  |--------|-----------|------------|------------|
  | vec/flat | `vector` | `vec (no quantization)` | 38 GB |
  | vec/halfvec | `vector` | `halfvec` | 19 GB |
  | halfvec/halfvec | `halfvec` | `halfvec` | 19 GB |

  ### Observation 1: QPS Degradation

  At `maintenance_work_mem=30GB`, both halfvec configurations show consistently lower QPS than vec/flat across all `ef_search` values.

  | ef_search | vec/flat | vec/halfvec | halfvec/halfvec |
  |-----------|---------|-------------|-----------------|
  | 40 | 2,349 | 1,717 (**-27%**) | 1,891 (**-19%**) |
  | 80 | 1,835 | 1,312 (**-29%**) | 1,478 (**-19%**) |
  | 220 | 1,191 | 1,065 (**-11%**) | 1,147 (**-4%**) |

  I can understand that `vec/halfvec` needs extra overhead for float32→float16 type conversion at query time. However, **`halfvec/halfvec` — where no type conversion should be needed — still shows ~19% lower QPS**. This is the part I don't fully understand.

  ### Observation 2: Index Build Time Inversion at Low Memory

  At low `maintenance_work_mem`, the halfvec index build (optimize phase) is significantly **slower** than vec/flat, despite the index being half the size (19 GB vs 38 GB).

  | maintenance_work_mem | vec/flat | vec/halfvec | halfvec/halfvec |
  |---------------------|---------|-------------|-----------------|
  | 512MB | 130 min | 366 min (**2.8x**) | 366 min (**2.8x**) |
  | 1GB | 130 min | 358 min (**2.8x**) | 358 min (**2.8x**) |
  | 10GB | 132 min | 221 min (1.7x) | 220 min (1.7x) |
  | 20GB | 137 min | 83 min | 81 min |
  | 30GB | 110 min | 73 min | 73 min |

  At 20GB+ `maintenance_work_mem`, halfvec builds faster as expected (smaller index fits in memory). But at 512MB–1GB, it's **2.8x slower** — this seems counterintuitive for a half-sized index.

  ### Benchmark Results

<img width="2676" height="1032" alt="Image" src="https://github.com/user-attachments/assets/11d27229-97bd-41ce-b222-2e6a1e27e08d"; />

  ### Questions

  1. Why does `halfvec/halfvec` show ~19% lower QPS than `vec/flat`? Since both table and index use halfvec natively, there should be no type conversion overhead. Is this possibly related to halfvec distance computation being less optimized (e.g. SIMD) compared to
  float32?

  2. Why is the halfvec index build dramatically slower at low `maintenance_work_mem`? The index is half the size — shouldn't it build faster regardless of memory?

  If you need more additional information please let me know.

  Thanks!

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #967: `halfvec` table + index shows unexpected QPS degradation and slower index build vs `vector`/flat in HNSW
@ 2026-03-09 13:27 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: jkatz (@jkatz) @ 2026-03-09 13:27 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

This [doesn't match my experience](https://jkatz05.com/post/postgres/pgvector-performance-150x-speedup/). `halfvec` index builds tend to be much faster than `vector` with comparable settings. Even with fixing `recall`, `halfvec` should typically be comparable in throughput. What hardware/architecture/environment did you run on? Are you sure your compiler supports building `halfvec` support with SIMD?

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #967: `halfvec` table + index shows unexpected QPS degradation and slower index build vs `vector`/flat in HNSW
@ 2026-03-09 14:18 ` "R3gardless (@R3gardless)" <noreply+R3gardless@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: R3gardless (@R3gardless) @ 2026-03-09 14:18 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @jkatz, thanks for the response.

You might be right that SIMD is the issue. I installed pgvector from the PGDG RPM repository, So I didn't explicitly control the compiler flags.

I checked that my experiment envrionment support SIMD instruction using following command:

```
cat /proc/cpuinfo | grep flags | head -1
```

The flags include `avx`, `avx2` and `avx512*`.

Also I checked the installed vector shared library (vector.so) file, I couldn't find SIMD registers in the compiled binary using following command:

```
objdump -d -M intel /usr/pgsql-15/lib/vector.so | egrep '\b(xmm|ymm|zmm)\b' | head
```

Based on this, I'm currently thinking that the halfvec test cases may not be using the SIMD path, which could explain the performance degradation I observed. However, I'm not sure if this is the correct way to verify it.

Does this seem like the right direction to investigate?

Thanks.

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #967: `halfvec` table + index shows unexpected QPS degradation and slower index build vs `vector`/flat in HNSW
@ 2026-03-09 14:49 ` "ankane (@ankane)" <noreply+ankane@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: ankane (@ankane) @ 2026-03-09 14:49 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @R3gardless, which OS version are you on? If the extension is compiled with GCC < 9, it won't include `halfvec` dispatching (which is probably the case here). I'd recommend building it from source with a more recent compiler.

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #967: `halfvec` table + index shows unexpected QPS degradation and slower index build vs `vector`/flat in HNSW
@ 2026-03-09 15:09 ` "R3gardless (@R3gardless)" <noreply+R3gardless@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: R3gardless (@R3gardless) @ 2026-03-09 15:09 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @ankane, thanks for the response. I'm currently using Rocky Linux 8.10 (Green Obsidian).

Since I installed pgvector from the PGDG RPM repository, is there any way to check which compiler version was used to build the extension?

Thanks!

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #967: `halfvec` table + index shows unexpected QPS degradation and slower index build vs `vector`/flat in HNSW
@ 2026-03-09 15:23 ` "ankane (@ankane)" <noreply+ankane@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: ankane (@ankane) @ 2026-03-09 15:23 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

It looks like it was compiled with GCC 8.5.0, which is the default version for Rocky Linux 8.

```sh
strings /usr/pgsql-15/lib/vector.so | grep gcc
```

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #967: `halfvec` table + index shows unexpected QPS degradation and slower index build vs `vector`/flat in HNSW
@ 2026-03-09 15:23 ` "ankane (@ankane)" <noreply+ankane@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: ankane (@ankane) @ 2026-03-09 15:23 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 8+ messages in thread

* Re: [pgvector/pgvector] issue #967: `halfvec` table + index shows unexpected QPS degradation and slower index build vs `vector`/flat in HNSW
@ 2026-03-15 08:52 ` "R3gardless (@R3gardless)" <noreply+R3gardless@github.com>
  6 siblings, 0 replies; 8+ messages in thread

From: R3gardless (@R3gardless) @ 2026-03-15 08:52 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @ankane @jkatz 

I tested pgvector 0.8.2 built with GCC 14.2.1, and I observed that `halfvec` (both table quantization and index quantization) performs significantly faster overall compared to `vector`.

Thank you for your guidance.

I really appreciate it.

^ permalink  raw  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2026-03-15 08:52 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-03-09 10:08 [pgvector/pgvector] issue #967: `halfvec` table + index shows unexpected QPS degradation and slower index build vs `vector`/flat in HNSW "R3gardless (@R3gardless)" <noreply+R3gardless@github.com>
2026-03-09 13:27 ` "jkatz (@jkatz)" <noreply+jkatz@github.com>
2026-03-09 14:18 ` "R3gardless (@R3gardless)" <noreply+R3gardless@github.com>
2026-03-09 14:49 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-03-09 15:09 ` "R3gardless (@R3gardless)" <noreply+R3gardless@github.com>
2026-03-09 15:23 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-03-09 15:23 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-03-15 08:52 ` "R3gardless (@R3gardless)" <noreply+R3gardless@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox