Skip to content

Commit a0d944f

Browse files
craig[bot]wenyihu6andy-kimball
committed
149847: asim: more asim follow up r=tbg a=wenyihu6 **asim: add replace = true to example_splitting** Previously, we added a replace option to gen_load in data driven tests to control whether the load generator is replaced or appended. The new default is replace = false (append) which changed the original behaviour of replacing the generator. This test expected the original behavior when re-running eval, but we forgot to explicitly set replace = true. This commit fixes that. Epic: none Release note: none --- **asim: add comment for BasicCluster.info** This commit adds a comment to BasicCluster.info to highlight the inefficiency of constructing the region node ratio when nodes_per_region is used with gen_cluster just to reuse ClusterInfoWithDistribution. Epic: none Release note: none 149858: vecindex: improve vector reranking r=drewkimball a=andy-kimball This commit exposes a new vector_search_rerank_multiplier session setting that controls how many vectors will be reranked at the end of a search. Empirical testing shows that for difficult datasets (e.g. Glove and CLIP), the number of vectors that need to be reranked is proportional to: log2(search_beam_size) * log2(top-k-results) We multiply this number by the vector_search_rerank_multiplier setting, which is set to 50 by default (also derived empirically). This formula will rerank enough vectors to allow us to achieve high accuracies while still providing a safeguard that prevents runaway evaluation in edge cases. Less difficult datasets need to rerank far fewer vectors, but it doesn't hurt to have a limit that's too high, since RaBitQ error bounds let us avoid actually evaluating unneeded vectors. This commit also increases the max value of vector_search_beam_size from 512 to 2048, since some datasets need it. Epic: CRDB-42943 Release note: None Co-authored-by: wenyihu6 <[email protected]> Co-authored-by: Andrew Kimball <[email protected]>
3 parents 8e997ca + 40a1874 + 66ca292 commit a0d944f

27 files changed

+275
-94
lines changed

