pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #1044: sparsevec `<=>` returns NaN self-distance and 1.0 for a collinear pair
3+ messages / 2 participants
[nested] [flat]
* [pgvector/pgvector] issue #1044: sparsevec `<=>` returns NaN self-distance and 1.0 for a collinear pair
@ 2026-10-21 12:53 "JoeyLYZ666 (@JoeyLYZ666)" <noreply+JoeyLYZ666@github.com>
0 siblings, 0 replies; 3+ messages in thread
From: JoeyLYZ666 (@JoeyLYZ666) @ 2026-10-21 12:53 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
## Description
For the finite sparse vector `{1:3e19,2:4e19}/2` (each value legal float4;
squared norm `25e38` overflows float4):
- self cosine distance `v <=> v` → `NaN` (0/0 after norm overflow)
- cosine distance to the collinear normal vector `{1:3,2:4}/2` → `1.0`
(maximum distance) instead of `0`
Normal-scale control (`{1:3,2:4}/2 <=> {1:3,2:4}/2`) is exactly `0`.
A NaN self-distance also poisons ordering: it sorts inconsistently and
breaks `ORDER BY v <=> q` result expectations.
## Environment
- pgvector 0.8.6 on PostgreSQL 18; deterministic;
## Steps to reproduce
```sql
SELECT '{1:3,2:4}/2'::sparsevec <=> '{1:3,2:4}/2'::sparsevec; -- 0 (control)
SELECT '{1:3e19,2:4e19}/2'::sparsevec <=> '{1:3e19,2:4e19}/2'::sparsevec; -- NaN
SELECT '{1:3e19,2:4e19}/2'::sparsevec <=> '{1:3,2:4}/2'::sparsevec; -- 1.0 (true 0)
```
[reproduce.py](https://github.com/user-attachments/files/33769334/reproduce.py)
## Expected behavior
`0` and `0` (compute norms in float8, or pre-scale).
## Actual behavior
`NaN` and `1.0`.
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #1044: sparsevec `<=>` returns NaN self-distance and 1.0 for a collinear pair
@ 2026-10-23 00:21 "ankane (@ankane)" <noreply+ankane@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: ankane (@ankane) @ 2026-10-23 00:21 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hi @JoeyLYZ666, this is the same situation as #1033 (both `vector` and `sparsevec` have the same behavior).
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #1044: sparsevec `<=>` returns NaN self-distance and 1.0 for a collinear pair
@ 2026-10-23 00:21 "ankane (@ankane)" <noreply+ankane@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: ankane (@ankane) @ 2026-10-23 00:21 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
@ankane closed this.
^ permalink raw [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-10-23 00:21 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 12:53 [pgvector/pgvector] issue #1044: sparsevec `<=>` returns NaN self-distance and 1.0 for a collinear pair "JoeyLYZ666 (@JoeyLYZ666)" <noreply+JoeyLYZ666@github.com>
2026-10-23 00:21 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-10-23 00:21 ` "ankane (@ankane)" <noreply+ankane@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