Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/VecSim/index_factories/hnsw_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ VecSimIndex *NewIndex(const VecSimParams *params, bool is_normalized) {

VecSimIndex *NewIndex(const HNSWParams *params, bool is_normalized) {
VecSimParams vecSimParams = {.algoParams = {.hnswParams = HNSWParams{*params}}};
return NewIndex(&vecSimParams);
return NewIndex(&vecSimParams, is_normalized);
}

template <typename DataType, typename DistType = DataType>
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_hnsw_sq8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,28 @@ TEST(HNSWSQ8ParamsTest, RejectsOutOfRangeMetric) {
EXPECT_EQ(EstimateInitialSize(hnsw_params), SIZE_MAX);
}

// The HNSWParams overload of NewIndex must forward is_normalized. A standalone SQ8 index accepts
// Cosine only when the caller declares the input already normalized (it then resolves to IP).
TEST(HNSWSQ8ParamsTest, HNSWParamsOverloadForwardsIsNormalized) {
HNSWParams params = {.type = VecSimType_FLOAT32,
.dim = 16,
.metric = VecSimMetric_Cosine,
.quantType = VecSimQuant_SQ8};

// VecSimIndex_Free does not accept NULL, so free only what was created.
VecSimIndex *normalized = HNSWFactory::NewIndex(&params, true);
EXPECT_NE(normalized, nullptr);
if (normalized) {
VecSimIndex_Free(normalized);
}

VecSimIndex *unnormalized = HNSWFactory::NewIndex(&params, false);
EXPECT_EQ(unnormalized, nullptr);
if (unnormalized) {
VecSimIndex_Free(unnormalized);
}
}

// Exercise both endpoints, a mean not representable in FP16, and odd dimensions that
// also cover SIMD residual handling.
TEST(HNSWSQ8ParamsTest, MeanCenteredFP16L2BoundedValues) {
Expand Down
Loading