Skip to contents

Inverted file over k-means Voronoi cells. Cheap to build and easy to tune: nlist sets how finely the space is cut, nprobe how many cells a query visits. The smallest of the unquantised approximate indices. No Manhattan.

References

Sivic J, Zisserman A (2003). Video Google: a text retrieval approach to object matching in videos. Proceedings Ninth IEEE International Conference on Computer Vision, 1470-1477. doi:10.1109/ICCV.2003.1238663

Jégou H, Douze M, Schmid C (2011). Product quantization for nearest neighbor search. IEEE Transactions on Pattern Analysis and Machine Intelligence, 33, 117-128. doi:10.1109/TPAMI.2010.57

Super class

AnnIndex -> IvfIndex

Active bindings

nprobe

Integer or NULL. Cells visited per query.

Methods

Inherited methods


IvfIndex$new()

Build the index.

Usage

IvfIndex$new(
  data,
  metric = c("euclidean", "sqeuclidean", "cosine"),
  nlist = NULL,
  nprobe = NULL,
  kmeans_iters = NULL,
  kmeans_balanced = FALSE,
  seed = 42L,
  precision = c("float", "double"),
  .verbose = FALSE
)

Arguments

data

Numeric matrix or data.frame. Samples x features. An index pointer is also accepted; load_ann_index() uses that path.

metric

String. One of c("euclidean", "sqeuclidean", "cosine").

nlist

Integer or NULL. Number of Voronoi cells. NULL uses sqrt(n).

nprobe

Integer or NULL. Cells visited per query. NULL uses sqrt(nlist). Can be changed after the build.

kmeans_iters

Integer or NULL. Lloyd iterations. NULL uses 30.

kmeans_balanced

Boolean. Reseed starved centroids each iteration.

seed

Integer. Fixes the k-means initialisation.

precision

String. "float" stores the data as f32, "double" as f64.

.verbose

Boolean. Print build progress from Rust.


IvfIndex$clone()

The objects of this class are cloneable with this method.

Usage

IvfIndex$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

x <- generate_clustered_data(1000L, 16L)$data
idx <- IvfIndex$new(x)
idx$nprobe <- 10L
res <- idx$predict(x[1:5, ], k = 10L)