hnswlib icon indicating copy to clipboard operation
hnswlib copied to clipboard

Where is Cosine similarity in C++ version

Open bejoechen opened this issue 2 years ago • 1 comments

Hi, I'm wondering why there is no cosine space in hnswlib. How to use cosine similarity in C++ version? Thanks

bejoechen avatar Jun 10 '22 09:06 bejoechen

Hi @bejoechen,

For cosine you can first normalize the vectors and then use inner product or L2 (inner product would be a bit faster). You can use the normalization logic from the python bindings https://github.com/nmslib/hnswlib/blob/443d667478fddf1e13f2e06b1da4e1ec3a9fe716/python_bindings/bindings.cpp#L166

yurymalkov avatar Jun 14 '22 21:06 yurymalkov