Skip to content

Commit 18d41bb

Browse files
committed
add batch size cap and comments to adaptive filtered search
- Cap batch size with std::min instead of modulo to avoid SIGFPE - Add comments explaining adaptive batch sizing logic
1 parent 302e58d commit 18d41bb

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

bindings/cpp/src/dynamic_vamana_index_impl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,18 @@ class DynamicVamanaIndexImpl {
126126
auto iterator = impl_->batch_iterator(query);
127127
size_t found = 0;
128128
size_t total_checked = 0;
129+
// Use adaptive batch sizing: start with at least k candidates,
130+
// then adjust based on observed filter hit rate.
129131
auto batch_size = std::max(k, sp.buffer_config_.get_search_window_size());
132+
const auto max_batch_size = batch_size;
130133
do {
131-
batch_size =
132-
predict_further_processing(total_checked, found, k, batch_size);
134+
// Estimate how many candidates we need to find remaining
135+
// results given the observed hit rate so far.
136+
batch_size = predict_further_processing(
137+
total_checked, found, k, batch_size
138+
);
139+
// Cap to avoid oversized batches in the iterator.
140+
batch_size = std::min(batch_size, max_batch_size);
133141
iterator.next(batch_size);
134142
total_checked += iterator.size();
135143
for (auto& neighbor : iterator.results()) {

bindings/cpp/src/vamana_index_impl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,18 @@ class VamanaIndexImpl {
132132
auto iterator = get_impl()->batch_iterator(query);
133133
size_t found = 0;
134134
size_t total_checked = 0;
135+
// Use adaptive batch sizing: start with at least k candidates,
136+
// then adjust based on observed filter hit rate.
135137
auto batch_size = std::max(k, sp.buffer_config_.get_search_window_size());
138+
const auto max_batch_size = batch_size;
136139
do {
137-
batch_size =
138-
predict_further_processing(total_checked, found, k, batch_size);
140+
// Estimate how many candidates we need to find remaining
141+
// results given the observed hit rate so far.
142+
batch_size = predict_further_processing(
143+
total_checked, found, k, batch_size
144+
);
145+
// Cap to avoid oversized batches in the iterator.
146+
batch_size = std::min(batch_size, max_batch_size);
139147
iterator.next(batch_size);
140148
total_checked += iterator.size();
141149
for (auto& neighbor : iterator.results()) {

0 commit comments

Comments
 (0)