def toptexts(query, texts, index, n=10):
 sims = index[query]
 sims = sorted(enumerate(sims), key=(lambda item: (- item[1])))
 result = []
 for (topid, topcosine) in sims[:n]:
  result.append((topid, topcosine, texts[topid]))
 return result

def toptexts ( query , texts , index , n = 10 ) : sims = index [ query ] sims = sorted ( enumerate ( sims ) , key = ( lambda item : ( - item [ 1 ] ) ) ) result = [ ] for ( topid , topcosine ) in sims [ : n ] : result . append ( ( topid , topcosine , texts [ topid ] ) ) return result
debug fnc to help inspect the top n most similar documents .