New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while inserting/searching for a single vector #93

Closed
symisc opened this Issue Jan 27, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@symisc
Copy link

symisc commented Jan 27, 2019

Greeting,

I'm currently experimenting with HNSW and having a hard time figuring how to insert a single entry which is a numpy vector of dimension 512. Basically my computed vector have the following shape:

f1 = [-6.84065297e-02  2.42091250e-03 -3.57803353e-03  3.89208528e-03
 -2.28513479e-02  4.16927785e-02  2.04421561e-02  3.19429524e-02
 -3.44496779e-02  2.01440826e-02  7.60645140e-03  7.55775422e-02
 -6.46838024e-02  6.18326711e-03  4.17486131e-02  2.66419481e-02
 -4.48573716e-02  1.12289740e-02 -6.68355823e-02 -2.21468620e-02
... (512 entries)
]

My insertion code looks like the following:

index = hnswlib.Index(space = 'l2', dim = 512) 
index.init_index(max_elements = 100, ef_construction = 200, M = 16)

# Insert this single entry
index.add_items(f1, np.asarray([8512]))

My lookup code:

index.set_ef(50)
labels, distances = index.knn_query(f1, k = 4)

The following exception is thrown when searching: RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is to small

Any help is really appreciated! Thank you @searchivarius @yurymalkov for the awesome library!

@symisc symisc changed the title Issue while inserting/searchine for a single vector Issue while inserting/searching for a single vector Jan 27, 2019

@yurymalkov

This comment has been minimized.

Copy link
Member

yurymalkov commented Jan 27, 2019

Hi @symisc,
The problem is that the search algorithm cannot find k=4 neighbors (there is only one element in the dataset), this triggers the exception which checks that the number of search results is exactly k (to return all the results in the contiguous array N*k). Probably, we need change this behavior in the future.

Summing up, if you add 3 new elements, the exception will disappear.

@symisc

This comment has been minimized.

Copy link
Author

symisc commented Jan 27, 2019

Make sense thanks! The behavior have to be changed in the future because it introduce a lot of confusion.

@symisc symisc closed this Jan 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment