| index_search | R Documentation |
Searches the index for the k nearest neighbors of the query vector(s).
index_search(index, query, k = 10L, filter = NULL, prefilter_k = 100L)
index |
An |
query |
Numeric vector of length |
k |
Integer. Number of nearest neighbors to return. |
filter |
Optional function that takes the metadata data.frame and returns a logical vector indicating which rows to keep, or a filtered data.frame. |
prefilter_k |
Integer. Number of candidates to retrieve from the C++ layer before applying the filter. Should be >= k. |
A list with components:
Integer vector (or matrix for batch) of neighbor IDs
Numeric vector (or matrix for batch) of distances
Data.frame of metadata for returned IDs
tmp <- tempfile()
dir.create(tmp)
idx <- index_new(3L, tmp)
idx <- index_add(idx, 1L, c(1, 0, 0), meta = list(category = "a"))
idx <- index_add(idx, 2L, c(0, 1, 0), meta = list(category = "b"))
res <- index_search(idx, c(1, 0, 0), k = 2L)
res <- index_search(idx, c(1, 0, 0), k = 2L,
filter = function(m) m$category == "a")
unlink(tmp, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.