From b26a21b848fdb0a642fa16053ebdd1baddac0e25 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 11 Oct 2024 11:07:11 -0700 Subject: [PATCH] Added regression tests for iterative search [skip ci] --- test/expected/hnsw_vector.out | 43 ++++++++++++++++++++++++++++++++ test/expected/ivfflat_vector.out | 38 ++++++++++++++++++++++++++++ test/sql/hnsw_vector.sql | 25 +++++++++++++++++++ test/sql/ivfflat_vector.sql | 24 ++++++++++++++++++ 4 files changed, 130 insertions(+) diff --git a/test/expected/hnsw_vector.out b/test/expected/hnsw_vector.out index cbda5fa..6a1f984 100644 --- a/test/expected/hnsw_vector.out +++ b/test/expected/hnsw_vector.out @@ -99,6 +99,32 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <+> (SELECT NULL::vector)) t2 4 (1 row) +DROP TABLE t; +-- iterative +CREATE TABLE t (val vector(3)); +INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL); +CREATE INDEX ON t USING hnsw (val vector_l2_ops); +SET hnsw.iterative_search = strict_order; +SET hnsw.ef_search = 1; +SELECT * FROM t ORDER BY val <-> '[3,3,3]'; + val +--------- + [1,2,3] + [1,1,1] + [0,0,0] +(3 rows) + +SET hnsw.iterative_search = relaxed_order; +SELECT * FROM t ORDER BY val <-> '[3,3,3]'; + val +--------- + [1,2,3] + [1,1,1] + [0,0,0] +(3 rows) + +RESET hnsw.iterative_search; +RESET hnsw.ef_search; DROP TABLE t; -- unlogged CREATE UNLOGGED TABLE t (val vector(3)); @@ -139,4 +165,21 @@ SET hnsw.ef_search = 0; ERROR: 0 is outside the valid range for parameter "hnsw.ef_search" (1 .. 1000) SET hnsw.ef_search = 1001; ERROR: 1001 is outside the valid range for parameter "hnsw.ef_search" (1 .. 1000) +SHOW hnsw.iterative_search; + hnsw.iterative_search +----------------------- + off +(1 row) + +SET hnsw.iterative_search = on; +ERROR: invalid value for parameter "hnsw.iterative_search": "on" +HINT: Available values: off, relaxed_order, strict_order. +SHOW hnsw.iterative_search_max_tuples; + hnsw.iterative_search_max_tuples +---------------------------------- + -1 +(1 row) + +SET hnsw.iterative_search_max_tuples = -2; +ERROR: -2 is outside the valid range for parameter "hnsw.iterative_search_max_tuples" (-1 .. 2147483647) DROP TABLE t; diff --git a/test/expected/ivfflat_vector.out b/test/expected/ivfflat_vector.out index 84871b4..c22135a 100644 --- a/test/expected/ivfflat_vector.out +++ b/test/expected/ivfflat_vector.out @@ -81,6 +81,21 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <=> (SELECT NULL::vector)) t2 3 (1 row) +DROP TABLE t; +-- iterative +CREATE TABLE t (val vector(3)); +INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL); +CREATE INDEX ON t USING ivfflat (val vector_l2_ops) WITH (lists = 3); +SET ivfflat.iterative_search = relaxed_order; +SELECT * FROM t ORDER BY val <-> '[3,3,3]'; + val +--------- + [1,2,3] + [1,1,1] + [0,0,0] +(3 rows) + +RESET ivfflat.iterative_search; DROP TABLE t; -- unlogged CREATE UNLOGGED TABLE t (val vector(3)); @@ -109,4 +124,27 @@ SHOW ivfflat.probes; 1 (1 row) +SET ivfflat.probes = 0; +ERROR: 0 is outside the valid range for parameter "ivfflat.probes" (1 .. 32768) +SET ivfflat.probes = 32769; +ERROR: 32769 is outside the valid range for parameter "ivfflat.probes" (1 .. 32768) +SHOW ivfflat.iterative_search; + ivfflat.iterative_search +-------------------------- + off +(1 row) + +SET ivfflat.iterative_search = on; +ERROR: invalid value for parameter "ivfflat.iterative_search": "on" +HINT: Available values: off, relaxed_order. +SHOW ivfflat.iterative_search_max_probes; + ivfflat.iterative_search_max_probes +------------------------------------- + 0 +(1 row) + +SET ivfflat.iterative_search_max_probes = -1; +ERROR: -1 is outside the valid range for parameter "ivfflat.iterative_search_max_probes" (0 .. 32768) +SET ivfflat.iterative_search_max_probes = 32769; +ERROR: 32769 is outside the valid range for parameter "ivfflat.iterative_search_max_probes" (0 .. 32768) DROP TABLE t; diff --git a/test/sql/hnsw_vector.sql b/test/sql/hnsw_vector.sql index b7896cf..8f69a4c 100644 --- a/test/sql/hnsw_vector.sql +++ b/test/sql/hnsw_vector.sql @@ -57,6 +57,23 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <+> (SELECT NULL::vector)) t2 DROP TABLE t; +-- iterative + +CREATE TABLE t (val vector(3)); +INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL); +CREATE INDEX ON t USING hnsw (val vector_l2_ops); + +SET hnsw.iterative_search = strict_order; +SET hnsw.ef_search = 1; +SELECT * FROM t ORDER BY val <-> '[3,3,3]'; + +SET hnsw.iterative_search = relaxed_order; +SELECT * FROM t ORDER BY val <-> '[3,3,3]'; + +RESET hnsw.iterative_search; +RESET hnsw.ef_search; +DROP TABLE t; + -- unlogged CREATE UNLOGGED TABLE t (val vector(3)); @@ -81,4 +98,12 @@ SHOW hnsw.ef_search; SET hnsw.ef_search = 0; SET hnsw.ef_search = 1001; +SHOW hnsw.iterative_search; + +SET hnsw.iterative_search = on; + +SHOW hnsw.iterative_search_max_tuples; + +SET hnsw.iterative_search_max_tuples = -2; + DROP TABLE t; diff --git a/test/sql/ivfflat_vector.sql b/test/sql/ivfflat_vector.sql index 32759e3..93f4224 100644 --- a/test/sql/ivfflat_vector.sql +++ b/test/sql/ivfflat_vector.sql @@ -44,6 +44,18 @@ SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <=> (SELECT NULL::vector)) t2 DROP TABLE t; +-- iterative + +CREATE TABLE t (val vector(3)); +INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL); +CREATE INDEX ON t USING ivfflat (val vector_l2_ops) WITH (lists = 3); + +SET ivfflat.iterative_search = relaxed_order; +SELECT * FROM t ORDER BY val <-> '[3,3,3]'; + +RESET ivfflat.iterative_search; +DROP TABLE t; + -- unlogged CREATE UNLOGGED TABLE t (val vector(3)); @@ -62,4 +74,16 @@ CREATE INDEX ON t USING ivfflat (val vector_l2_ops) WITH (lists = 32769); SHOW ivfflat.probes; +SET ivfflat.probes = 0; +SET ivfflat.probes = 32769; + +SHOW ivfflat.iterative_search; + +SET ivfflat.iterative_search = on; + +SHOW ivfflat.iterative_search_max_probes; + +SET ivfflat.iterative_search_max_probes = -1; +SET ivfflat.iterative_search_max_probes = 32769; + DROP TABLE t;