Simple annoy.AnnoyIndex with examples#

An example showing the AnnoyIndex class.

from annoy import AnnoyIndex from scikitplot.cexternals.annoy import AnnoyIndex

from scikitplot.cexternals.annoy import Index as AnnoyIndex

a = AnnoyIndex(
    f=3,
    metric='angular',
)
a.add_item(0, [1, 0, 0])
a.add_item(1, [0, 1, 0])
a.add_item(2, [0, 0, 1])
a.build(-1)

print(a.get_nns_by_item(0, 100))
print(a.get_nns_by_vector([1.0, 0.5, 0.5], 100))
[0, 1, 2]
[0, 1, 2]

Tags: model-type: classification model-workflow: impute plot-type: bar level: beginner purpose: showcase

Total running time of the script: (0 minutes 0.002 seconds)

Related examples

Mmap annoy.AnnoyIndex with examples

Mmap annoy.AnnoyIndex with examples

Precision annoy.AnnoyIndex with examples

Precision annoy.AnnoyIndex with examples

sphx_glr_auto_examples_annoy_plot_s_compile_cpp.py

Compile and run the C++ Annoy precision example.

annoy impute with examples

annoy impute with examples

Gallery generated by Sphinx-Gallery