You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import numpy as np
import usearch
index = usearch.Index(
ndim=256, # Define the number of dimensions in input vectors
metric='cos', # Choose the "metric" or "distance", default = 'ip', optional
dtype='f32', # Quantize to 'f16' or 'i8q100' if needed, default = 'f32', optional
connectivity=16, # How frequent should the connections in the graph be, optional
expansion_add=128, # Control the recall of indexing, optional
expansion_search=64, # Control the quality of search, optional
)
vector = np.random.uniform(0, 0.3, (index.ndim)).astype(np.float32)
index.add(42, vector)
matches, distances, count = index.search(vector, 10)
I get "distances" of array([0.99999994], dtype=float32).
Looks like this is inverted - the distance between vector and itself should be 0 (float eps notwithstanding).
This is a problem with big indexes, where the number of results is much smaller than the number of vectors in the index. I want the lowest distance vectors, which is the opposite . AFACIT there is no way to invert the order used in the search function.
Am I missing something here, or is there an option to invert the order of vectors returned by search?
Yes, you are right, the distance for some measures are inverted for efficiency in the low-level implementation. I will adjust that behavior to work in expected manner across all distances. Thank you!
Activity
ashvardanian commentedon May 11, 2023
Yes, you are right, the distance for some measures are inverted for efficiency in the low-level implementation. I will adjust that behavior to work in expected manner across all distances. Thank you!
Fix: Inverting angular distance
Build: Released 0.2.0 [skip ci]