mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-06 05:51:21 +08:00
Updated range and defaults for iterative search parameters
This commit is contained in:
@@ -84,8 +84,8 @@ HnswInit(void)
|
||||
|
||||
/* This is approximate and does not apply to the initial scan */
|
||||
DefineCustomIntVariable("hnsw.max_search_tuples", "Sets the max number of candidates to visit for iterative search",
|
||||
"-1 means no limit", &hnsw_max_search_tuples,
|
||||
-1, -1, INT_MAX, PGC_USERSET, 0, NULL, NULL, NULL);
|
||||
NULL, &hnsw_max_search_tuples,
|
||||
20000, 1, INT_MAX, PGC_USERSET, 0, NULL, NULL, NULL);
|
||||
|
||||
MarkGUCPrefixReserved("hnsw");
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ hnswgettuple(IndexScanDesc scan, ScanDirection dir)
|
||||
break;
|
||||
|
||||
/* Reached max number of tuples */
|
||||
if (hnsw_max_search_tuples != -1 && so->tuples >= hnsw_max_search_tuples)
|
||||
if (so->tuples >= hnsw_max_search_tuples)
|
||||
{
|
||||
if (pairingheap_is_empty(so->discarded))
|
||||
break;
|
||||
|
||||
@@ -47,8 +47,8 @@ IvfflatInit(void)
|
||||
|
||||
/* If this is less than probes, probes is used */
|
||||
DefineCustomIntVariable("ivfflat.max_probes", "Sets the max number of probes for iterative search",
|
||||
"-1 means no limit", &ivfflat_max_probes,
|
||||
-1, -1, IVFFLAT_MAX_LISTS, PGC_USERSET, 0, NULL, NULL, NULL);
|
||||
NULL, &ivfflat_max_probes,
|
||||
IVFFLAT_MAX_LISTS, IVFFLAT_MIN_LISTS, IVFFLAT_MAX_LISTS, PGC_USERSET, 0, NULL, NULL, NULL);
|
||||
|
||||
MarkGUCPrefixReserved("ivfflat");
|
||||
}
|
||||
|
||||
@@ -264,17 +264,7 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
|
||||
IvfflatGetMetaPageInfo(index, &lists, &dimensions);
|
||||
|
||||
if (ivfflat_iterative_search != IVFFLAT_ITERATIVE_SEARCH_OFF)
|
||||
{
|
||||
maxProbes = ivfflat_max_probes;
|
||||
|
||||
if (maxProbes < 0)
|
||||
maxProbes = lists;
|
||||
else if (maxProbes < probes)
|
||||
{
|
||||
/* TODO Show notice */
|
||||
maxProbes = probes;
|
||||
}
|
||||
}
|
||||
maxProbes = Max(ivfflat_max_probes, probes);
|
||||
else
|
||||
maxProbes = probes;
|
||||
|
||||
|
||||
@@ -177,9 +177,9 @@ HINT: Available values: off, relaxed_order, strict_order.
|
||||
SHOW hnsw.max_search_tuples;
|
||||
hnsw.max_search_tuples
|
||||
------------------------
|
||||
-1
|
||||
20000
|
||||
(1 row)
|
||||
|
||||
SET hnsw.max_search_tuples = -2;
|
||||
ERROR: -2 is outside the valid range for parameter "hnsw.max_search_tuples" (-1 .. 2147483647)
|
||||
SET hnsw.max_search_tuples = 0;
|
||||
ERROR: 0 is outside the valid range for parameter "hnsw.max_search_tuples" (1 .. 2147483647)
|
||||
DROP TABLE t;
|
||||
|
||||
@@ -95,13 +95,6 @@ SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
||||
[0,0,0]
|
||||
(3 rows)
|
||||
|
||||
SET ivfflat.max_probes = 0;
|
||||
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
||||
val
|
||||
---------
|
||||
[1,2,3]
|
||||
(1 row)
|
||||
|
||||
SET ivfflat.max_probes = 1;
|
||||
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
||||
val
|
||||
@@ -163,11 +156,11 @@ HINT: Available values: off, relaxed_order.
|
||||
SHOW ivfflat.max_probes;
|
||||
ivfflat.max_probes
|
||||
--------------------
|
||||
-1
|
||||
32768
|
||||
(1 row)
|
||||
|
||||
SET ivfflat.max_probes = -2;
|
||||
ERROR: -2 is outside the valid range for parameter "ivfflat.max_probes" (-1 .. 32768)
|
||||
SET ivfflat.max_probes = 0;
|
||||
ERROR: 0 is outside the valid range for parameter "ivfflat.max_probes" (1 .. 32768)
|
||||
SET ivfflat.max_probes = 32769;
|
||||
ERROR: 32769 is outside the valid range for parameter "ivfflat.max_probes" (-1 .. 32768)
|
||||
ERROR: 32769 is outside the valid range for parameter "ivfflat.max_probes" (1 .. 32768)
|
||||
DROP TABLE t;
|
||||
|
||||
@@ -104,6 +104,6 @@ SET hnsw.iterative_search = on;
|
||||
|
||||
SHOW hnsw.max_search_tuples;
|
||||
|
||||
SET hnsw.max_search_tuples = -2;
|
||||
SET hnsw.max_search_tuples = 0;
|
||||
|
||||
DROP TABLE t;
|
||||
|
||||
@@ -53,9 +53,6 @@ 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]';
|
||||
|
||||
SET ivfflat.max_probes = 0;
|
||||
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
||||
|
||||
SET ivfflat.max_probes = 1;
|
||||
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
||||
|
||||
@@ -93,7 +90,7 @@ SET ivfflat.iterative_search = on;
|
||||
|
||||
SHOW ivfflat.max_probes;
|
||||
|
||||
SET ivfflat.max_probes = -2;
|
||||
SET ivfflat.max_probes = 0;
|
||||
SET ivfflat.max_probes = 32769;
|
||||
|
||||
DROP TABLE t;
|
||||
|
||||
@@ -27,6 +27,7 @@ $node->safe_psql("postgres", qq(
|
||||
my $count = $node->safe_psql("postgres", qq(
|
||||
SET enable_seqscan = off;
|
||||
SET hnsw.iterative_search = relaxed_order;
|
||||
SET hnsw.max_search_tuples = 100000;
|
||||
SET work_mem = '8MB';
|
||||
SELECT COUNT(*) FROM (SELECT v FROM tst WHERE i % 10000 = 0 ORDER BY v <-> (SELECT v FROM tst LIMIT 1) LIMIT 11) t;
|
||||
));
|
||||
@@ -59,7 +60,7 @@ my ($ret, $stdout, $stderr) = $node->psql("postgres", qq(
|
||||
SET enable_seqscan = off;
|
||||
SET hnsw.iterative_search = relaxed_order;
|
||||
SET client_min_messages = debug1;
|
||||
SET work_mem = '2MB';
|
||||
SET work_mem = '1MB';
|
||||
SELECT COUNT(*) FROM (SELECT v FROM tst WHERE i % 10000 = 0 ORDER BY v <-> (SELECT v FROM tst LIMIT 1) LIMIT 11) t;
|
||||
));
|
||||
like($stderr, qr/hnsw index scan exceeded work_mem after \d+ tuples/);
|
||||
|
||||
Reference in New Issue
Block a user