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

Index is not loading from disk #53

Open
SilvioM97 opened this issue Oct 3, 2024 · 1 comment
Open

Index is not loading from disk #53

SilvioM97 opened this issue Oct 3, 2024 · 1 comment

Comments

@SilvioM97
Copy link

SilvioM97 commented Oct 3, 2024

Hi,
I'm not able to load the index from disk in python.
I saved an index in this way:

index = HnswIndex(d, distance)
for sample in documents:
    index.add_data(sample)
index.build(m=m, max_m0=m0, ef_construction=ef_construction, n_threads=n_threads, neighbor_selecting="heuristic")
index.save(index_path)

The index is indeed saved, I see its memory occupancy on the disk.

Then I load it in this way:

index_n2 = HnswIndex(d)
loaded = index_n2.load(path_n2)

if loaded:
    print("Loaded n2 index")
else:
    print("Failed to load n2 index")

But the load fails, it prints "Failed to load n2 index" and I don't see it in main memory.
Why does this happen? What am I doing wrong?

@SilvioM97 SilvioM97 changed the title Index is not loading from memory Index is not loading from disk Oct 3, 2024
@lancifollia
Copy link
Collaborator

Hello @SilvioM97 I apologize for the delay in responding.

I think there is a missing point in the python binding code. The load() function doesn't have return value.
https://github.com/kakao/n2/blob/dev/bindings/python/n2.pyx#L74C22-L74C31

After loading your index file, could you try running the search_by_id() function? (ignoring the loading function return value check)

index_n2 = HnswIndex(d)
loaded = index_n2.load(path_n2)

#if loaded:
#   print("Loaded n2 index")
#else:
#    print("Failed to load n2 index")

index_n2.search_by_id(0, 10)

In n2, virtual memory is pre-allocated on model load, and disk -> memory actually happens at inference time. This may have caused you to miss something in your memory check, so you may want to check that as well.

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