mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-25 19:59:54 -05:00
Merged PR 1668682: [Vector Search] Add GUC for the default search parameter calculation
### Does this PR have any customer impact? Yes ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Perf ### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) No ### Are you introducing any new config? If yes, do you have tests with and without them being set? Yes ### ChangeLog (Refer [Template](../oss/CHANGELOG.md)) ### Description Adding the GUC documentdb.enableVectorCalculateDefaultSearchParam to enable or disable the calculation of default search parameters. The default value is on Adding feature counts for the usage of default search parameters. ---- #### AI description (iteration 1) #### PR Classification This PR implements a new configuration option to enable or disable the dynamic calculation of default search parameters for vector search indexes. #### PR Summary The pull request adds a GUC flag that controls whether default search parameters (e.g., nProbes for IVF and efSearch for HNSW) are computed dynamically based on collection size. It updates internal calculation functions, test expectations, and feature counters accordingly. - `src/vector/vector_index_kind_impl.c`: Revised the IVF and HNSW search parameter calculation functions to conditionally compute default parameters when the new GUC is enabled. - `src/configs/feature_flag_configs.c` and `include/vector/vector_common.h`: Introduced the new boolean GUC `enableVectorCalculateDefaultSearchParam`. - Test files (e.g., files under `/oss/internal/pg_documentdb_distributed/src/test/regress/expected/` and corresponding `pgmongo` tests): Updated expected outputs and query plans to reflect the new default parameter values. - Feature counter outputs and related SQL tests: Modified to include metrics for the new default search parameter usage. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #4194082
This commit is contained in:
1 parent
c5bbda3241
commit
4b79ce38d4
11 files changed
+324
-54
No files matched your search
@@ -39,6 +39,10 @@ bool EnableVectorCompressionHalf = DEFAULT_ENABLE_VECTOR_COMPRESSION_HALF;
|
||||
#define DEFAULT_ENABLE_VECTOR_COMPRESSION_PQ true
|
||||
bool EnableVectorCompressionPQ = DEFAULT_ENABLE_VECTOR_COMPRESSION_PQ;
|
||||
|
||||
#define DEFAULT_ENABLE_VECTOR_CALCULATE_DEFAULT_SEARCH_PARAM true
|
||||
bool EnableVectorCalculateDefaultSearchParameter =
|
||||
DEFAULT_ENABLE_VECTOR_CALCULATE_DEFAULT_SEARCH_PARAM;
|
||||
|
||||
/*
|
||||
* SECTION: Indexing feature flags
|
||||
*/
|
||||
@@ -198,14 +202,21 @@ InitializeFeatureFlagConfigurations(const char *prefix, const char *newGucPrefix
|
||||
NULL, &EnableVectorCompressionHalf, DEFAULT_ENABLE_VECTOR_COMPRESSION_HALF,
|
||||
PGC_USERSET, 0, NULL, NULL, NULL);
|
||||
|
||||
DefineCustomBoolVariable
|
||||
(
|
||||
DefineCustomBoolVariable(
|
||||
psprintf("%s.enableVectorCompressionPQ", newGucPrefix),
|
||||
gettext_noop(
|
||||
"Enables support for vector index compression product quantization"),
|
||||
NULL, &EnableVectorCompressionPQ, DEFAULT_ENABLE_VECTOR_COMPRESSION_PQ,
|
||||
PGC_USERSET, 0, NULL, NULL, NULL);
|
||||
|
||||
DefineCustomBoolVariable(
|
||||
psprintf("%s.enableVectorCalculateDefaultSearchParam", newGucPrefix),
|
||||
gettext_noop(
|
||||
"Enables support for vector index default search parameter calculation"),
|
||||
NULL, &EnableVectorCalculateDefaultSearchParameter,
|
||||
DEFAULT_ENABLE_VECTOR_CALCULATE_DEFAULT_SEARCH_PARAM,
|
||||
PGC_USERSET, 0, NULL, NULL, NULL);
|
||||
|
||||
DefineCustomBoolVariable(
|
||||
psprintf("%s.enable_large_unique_index_keys", newGucPrefix),
|
||||
gettext_noop("Whether or not to enable large index keys on unique indexes."),
|
||||
|
||||
@@ -296,6 +296,9 @@ static char FeatureMapping[MAX_FEATURE_COUNT][MAX_FEATURE_NAME_LENGTH] = {
|
||||
[FEATURE_STAGE_SEARCH_VECTOR] = "search_vector",
|
||||
[FEATURE_STAGE_SEARCH_VECTOR_COMPRESSION_HALF] = "search_vector_compression_half",
|
||||
[FEATURE_STAGE_SEARCH_VECTOR_COMPRESSION_PQ] = "search_vector_compression_pq",
|
||||
[FEATURE_STAGE_SEARCH_VECTOR_DEFAULT_NPROBES] = "search_vector_default_nprobes",
|
||||
[FEATURE_STAGE_SEARCH_VECTOR_DEFAULT_EFSEARCH] = "search_vector_default_efsearch",
|
||||
[FEATURE_STAGE_SEARCH_VECTOR_DEFAULT_LSEARCH] = "search_vector_default_lsearch",
|
||||
[FEATURE_STAGE_SEARCH_VECTOR_DISKANN] = "search_vector_diskann",
|
||||
[FEATURE_STAGE_SEARCH_VECTOR_EXACT] = "search_vector_exact",
|
||||
[FEATURE_STAGE_SEARCH_VECTOR_GEN_EMBEDDINGS] = "search_vector_gen_embeddings",
|
||||
|
||||
@@ -631,6 +631,8 @@ CalculateIVFSearchParamBson(bytea *indexOptions, Cardinality indexRows,
|
||||
return searchParamBson;
|
||||
}
|
||||
|
||||
ReportFeatureUsage(FEATURE_STAGE_SEARCH_VECTOR_DEFAULT_NPROBES);
|
||||
|
||||
/* Calculate the default nProbes */
|
||||
int numLists = -1;
|
||||
if (indexOptions == NULL)
|
||||
@@ -645,27 +647,40 @@ CalculateIVFSearchParamBson(bytea *indexOptions, Cardinality indexRows,
|
||||
}
|
||||
|
||||
int defaultNumProbes = -1;
|
||||
if (numLists < 0)
|
||||
if (numLists <= 0)
|
||||
{
|
||||
defaultNumProbes = IVFFLAT_DEFAULT_NPROBES;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* nProbes
|
||||
* < 10000 rows: numLists
|
||||
* < 1M rows: rows / 1000
|
||||
* >= 1M rows: sqrt(rows) */
|
||||
if (indexRows < VECTOR_SEARCH_SMALL_COLLECTION_ROWS)
|
||||
if (EnableVectorCalculateDefaultSearchParameter)
|
||||
{
|
||||
defaultNumProbes = numLists;
|
||||
}
|
||||
else if (indexRows < VECTOR_SEARCH_1M_COLLECTION_ROWS)
|
||||
{
|
||||
defaultNumProbes = indexRows / 1000;
|
||||
/* nProbes < 10000 rows: numLists */
|
||||
if (indexRows < VECTOR_SEARCH_SMALL_COLLECTION_ROWS)
|
||||
{
|
||||
defaultNumProbes = numLists;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* >= 10000 rows: we calculate nProbes based on estimated rowsPerCluster
|
||||
* To make sure we don't scan too many rows */
|
||||
double rowsPerCluster = indexRows / numLists;
|
||||
defaultNumProbes = ceil(VECTOR_SEARCH_SMALL_COLLECTION_ROWS /
|
||||
rowsPerCluster);
|
||||
if (defaultNumProbes > numLists)
|
||||
{
|
||||
defaultNumProbes = numLists;
|
||||
}
|
||||
|
||||
if (defaultNumProbes < 1)
|
||||
{
|
||||
defaultNumProbes = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultNumProbes = sqrt(indexRows);
|
||||
defaultNumProbes = IVFFLAT_DEFAULT_NPROBES;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -700,6 +715,8 @@ CalculateHNSWSearchParamBson(bytea *indexOptions, Cardinality indexRows,
|
||||
return searchParamBson;
|
||||
}
|
||||
|
||||
ReportFeatureUsage(FEATURE_STAGE_SEARCH_VECTOR_DEFAULT_EFSEARCH);
|
||||
|
||||
/* Calculate the default efSearch */
|
||||
int efConstruction = -1;
|
||||
|
||||
@@ -721,9 +738,16 @@ CalculateHNSWSearchParamBson(bytea *indexOptions, Cardinality indexRows,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (indexRows < VECTOR_SEARCH_SMALL_COLLECTION_ROWS)
|
||||
if (EnableVectorCalculateDefaultSearchParameter)
|
||||
{
|
||||
defaultEfSearch = efConstruction;
|
||||
if (indexRows < VECTOR_SEARCH_SMALL_COLLECTION_ROWS)
|
||||
{
|
||||
defaultEfSearch = efConstruction;
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultEfSearch = HNSW_DEFAULT_EF_SEARCH;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user