hnsw_search | R Documentation |
Search an hnswlib nearest neighbor index
hnsw_search(
X,
ann,
k,
ef = 10,
verbose = FALSE,
progress = "bar",
n_threads = 0,
grain_size = 1,
byrow = TRUE
)
X |
A numeric matrix of data to search for neighbors. If |
ann |
an instance of a |
k |
Number of neighbors to return. This can't be larger than the number
of items that were added to the index |
ef |
Size of the dynamic list used during search. Higher values lead
to improved recall at the expense of longer search time. Can take values
between |
verbose |
If |
progress |
defunct and has no effect. |
n_threads |
Maximum number of threads to use. The exact number is
determined by |
grain_size |
Minimum amount of work to do (items in |
byrow |
if |
a list containing:
idx
a matrix containing the nearest neighbor indices.
dist
a matrix containing the nearest neighbor distances.
The dimensions of the matrices respect the storage (row or column-based) of
X
as indicated by the byrow
parameter. If byrow = TRUE
(the default)
each row of idx
and dist
contain the neighbor information for the item
passed in the equivalent row of X
, i.e. the dimensions are n x k
where
n
is the number of items in X
. If byrow = FALSE
, then each column of
idx
and dist
contain the neighbor information for the item passed in
the equivalent column of X
, i.e. the dimensions are k x n
.
Every item in the dataset is considered to be a neighbor of itself, so the
first neighbor of item i
should always be i
itself. If that isn't the
case, then any of M
or ef
may need increasing.
irism <- as.matrix(iris[, -5])
ann <- hnsw_build(irism)
iris_nn <- hnsw_search(irism, ann, k = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.