yahoojapan / NGT

Nearest Neighbor Search with Neighborhood Graph and Tree for High-dimensional Data
Apache License 2.0
1.24k stars 114 forks source link

Using float16 in C API #125

Closed lerouxrgd closed 1 year ago

lerouxrgd commented 1 year ago

Hello @masajiro ,

I see that the C API has ngt_set_property_object_type_float16 but not:

Are some of these functions needed to use float16 ? Or just using ngt_set_property_object_type_float16 and then ngt_get_object_as_float is enough ?

By the way, what is the difference between ngt_insert_index and ngt_append_index ?

masajiro commented 1 year ago

Hello @lerouxrgd , The TYPE of ngt_XXX_indexasTYPE doesn't need to coincide with the object type for the indexed object. TYPE is just for the specified vector of ngt_XXX_indexasTYPE. On the other hand, TYPE of ngt_get_objectasTYPE should coincide with the object type for the indexed object.

ngt_append_index always appends the object to the end of the object list in the NGT index. However, if there is a removed object entry in the object list, ngt_append_index inserts the object into the entry and returns the ID of the entry. Otherwise, it appends the object to the end of the list.

lerouxrgd commented 1 year ago

Thank you for the explanation, I got it ! So I guess we still need ngt_get_object_as_float16 to be able to use float16 from C API.

masajiro commented 1 year ago

ngt_get_object_as_float and ngt_get_object_as_integer return just the same address of the specified object inside the NGT index. Therefore, you can get float 16 objects as follows.

NGT::float16 *objectVector = reinterpret_cast<NGT::float16*>(ngt_get_object_as_float(objectSpace, object.id, err));
for (size_t i = 0; i < dimension; i++) {
      std::cout << objectVector[i] << " ";
}
std::cout << std::endl;
lerouxrgd commented 1 year ago

Ok I see. Thank you again for the explanation.