Class ANNIndex
java.lang.Object
org.opencv.features.ANNIndex
*************************************************************************************\
Approximate Nearest Neighbors *
\***************************************************************************************
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intprotected final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ANNIndex__fromPtr__(long addr) voidAdd feature vectors to index.voidbuild()Build the index.voidbuild(int trees) Build the index.static ANNIndexcreate(int dim) Creates an instance of annoy index class with given parametersstatic ANNIndexcreate(int dim, int distType) Creates an instance of annoy index class with given parametersintReturn the number of feature vectors in the index.longintReturn the number of trees in the index.voidPerforms a K-nearest neighbor search for given query vector(s) using the index.voidPerforms a K-nearest neighbor search for given query vector(s) using the index.voidLoads (mmaps) an index from disk.voidLoads (mmaps) an index from disk.voidSave the index to disk and loads it.voidSave the index to disk and loads it.booleansetOnDiskBuild(String filename) Prepare to build the index in the specified file instead of RAM (execute before adding items, no need to save after build)voidsetSeed(int seed) Initialize the random number generator with the given seed.
-
Field Details
-
nativeObj
protected final long nativeObj -
DIST_EUCLIDEAN
public static final int DIST_EUCLIDEAN- See Also:
-
DIST_MANHATTAN
public static final int DIST_MANHATTAN- See Also:
-
DIST_ANGULAR
public static final int DIST_ANGULAR- See Also:
-
DIST_HAMMING
public static final int DIST_HAMMING- See Also:
-
DIST_DOTPRODUCT
public static final int DIST_DOTPRODUCT- See Also:
-
-
Constructor Details
-
ANNIndex
protected ANNIndex(long addr)
-
-
Method Details
-
getNativeObjAddr
public long getNativeObjAddr() -
__fromPtr__
-
addItems
Add feature vectors to index.- Parameters:
features- Matrix containing the feature vectors to index. The size of the matrix is num_features x feature_dimension.
-
build
public void build(int trees) Build the index.- Parameters:
trees- Number of trees in the index. If not provided, the number is determined automatically in a way that at most 2x as much memory as the features vectors take is used.
-
build
public void build()Build the index. in a way that at most 2x as much memory as the features vectors take is used. -
knnSearch
Performs a K-nearest neighbor search for given query vector(s) using the index.- Parameters:
query- The query vector(s).indices- Matrix that will contain the indices of the K-nearest neighbors found, optional.dists- Matrix that will contain the distances to the K-nearest neighbors found, optional.knn- Number of nearest neighbors to search for.search_k- The maximum number of nodes to inspect, which defaults to trees x knn if not provided.
-
knnSearch
Performs a K-nearest neighbor search for given query vector(s) using the index.- Parameters:
query- The query vector(s).indices- Matrix that will contain the indices of the K-nearest neighbors found, optional.dists- Matrix that will contain the distances to the K-nearest neighbors found, optional.knn- Number of nearest neighbors to search for.
-
save
Save the index to disk and loads it. After saving, no more vectors can be added.- Parameters:
filename- Filename of the index to be saved.prefault- If prefault is set to true, it will pre-read the entire file into memory (using mmap with MAP_POPULATE). Default is false.
-
save
Save the index to disk and loads it. After saving, no more vectors can be added.- Parameters:
filename- Filename of the index to be saved. with MAP_POPULATE). Default is false.
-
load
Loads (mmaps) an index from disk.- Parameters:
filename- Filename of the index to be loaded.prefault- If prefault is set to true, it will pre-read the entire file into memory (using mmap with MAP_POPULATE). Default is false.
-
load
Loads (mmaps) an index from disk.- Parameters:
filename- Filename of the index to be loaded. with MAP_POPULATE). Default is false.
-
getTreeNumber
public int getTreeNumber()Return the number of trees in the index.- Returns:
- automatically generated
-
getItemNumber
public int getItemNumber()Return the number of feature vectors in the index.- Returns:
- automatically generated
-
setOnDiskBuild
Prepare to build the index in the specified file instead of RAM (execute before adding items, no need to save after build)- Parameters:
filename- Filename of the index to be built.- Returns:
- automatically generated
-
setSeed
public void setSeed(int seed) Initialize the random number generator with the given seed. Only necessary to pass this before adding the items. Will have no effect after calling build() or load().- Parameters:
seed- The given seed of the random number generator. Its value should be within the range of uint32_t.
-
create
Creates an instance of annoy index class with given parameters- Parameters:
dim- The dimension of the feature vector.distType- Metric to calculate the distance between two feature vectors, can be DIST_EUCLIDEAN, DIST_MANHATTAN, DIST_ANGULAR, DIST_HAMMING, or DIST_DOTPRODUCT.- Returns:
- automatically generated
-
create
Creates an instance of annoy index class with given parameters- Parameters:
dim- The dimension of the feature vector. DIST_MANHATTAN, DIST_ANGULAR, DIST_HAMMING, or DIST_DOTPRODUCT.- Returns:
- automatically generated
-