KNN is instance based so it will store all training instances in memory. Since you are using images this will add up quickly. KNN on unfiltered images might not perform that well anyway, you could look into filter banks to transform your images to a bag-of-word-representation (which is smaller and more invariant).
However if it is accuracy you are aiming for I would recommend skipping all that (it is very 2012 anyway) in favor of using deep learning, fi: construct an autoencoder and determine simlarity on the encoded representation of an image (which could in turn be done using knn btw).