Python binding with pybind11 (ngtpy) is installed as follows.
pip3 install ngt
If you would like to use python binding with ctypes (ngt), additionally you have to install the NGT library according to the README.
You can install the python bindings with pybind11 and ctypes from source code. You MUST install the NGT library according to the README before installing the python bindings as follows.
Please note that the search speed of the ngtpy packages from PyPI is slower than that of the ngtpy that is built on your computer so that the package can be run on older CPUs.
fromngtimportbaseasngtimportrandomdim=10objects=[]foriinrange(0,100):vector=random.sample(range(100),dim)objects.append(vector)query=objects[0]index=ngt.Index.create(b"tmp",dim)index.insert(objects)# You can also insert objects from a file like this.# index.insert_from_tsv('list.tsv') index.save()# You can load saved the index like this.# index = ngt.Index(b"tmp")result=index.search(query,3)fori,oinenumerate(result):print(str(i)+": "+str(o.id)+", "+str(o.distance))object=index.get_object(o.id)print(object)