mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-11 07:06:57 +08:00
Use -1 for no limit for ivfflat.max_probes [skip ci]
This commit is contained in:
@@ -82,7 +82,6 @@ HnswInit(void)
|
|||||||
NULL, &hnsw_iterative_search,
|
NULL, &hnsw_iterative_search,
|
||||||
HNSW_ITERATIVE_SEARCH_OFF, hnsw_iterative_search_options, PGC_USERSET, 0, NULL, NULL, NULL);
|
HNSW_ITERATIVE_SEARCH_OFF, hnsw_iterative_search_options, PGC_USERSET, 0, NULL, NULL, NULL);
|
||||||
|
|
||||||
/* TODO Ensure ivfflat.max_probes uses same value for no limit */
|
|
||||||
DefineCustomIntVariable("hnsw.max_search_tuples", "Sets the max number of candidates to visit for iterative search",
|
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 means no limit", &hnsw_max_search_tuples,
|
||||||
-1, -1, INT_MAX, PGC_USERSET, 0, NULL, NULL, NULL);
|
-1, -1, INT_MAX, PGC_USERSET, 0, NULL, NULL, NULL);
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ IvfflatInit(void)
|
|||||||
IVFFLAT_ITERATIVE_SEARCH_OFF, ivfflat_iterative_search_options, PGC_USERSET, 0, NULL, NULL, NULL);
|
IVFFLAT_ITERATIVE_SEARCH_OFF, ivfflat_iterative_search_options, PGC_USERSET, 0, NULL, NULL, NULL);
|
||||||
|
|
||||||
DefineCustomIntVariable("ivfflat.max_probes", "Sets the max number of probes for iterative search",
|
DefineCustomIntVariable("ivfflat.max_probes", "Sets the max number of probes for iterative search",
|
||||||
"Zero sets to the number of lists", &ivfflat_max_probes,
|
"-1 means no limit", &ivfflat_max_probes,
|
||||||
0, 0, IVFFLAT_MAX_LISTS, PGC_USERSET, 0, NULL, NULL, NULL);
|
-1, -1, IVFFLAT_MAX_LISTS, PGC_USERSET, 0, NULL, NULL, NULL);
|
||||||
|
|
||||||
MarkGUCPrefixReserved("ivfflat");
|
MarkGUCPrefixReserved("ivfflat");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,19 +259,27 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
|
|||||||
/* Get lists and dimensions from metapage */
|
/* Get lists and dimensions from metapage */
|
||||||
IvfflatGetMetaPageInfo(index, &lists, &dimensions);
|
IvfflatGetMetaPageInfo(index, &lists, &dimensions);
|
||||||
|
|
||||||
if (probes > lists)
|
|
||||||
probes = lists;
|
|
||||||
|
|
||||||
if (ivfflat_iterative_search != IVFFLAT_ITERATIVE_SEARCH_OFF)
|
if (ivfflat_iterative_search != IVFFLAT_ITERATIVE_SEARCH_OFF)
|
||||||
{
|
{
|
||||||
if (ivfflat_max_probes == 0)
|
maxProbes = ivfflat_max_probes;
|
||||||
|
|
||||||
|
if (maxProbes < 0)
|
||||||
maxProbes = lists;
|
maxProbes = lists;
|
||||||
else
|
else if (maxProbes < probes)
|
||||||
maxProbes = Min(ivfflat_max_probes, lists);
|
{
|
||||||
|
/* TODO Show notice */
|
||||||
|
maxProbes = probes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
maxProbes = probes;
|
maxProbes = probes;
|
||||||
|
|
||||||
|
if (probes > lists)
|
||||||
|
probes = lists;
|
||||||
|
|
||||||
|
if (maxProbes > lists)
|
||||||
|
maxProbes = lists;
|
||||||
|
|
||||||
so = (IvfflatScanOpaque) palloc(offsetof(IvfflatScanOpaqueData, lists) + maxProbes * sizeof(IvfflatScanList));
|
so = (IvfflatScanOpaque) palloc(offsetof(IvfflatScanOpaqueData, lists) + maxProbes * sizeof(IvfflatScanList));
|
||||||
so->typeInfo = IvfflatGetTypeInfo(index);
|
so->typeInfo = IvfflatGetTypeInfo(index);
|
||||||
so->first = true;
|
so->first = true;
|
||||||
|
|||||||
@@ -95,7 +95,30 @@ SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
|||||||
[0,0,0]
|
[0,0,0]
|
||||||
(3 rows)
|
(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
|
||||||
|
---------
|
||||||
|
[1,2,3]
|
||||||
|
(1 row)
|
||||||
|
|
||||||
|
SET ivfflat.max_probes = 2;
|
||||||
|
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
||||||
|
val
|
||||||
|
---------
|
||||||
|
[1,2,3]
|
||||||
|
[1,1,1]
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
RESET ivfflat.iterative_search;
|
RESET ivfflat.iterative_search;
|
||||||
|
RESET ivfflat.max_probes;
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
-- unlogged
|
-- unlogged
|
||||||
CREATE UNLOGGED TABLE t (val vector(3));
|
CREATE UNLOGGED TABLE t (val vector(3));
|
||||||
@@ -140,11 +163,11 @@ HINT: Available values: off, relaxed_order.
|
|||||||
SHOW ivfflat.max_probes;
|
SHOW ivfflat.max_probes;
|
||||||
ivfflat.max_probes
|
ivfflat.max_probes
|
||||||
--------------------
|
--------------------
|
||||||
0
|
-1
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SET ivfflat.max_probes = -1;
|
SET ivfflat.max_probes = -2;
|
||||||
ERROR: -1 is outside the valid range for parameter "ivfflat.max_probes" (0 .. 32768)
|
ERROR: -2 is outside the valid range for parameter "ivfflat.max_probes" (-1 .. 32768)
|
||||||
SET ivfflat.max_probes = 32769;
|
SET ivfflat.max_probes = 32769;
|
||||||
ERROR: 32769 is outside the valid range for parameter "ivfflat.max_probes" (0 .. 32768)
|
ERROR: 32769 is outside the valid range for parameter "ivfflat.max_probes" (-1 .. 32768)
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
|
|||||||
@@ -53,7 +53,17 @@ CREATE INDEX ON t USING ivfflat (val vector_l2_ops) WITH (lists = 3);
|
|||||||
SET ivfflat.iterative_search = relaxed_order;
|
SET ivfflat.iterative_search = relaxed_order;
|
||||||
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
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]';
|
||||||
|
|
||||||
|
SET ivfflat.max_probes = 2;
|
||||||
|
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
||||||
|
|
||||||
RESET ivfflat.iterative_search;
|
RESET ivfflat.iterative_search;
|
||||||
|
RESET ivfflat.max_probes;
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
|
|
||||||
-- unlogged
|
-- unlogged
|
||||||
@@ -83,7 +93,7 @@ SET ivfflat.iterative_search = on;
|
|||||||
|
|
||||||
SHOW ivfflat.max_probes;
|
SHOW ivfflat.max_probes;
|
||||||
|
|
||||||
SET ivfflat.max_probes = -1;
|
SET ivfflat.max_probes = -2;
|
||||||
SET ivfflat.max_probes = 32769;
|
SET ivfflat.max_probes = 32769;
|
||||||
|
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
|
|||||||
Reference in New Issue
Block a user