nmslib / hnswlib

Header-only C++/python library for fast approximate nearest neighbors
https://github.com/nmslib/hnswlib
Apache License 2.0
4.11k stars 607 forks source link

How can I ensure consistent results every time I run the code? I get different results each time I run the code #540

Open 2673380801 opened 4 months ago

2673380801 commented 4 months ago

How can I ensure consistent results every time I run the code? I get different results each time I run the code

yurymalkov commented 4 months ago

Search should be deterministic. Construction is not deterministic if using more than a single thread

2673380801 commented 4 months ago

Search should be deterministic. Construction is not deterministic if using more than a single thread

thanks for your reply

2673380801 commented 4 months ago

Search should be deterministic. Construction is not deterministic if using more than a single thread

Search should be deterministic. Construction is not deterministic if using more than a single thread

I tried setting only one thread, but the results are still different every time

yurymalkov commented 3 months ago

Hm. That is strange. Is the data order is the same?

2673380801 commented 3 months ago

Hm. That is strange. Is the data order is the same?

the data order is the same.I used hnswlib in python. I tried calculating mutual nearest neighbors, but each time the same group of data is calculated, the quantity is different.

2673380801 commented 3 months ago

Hm. That is strange. Is the data order is the same?

here is the code:
dim = dataset2.shape[1] num_elements = dataset2.shape[0] tree = hnswlib.Index(space="cosine", dim=dim) tree.init_index(max_elements=num_elements, ef_construction=200, M=16) tree.set_ef(50) tree.set_num_threads(1) tree.additems(dataset2) ind, = tree.knn_query(dataset1, k=knn,num_threads =1)