Skip to content

Commit 02ef0b1

Browse files
authored
[SVS] Add multi-vector support to the Tiered SVS Index (#699)
* [SVS] Add multi-vector support to the Tiered SVS Index * Code refine * Add tests and fixes for swaps journal processing * Code review s1e1: Extract complex logic to dedicated funcs * Update algorithm for swaps journal processing * Improve code coverage * Code review s2e1
1 parent e6b4bc8 commit 02ef0b1

File tree

7 files changed

+888
-152
lines changed

7 files changed

+888
-152
lines changed

src/VecSim/algorithms/brute_force/brute_force.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ class BruteForceIndex : public VecSimIndexAbstract<DataType, DistType> {
5959

6060
const RawDataContainer *getVectorsContainer() const { return this->vectors; }
6161

62-
const labelType getLabelByInternalId(idType internal_id) const {
63-
return idToLabelMapping.at(internal_id);
64-
}
6562
// Remove a specific vector that is stored under a label from the index by its internal id.
6663
virtual int deleteVectorById(labelType label, idType id) = 0;
6764
// Remove a vector and return a map between internal ids and the original internal ids of the
@@ -71,6 +68,9 @@ class BruteForceIndex : public VecSimIndexAbstract<DataType, DistType> {
7168
// Check if a certain label exists in the index.
7269
virtual bool isLabelExists(labelType label) = 0;
7370

71+
// Unsafe (assume index data guard is held in MT mode).
72+
virtual vecsim_stl::vector<idType> getElementIds(size_t label) const = 0;
73+
7474
virtual ~BruteForceIndex() = default;
7575
#ifdef BUILD_TESTS
7676
void fitMemory() override {

src/VecSim/algorithms/brute_force/brute_force_multi.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,15 @@ class BruteForceIndex_Multi : public BruteForceIndex<DataType, DistType> {
9494
keys.insert(it.first);
9595
}
9696
return keys;
97-
};
97+
}
98+
99+
inline vecsim_stl::vector<idType> getElementIds(size_t label) const override {
100+
auto it = labelToIdsLookup.find(label);
101+
if (it == labelToIdsLookup.end()) {
102+
return vecsim_stl::vector<idType>{this->allocator}; // return an empty collection
103+
}
104+
return it->second;
105+
}
98106

99107
inline vecsim_stl::abstract_priority_queue<DistType, labelType> *
100108
getNewMaxPriorityQueue() const override {

src/VecSim/algorithms/brute_force/brute_force_single.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,16 @@ class BruteForceIndex_Single : public BruteForceIndex<DataType, DistType> {
9393
keys.insert(it.first);
9494
}
9595
return keys;
96-
};
96+
}
97+
98+
vecsim_stl::vector<idType> getElementIds(size_t label) const override {
99+
vecsim_stl::vector<idType> ids(this->allocator);
100+
auto it = labelToIdLookup.find(label);
101+
if (it != labelToIdLookup.end()) {
102+
ids.push_back(it->second);
103+
}
104+
return ids;
105+
}
97106

98107
vecsim_stl::abstract_priority_queue<DistType, labelType> *
99108
getNewMaxPriorityQueue() const override {

src/VecSim/algorithms/hnsw/hnsw_tiered.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ void TieredHNSWIndex<DataType, DistType>::executeInsertJob(HNSWInsertJob *job) {
571571
// corresponding job id. Note that after calling deleteVectorById, the last id's label
572572
// shouldn't be available, since it is removed from the lookup.
573573
labelType last_vec_label =
574-
this->frontendIndex->getLabelByInternalId(this->frontendIndex->indexSize() - 1);
574+
this->frontendIndex->getVectorLabel(this->frontendIndex->indexSize() - 1);
575575
int deleted = this->frontendIndex->deleteVectorById(job->label, job->id);
576576
if (deleted && job->id != this->frontendIndex->indexSize()) {
577577
// If the vector removal caused a swap with the last id, update the relevant insert job.

src/VecSim/algorithms/svs/svs_tiered.h

Lines changed: 201 additions & 97 deletions
Large diffs are not rendered by default.

src/VecSim/index_factories/tiered_factory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ BFParams NewBFParams(const TieredIndexParams *params) {
127127
return BFParams{.type = svs_params.type,
128128
.dim = svs_params.dim,
129129
.metric = svs_params.metric,
130-
.multi = false, // multi not supported
130+
.multi = svs_params.multi,
131131
.blockSize = svs_params.blockSize};
132132
}
133133

@@ -155,7 +155,7 @@ inline VecSimIndex *NewIndex(const TieredIndexParams *params) {
155155
.blockSize = bf_params.blockSize,
156156
.multi = bf_params.multi,
157157
.logCtx = params->primaryIndexParams->logCtx};
158-
auto frontendIndex = static_cast<BruteForceIndex_Single<DataType, float> *>(
158+
auto frontendIndex = static_cast<BruteForceIndex<DataType, float> *>(
159159
BruteForceFactory::NewIndex(&bf_params, abstractInitParams, false));
160160

161161
// Create new tiered svs index

0 commit comments

Comments
 (0)