hnswlib icon indicating copy to clipboard operation
hnswlib copied to clipboard

I want to know how many distance calculations are needed to complete a query with fixed parameters

Open qxzhou1010 opened this issue 5 years ago • 6 comments

Hi, I want to know how many distance calculations are needed to complete a query with fixed parameters. How can I get this value? Do I need to change the source code? Another question is how to run the corresponding. cpp file in vs2019?

qxzhou1010 avatar Jun 23 '20 09:06 qxzhou1010

  1. You can add something to count the number of times the distance computation function is called https://github.com/nmslib/hnswlib/blob/3c6a84fb54a2a92dc4b7dc3e13dbae3d99892444/hnswlib/hnswlib.h#L52-L53

  2. You can goole how cmake is used together with visual studio

orrorcol avatar Jun 23 '20 13:06 orrorcol

Thanks for your reply, for the first problem, I have another question, now I only run the code in python. I modified the code in hnswlib/hnswlib/hnswlib.h and added a variable for counting. How can the counting result be displayed in the running result of python?

qxzhou1010 avatar Jun 24 '20 01:06 qxzhou1010

  1. You can add something to count the number of times the distance computation function is called https://github.com/nmslib/hnswlib/blob/3c6a84fb54a2a92dc4b7dc3e13dbae3d99892444/hnswlib/hnswlib.h#L52-L53
  2. You can goole how cmake is used together with visual studio Thanks for your reply, for the first problem, I have another question, now I only run the code in python. I modified the code in hnswlib/hnswlib/hnswlib.h and added a variable for counting. How can the counting result be displayed in the running result of python?

qxzhou1010 avatar Jun 24 '20 01:06 qxzhou1010

The easisst way is to print the result to stdout or a file.他Or you can refer to the python binding code

orrorcol avatar Jun 25 '20 04:06 orrorcol

@qxzhou1010 You can also change line https://github.com/nmslib/hnswlib/blob/master/hnswlib/hnswalg.h#L556 From searchBaseLayerST<false> to searchBaseLayerST<true>. It will start collecting the number of calculations (metric_distance_computations, metric_hops fields) until you manually reset them. To access the from python you would need to add a method to bindings. That is pretty straighforward, you can just copy the get_M method https://github.com/nmslib/hnswlib/blob/master/python_bindings/bindings.cpp#L402 . To build and install the bindings you can run from the root repository:

pip3 install pybind11 numpy setuptools
cd python_bindings
python3 setup.py install

yurymalkov avatar Jun 27 '20 04:06 yurymalkov

@qxzhou1010 You can also change line https://github.com/nmslib/hnswlib/blob/master/hnswlib/hnswalg.h#L556 From searchBaseLayerST<false> to searchBaseLayerST<true>. It will start collecting the number of calculations (metric_distance_computations, metric_hops fields) until you manually reset them. To access the from python you would need to add a method to bindings. That is pretty straighforward, you can just copy the get_M method https://github.com/nmslib/hnswlib/blob/master/python_bindings/bindings.cpp#L402 . To build and install the bindings you can run from the root repository:

pip3 install pybind11 numpy setuptools
cd python_bindings
python3 setup.py install

Could you give a demo, as some of the code has been updated?

zzzmm1 avatar Nov 04 '22 03:11 zzzmm1