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.load function exhibits unexpected behavior with filename:str argument #97

Open
JF235 opened this issue Nov 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@JF235
Copy link

JF235 commented Nov 5, 2024

The Index.load function is producing an error when called with a file name instead of a file object.

Expected behaviour

Output:

# For Case 2.
[ 1 22 43 93 36]
[0.   0.08 0.11 0.31 0.32]

Actual behaviour

Output:

# For Case 1.
RuntimeError: Index seems to be corrupted or unsupported. 
Advancing to the next linked list requires 13312 additional bytes (from position 13337), 
but index data only has 13575 bytes in total.

Perhaps there is some detail I missed, but I couldn't find information about this in the Python API documentation.

Steps to reproduce the behaviour

  • Python: 3.12.0
  • voyager: 2.0.9
  • Windows, x86_64
import numpy as np
from voyager import Index, Space

n = 100
q = 1
index = Index(Space.Euclidean, num_dimensions=5, random_seed=21)
np.random.seed(42)
data = np.random.rand(n, 5)
index.add_items(data)

index.save("output_file.voy")

# Case 1.
# cp = Index.load("output_file.voy")
#  => RuntimeError: Index seems to be corrupted or unsupported. 
# Advancing to the next linked list requires 13312 additional bytes (from position 13337),
# but index data only has 13575 bytes in total.


# Case 2.
with open("output_file.voy", "rb") as f:
    cp = Index.load(f)

neighbors, distances = cp.query(data[q], k=5)
print(neighbors) # => [ 1 22 43 93 36]
print(np.round(distances, 2)) # => [0.   0.08 0.11 0.31 0.32]
@JF235
Copy link
Author

JF235 commented Nov 5, 2024

It seems to be a manifestation of the #40. Maybe a problem with Windows?

@stephen29xie stephen29xie added the bug Something isn't working label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants