MetricKnn API
Fast Similarity Search using the Metric Space Approach
Functions
mknn_index.h File Reference

A MknnIndex represents the index structure. More...

#include "../metricknn_c.h"

Go to the source code of this file.

Functions

MknnIndexmknn_index_newPredefined (MknnIndexParams *parameters, bool free_parameters_on_index_release, MknnDataset *search_dataset, bool free_search_dataset_on_index_release, MknnDistance *distance, bool free_distance_on_index_release)
 Instantiates a new index identified by the given parameters. More...
 
MknnIndexParamsmknn_index_getParameters (MknnIndex *index)
 Returns the parameters used to create or load the index. More...
 
MknnDatasetmknn_index_getSearchDataset (MknnIndex *index)
 Returns the dataset used to create or load the index. More...
 
MknnDistancemknn_index_getDistance (MknnIndex *index)
 Returns the distance used to create or load the index. More...
 
const char * mknn_index_getIdPredefinedIndex (MknnIndex *index)
 returns the id of the predefined index. More...
 
void mknn_index_save (MknnIndex *index, const char *filename_write)
 Saves the built index to a file. More...
 
MknnIndexmknn_index_restore (const char *filename_read, MknnDataset *search_dataset, bool free_search_dataset_on_index_release, MknnDistance *distance, bool free_distance_on_index_release, MknnIndexParams *more_parameters, bool free_parameters_on_index_release)
 Loads an index from a file. More...
 
MknnResolvermknn_index_newResolver (MknnIndex *index, MknnResolverParams *parameters_resolver, bool free_parameters_on_resolver_release)
 Configures a new similarity search using the given index. More...
 
void mknn_index_release (MknnIndex *index)
 Releases the index. More...
 

Detailed Description

A MknnIndex represents the index structure.

In order to create an index, at least two parameters must be provided:

MetricKnn provides a set of pre-defined indexes identified by a unique distance identifier. Some valid IDs are:

The multidimensional indexes are implemented by the FLANN library. http://www.cs.ubc.ca/research/flann/

In order to simplify the creation of distances, there are function that returns the parameters for building the different indexes with mknn_index_newPredefined.

Note
The complete list of pre-defined indexes provided by MetricKnn can be printed by calling mknn_predefIndex_helpListIndexes. The parameters supported by each index can be printed by calling mknn_predefIndex_helpPrintIndex.

Function Documentation

MknnDistance* mknn_index_getDistance ( MknnIndex index)

Returns the distance used to create or load the index.

Parameters
indexthe index
Returns
the distance used to create or load the index.
const char* mknn_index_getIdPredefinedIndex ( MknnIndex index)

returns the id of the predefined index.

Parameters
indexthe index
Returns
the id of the predefined index.
MknnIndexParams* mknn_index_getParameters ( MknnIndex index)

Returns the parameters used to create or load the index.

Parameters
indexthe index
Returns
the parameters used to create or load the index.
MknnDataset* mknn_index_getSearchDataset ( MknnIndex index)

Returns the dataset used to create or load the index.

Parameters
indexthe index
Returns
the dataset used to create or load the index.
MknnIndex* mknn_index_newPredefined ( MknnIndexParams parameters,
bool  free_parameters_on_index_release,
MknnDataset search_dataset,
bool  free_search_dataset_on_index_release,
MknnDistance distance,
bool  free_distance_on_index_release 
)

Instantiates a new index identified by the given parameters.

Parameters
parametersthe definition of the index.
free_parameters_on_index_releasebinds the lifetime of parameters to the new index.
search_datasetthe data to be indexed. Any search on this index will return some object from search_data.
free_search_dataset_on_index_releasebinds the lifetime of search_dataset to the new index.
distancea distance.
free_distance_on_index_releasebinds the lifetime of distance to the new index.
Returns
a index (must be released)
MknnResolver* mknn_index_newResolver ( MknnIndex index,
MknnResolverParams parameters_resolver,
bool  free_parameters_on_resolver_release 
)

Configures a new similarity search using the given index.

Parameters
indexthe index that will resolve the search.
parameters_resolverparameters to be given to the index in order to resolve the search.
free_parameters_on_resolver_releasetrue if parameters_resolver must be released during mknn_resolver_release.
Returns
an object configured to resolve a similarity search.
void mknn_index_release ( MknnIndex index)

Releases the index.

Parameters
indexthe index to be released.
MknnIndex* mknn_index_restore ( const char *  filename_read,
MknnDataset search_dataset,
bool  free_search_dataset_on_index_release,
MknnDistance distance,
bool  free_distance_on_index_release,
MknnIndexParams more_parameters,
bool  free_parameters_on_index_release 
)

Loads an index from a file.

The file must have been created by mknn_index_save.

Remarks
search_dataset and distance must be the same that were used to create and save the index.
Parameters
filename_readFile to read. If the file does not exists an error is raised.
search_datasetThe search dataset that was used to build the index.
free_search_dataset_on_index_releasebinds the lifetime of search_dataset to the new index.
distanceThe distance that was used to build the index.
free_distance_on_index_releasebinds the lifetime of distance to the new index.
more_parametersany parameter that may override the stored parameters or new parameters that could not be saved.
free_parameters_on_index_releasebinds the lifetime of more_parameters to the new index.
Returns
a new index (it must be released with mknn_index_release).
void mknn_index_save ( MknnIndex index,
const char *  filename_write 
)

Saves the built index to a file.

It may create other files using filename_write as prefix. The created files may be in binary format for fast loading.

Remarks
The search_dataset and the distance are not saved.
Parameters
filename_writeFile to create. If the file already exists it is overwritten.
indexthe index to save
Powered by Download MetricKnn