Skip to main content

python NGT

Project description

python NGT

日本語

Install

Python bindings with ctypes (ngt) and pybind11 (ngtpy) are both installed as follows.

pip install ngt

Or, you can install from source source. You MUST install the NGT library according to the README before installing python NGT as follows.

pip install pybind11
cd NGT_ROOT/python
python setup.py sdist
pip install dist/ngt-1.2.0.tar.gz

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)

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)

See also sample.py.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

ngt-1.5.1-cp37-cp37m-manylinux1_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.7m

ngt-1.5.1-cp37-cp37m-macosx_10_13_x86_64.whl (279.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.13+ x86-64

ngt-1.5.1-cp36-cp36m-manylinux1_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.6m

ngt-1.5.1-cp35-cp35m-manylinux1_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.5m

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page