Calmcode - annoy: final features

Extra Features of Annoy

1 2 3 4 5 6 7 8

The full annoy API is defined on the github page.

If you want to pick up the full notebook of everything done here you can find it over at the calmcode notebook repo.

Metrics

Metrics can be angular, euclidean, manhattan, hamming, or dot.

Disk

If you want to save and load from disk you can use this code;

columns = 2
vecs = np.concatenate([
    np.random.normal(-1, 1, (5000, columns)),
    np.random.normal(0, 0.5, (5000, columns)),
])

metric = 'euclidean'

annoy = AnnoyIndex(columns, metric)
for i in range(vecs.shape[0]):
    annoy.add_item(i, vecs[i, :])
annoy.build(n_trees=1)

# here we save the annoy index
annoy.save('test.ann')

# next we make a new object with the same settings
annoy_from_disk = AnnoyIndex(columns, metric)
# here we load it in again
annoy_from_disk.load('test.ann')