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

Bug: Index.get() returns inconsistent values for non-existent key #494

Open
3 tasks done
45deg opened this issue Sep 25, 2024 · 1 comment
Open
3 tasks done

Bug: Index.get() returns inconsistent values for non-existent key #494

45deg opened this issue Sep 25, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@45deg
Copy link

45deg commented Sep 25, 2024

Describe the bug

When calling Index.get() with a key that doesn't exist in the index, it sometimes returns the vector of some values, instead of consistently returning None as specified in the official documentation.

Steps to reproduce

Code to Reproduce

# Python 3.12
from usearch.index import Index
import numpy as nd
index = Index(ndim=10)
index.add(1, nd.array([0.5]*10))
index.add(2, nd.array([0.4]*10))
print(index.contains(1), index.get(1))
print(index.contains(2), index.get(2))
print(index.contains(3), index.get(3))
print(index.contains(102030), index.get(102030))

Output:

True [0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5]
True [0.3984375 0.3984375 0.3984375 0.3984375 0.3984375 0.3984375 0.3984375
 0.3984375 0.3984375 0.3984375]
False [0.3984375 0.3984375 0.3984375 0.3984375 0.3984375 0.3984375 0.3984375
 0.3984375 0.3984375 0.3984375]
False [0.3984375 0.3984375 0.3984375 0.3984375 0.3984375 0.3984375 0.3984375
 0.3984375 0.3984375 0.3984375]

The last two lines should be False None

Expected behavior

As document noted, it should return None, if one key is requested and its not present.

USearch version

2.15.1

Operating System

macOS Sonoma

Hardware architecture

Arm

Which interface are you using?

Python bindings

Contact Details

No response

Are you open to being tagged as a contributor?

  • I am open to being mentioned in the project .git history as a contributor

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@45deg 45deg added the bug Something isn't working label Sep 25, 2024
@sdenton4
Copy link
Contributor

Interestingly, trying to access the key -1 gives values which change over time, while too-large keys seems to give the last embedding again (as in the reporter's case)

x = usearch_index.Index(metric='IP', dtype=uindex.ScalarKind(12), ndim=3)
embs = np.float16(np.random.normal(scale=1e-4, size=[128, 3]))
x.add(np.arange(128), embs)

for i in (-2, -1, 0, 127, 128, 256):
  print(i)
  print(x.get(i))
  print(x.get(i))
  if i < 128:
    print(embs[i])

Output:

-2
[5.555e-05 4.506e-05 6.932e-05]
[5.555e-05 4.506e-05 6.932e-05]
[ 2.307e-05  5.108e-05 -3.988e-05]
-1
[2.307e-05 5.108e-05 3.988e-05]
[2.307e-05 5.108e-05 3.988e-05]
[ 7.74e-05  8.04e-05 -9.01e-05]
0
[-6.193e-05  7.033e-06  1.405e-04]
[-6.193e-05  7.033e-06  1.405e-04]
[-6.193e-05  7.033e-06  1.405e-04]
127
[ 7.74e-05  8.04e-05 -9.01e-05]
[ 7.74e-05  8.04e-05 -9.01e-05]
[ 7.74e-05  8.04e-05 -9.01e-05]
128
[7.74e-05 8.04e-05 9.01e-05]
[7.74e-05 8.04e-05 9.01e-05]
256
[7.74e-05 8.04e-05 9.01e-05]
[7.74e-05 8.04e-05 9.01e-05]

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