ngt
Index
```python
Index(self, path)
```
NGT: Neighborhood Graph and Tree for Indexing High-dimensional Data
NGT provides the functionality of searching for approximate nearest neighbors in high-dimensional data.
Example:
```python
from ngt import base as ngt
import random
dim = 10
objects = []
for i in range(0, 100) :
vector = random.sample(range(100), dim)
objects.append(vector)
query = objects[0]
index = ngt.Index.create("tmp", dim)
index.insert(objects)
# You can also insert objects from a file like this.
# index.insert_from_tsv('list.dat')
index.save()
result = index.search(query, 3)
for i, o in enumerate(result) :
print(str(i) + ": " + str(o.id) + ", " + str(o.distance))
object = index.get_object(o.id)
print(object)
```
insert
```python
Index.insert(self, objects, num_threads=8)
```
insert the specified objects into the index and build the index.
objects : Inserted objects.
return : List of the IDs of the inserted objects.
get_object
```python
Index.get_object(self, id)
```
get the specfied object by id.
id : Object id.
insert_object
```python
Index.insert_object(self, object)
```
insert the specified object into the index.
must call build_index after call this method.
object : Inserted object.
return : The ID of the inserted object.
insert_from_tsv
```python
Index.insert_from_tsv(self, path, num_threads=8, dlmt='\t')
```
insert objects in the specified file and build the index.
path : Path of the object file.
num_threads : Number of threads in building index.
dlmt : Delimiter to sepalate each element in the object file.
remove
```python
Index.remove(self, id)
```
remove the specified object by id
id : Object id.
build_index
```python
Index.build_index(self, num_threads=8)
```
build the inserted objects into the index.
num_threads : Number of threads in building index.
search
```python
Index.search(self, query, k=20, epsilon=0.1)
```
search for the k nearest neighbors of the specifiecd query object.
query : Query object.
k : Number of searched objects.
epsilon : Epsilon defines a search range.
create
```python
Index.create(path, dimension, edge_size_for_creation=10, edge_size_for_search=40, object_type='Float', distance_type='L2')
```
create an empty index with the specified parameters.
edge_size_for_creation : Number of edges for each node in the graph.
edge_size_for_search : Number of edges to search.
object_type : Type of the data object. (Float, Integer [Integer is 1 byte])
distance_type : Type of the distance function. (L1,L2,Angle,Hamming,Jaccard)
save
```python
Index.save(self, path=None)
```
save the index.
path : Path to save the index. default overwrite the files.
insert_blob
```python
Index.insert_blob(self, objects, num_threads=8)
```
insert the specified objects into the index and build the index.
Although this is the same as the fucntion, both implementations are different.
objects : Inserted objects.
num_threads : Number of threads in building index.