pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #1051: [Bug] Dense scalar distances overflow on finite `vector` inputs
3+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #1051: [Bug] Dense scalar distances overflow on finite `vector` inputs
@ 2026-10-31 08:55 "JoeyLYZ666 (@JoeyLYZ666)" <noreply+JoeyLYZ666@github.com>
  0 siblings, 0 replies; 3+ messages in thread

From: JoeyLYZ666 (@JoeyLYZ666) @ 2026-10-31 08:55 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

## Describe the bug

pgvector 0.8.7 returns `Infinity` or `NaN` from dense `vector` scalar distance
functions for finite input values whose exact result is still representable as
`double precision`.

## Reproduce

Run `testcase.py` against PostgreSQL with pgvector 0.8.7:

```powershell
python testcase.py
```

The query evaluates `l1_distance`, `l2_distance`, and `cosine_distance` on
finite dense vectors containing `1e38` and `1e20`.

[testcase.py](https://github.com/user-attachments/files/34213300/testcase.py)

## Expected behavior

All results should be finite. For the selected values, the expected results are
approximately `4e38`, `2.828427e38`, and `0` for the identical cosine input.

## Actual behavior

The affected release returns:

```text
Infinity, Infinity, NaN
```

The dense implementation accumulates intermediate values in `float` before
converting the result to the declared `double precision` return type.

## Impact

Finite vectors can produce non-finite scalar distances, breaking ordering,
threshold checks, and any oracle requiring finite non-negative distances.

## Environment

- pgvector 0.8.7
- PostgreSQL 18
- dense `vector(2)` values


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

* Re: [pgvector/pgvector] issue #1051: [Bug] Dense scalar distances overflow on finite `vector` inputs
@ 2026-10-31 09:45 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2026-10-31 09:45 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @JoeyLYZ666, see https://github.com/pgvector/pgvector/issues/1033#issuecomment-5884285142.

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

* Re: [pgvector/pgvector] issue #1051: [Bug] Dense scalar distances overflow on finite `vector` inputs
@ 2026-10-31 09:45 ` "ankane (@ankane)" <noreply+ankane@github.com>
  1 sibling, 0 replies; 3+ messages in thread

From: ankane (@ankane) @ 2026-10-31 09:45 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-31 09:45 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-31 08:55 [pgvector/pgvector] issue #1051: [Bug] Dense scalar distances overflow on finite `vector` inputs "JoeyLYZ666 (@JoeyLYZ666)" <noreply+JoeyLYZ666@github.com>
2026-10-31 09:45 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-10-31 09:45 ` "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