pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feed[pgvector/pgvector] issue #961: Feature Request: Jaccard Distance for Integer Arrays
3+ messages / 2 participants
[nested] [flat]
* [pgvector/pgvector] issue #961: Feature Request: Jaccard Distance for Integer Arrays
@ 2026-03-04 05:45 "gerrylwk (@gerrylwk)" <noreply+gerrylwk@github.com>
0 siblings, 0 replies; 3+ messages in thread
From: gerrylwk (@gerrylwk) @ 2026-03-04 05:45 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hello,
I'm exploring vector databases to see if there's any that can serve this particular purpose and pgvector looks promising:
I have MinHash Signatures (e.g. fixed length M array of integers). I want to perform jaccard distance query where I get other signatures that are of at least a certain similarity threshold when compared to a query signature.
I've looked at bit vectors since jaccard distance operator is available for it and I think it's the wrong data type for me (Pls correct me if I'm wrong), since the jaccard distance operator works on bit vector '101' but not an array of integers '[12345, 6789, 888]'
I initially tried normalising the integer vectors into floats, but cosine similarity does not give me the exact results I want. I'm trying to leverage any internal jaccard distance indexing that pgvector has so that I can avoid doing it myself (extracting then using python).
If anyone has any suggestions pls do share! :)
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #961: Feature Request: Jaccard Distance for Integer Arrays
@ 2026-03-04 07:21 "ankane (@ankane)" <noreply+ankane@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: ankane (@ankane) @ 2026-03-04 07:21 UTC (permalink / raw)
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Hi @gerrylwk, I looked into MinHash a while back for #806, but don't think it's common enough to add.
For exact search, you can create a SQL function for it.
```sql
CREATE FUNCTION approximate_jaccard_distance(a bigint[], b bigint[]) RETURNS double precision AS $$
SELECT AVG(CASE WHEN a[i] = b[i] THEN 0 ELSE 1 END) FROM generate_series(1, array_length(a, 1)) i
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;
```
For approximate search, you can convert the hash to binary and create a custom operator class, but it's not officially supported, so it could break at any time.
```sql
CREATE FUNCTION minhash_distance(a bit, b bit) RETURNS double precision AS $$
SELECT AVG(CASE WHEN substring(a FROM i FOR 64) = substring(b FROM i FOR 64) THEN 0 ELSE 1 END) FROM generate_series(1, bit_length(a), 64) i
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE;
CREATE OPERATOR <!> (
LEFTARG = bit, RIGHTARG = bit, PROCEDURE = minhash_distance,
COMMUTATOR = '<!>'
);
CREATE OPERATOR CLASS bit_minhash_ops
FOR TYPE bit USING hnsw AS
OPERATOR 1 <!> (bit, bit) FOR ORDER BY float_ops,
FUNCTION 1 minhash_distance(bit, bit),
FUNCTION 3 hnsw_bit_support(internal);
```
^ permalink raw [nested|flat] 3+ messages in thread
* Re: [pgvector/pgvector] issue #961: Feature Request: Jaccard Distance for Integer Arrays
@ 2026-03-04 07:21 "ankane (@ankane)" <noreply+ankane@github.com>
1 sibling, 0 replies; 3+ messages in thread
From: ankane (@ankane) @ 2026-03-04 07: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-03-04 07:21 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-03-04 05:45 [pgvector/pgvector] issue #961: Feature Request: Jaccard Distance for Integer Arrays "gerrylwk (@gerrylwk)" <noreply+gerrylwk@github.com>
2026-03-04 07:21 ` "ankane (@ankane)" <noreply+ankane@github.com>
2026-03-04 07: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