mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-10 14:46:56 +08:00
Added support for bigint attributes [skip ci]
This commit is contained in:
@@ -4,7 +4,15 @@
|
|||||||
CREATE FUNCTION hnsw_attribute_distance(integer, integer) RETURNS float8
|
CREATE FUNCTION hnsw_attribute_distance(integer, integer) RETURNS float8
|
||||||
AS 'MODULE_PATHNAME', 'hnsw_int4_attribute_distance' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME', 'hnsw_int4_attribute_distance' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
|
CREATE FUNCTION hnsw_attribute_distance(bigint, bigint) RETURNS float8
|
||||||
|
AS 'MODULE_PATHNAME', 'hnsw_int8_attribute_distance' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
CREATE OPERATOR CLASS vector_integer_ops
|
CREATE OPERATOR CLASS vector_integer_ops
|
||||||
DEFAULT FOR TYPE integer USING hnsw AS
|
DEFAULT FOR TYPE integer USING hnsw AS
|
||||||
OPERATOR 2 = (integer, integer),
|
OPERATOR 2 = (integer, integer),
|
||||||
FUNCTION 3 hnsw_attribute_distance(integer, integer);
|
FUNCTION 3 hnsw_attribute_distance(integer, integer);
|
||||||
|
|
||||||
|
CREATE OPERATOR CLASS vector_bigint_ops
|
||||||
|
DEFAULT FOR TYPE bigint USING hnsw AS
|
||||||
|
OPERATOR 2 = (bigint, bigint),
|
||||||
|
FUNCTION 3 hnsw_attribute_distance(bigint, bigint);
|
||||||
|
|||||||
@@ -296,7 +296,15 @@ CREATE OPERATOR CLASS vector_cosine_ops
|
|||||||
CREATE FUNCTION hnsw_attribute_distance(integer, integer) RETURNS float8
|
CREATE FUNCTION hnsw_attribute_distance(integer, integer) RETURNS float8
|
||||||
AS 'MODULE_PATHNAME', 'hnsw_int4_attribute_distance' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
AS 'MODULE_PATHNAME', 'hnsw_int4_attribute_distance' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
|
CREATE FUNCTION hnsw_attribute_distance(bigint, bigint) RETURNS float8
|
||||||
|
AS 'MODULE_PATHNAME', 'hnsw_int8_attribute_distance' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
||||||
|
|
||||||
CREATE OPERATOR CLASS vector_integer_ops
|
CREATE OPERATOR CLASS vector_integer_ops
|
||||||
DEFAULT FOR TYPE integer USING hnsw AS
|
DEFAULT FOR TYPE integer USING hnsw AS
|
||||||
OPERATOR 2 = (integer, integer),
|
OPERATOR 2 = (integer, integer),
|
||||||
FUNCTION 3 hnsw_attribute_distance(integer, integer);
|
FUNCTION 3 hnsw_attribute_distance(integer, integer);
|
||||||
|
|
||||||
|
CREATE OPERATOR CLASS vector_bigint_ops
|
||||||
|
DEFAULT FOR TYPE bigint USING hnsw AS
|
||||||
|
OPERATOR 2 = (bigint, bigint),
|
||||||
|
FUNCTION 3 hnsw_attribute_distance(bigint, bigint);
|
||||||
|
|||||||
14
src/hnsw.c
14
src/hnsw.c
@@ -236,3 +236,17 @@ hnsw_int4_attribute_distance(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
PG_RETURN_FLOAT8(distance);
|
PG_RETURN_FLOAT8(distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the distance between two int8 attributes
|
||||||
|
*/
|
||||||
|
PGDLLEXPORT PG_FUNCTION_INFO_V1(hnsw_int8_attribute_distance);
|
||||||
|
Datum
|
||||||
|
hnsw_int8_attribute_distance(PG_FUNCTION_ARGS)
|
||||||
|
{
|
||||||
|
int64 a = PG_GETARG_INT64(0);
|
||||||
|
int64 b = PG_GETARG_INT64(1);
|
||||||
|
double distance = ((double) a) - ((double) b);
|
||||||
|
|
||||||
|
PG_RETURN_FLOAT8(distance);
|
||||||
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ $node->start;
|
|||||||
|
|
||||||
# Create table
|
# Create table
|
||||||
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
|
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
|
||||||
$node->safe_psql("postgres", "CREATE TABLE tst (i int4, v vector($dim), c int4);");
|
$node->safe_psql("postgres", "CREATE TABLE tst (i int4, v vector($dim), c int8);");
|
||||||
$node->safe_psql("postgres",
|
$node->safe_psql("postgres",
|
||||||
"INSERT INTO tst SELECT i, ARRAY[$array_sql], i % $nc FROM generate_series(1, 20000) i;"
|
"INSERT INTO tst SELECT i, ARRAY[$array_sql], i % $nc FROM generate_series(1, 20000) i;"
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user