pkg/cmd/vecbench/mem_provider.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ func (m *MemProvider) Search(
165165
// Search the store.
166166
var idxCtx cspann.Context
167167
idxCtx.Init(txn)
168-
searchSet := cspann.SearchSet{MaxResults: memState.maxResults}
168+
maxResults, maxExtraResults :=
169+
cspann.IncreaseRerankResults(memState.beamSize, memState.maxResults, 50)
170+
searchSet := cspann.SearchSet{MaxResults: maxResults, MaxExtraResults: maxExtraResults}
169171
searchOptions := cspann.SearchOptions{BaseBeamSize: memState.beamSize}
170172
err = m.index.Search(ctx, &idxCtx, nil /* treeKey */, vec, &searchSet, searchOptions)
171173
if err != nil {

pkg/kv/kvserver/asim/gen/generator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ func (bc BasicCluster) info() state.ClusterInfo {
232232
return state.ClusterInfoWithStoreCount(bc.Nodes, bc.StoresPerNode)
233233
}
234234

235+
// TODO(wenyihu6): we have the number of nodes and their localities already.
236+
// We could construct ClusterInfo without a ratio calculation. We are doing
237+
// this for now just to reuse ClusterInfoWithDistribution. But there may be
238+
// rounding errors.
235239
regionNodeWeights := make([]float64, len(bc.NodesPerRegion))
236240
totalNodes := 0
237241
for i, nodes := range bc.NodesPerRegion {

pkg/kv/kvserver/asim/tests/testdata/non_rand/example_splitting.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ last store values: [s1=6] (stddev=0.00, mean=6.00, sum=6)
5454
# repeatedly - if the load split algorithm is good, we should expect the same
5555
# number of splits as the uniform workload. However, that is not the case as we
5656
# require more splits with a zipfian distribution.
57-
gen_load rate=10000 rw_ratio=1 access_skew=true
57+
gen_load rate=10000 rw_ratio=1 access_skew=true replace=true
5858
----
5959

6060
eval duration=5m samples=2 seed=42
@@ -63,24 +63,24 @@ OK
6363

6464
plot stat=replicas sample=4
6565
----
66-
15.00 ┤ ──────────────────────────────────────────────
67-
14.07 ╭──╯
68-
13.13 ┤ ╭───╯
69-
12.20╭──╯
70-
11.27 ┤ ╭──╯
71-
10.33 ┤ ╭──╯
72-
9.40 ┤ ╭───╯
73-
8.47╭──╯
74-
7.53
75-
6.60
76-
5.67 ┤ │
77-
4.73
78-
3.80╭──╯
79-
2.87
80-
1.93╭──╯
81-
1.00 ┼───╯
82-
replicas
66+
9.00 ┤ ╭────────────────────────────────────────────────────
67+
8.47
68+
7.93 ┤ ╭───╯
69+
7.40
70+
6.87 ┤ ╭──╯
71+
6.33 ┤
72+
5.80 ┤ ╭───╯
73+
5.27
74+
4.73 ╭──╯
75+
4.20╭──╯
76+
3.67 ┤ │
77+
3.13╭──╯
78+
2.60
79+
2.07╭──╯
80+
1.53
81+
1.00 ┼───╯
82+
replicas
8383
initial store values: [s1=1] (stddev=0.00, mean=1.00, sum=1)
84-
last store values: [s1=15] (stddev=0.00, mean=15.00, sum=15)
84+
last store values: [s1=9] (stddev=0.00, mean=9.00, sum=9)
8585

8686
# vim:ft=sh

pkg/sql/exec_util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,6 +4212,10 @@ func (m *sessionDataMutator) SetVectorSearchBeamSize(val int32) {
42124212
m.data.VectorSearchBeamSize = val
42134213
}
42144214

4215+
func (m *sessionDataMutator) SetVectorSearchRerankMultiplier(val int32) {
4216+
m.data.VectorSearchRerankMultiplier = val
4217+
}
4218+
42154219
func (m *sessionDataMutator) SetPropagateAdmissionHeaderToLeafTransactions(val bool) {
42164220
m.data.PropagateAdmissionHeaderToLeafTransactions = val
42174221
}

pkg/sql/logictest/testdata/logic_test/information_schema

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4141,6 +4141,7 @@ use_pre_25_2_variadic_builtins off
41414141
use_proc_txn_control_extended_protocol_fix on
41424142
variable_inequality_lookup_join_enabled on
41434143
vector_search_beam_size 32
4144+
vector_search_rerank_multiplier 50
41444145
xmloption content
41454146

41464147
# information_schema can be used with the anonymous database.

pkg/sql/logictest/testdata/logic_test/pg_catalog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,6 +3146,7 @@ use_pre_25_2_variadic_builtins off
31463146
use_proc_txn_control_extended_protocol_fix on NULL NULL NULL string
31473147
variable_inequality_lookup_join_enabled on NULL NULL NULL string
31483148
vector_search_beam_size 32 NULL NULL NULL string
3149+
vector_search_rerank_multiplier 50 NULL NULL NULL string
31493150
vectorize on NULL NULL NULL string
31503151
xmloption content NULL NULL NULL string
31513152

@@ -3382,6 +3383,7 @@ use_pre_25_2_variadic_builtins off
33823383
use_proc_txn_control_extended_protocol_fix on NULL user NULL on on
33833384
variable_inequality_lookup_join_enabled on NULL user NULL on on
33843385
vector_search_beam_size 32 NULL user NULL 32 32
3386+
vector_search_rerank_multiplier 50 NULL user NULL 50 50
33853387
vectorize on NULL user NULL on on
33863388
xmloption content NULL user NULL content content
33873389

@@ -3610,6 +3612,7 @@ use_pre_25_2_variadic_builtins NULL NULL
36103612
use_proc_txn_control_extended_protocol_fix NULL NULL NULL NULL NULL
36113613
variable_inequality_lookup_join_enabled NULL NULL NULL NULL NULL
36123614
vector_search_beam_size NULL NULL NULL NULL NULL
3615+
vector_search_rerank_multiplier NULL NULL NULL NULL NULL
36133616
vectorize NULL NULL NULL NULL NULL
36143617
xmloption NULL NULL NULL NULL NULL
36153618

pkg/sql/logictest/testdata/logic_test/show_source

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ use_pre_25_2_variadic_builtins off
250250
use_proc_txn_control_extended_protocol_fix on
251251
variable_inequality_lookup_join_enabled on
252252
vector_search_beam_size 32
253+
vector_search_rerank_multiplier 50
253254
vectorize on
254255
xmloption content
255256

pkg/sql/logictest/testdata/logic_test/vector_index

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,11 +843,31 @@ SHOW vector_search_beam_size;
843843
----
844844
8
845845

846-
statement error vector_search_beam_size cannot be less than 1 or greater than 512
846+
statement error vector_search_beam_size cannot be less than 1 or greater than 2048
847847
SET vector_search_beam_size=0
848848

849-
statement error vector_search_beam_size cannot be less than 1 or greater than 512
850-
SET vector_search_beam_size=513
849+
statement error vector_search_beam_size cannot be less than 1 or greater than 2048
850+
SET vector_search_beam_size=2049
851+
852+
# Ensure that the vector_search_rerank_multiplier session setting is settable.
853+
query T
854+
SHOW vector_search_rerank_multiplier;
855+
----
856+
50
857+
858+
statement ok
859+
SET vector_search_rerank_multiplier=100
860+
861+
query T
862+
SHOW vector_search_rerank_multiplier;
863+
----
864+
100
865+
866+
statement error vector_search_rerank_multiplier cannot be less than 0 or greater than 100
867+
SET vector_search_rerank_multiplier=-1
868+
869+
statement error vector_search_rerank_multiplier cannot be less than 0 or greater than 100
870+
SET vector_search_rerank_multiplier=101
851871

852872
subtest end
853873

pkg/sql/rowexec/vector_search.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ func newVectorSearchProcessor(
6161
}
6262
searchBeamSize := int(flowCtx.EvalCtx.SessionData().VectorSearchBeamSize)
6363
maxResults := int(v.targetCount)
64-
v.searcher.Init(flowCtx.EvalCtx, idx, flowCtx.Txn, &spec.GetFullVectorsFetchSpec, searchBeamSize, maxResults)
64+
rerankMultiplier := int(flowCtx.EvalCtx.SessionData().VectorSearchRerankMultiplier)
65+
v.searcher.Init(flowCtx.EvalCtx,
66+
idx, flowCtx.Txn, &spec.GetFullVectorsFetchSpec, searchBeamSize, maxResults, rerankMultiplier)
6567
colTypes := make([]*types.T, len(v.fetchSpec.FetchedColumns))
6668
for i, col := range v.fetchSpec.FetchedColumns {
6769
colTypes[i] = col.Type

pkg/sql/sessiondatapb/local_only_session_data.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,11 @@ message LocalOnlySessionData {
694694
bool enable_scrub_job = 176;
695695
// AllowViewWithSecurityInvokerClause indicates whether security invoker for views is enabled
696696
bool allow_view_with_security_invoker_clause = 177;
697+
// VectorSearchRerankMultiplier controls how many of the initial search results
698+
// can be reranked using exact distance calculations with the original
699+
// full-size vectors. It acts as a multiplier on a base limit derived from the
700+
// search beam size and the top-k results requested by the query.
701+
int32 vector_search_rerank_multiplier = 178;
697702

698703
///////////////////////////////////////////////////////////////////////////
699704
// WARNING: consider whether a session parameter you're adding needs to //

0 commit comments

Comments
 (0)