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

Vector elements are truncated to ints #73

Closed
atqamar opened this issue Jun 8, 2015 · 4 comments
Closed

Vector elements are truncated to ints #73

atqamar opened this issue Jun 8, 2015 · 4 comments

Comments

@atqamar
Copy link

atqamar commented Jun 8, 2015

I did a sudo pip install of annoy on my OSX laptop and had the following unusual results:

>>> from annoy import AnnoyIndex
>>> import random
>>>
>>> f = 2
>>> t = AnnoyIndex(f)
>>> t.add_item(0, [0, 2.5])
0
>>> t.add_item(1, [3.5, 0])
0
>>> t.build(10)
0
>>> t.get_item_vector(0)
[0, 2]
>>> t.get_item_vector(1)
[3, 0]
>>> t.get_distance(0,1)
2.0

A few issues:

  • A 0 is returned and printed by the add_item() and build() methods.
  • When the items are queried, the vector that is returned has truncated elements.
  • The get_distance() method doesn't return the proper angular distance, nor the distance under the assumption that the vector elements are truncated.
@atqamar atqamar changed the title vector values are truncated to ints Vector elements are truncated to ints Jun 8, 2015
@erikbern
Copy link
Collaborator

erikbern commented Jun 8, 2015

This was fixed in #72 however I didn't publish a new version to pypi yet. Will do right away.

The problem was just returning data, it was still properly inserted etc

@erikbern
Copy link
Collaborator

erikbern commented Jun 8, 2015

I uploaded 1.3.2 to PyPI – can you verify that it works if you install the latest version from PyPI?

Also see #74 – silly PR but I can't push directly and/or merge my own stuff any more :(

@atqamar
Copy link
Author

atqamar commented Jun 8, 2015

Great! get_item_vector() method works fine. And I was mistaken about the get_distance() method not working.

Is there a way to prevent 0 being returned by add_item()? It feels unnecessarily verbose:

>>> from annoy import AnnoyIndex
>>> import random
>>> f=2
>>> t = AnnoyIndex(f)
>>> t.add_item(0, [0, 2.5])
0
>>> t.add_item(1, [3.5, 0])
0
>>> t.build(10)
True
>>> t.get_item_vector(0)
[0.0, 2.5]
>>> t.get_item_vector(1)
[3.5, 0.0]

@erikbern erikbern closed this as completed Jun 8, 2015
@erikbern
Copy link
Collaborator

erikbern commented Jun 8, 2015

Should be easy to fix the add_item return value so feel free to send a PR if you have time!

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