Skip to content

Commit 5e94154

Browse files
committed
Fix handling of cmake USE_SVS=OFF and HAVE_SVS=false in Tiered SVS index
1 parent 57ae3b5 commit 5e94154

File tree

4 files changed

+102
-62
lines changed

4 files changed

+102
-62
lines changed

src/VecSim/index_factories/tiered_factory.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
#include "VecSim/algorithms/hnsw/hnsw_tiered.h"
1212
#include "VecSim/types/bfloat16.h"
1313
#include "VecSim/types/float16.h"
14-
#if HAVE_SVS
1514
#include "VecSim/index_factories/svs_factory.h"
15+
16+
#if HAVE_SVS
1617
#include "VecSim/algorithms/svs/svs_tiered.h"
1718
#endif
1819

@@ -118,10 +119,8 @@ VecSimIndex *NewIndex(const TieredIndexParams *params) {
118119
}
119120
} // namespace TieredHNSWFactory
120121

121-
#if HAVE_SVS
122122
namespace TieredSVSFactory {
123-
124-
static inline BFParams NewBFParams(const TieredIndexParams *params) {
123+
BFParams NewBFParams(const TieredIndexParams *params) {
125124
auto &svs_params = params->primaryIndexParams->algoParams.svsParams;
126125
return BFParams{.type = svs_params.type,
127126
.dim = svs_params.dim,
@@ -130,6 +129,7 @@ static inline BFParams NewBFParams(const TieredIndexParams *params) {
130129
.blockSize = svs_params.blockSize};
131130
}
132131

132+
#if HAVE_SVS
133133
template <typename DataType>
134134
inline VecSimIndex *NewIndex(const TieredIndexParams *params) {
135135

@@ -191,7 +191,7 @@ inline size_t EstimateInitialSize(const TieredIndexParams *params) {
191191
}
192192

193193
VecSimIndex *NewIndex(const TieredIndexParams *params) {
194-
// Tiered index that contains HNSW index as primary index
194+
// Tiered index that contains SVS index as primary index
195195
VecSimType type = params->primaryIndexParams->algoParams.svsParams.type;
196196
switch (type) {
197197
case VecSimType_FLOAT32:
@@ -204,19 +204,25 @@ VecSimIndex *NewIndex(const TieredIndexParams *params) {
204204
}
205205
return nullptr; // Invalid type.
206206
}
207-
} // namespace TieredSVSFactory
207+
208+
// This is a temporary solution to avoid breaking the build when SVS is not available
209+
// and to allow the code to compile without SVS support.
210+
// TODO: remove HAVE_SVS when SVS will support all Redis platfoms and compilers
211+
#else // HAVE_SVS
212+
inline VecSimIndex *NewIndex(const TieredIndexParams *params) { return nullptr; }
213+
inline size_t EstimateInitialSize(const TieredIndexParams *params) { return 0; }
214+
inline size_t EstimateElementSize(const TieredIndexParams *params) { return 0; }
208215
#endif
216+
} // namespace TieredSVSFactory
209217

210218
VecSimIndex *NewIndex(const TieredIndexParams *params) {
211219
switch (params->primaryIndexParams->algo) {
212220
// Tiered index that contains HNSW index as primary index
213221
case VecSimAlgo_HNSWLIB:
214222
return TieredHNSWFactory::NewIndex(params);
215-
#if HAVE_SVS
216-
// Tiered index that contains SVS index as primary index
223+
// Tiered index that contains SVS index as primary index
217224
case VecSimAlgo_SVS:
218225
return TieredSVSFactory::NewIndex(params);
219-
#endif
220226
default:
221227
return nullptr; // Invalid algorithm.
222228
}
@@ -232,12 +238,10 @@ size_t EstimateInitialSize(const TieredIndexParams *params) {
232238
est += TieredHNSWFactory::EstimateInitialSize(params);
233239
bf_params = TieredHNSWFactory::NewBFParams(params);
234240
break;
235-
#if HAVE_SVS
236241
case VecSimAlgo_SVS:
237242
est += TieredSVSFactory::EstimateInitialSize(params);
238243
bf_params = TieredSVSFactory::NewBFParams(params);
239244
break;
240-
#endif
241245
default:
242246
assert(false && "Invalid algorithm");
243247
}
@@ -252,11 +256,9 @@ size_t EstimateElementSize(const TieredIndexParams *params) {
252256
case VecSimAlgo_HNSWLIB:
253257
est = HNSWFactory::EstimateElementSize(&params->primaryIndexParams->algoParams.hnswParams);
254258
break;
255-
#if HAVE_SVS
256259
case VecSimAlgo_SVS:
257260
est = SVSFactory::EstimateElementSize(&params->primaryIndexParams->algoParams.svsParams);
258261
break;
259-
#endif
260262
default:
261263
assert(false && "Invalid algorithm");
262264
}

src/VecSim/index_factories/tiered_factory.h

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ VecSimIndex *NewIndex(const TieredIndexParams *params, HNSWIndex<DataType, DistT
5555
hnsw_index, frontendIndex, *params, management_layer_allocator);
5656
}
5757
} // namespace TieredHNSWFactory
58+
59+
namespace TieredSVSFactory {
60+
BFParams NewBFParams(const TieredIndexParams *params);
61+
}
5862
#endif
5963

6064
}; // namespace TieredFactory

tests/unit/test_svs.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -1453,21 +1453,23 @@ TYPED_TEST(SVSTest, svs_vector_search_test_cosine) {
14531453
TYPED_TEST(SVSTest, testSizeEstimation) {
14541454
size_t dim = 64;
14551455

1456+
auto quantBits = TypeParam::get_quant_bits();
1457+
// Get the fallback quantization mode
1458+
quantBits = std::get<0>(svs_details::isSVSQuantBitsSupported(quantBits));
1459+
1460+
#if HAVE_SVS_LVQ
14561461
// SVS block sizes always rounded to a power of 2
14571462
// This why, in case of quantization, actual block size can be differ than requested
14581463
// In addition, block size to be passed to graph and dataset counted in bytes,
14591464
// converted then to a number of elements.
14601465
// IMHO, would be better to always interpret block size to a number of elements
14611466
// rather than conversion to-from number of bytes
1462-
auto quantBits = TypeParam::get_quant_bits();
1463-
// Get the fallback quantization mode
1464-
quantBits = std::get<0>(svs_details::isSVSQuantBitsSupported(quantBits));
14651467
if (quantBits != VecSimSvsQuant_NONE) {
14661468
// Extra data in LVQ vector
14671469
const auto lvq_vector_extra = sizeof(svs::quantization::lvq::ScalarBundle);
14681470
dim -= (lvq_vector_extra * 8) / TypeParam::get_quant_bits();
14691471
}
1470-
1472+
#endif
14711473
size_t n = 0;
14721474
size_t bs = DEFAULT_BLOCK_SIZE;
14731475

0 commit comments

Comments
 (0)