pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: duongynhi000005-oss (@duongynhi000005-oss) <noreply+duongynhi000005-oss@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #1043: bit Jaccard distance returns 1.0 for identical all-zero bit vectors
Date: Fri, 30 Oct 2026 18:23:54 +0000
Message-ID: <gh-pgvector-pgvector-1043-c6530374209@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-1043@github.com>
References: <gh-pgvector-pgvector-1043@github.com>

I investigated #1043 and traced the all-zero bit vector edge case in `src/bitutils.c`:

### Root Cause
In `BitJaccardDistanceDefault` (`src/bitutils.c:127-130`), the function checks:
```c
if (ab == 0)
    return 1;
```
When both bit vectors are all-zero (`'00000000'`), `ab == 0`, `aa == 0`, and `bb == 0`, so `BitJaccardDistanceDefault` returns `1.0` instead of `0.0` (violating $d(x, x) = 0$ and standard $d(\emptyset, \emptyset) = 0$).

### Proposed Fix
Add `if (aa + bb == 0) return 0;` before `if (ab == 0)` in `src/bitutils.c`.

I have a branch ready (`duongynhi000005-oss/pgvector:fix-issue-1043-bit-jaccard-distance-all-zero-vectors`) and would be happy to open a PR!

view thread (7+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-1043-c6530374209@github.com>
Permalink:  ../gh-pgvector-pgvector-1043-c6530374209@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