Exclude zero vectors for cosine distance to be consistent with other types [skip ci]

This commit is contained in:
Andrew Kane
2024-09-23 13:35:36 -07:00
parent 0296a08ccf
commit ffca8e720c
5 changed files with 16 additions and 5 deletions

View File

@@ -692,6 +692,9 @@ CREATE FUNCTION cosine_distance(intvec, intvec) RETURNS float8
CREATE FUNCTION l1_distance(intvec, intvec) RETURNS float8
AS 'MODULE_PATHNAME', 'intvec_l1_distance' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION l2_norm(intvec) RETURNS float8
AS 'MODULE_PATHNAME', 'intvec_l2_norm' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
-- intvec private functions
CREATE FUNCTION intvec_l2_squared_distance(intvec, intvec) RETURNS float8
@@ -756,6 +759,7 @@ CREATE OPERATOR CLASS intvec_cosine_ops
FOR TYPE intvec USING hnsw AS
OPERATOR 1 <=> (intvec, intvec) FOR ORDER BY float_ops,
FUNCTION 1 cosine_distance(intvec, intvec),
FUNCTION 2 l2_norm(intvec),
FUNCTION 3 hnsw_intvec_support(internal);
CREATE OPERATOR CLASS intvec_l1_ops