hnswlib
hnswlib copied to clipboard
Normalization should not be done in the wrapper
Normalization should be done on the C++ side (if any, my vectors come out from my models already normalised). If not every time the C++ code is used by another programming languages (i.e. nodejs) normalization has to be reimplemented
https://github.com/nmslib/hnswlib/blob/359b2ba87358224963986f709e593d799064ace6/python_bindings/bindings.cpp#L273
Proposed solution is to move this within the lib
void normalize_vector(float* data, float* norm_array) {
float norm = 0.0f;
for (int i = 0; i < dim; i++)
norm += data[i] * data[i];
norm = 1.0f / (sqrtf(norm) + 1e-30f);
for (int i = 0; i < dim; i++)
norm_array[i] = data[i] * norm;
}
Hi @DavidGOrtega, Sure, we can move it. PRs are welcome. Thanks!
I agree. I think it would be a good idea to have this functionality implemented internally, as opposed to being binding specific.