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]
Total running time of the script: (0 minutes 0.002 seconds)
Related examples
sphx_glr_auto_examples_annoy_plot_s_compile_cpp.py
Compile and run the C++ Annoy precision example.