annoy (simple) with examples#
An example showing the annoy function.
# Authors: Spotify AB
# SPDX-License-Identifier: Apache-2.0
from annoy import AnnoyIndex
from scikitplot.cexternals.annoy import AnnoyIndex
a = AnnoyIndex(3, '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
Visualkeras: Spam Classification Conv1D Dense Example
Visualkeras: Spam Classification Conv1D Dense Example