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
1 change: 1 addition & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ on:
- bm-svs-train-fp16
- bm-basics-svs-fp32-single
- bm-spaces
- bm-hnsw-internals-incoming-edges
description: 'Benchmarks set to run'
default: benchmarks-all
architecture:
Expand Down
15 changes: 14 additions & 1 deletion src/VecSim/algorithms/hnsw/graph_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <mutex>
#include "VecSim/utils/vec_utils.h"

// Amortized shrink thresholds for incoming edges vectors.
// Shrink is triggered when: capacity > SHRINK_RATIO * size
constexpr size_t INCOMING_EDGES_SHRINK_RATIO = 2;

template <typename DistType>
using candidatesList = vecsim_stl::vector<std::pair<DistType, idType>>;

Expand Down Expand Up @@ -73,7 +77,16 @@ struct ElementLevelData {
this->incomingUnidirectionalEdges->push_back(node_id);
}
bool removeIncomingUnidirectionalEdgeIfExists(idType node_id) {
return this->incomingUnidirectionalEdges->remove(node_id);
bool result = this->incomingUnidirectionalEdges->remove(node_id);

if (result) {
auto &vec = *this->incomingUnidirectionalEdges;
if (vec.capacity() > INCOMING_EDGES_SHRINK_RATIO * vec.size()) {
vec.shrink_to_fit();
}
}

return result;
}
void swapNodeIdInIncomingEdges(idType id_before, idType id_after) {
auto it = std::find(this->incomingUnidirectionalEdges->begin(),
Expand Down
2 changes: 2 additions & 0 deletions src/VecSim/algorithms/hnsw/hnsw_tiered_tests_friends.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ friend class CommonTypeMetricTieredTests_TestDataSizeTieredHNSW_Test;

INDEX_TEST_FRIEND_CLASS(BM_VecSimBasics)
INDEX_TEST_FRIEND_CLASS(BM_VecSimCommon)

friend class BM_IncomingEdgesBase;
5 changes: 5 additions & 0 deletions tests/benchmark/benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if [ -z "$BM_TYPE" ] || [ "$BM_TYPE" = "benchmarks-all" ]; then
done
done
echo updated_index_single_fp32
echo index_internals_incoming_edges_fp32
echo svs_training_fp32
echo svs_training_fp16
echo basics_svs_single_fp32
Expand Down Expand Up @@ -89,6 +90,10 @@ elif [ "$BM_TYPE" = "bm-batch-iter-uint8-multi" ] ; then
elif [ "$BM_TYPE" = "bm-updated-fp32-single" ] ; then
echo updated_index_single_fp32

# hnsw internals benchmarks
elif [ "$BM_TYPE" = "bm-hnsw-internals-incoming-edges" ] ; then
echo index_internals_incoming_edges_fp32

# SVS benchmarks
elif [ "$BM_TYPE" = "bm-svs-train-fp32" ] ; then
echo svs_training_fp32
Expand Down
Loading
Loading