Skip to content

Cpp Quick Reference

masajiro edited this page May 27, 2020 · 3 revisions

Class NGT::Index

Member Functions

Index(const std::string &indexPath, bool readOnly)

Construct the Index object and open the specified index.

indexPath
Specify an existing index path.

readOnly
Specify if read only mode or not. Read only mode can reduce the search times.

static void create(const std::string &indexPath, NGT::Property &property)

Create an empty index specified with the NGT::Property.

indexPath
Specify an index path where the empty index is created.

property
Specify the index properties.

size_t append(std::vector<TYPE> &object)

Append the specified object at the end of the index repository. Not build the index for the object. The function createIndex() below should be called to build the index after appending objects with this function. Float, double and uint8_t are available for the TYPE.

Returns
ID for the appended object.

size_t insert(std::vector<TYPE> &object)

Insert the specified object into the index repository. Not build the index for the object. The function createIndex() below should be called to build the index after inserting objects with this function. Float, double and uint8_t are available for the TYPE.

Returns
ID for the inserted object.

void createIndex(size_t numThreads)

Build the index for the objects that have been inserted by using the function insert.

numThreads
Specify the number of threads to build the index.

void save()

Save the index.

void disableLog()

Disable logging to the standard error.

void search(SearchQuery &searchQuery)

Search the nearest objects with the specified query.

searchQuery
Specify a query to search.

Class NGT::Property

Define the index property.

Member Variables

int dimension
The dimensionality of the inserted object.

int16_t edgeSizeForCreation
The initial number of edges for each node.

DistanceType distanceType
The distance function for the objects.

  • DistanceTypeL1: L1 distance
  • DistanceTypeL2: L2 distance (default)
  • DistanceTypeAngle: Angle distance
  • DistanceTypeNormalizedAngle: Normalized angle distance. The specified data are automatically normalized to be appended to the index.
  • DistanceTypeCosine: Cosine similarity
  • DistanceTypeNormalizedCosine: Normalized cosine similarity. The specified data are automatically normalized to be appended to the index.
  • DistanceTypeHamming: Hamming distance
  • DistanceTypeJaccard: Jaccard distance

ObjectSpace::ObjectType objectType
The data type of the objects.

  • Float: 4 byte floating point number
  • Uint8: 1 byte unsigned integer

Class NGT::SearchQuery

Define the search query to search.

Member Functions

SearchQuery(std::vector<TYPE> &query)

Construct the search query object including the specified query object.

query
Specify the query object. Float, double and uint8_t are available for TYPE.

void setResults(ObjectDistances *results)

Specify an object that is stored search results.

void setSize(size_t size)

Specify the number of resultant search objects.

void setEpsilon(float epsilon)

Specify the epsilon value that defines an explored search range. The default value is 0.1.

void setExpectedAccuracy(float accuracy)

Specify the expected accuracy value. When the expected accuracy value is specified, the epsilon converted from the expected accuracy with the accuracy table will be used, instead of the epsilon that is specified with setEpsilon(). This accuracy table is generated by GraphOptimizer::execute.

Class NGT::ObjectDistance

A pair of an object ID and a distance to a query.

Member Variables

uint32_t id

float distance

Class NGT::ObjectDistances

A vector container of object IDs with distances. This class inherits vector<ObjectDistance>.

Class NGT::GraphOptimizer

Member Functions

GraphOptimizer(bool logDisabled)

Construct the GraphOptimizer object to optimize a graph.

logDisabled
Standard error logging is disabled when true is set.

void set(int outgoing, int incoming, int noOfQueries, int noOfResultantObjects)

Specify the parameters to reconstruct and optimize a graph for execute().

outgoing
Specify the number of outgoing edges to build an ONNG.

incoming
Specify the number of incoming edges to build an ONNG.

noOfQueries
Specify the number of queries to be used for the optimization.

noOfResultantObjects
Specify the number of resultant objects for search. the number which will be specified for search after this optimization should be specified.

void setProcessingModes(bool shortcut, bool searchParameter, bool prefetchParameter, bool accuracyTable)

Specify the processingModes for execute().

shortcut
When true is set, the shortcut reduction is executed by execute().

searchparameter
When true is set, the search parameter optimization is executed by execute().

prefetchParameter
When true is set, the prefetch parameter optimization is executed by execute().

accuracyTable
When true is set, the accuracy table generation is executed by execute().

void execute(const string &optimizedGraph, const string &inputGraph)

Construct an optimized graph from the specified graph.

optimizedGraph
Specify the path of the optimized graph to be saved.

inputGraph
Specify the path of the existing graph.