Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/VecSim/algorithms/svs/svs_tiered.h
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,19 @@ class TieredSVSIndex : public VecSimTieredIndex<DataType, float> {
.updateJobWaitTime = this->updateJobWaitTime,
};
{
std::lock_guard<std::mutex> lock(this->updateJobMutex);
svsTieredInfo.indexUpdateScheduled =
this->indexUpdateScheduled.test() == VecSimBool_TRUE;
// Use try_lock to avoid blocking the main thread during long-running
// training operations. updateSVSIndexWrapper holds updateJobMutex for
// the entire training duration (which can take 40-85s on slow machines).
// If the mutex is held, training is actively running, so we report
// indexUpdateScheduled = true (BACKGROUND_INDEXING = 1).
std::unique_lock<std::mutex> lock(this->updateJobMutex, std::try_to_lock);
if (lock.owns_lock()) {
svsTieredInfo.indexUpdateScheduled =
this->indexUpdateScheduled.test() == VecSimBool_TRUE;
} else {
// Mutex is held by updateSVSIndexWrapper — training is in progress.
svsTieredInfo.indexUpdateScheduled = true;
}
}
info.tieredInfo.specificTieredBackendInfo.svsTieredInfo = svsTieredInfo;
info.tieredInfo.backgroundIndexing =
Expand Down
9 changes: 1 addition & 8 deletions tests/flow/test_svs_tiered.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,35 +235,28 @@ def search_insert(test_logger, is_multi: bool, num_per_label=1, data_type=VecSim
searches_number = 0
# run knn query every 1 s.
total_tiered_search_time = 0
prev_bf_size = num_labels
cur_svs_label_count = index.svs_label_count()

test_logger.info(f"SVS labels number = {cur_svs_label_count}")
while searches_number == 0 or cur_svs_label_count < num_labels - updateThreshold:
# For each run get the current svs size and the query time.
bf_curr_size = index.get_curr_bf_size()
query_start = time.time()
tiered_labels, _ = index.knn_query(query_data, k)
query_dur = time.time() - query_start
total_tiered_search_time += query_dur

test_logger.info(f"query time = {round_ms(query_dur)} ms")

# BF size should decrease.
test_logger.info(f"bf size = {bf_curr_size}")
assert bf_curr_size < prev_bf_size

# Run the query also in the bf index to get the ground truth results.
bf_labels, _ = bf_index.knn_query(query_data, k)
correct += len(np.intersect1d(tiered_labels[0], bf_labels[0]))
time.sleep(1)
searches_number += 1
prev_bf_size = bf_curr_size
cur_svs_label_count = index.svs_label_count()

# SVS labels count updates before the job is done, so we need to wait for the queue to be empty.
index.wait_for_index(1)
index_dur = time.time() - index_start
assert index.get_curr_bf_size() == 0
test_logger.info(f"Indexing in the tiered index took {round_(index_dur)} s")

# Measure recall.
Expand Down
Loading