@@ -33,10 +33,14 @@ NewIndex_ChooseMultiOrSingle(const HNSWParams *params,
3333
3434static AbstractIndexInitParams NewAbstractInitParams (const VecSimParams *params) {
3535 const HNSWParams *hnswParams = ¶ms->algoParams .hnswParams ;
36+
37+ size_t dataSize =
38+ VecSimParams_GetDataSize (hnswParams->type , hnswParams->dim , hnswParams->metric );
3639 AbstractIndexInitParams abstractInitParams = {.allocator =
3740 VecSimAllocator::newVecsimAllocator (),
3841 .dim = hnswParams->dim ,
3942 .vecType = hnswParams->type ,
43+ .dataSize = dataSize,
4044 .metric = hnswParams->metric ,
4145 .blockSize = hnswParams->blockSize ,
4246 .multi = hnswParams->multi ,
@@ -48,34 +52,25 @@ VecSimIndex *NewIndex(const VecSimParams *params, bool is_normalized) {
4852 const HNSWParams *hnswParams = ¶ms->algoParams .hnswParams ;
4953 AbstractIndexInitParams abstractInitParams = NewAbstractInitParams (params);
5054
51- // If the index metric is Cosine, and is_normalized == true, we will skip normalizing vectors
52- // and query blobs.
53- VecSimMetric metric;
54- if (is_normalized && hnswParams->metric == VecSimMetric_Cosine) {
55- metric = VecSimMetric_IP;
56- } else {
57- metric = hnswParams->metric ;
58- }
59-
6055 if (hnswParams->type == VecSimType_FLOAT32) {
6156 IndexComponents<float , float > indexComponents = CreateIndexComponents<float , float >(
62- abstractInitParams.allocator , metric, hnswParams->dim );
57+ abstractInitParams.allocator , hnswParams-> metric , hnswParams->dim , is_normalized );
6358 return NewIndex_ChooseMultiOrSingle<float >(hnswParams, abstractInitParams, indexComponents);
6459
6560 } else if (hnswParams->type == VecSimType_FLOAT64) {
6661 IndexComponents<double , double > indexComponents = CreateIndexComponents<double , double >(
67- abstractInitParams.allocator , metric, hnswParams->dim );
62+ abstractInitParams.allocator , hnswParams-> metric , hnswParams->dim , is_normalized );
6863 return NewIndex_ChooseMultiOrSingle<double >(hnswParams, abstractInitParams,
6964 indexComponents);
7065
7166 } else if (hnswParams->type == VecSimType_BFLOAT16) {
7267 IndexComponents<bfloat16, float > indexComponents = CreateIndexComponents<bfloat16, float >(
73- abstractInitParams.allocator , metric, hnswParams->dim );
68+ abstractInitParams.allocator , hnswParams-> metric , hnswParams->dim , is_normalized );
7469 return NewIndex_ChooseMultiOrSingle<bfloat16, float >(hnswParams, abstractInitParams,
7570 indexComponents);
7671 } else if (hnswParams->type == VecSimType_FLOAT16) {
7772 IndexComponents<float16, float > indexComponents = CreateIndexComponents<float16, float >(
78- abstractInitParams.allocator , metric, hnswParams->dim );
73+ abstractInitParams.allocator , hnswParams-> metric , hnswParams->dim , is_normalized );
7974 return NewIndex_ChooseMultiOrSingle<float16, float >(hnswParams, abstractInitParams,
8075 indexComponents);
8176 }
@@ -203,32 +198,25 @@ VecSimIndex *NewIndex(const std::string &location, bool is_normalized) {
203198 VecSimParams vecsimParams = {.algo = VecSimAlgo_HNSWLIB,
204199 .algoParams = {.hnswParams = HNSWParams{params}}};
205200
206- VecSimMetric metric;
207- if (is_normalized && params.metric == VecSimMetric_Cosine) {
208- metric = VecSimMetric_IP;
209- } else {
210- metric = params.metric ;
211- }
212-
213201 AbstractIndexInitParams abstractInitParams = NewAbstractInitParams (&vecsimParams);
214202 if (params.type == VecSimType_FLOAT32) {
215203 IndexComponents<float , float > indexComponents = CreateIndexComponents<float , float >(
216- abstractInitParams.allocator , metric, abstractInitParams.dim );
204+ abstractInitParams.allocator , params. metric , abstractInitParams.dim , is_normalized );
217205 return NewIndex_ChooseMultiOrSingle<float >(input, ¶ms, abstractInitParams,
218206 indexComponents, version);
219207 } else if (params.type == VecSimType_FLOAT64) {
220208 IndexComponents<double , double > indexComponents = CreateIndexComponents<double , double >(
221- abstractInitParams.allocator , metric, abstractInitParams.dim );
209+ abstractInitParams.allocator , params. metric , abstractInitParams.dim , is_normalized );
222210 return NewIndex_ChooseMultiOrSingle<double >(input, ¶ms, abstractInitParams,
223211 indexComponents, version);
224212 } else if (params.type == VecSimType_BFLOAT16) {
225213 IndexComponents<bfloat16, float > indexComponents = CreateIndexComponents<bfloat16, float >(
226- abstractInitParams.allocator , metric, abstractInitParams.dim );
214+ abstractInitParams.allocator , params. metric , abstractInitParams.dim , is_normalized );
227215 return NewIndex_ChooseMultiOrSingle<bfloat16, float >(input, ¶ms, abstractInitParams,
228216 indexComponents, version);
229217 } else if (params.type == VecSimType_FLOAT16) {
230218 IndexComponents<float16, float > indexComponents = CreateIndexComponents<float16, float >(
231- abstractInitParams.allocator , metric, abstractInitParams.dim );
219+ abstractInitParams.allocator , params. metric , abstractInitParams.dim , is_normalized );
232220 return NewIndex_ChooseMultiOrSingle<float16, float >(input, ¶ms, abstractInitParams,
233221 indexComponents, version);
234222 } else {
0 commit comments