Skip to content

Cpp Quick Reference

masajiro edited this page Nov 25, 2019 · 3 revisions

Class NGT::Index

Member Functions

Index(NGT::Property &property)

Construct the index object for the index specified with the NGT::Property.

property
Specify the index properties.

Index(const std::string &indexPath)

Open the specified index.

indexPath
Specify an existing index path.

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 saveIndex(const std::string indexPath)

Save the index.

indexPath
Specify the path of the created index to be saved.

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. 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 epsilon that defines an explored search range.

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

Construct an optimized graph from the specified graph.

Member Variables

numOfOutgoingEdges
The number of outgoing edges for each node of an optimized graph.

numOfIncomingEdges
The number of incoming edges for each node of an optimized graph.

Member Functions

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.