ANNIndex
import { ANNIndex } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods.
Approximate Nearest Neighbors *
***************************************************************************************
Constructors and members
static create
Creates an instance of annoy index class with given parameters
create(dim: number, distType: number): ANNIndex | null;2 available overloads
create(dim: number): ANNIndex | null;create(dim: number, distType: number): ANNIndex | null;dimThe dimension of the feature vector.
distTypeMetric to calculate the distance between two feature vectors, can be DIST_EUCLIDEAN, DIST_MANHATTAN, DIST_ANGULAR, DIST_HAMMING, or DIST_DOTPRODUCT.
The ANNIndex | null result.
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
addItems
Add feature vectors to index.
addItems(features: Mat): void;featuresMatrix containing the feature vectors to index. The size of the matrix is num_features x feature_dimension.
build
Build the index.
build(trees: number): void;2 available overloads
build(): void;build(trees: number): void;treesNumber 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.
knnSearch
Performs a K-nearest neighbor search for given query vector(s) using the index.
knnSearch(query: Mat, indices: Mat, dists: Mat, knn: number, search_k: number): void;2 available overloads
knnSearch(query: Mat, indices: Mat, dists: Mat, knn: number): void;knnSearch(query: Mat, indices: Mat, dists: Mat, knn: number, search_k: number): void;queryThe query vector(s).
indicesOutput destination, filled by the native operation. Matrix that will contain the indices of the K-nearest neighbors found, optional.
distsOutput destination, filled by the native operation. Matrix that will contain the distances to the K-nearest neighbors found, optional.
knnNumber of nearest neighbors to search for.
search_kThe maximum number of nodes to inspect, which defaults to trees x knn if not provided.
save
Save the index to disk and loads it. After saving, no more vectors can be added.
save(filename: EmbindString, prefault: boolean): void;2 available overloads
save(filename: EmbindString): void;save(filename: EmbindString, prefault: boolean): void;filenameFilename of the index to be saved.
prefaultIf 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.
load(filename: EmbindString, prefault: boolean): void;2 available overloads
load(filename: EmbindString): void;load(filename: EmbindString, prefault: boolean): void;filenameFilename of the index to be loaded.
prefaultIf prefault is set to true, it will pre-read the entire file into memory (using mmap with MAP_POPULATE). Default is false.
getTreeNumber
Return the number of trees in the index.
getTreeNumber(): number;The number result.
getItemNumber
Return the number of feature vectors in the index.
getItemNumber(): number;The number result.
setOnDiskBuild
Prepare to build the index in the specified file instead of RAM (execute before adding items, no need to save after build)
setOnDiskBuild(filename: EmbindString): boolean;filenameFilename of the index to be built.
The boolean result.
setSeed
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().
setSeed(seed: number): void;seedThe given seed of the random number generator. Its value should be within the range of uint32_t.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.