pg.ddx.io pgvector/pgvector GitHub issues and pull requests
help / color / mirror / Atom feedFrom: astanabe (@astanabe) <noreply+astanabe@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] PR #806: Added support of inner product distance for bit vectors
Date: Tue, 25 Mar 2025 16:32:01 +0000
Message-ID: <gh-pgvector-pgvector-806@github.com> (raw)
In my molecular sequence (i.e. DNA nucleotide or amino-acid sequences) analysis experience, (negative) inner product distance is often the best distance metric.
Recently, I faced to handle very large data contains over 5 billion vectors of 4096 dimensions, and, binary quantization is required.
For this analysis, I implemented inner product distance support for bit vectors.
inline patch 1: META.json, Makefile, Makefile.win and 15 more (+291/-11 lines) download inline-1.patch
diff --git a/META.json b/META.json
index b9a68f62a..343518d1c 100644
--- a/META.json
+++ b/META.json
@@ -2,7 +2,7 @@
"name": "vector",
"abstract": "Open-source vector similarity search for Postgres",
"description": "Supports L2 distance, inner product, and cosine distance",
- "version": "0.8.0",
+ "version": "0.8.1",
"maintainer": [
"Andrew Kane <andrew@ankane.org>"
],
@@ -20,7 +20,7 @@
"vector": {
"file": "sql/vector.sql",
"docfile": "README.md",
- "version": "0.8.0",
+ "version": "0.8.1",
"abstract": "Open-source vector similarity search for Postgres"
}
},
diff --git a/Makefile b/Makefile
index 7a4b88caf..6431ba8ac 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
EXTENSION = vector
-EXTVERSION = 0.8.0
+EXTVERSION = 0.8.1
MODULE_big = vector
DATA = $(wildcard sql/*--*--*.sql)
diff --git a/Makefile.win b/Makefile.win
index 8c62f9d5f..1fee4a683 100644
--- a/Makefile.win
+++ b/Makefile.win
@@ -1,5 +1,5 @@
EXTENSION = vector
-EXTVERSION = 0.8.0
+EXTVERSION = 0.8.1
DATA_built = sql\$(EXTENSION)--$(EXTVERSION).sql
OBJS = src\bitutils.obj src\bitvec.obj src\halfutils.obj src\halfvec.obj src\hnsw.obj src\hnswbuild.obj src\hnswinsert.obj src\hnswscan.obj src\hnswutils.obj src\hnswvacuum.obj src\ivfbuild.obj src\ivfflat.obj src\ivfinsert.obj src\ivfkmeans.obj src\ivfscan.obj src\ivfutils.obj src\ivfvacuum.obj src\sparsevec.obj src\vector.obj
diff --git a/sql/vector--0.8.0--0.8.1.sql b/sql/vector--0.8.0--0.8.1.sql
new file mode 100644
index 000000000..b75ba126f
--- /dev/null
+++ b/sql/vector--0.8.0--0.8.1.sql
@@ -0,0 +1,26 @@
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "ALTER EXTENSION vector UPDATE TO '0.8.1'" to load this file. \quit
+
+CREATE FUNCTION inner_product(bit, bit) RETURNS float8
+ AS 'MODULE_PATHNAME', 'bit_inner_product' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE FUNCTION bit_negative_inner_product(bit, bit) RETURNS float8
+ AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
+CREATE OPERATOR <#> (
+ LEFTARG = bit, RIGHTARG = bit, PROCEDURE = bit_negative_inner_product,
+ COMMUTATOR = '<#>'
+);
+
+CREATE OPERATOR CLASS bit_ip_ops
+ FOR TYPE bit USING ivfflat AS
+ OPERATOR 1 <#> (bit, bit) FOR ORDER BY float_ops,
+ FUNCTION 1 bit_negative_inner_product(bit, bit),
+ FUNCTION 3 bit_negative_inner_product(bit, bit),
+ FUNCTION 5 ivfflat_bit_support(internal);
+
+CREATE OPERATOR CLASS bit_ip_ops
+ FOR TYPE bit USING hnsw AS
+ OPERATOR 1 <#> (bit, bit) FOR ORDER BY float_ops,
+ FUNCTION 1 bit_negative_inner_product(bit, bit),
+ FUNCTION 3 hnsw_bit_support(internal);
diff --git a/sql/vector.sql b/sql/vector.sql
index 7fc36712b..6199430f0 100644
--- a/sql/vector.sql
+++ b/sql/vector.sql
@@ -652,9 +652,17 @@ CREATE OPERATOR CLASS halfvec_l1_ops
CREATE FUNCTION hamming_distance(bit, bit) RETURNS float8
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+CREATE FUNCTION inner_product(bit, bit) RETURNS float8
+ AS 'MODULE_PATHNAME', 'bit_inner_product' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
CREATE FUNCTION jaccard_distance(bit, bit) RETURNS float8
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+-- bit private functions
+
+CREATE FUNCTION bit_negative_inner_product(bit, bit) RETURNS float8
+ AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
+
-- bit operators
CREATE OPERATOR <~> (
@@ -662,6 +670,11 @@ CREATE OPERATOR <~> (
COMMUTATOR = '<~>'
);
+CREATE OPERATOR <#> (
+ LEFTARG = bit, RIGHTARG = bit, PROCEDURE = bit_negative_inner_product,
+ COMMUTATOR = '<#>'
+);
+
CREATE OPERATOR <%> (
LEFTARG = bit, RIGHTARG = bit, PROCEDURE = jaccard_distance,
COMMUTATOR = '<%>'
@@ -676,12 +689,25 @@ CREATE OPERATOR CLASS bit_hamming_ops
FUNCTION 3 hamming_distance(bit, bit),
FUNCTION 5 ivfflat_bit_support(internal);
+CREATE OPERATOR CLASS bit_ip_ops
+ FOR TYPE bit USING ivfflat AS
+ OPERATOR 1 <#> (bit, bit) FOR ORDER BY float_ops,
+ FUNCTION 1 bit_negative_inner_product(bit, bit),
+ FUNCTION 3 bit_negative_inner_product(bit, bit),
+ FUNCTION 5 ivfflat_bit_support(internal);
+
CREATE OPERATOR CLASS bit_hamming_ops
FOR TYPE bit USING hnsw AS
OPERATOR 1 <~> (bit, bit) FOR ORDER BY float_ops,
FUNCTION 1 hamming_distance(bit, bit),
FUNCTION 3 hnsw_bit_support(internal);
+CREATE OPERATOR CLASS bit_ip_ops
+ FOR TYPE bit USING hnsw AS
+ OPERATOR 1 <#> (bit, bit) FOR ORDER BY float_ops,
+ FUNCTION 1 bit_negative_inner_product(bit, bit),
+ FUNCTION 3 hnsw_bit_support(internal);
+
CREATE OPERATOR CLASS bit_jaccard_ops
FOR TYPE bit USING hnsw AS
OPERATOR 1 <%> (bit, bit) FOR ORDER BY float_ops,
diff --git a/src/bitutils.c b/src/bitutils.c
index 578bcad1d..6a1f03a4c 100644
--- a/src/bitutils.c
+++ b/src/bitutils.c
@@ -42,6 +42,7 @@
#endif
uint64 (*BitHammingDistance) (uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 distance);
+uint64 (*BitInnerProduct) (uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 innerproduct);
double (*BitJaccardDistance) (uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 ab, uint64 aa, uint64 bb);
BIT_TARGET_CLONES static uint64
@@ -93,6 +94,55 @@ BitHammingDistanceAvx512Popcount(uint32 bytes, unsigned char *ax, unsigned char
}
#endif
+BIT_TARGET_CLONES static uint64
+BitInnerProductDefault(uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 innerproduct)
+{
+#ifdef popcount64
+ for (; bytes >= sizeof(uint64); bytes -= sizeof(uint64))
+ {
+ uint64 axs;
+ uint64 bxs;
+
+ /* Ensure aligned */
+ memcpy(&axs, ax, sizeof(uint64));
+ memcpy(&bxs, bx, sizeof(uint64));
+
+ innerproduct += popcount64(axs & bxs);
+
+ ax += sizeof(uint64);
+ bx += sizeof(uint64);
+ }
+#endif
+
+ for (uint32 i = 0; i < bytes; i++)
+ innerproduct += pg_number_of_ones[ax[i] & bx[i]];
+
+ return innerproduct;
+}
+
+#ifdef BIT_DISPATCH
+TARGET_AVX512_POPCOUNT static uint64
+BitInnerProductAvx512Popcount(uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 innerproduct)
+{
+ __m512i shared = _mm512_setzero_si512();
+
+ for (; bytes >= sizeof(__m512i); bytes -= sizeof(__m512i))
+ {
+ __m512i axs = _mm512_loadu_si512((const __m512i *) ax);
+ __m512i bxs = _mm512_loadu_si512((const __m512i *) bx);
+
+ shared = _mm512_add_epi64(shared, _mm512_popcnt_epi64(_mm512_and_si512(axs, bxs)));
+
+ ax += sizeof(__m512i);
+ bx += sizeof(__m512i);
+ }
+
+ innerproduct += _mm512_reduce_add_epi64(shared);
+
+ return BitInnerProductDefault(bytes, ax, bx, innerproduct);
+}
+#endif
+
BIT_TARGET_CLONES static double
BitJaccardDistanceDefault(uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 ab, uint64 aa, uint64 bb)
{
@@ -210,12 +260,14 @@ BitvecInit(void)
* performance
*/
BitHammingDistance = BitHammingDistanceDefault;
+ BitInnerProduct = BitInnerProductDefault;
BitJaccardDistance = BitJaccardDistanceDefault;
#ifdef BIT_DISPATCH
if (SupportsAvx512Popcount())
{
BitHammingDistance = BitHammingDistanceAvx512Popcount;
+ BitInnerProduct = BitInnerProductAvx512Popcount;
BitJaccardDistance = BitJaccardDistanceAvx512Popcount;
}
#endif
diff --git a/src/bitutils.h b/src/bitutils.h
index b4d85bb1c..f647effbd 100644
--- a/src/bitutils.h
+++ b/src/bitutils.h
@@ -9,6 +9,7 @@
#endif
extern uint64 (*BitHammingDistance) (uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 distance);
+extern uint64 (*BitInnerProduct) (uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 innerproduct);
extern double (*BitJaccardDistance) (uint32 bytes, unsigned char *ax, unsigned char *bx, uint64 ab, uint64 aa, uint64 bb);
void BitvecInit(void);
diff --git a/src/bitvec.c b/src/bitvec.c
index 094ddd282..140b01a93 100644
--- a/src/bitvec.c
+++ b/src/bitvec.c
@@ -53,6 +53,36 @@ hamming_distance(PG_FUNCTION_ARGS)
PG_RETURN_FLOAT8((double) BitHammingDistance(VARBITBYTES(a), VARBITS(a), VARBITS(b), 0));
}
+/*
+ * Get the inner product between two bit vectors
+ */
+FUNCTION_PREFIX PG_FUNCTION_INFO_V1(bit_inner_product);
+Datum
+bit_inner_product(PG_FUNCTION_ARGS)
+{
+ VarBit *a = PG_GETARG_VARBIT_P(0);
+ VarBit *b = PG_GETARG_VARBIT_P(1);
+
+ CheckDims(a, b);
+
+ PG_RETURN_FLOAT8((double) BitInnerProduct(VARBITBYTES(a), VARBITS(a), VARBITS(b), 0));
+}
+
+/*
+ * Get the negative inner product between two bit vectors
+ */
+FUNCTION_PREFIX PG_FUNCTION_INFO_V1(bit_negative_inner_product);
+Datum
+bit_negative_inner_product(PG_FUNCTION_ARGS)
+{
+ VarBit *a = PG_GETARG_VARBIT_P(0);
+ VarBit *b = PG_GETARG_VARBIT_P(1);
+
+ CheckDims(a, b);
+
+ PG_RETURN_FLOAT8((double) -((double) BitInnerProduct(VARBITBYTES(a), VARBITS(a), VARBITS(b), 0)));
+}
+
/*
* Get the Jaccard distance between two bit vectors
*/
diff --git a/test/expected/bit.out b/test/expected/bit.out
index a9ba47255..6da1e371d 100644
--- a/test/expected/bit.out
+++ b/test/expected/bit.out
@@ -62,6 +62,70 @@ SELECT hamming_distance('111', '000'::varbit(4));
SELECT hamming_distance('111', '0000'::varbit(4));
ERROR: different bit lengths 3 and 4
+SELECT inner_product(B'111', B'111');
+ inner_product
+---------------
+ 3
+(1 row)
+
+SELECT inner_product(B'111', B'110');
+ inner_product
+---------------
+ 2
+(1 row)
+
+SELECT inner_product(B'111', B'100');
+ inner_product
+---------------
+ 1
+(1 row)
+
+SELECT inner_product(B'111', B'000');
+ inner_product
+---------------
+ 0
+(1 row)
+
+SELECT inner_product(B'10101010101010101010', B'01010101010101010101');
+ inner_product
+---------------
+ 0
+(1 row)
+
+SELECT inner_product(B'101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101', B'101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101');
+ inner_product
+---------------
+ 257
+(1 row)
+
+SELECT inner_product(B'101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101', B'010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010');
+ inner_product
+---------------
+ 0
+(1 row)
+
+SELECT inner_product(B'110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011', B'100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001');
+ inner_product
+---------------
+ 2
+(1 row)
+
+SELECT inner_product(B'', B'');
+ inner_product
+---------------
+ 0
+(1 row)
+
+SELECT inner_product(B'111', B'00');
+ERROR: different bit lengths 3 and 2
+SELECT inner_product(B'111', '000'::varbit(4));
+ inner_product
+---------------
+ 0
+(1 row)
+
+SELECT inner_product(B'111', '0000'::varbit(4));
+ERROR: different bit lengths 3 and 4
SELECT jaccard_distance('1111', '1111');
jaccard_distance
------------------
diff --git a/test/expected/hnsw_bit.out b/test/expected/hnsw_bit.out
index 047954a79..1844c988a 100644
--- a/test/expected/hnsw_bit.out
+++ b/test/expected/hnsw_bit.out
@@ -19,6 +19,27 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <~> (SELECT NULL::bit)) t2;
4
(1 row)
+DROP TABLE t;
+-- inner product
+CREATE TABLE t (val bit(3));
+INSERT INTO t (val) VALUES (B'000'), (B'100'), (B'111'), (NULL);
+CREATE INDEX ON t USING hnsw (val bit_ip_ops);
+INSERT INTO t (val) VALUES (B'110');
+SELECT * FROM t ORDER BY val <#> B'111';
+ val
+-----
+ 111
+ 110
+ 100
+ 000
+(4 rows)
+
+SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <#> (SELECT NULL::bit)) t2;
+ count
+-------
+ 4
+(1 row)
+
DROP TABLE t;
-- jaccard
CREATE TABLE t (val bit(4));
diff --git a/test/expected/ivfflat_bit.out b/test/expected/ivfflat_bit.out
index ab8adfd83..7733d0509 100644
--- a/test/expected/ivfflat_bit.out
+++ b/test/expected/ivfflat_bit.out
@@ -19,6 +19,27 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <~> (SELECT NULL::bit)) t2;
4
(1 row)
+DROP TABLE t;
+-- inner product
+CREATE TABLE t (val bit(3));
+INSERT INTO t (val) VALUES (B'000'), (B'100'), (B'111'), (NULL);
+CREATE INDEX ON t USING ivfflat (val bit_ip_ops) WITH (lists = 1);
+INSERT INTO t (val) VALUES (B'110');
+SELECT * FROM t ORDER BY val <#> B'111';
+ val
+-----
+ 111
+ 110
+ 100
+ 000
+(4 rows)
+
+SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <#> (SELECT NULL::bit)) t2;
+ count
+-------
+ 4
+(1 row)
+
DROP TABLE t;
-- varbit
CREATE TABLE t (val varbit(3));
diff --git a/test/sql/bit.sql b/test/sql/bit.sql
index eee9ce60c..c1905c341 100644
--- a/test/sql/bit.sql
+++ b/test/sql/bit.sql
@@ -11,6 +11,19 @@ SELECT hamming_distance('111', '00');
SELECT hamming_distance('111', '000'::varbit(4));
SELECT hamming_distance('111', '0000'::varbit(4));
+SELECT inner_product(B'111', B'111');
+SELECT inner_product(B'111', B'110');
+SELECT inner_product(B'111', B'100');
+SELECT inner_product(B'111', B'000');
+SELECT inner_product(B'10101010101010101010', B'01010101010101010101');
+SELECT inner_product(B'101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101', B'101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101');
+SELECT inner_product(B'101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101', B'010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010');
+SELECT inner_product(B'110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011', B'100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001');
+SELECT inner_product(B'', B'');
+SELECT inner_product(B'111', B'00');
+SELECT inner_product(B'111', '000'::varbit(4));
+SELECT inner_product(B'111', '0000'::varbit(4));
+
SELECT jaccard_distance('1111', '1111');
SELECT jaccard_distance('1111', '1110');
SELECT jaccard_distance('1111', '1100');
diff --git a/test/sql/hnsw_bit.sql b/test/sql/hnsw_bit.sql
index 5a7def759..99b8d019e 100644
--- a/test/sql/hnsw_bit.sql
+++ b/test/sql/hnsw_bit.sql
@@ -13,6 +13,19 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <~> (SELECT NULL::bit)) t2;
DROP TABLE t;
+-- inner product
+
+CREATE TABLE t (val bit(3));
+INSERT INTO t (val) VALUES (B'000'), (B'100'), (B'111'), (NULL);
+CREATE INDEX ON t USING hnsw (val bit_ip_ops);
+
+INSERT INTO t (val) VALUES (B'110');
+
+SELECT * FROM t ORDER BY val <#> B'111';
+SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <#> (SELECT NULL::bit)) t2;
+
+DROP TABLE t;
+
-- jaccard
CREATE TABLE t (val bit(4));
diff --git a/test/sql/ivfflat_bit.sql b/test/sql/ivfflat_bit.sql
index e0f9e2519..63b8557af 100644
--- a/test/sql/ivfflat_bit.sql
+++ b/test/sql/ivfflat_bit.sql
@@ -13,6 +13,19 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <~> (SELECT NULL::bit)) t2;
DROP TABLE t;
+-- inner product
+
+CREATE TABLE t (val bit(3));
+INSERT INTO t (val) VALUES (B'000'), (B'100'), (B'111'), (NULL);
+CREATE INDEX ON t USING ivfflat (val bit_ip_ops) WITH (lists = 1);
+
+INSERT INTO t (val) VALUES (B'110');
+
+SELECT * FROM t ORDER BY val <#> B'111';
+SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <#> (SELECT NULL::bit)) t2;
+
+DROP TABLE t;
+
-- varbit
CREATE TABLE t (val varbit(3));
diff --git a/test/t/020_hnsw_bit_build_recall.pl b/test/t/020_hnsw_bit_build_recall.pl
index 8772ed537..499bc019c 100644
--- a/test/t/020_hnsw_bit_build_recall.pl
+++ b/test/t/020_hnsw_bit_build_recall.pl
@@ -70,8 +70,8 @@ sub test_recall
}
# Check each index type
-my @operators = ("<~>", "<\%>");
-my @opclasses = ("bit_hamming_ops", "bit_jaccard_ops");
+my @operators = ("<~>", "<#>", "<\%>");
+my @opclasses = ("bit_hamming_ops", "bit_ip_ops", "bit_jaccard_ops");
for my $i (0 .. $#operators)
{
diff --git a/test/t/021_hnsw_bit_insert_recall.pl b/test/t/021_hnsw_bit_insert_recall.pl
index d9bd2e113..749d73394 100644
--- a/test/t/021_hnsw_bit_insert_recall.pl
+++ b/test/t/021_hnsw_bit_insert_recall.pl
@@ -67,8 +67,8 @@ sub test_recall
}
# Check each index type
-my @operators = ("<~>", "<\%>");
-my @opclasses = ("bit_hamming_ops", "bit_jaccard_ops");
+my @operators = ("<~>", "<#>", "<\%>");
+my @opclasses = ("bit_hamming_ops", "bit_ip_ops", "bit_jaccard_ops");
for my $i (0 .. $#operators)
{
diff --git a/test/t/035_ivfflat_bit_build_recall.pl b/test/t/035_ivfflat_bit_build_recall.pl
index d58d597f0..f6fb3cc8f 100644
--- a/test/t/035_ivfflat_bit_build_recall.pl
+++ b/test/t/035_ivfflat_bit_build_recall.pl
@@ -70,8 +70,8 @@ sub test_recall
}
# Check each index type
-my @operators = ("<~>");
-my @opclasses = ("bit_hamming_ops");
+my @operators = ("<~>", "<#>");
+my @opclasses = ("bit_hamming_ops", "bit_ip_ops");
for my $i (0 .. $#operators)
{
diff --git a/vector.control b/vector.control
index 7bfc0f1fa..2ad02286a 100644
--- a/vector.control
+++ b/vector.control
@@ -1,4 +1,4 @@
comment = 'vector data type and ivfflat and hnsw access methods'
-default_version = '0.8.0'
+default_version = '0.8.1'
module_pathname = '$libdir/vector'
relocatable = true
view thread (10+ messages) latest in thread
Message-ID: <gh-pgvector-pgvector-806@github.com>
Permalink: ../gh-pgvector-pgvector-806@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