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
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
Release history Release notifications | RSS feed
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
Close
Hashes for ngt-1.5.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de2aad5381f3d0b4f9ce031fec5c5b5303649b2e78375e0b4953fe0e873a04f8 |
|
MD5 | 4142cb56b1fd0263ee94da913cfb00db |
|
BLAKE2b-256 | 612ef517a7c6ff34e1b545962273b79784d720e067d7d08efc0a9f141a745171 |
Close
Hashes for ngt-1.5.1-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 018cdf821b84a9dd810319b4acbb802bc800be65f42345bc2e8e00bfd7336da3 |
|
MD5 | 32a035be9094926a975154aeafc76c3e |
|
BLAKE2b-256 | 8590515477f0f1a090b8a6a97291c8632da5a3a09488f013e7727b21ea58bd4c |
Close
Hashes for ngt-1.5.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e1b66e27ec57a3b253e3e40beb712a03584693304f74b756959458168bc06ad |
|
MD5 | e709ef7559d0eff57b3ff245b4e1dca0 |
|
BLAKE2b-256 | 98295549b913f744c210c3d7203866d5192fbaeb530f9fe009ad414ca7c84436 |
Close
Hashes for ngt-1.5.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebc7469e9a4d1d775d5cf4d051f00a47d0e64fe331b381d203bf5d53fd48f470 |
|
MD5 | 58c4aacc3acd6a7e3be5868869905ef3 |
|
BLAKE2b-256 | 6e5ff3c0035ff2a328ef961758edfb5a321556173ec3720e11098ac59f71c7a0 |