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

load file returns 0 #71

Closed
zhdeath opened this issue Jun 4, 2015 · 11 comments
Closed

load file returns 0 #71

zhdeath opened this issue Jun 4, 2015 · 11 comments

Comments

@zhdeath
Copy link

zhdeath commented Jun 4, 2015

I ran annoy 1.2.2 on Amazon EC2 with ubuntu linux 14.04, the file loading always return 0, any idea why? I would really appreciate your ideas.

from annoy import AnnoyIndex
f=50
i=AnnoyIndex(f)
i.load('items.tree')
0

PS: the file is small enough, several Kbs

@erikbern
Copy link
Collaborator

erikbern commented Jun 4, 2015

@zhdeath
Copy link
Author

zhdeath commented Jun 4, 2015

Thanks for your reply.
My own computer which is also ubuntu 14.04 works fun.
Any idea what I should do with Amazon EC2?

i.get_item_vector(..) always returns [0,0..]

@erikbern
Copy link
Collaborator

erikbern commented Jun 4, 2015

hm get_item_vector shouldn't return 0... that's weird

@zhdeath
Copy link
Author

zhdeath commented Jun 4, 2015

it indeed is!
i.get_item_vector(18)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

even i.get_nns_by_item(18, 10) works
But I need those vectors in my app

@erikbern
Copy link
Collaborator

erikbern commented Jun 4, 2015

That's strange. Let me add a unit test and try to repro

@erikbern
Copy link
Collaborator

erikbern commented Jun 4, 2015

I won't have time today unfortunately

@a1k0n
Copy link
Contributor

a1k0n commented Jun 4, 2015

@zhdeath can you post a snippet of code of how you're generating your annoy index, and how you're loading and using it?

the return value of load() isn't really of much consequence is it? I think it got changed to return 0 instead of true inadvertently to be more similar to POSIX return values, but it should still work.

@erikbern
Copy link
Collaborator

erikbern commented Jun 5, 2015

Not able to reproduce...see #72

@zhdeath
Copy link
Author

zhdeath commented Jun 5, 2015

@a1k0n Worked on these trivial code with 1.2.2 or 1.3.1

from annoy import AnnoyIndex
import random

f = 30
a = AnnoyIndex(f) # length of item vector

n = 1000  # number of vector
for i in xrange(n):
    v = []
    for z in xrange(f):
        v.append(random.gauss(0, 1))
    a.add_item(i, v)

a.build(-1)
a.save('test.tree')

b = AnnoyIndex(f)
b.load('test.tree')
print(i.get_item_vector(10))
print(b.get_nns_by_item(10, 10))

load() returns false, get_item_vector returns [0,0...]; but get_nss_by_item(10,10) works fun. Python is 2.7.6

I think it's version related.
With 1.0.5, load() returns true and get_item_vector() also works

@erikbern
Copy link
Collaborator

erikbern commented Jun 5, 2015

Hm it seems like the issue is some kind of integer casting.

The item vector looks like this for me:
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, -1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, -1, 0]

@erikbern
Copy link
Collaborator

erikbern commented Jun 5, 2015

I pushed a breaking test to #72

Will now fix it

@zhdeath zhdeath closed this as completed Jun 5, 2015
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

3 participants