Closed Cumberbatch08 closed 4 years ago
The easiest way to do this is with the dist() method, which returns the distance between two items.
You can also (unofficially) call the underlying Annoy get_nns_by_item()
method and set the include_distances
parameter to True
, which will return a list of 2-tuples with the index and the distance for each match:
nn = SimpleNeighbors(...)
# add a bunch of stuff to the index
results = nn.annoy.get_nns_by_item(idx, n, include_distances=True)
(Though in that case, you'll have to do the work of looking up the index of the item you want to look up and the value of the item at the indices returned from get_nns_by_item()
yourself.)
after I build the tree model, and I use the method nearest(vec, n) to get the nearest item in the candidate corpus, but I want get the similarity score. becase, some returned results are not very near. If I have the score of every returned result, I can filter the result. Is ther any method can do this?