Skip to content
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

How to change a data point after building index? #22

Closed
universewill opened this issue Jun 6, 2018 · 1 comment
Closed

How to change a data point after building index? #22

universewill opened this issue Jun 6, 2018 · 1 comment

Comments

@universewill
Copy link

I want to change a data point in the index. How can i do that?

import hnswlib
import numpy as np

# Generating sample data
a = np.array([1.0, 0.0, 0.0])
b = np.array([0.0, 1.0, 0.0])
c = np.array([0.0, 0.0, 1.0])
d = np.array([1.0, 1.0, 0.0])

# Declaring index
p = hnswlib.Index(space='l2', dim = 3)

# Initing index - the maximum number of elements should be known beforehand
p.init_index(max_elements = 50, ef_construction = 200, M = 16)

# Element insertion (can be called several times):
p.add_items(a)
p.add_items(b)
p.add_items(c)

labels, distances = p.knn_query(c, k =1)
print labels, distances

#change data points
p.add_items(d, 2)
p.add_items(c, 0)

labels, distances = p.knn_query(d, k =1)
print labels, distances

labels, distances = p.knn_query(c, k =1)
print labels, distances

The query result is not changed after i rewrite the data point label index.

@yurymalkov
Copy link
Member

@universewill Changing the element would require deleting the element from the index and adding a new one. Not supported currently, see #4.
Another possible solution (in case the update does not change the point significantly) is to rewire the links, which is not that much easier than support deletion.
What happens in your code is that you add 5 elements with two pairs of which share the same labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants