annoy with examples#
An example showing the annoy
function.
8 # Authors: Spotify AB
9 # SPDX-License-Identifier: Apache-2.0
from annoy import AnnoyIndex
13 from scikitplot.cexternals.annoy import AnnoyIndex
14
15 a = AnnoyIndex(3, 'angular')
16 a.add_item(0, [1, 0, 0])
17 a.add_item(1, [0, 1, 0])
18 a.add_item(2, [0, 0, 1])
19 a.build(-1)
20
21 print(a.get_nns_by_item(0, 100))
22 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.003 seconds)
Related examples

Visualkeras: Spam Classification Conv1D Dense Example
Visualkeras: Spam Classification Conv1D Dense Example