# What is the difference between exhaustive nearest neighbor search and k-nearest neighbour search?

I have two lists of feature vectors calculated from pre-trained CNN for image retrieval task:

Query: FV_Q and Reference FV_R.

>>> FV_R.shape
(3450, 128)

>>> FV_Q.shape
(3450, 128)


I am a little confused between the concept of exhaustive nearest neighbor search and k-nearest neighbor search.

In python, I use from sklearn.neighbors import KDTree to extract top k = 5 similar images from the reference database, given the query image!

Can somebody explain if there might be any similarities/differences between these two concepts?

Am I making a mistake somewhere in my feature vector comparison?

The $$k$$-nearest neighbor search finds the $$k$$ closest images. You typically do that by first building a KD-tree with your query (or target) image, so that to speed up the search for the $$k$$-nearest neighbors of your query image.
(Btw, in case you are interested in the concept of feature matching, in OpenCV, the class that you can use to perform an exhaustive search for the matches between two images is the BFMatcher (which stands for Brute Force Matcher), while the class to perform the search with a KD-tree for the k-nearest neighbhours is FlannBasedMatcher).