| HNSWIndex | R Documentation |
High-performance approximate nearest neighbor index
dimensionVector dimension
metricDistance metric
n_treesNumber of trees (for Annoy)
search_kSearch parameter
new()Create a new HNSWIndex
HNSWIndex$new(dimension, metric = "angular", n_trees = 50, search_k = -1)
dimensionVector dimension
metricDistance metric: "angular", "euclidean", "manhattan", "dot"
n_treesNumber of trees for index (higher = more accuracy)
search_kSearch parameter (higher = more accuracy, -1 = auto)
add_items()Add items to the index
HNSWIndex$add_items(ids, vectors)
idsCharacter vector of IDs
vectorsMatrix of vectors (rows = items)
Self
build()Build the index (required before searching)
HNSWIndex$build()
Self
search()Search for nearest neighbors
HNSWIndex$search(query, k = 10, include_distances = TRUE)
queryQuery vector
kNumber of neighbors
include_distancesReturn distances
Data frame with id, distance columns
get_vector()Get vector by ID
HNSWIndex$get_vector(id)
idItem ID
Vector or NULL
get_ids()Get all IDs
HNSWIndex$get_ids()
Character vector
size()Get item count
HNSWIndex$size()
Integer
remove_items()Remove items from index
HNSWIndex$remove_items(ids)
idsIDs to remove
Self
clear()Clear the index
HNSWIndex$clear()
Self
save()Save index to file
HNSWIndex$save(path)
pathFile path
load()Load index from file
HNSWIndex$load(path)
pathFile path
Self
clone()The objects of this class are cloneable with this method.
HNSWIndex$clone(deep = FALSE)
deepWhether to make a deep clone.
## Not run:
# Create index
index <- HNSWIndex$new(dimension = 128, metric = "angular")
# Add vectors
index$add_items(ids = c("a", "b", "c"),
vectors = matrix(rnorm(384), nrow = 3))
# Search
results <- index$search(query = rnorm(128), k = 5)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.