Skip to main content

python NGT

Project description

python NGT

日本語

Install

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.

pip3 install pybind11
pip3 install numpy
cd NGT_ROOT/python
python3 setup.py sdist
pip3 install dist/ngt-x.x.x.tar.gz

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.

Documents

ngtpy (pybind11) reference

Simple samples

ngtpy (pybind11)

ngtpy(pybind11) can reduce the processing times than ngt(ctypes). It is more effective especially for the short search time.

  import ngtpy
  import random

  dim = 10
  objects = []
  for i in range(0, 100) :
      vector = random.sample(range(100), dim)
      objects.append(vector)

  query = objects[0]

  ngtpy.create(b"tmp", dim)
  index = ngtpy.Index(b"tmp")
  index.batch_insert(objects)
  index.save()

  result = index.search(query, 3)

  for i, o in enumerate(result) :
      print(str(i) + ": " + str(o[0]) + ", " + str(o[1]))
      object = index.get_object(o[0])
      print(object)

See also sample.py.

ngt (ctypes)

  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(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)

  for i, o in enumerate(result) :
      print(str(i) + ": " + str(o.id) + ", " + str(o.distance))
      object = index.get_object(o.id)
      print(object)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ngt, version 1.8.4
Filename, size File type Python version Upload date Hashes
Filename, size ngt-1.8.4-cp34-cp34m-manylinux1_x86_64.whl (1.9 MB) File type Wheel Python version cp34 Upload date Hashes View hashes
Filename, size ngt-1.8.4-cp35-cp35m-manylinux1_x86_64.whl (1.9 MB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size ngt-1.8.4-cp36-cp36m-macosx_10_14_x86_64.whl (383.9 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size ngt-1.8.4-cp36-cp36m-manylinux1_x86_64.whl (1.9 MB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size ngt-1.8.4-cp37-cp37m-macosx_10_14_x86_64.whl (379.9 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size ngt-1.8.4-cp37-cp37m-manylinux1_x86_64.whl (1.9 MB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size ngt-1.8.4-cp38-cp38-macosx_10_14_x86_64.whl (380.1 kB) File type Wheel Python version cp38 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page