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
  nb = 100
  vectors = [[random.random() for _ in range(dim)] for _ in range(nb)]
  query = vectors[0]
  
  ngtpy.create(b"tmp", dim)
  index = ngtpy.Index(b"tmp")
  index.batch_insert(vectors)
  index.save()

  results = index.search(query, 3)
  for i, (id, distance) in enumerate(results) :
      print(str(i) + ": " + str(id) + ", " + str(distance))
      object = index.get_object(id)
      print(object)

See also sample.py.

ngt (ctypes)

  from ngt import base as ngt
  import random

  dim = 10
  nb = 100
  vectors = [[random.random() for _ in range(dim)] for _ in range(nb)]
  query = vectors[0]

  index = ngt.Index.create(b"tmp", dim)
  index.insert(vectors)
  # You can also insert vectors 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")


  results = index.search(query, 3)
  for i, result in enumerate(results) :
      print(str(i) + ": " + str(result.id) + ", " + str(result.distance))
      object = index.get_object(result.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.

Built Distributions

ngt-1.14.6-cp310-cp310-macosx_11_0_x86_64.whl (569.1 kB view hashes)

Uploaded cp310

ngt-1.14.6-cp39-cp39-macosx_11_0_x86_64.whl (569.2 kB view hashes)

Uploaded cp39

ngt-1.14.6-cp38-cp38-macosx_11_0_x86_64.whl (569.0 kB view hashes)

Uploaded cp38

ngt-1.14.6-cp37-cp37m-macosx_11_0_x86_64.whl (577.9 kB view hashes)

Uploaded cp37

ngt-1.14.6-cp36-cp36m-macosx_11_0_x86_64.whl (577.8 kB view hashes)

Uploaded cp36

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page