Getting top-k most similar matrices

Hi guys,

So I have a collection with gram matrices for different photos and then I have a user input photo for which I also calculate the gram matrix. My aim is to retrieve the indexes of the most similar matrices to the user input one. Is there a smart way to do that without iterating over the whole collection? Any input would be appreciated!