From: JoeyLYZ666 (@JoeyLYZ666) <noreply+JoeyLYZ666@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #1033: `<=>` returns NaN for small nonzero vectors due to float32 squared-norm underflow
Date: Mon, 26 Oct 2026 02:44:42 +0000
Message-ID: <gh-pgvector-pgvector-1033-c6407063102@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-1033@github.com>
References: <gh-pgvector-pgvector-1033@github.com>
@ankane hi,
I found a related issue in pgvector v0.8.6 involving the negative inner product operator (`<#>`), in addition to the L2 overflow described here.
Minimal reproduction:
```sql
SELECT '[1e20,1e20]'::vector <#> '[1e20,1e20]'::vector;
-- Actual: -Infinity
-- Expected: approximately -2e40 (finite in float64)
```
Both input vectors contain finite float32 values, and the mathematical result is representable in double precision. The L1 control with the same magnitude of inputs also returns a finite result.
The v0.8.6 implementation of `VectorInnerProduct()` uses a single-precision accumulator, which appears to cause the intermediate overflow before the result is widened to `double`.
I understand that single-precision accumulation may be an intentional performance trade-off for L2 distance. Does the same decision apply to the negative inner product operator, or would this be considered a separate issue worth addressing?
[reproduce.py](https://github.com/user-attachments/files/33944319/reproduce.py)