Reduce memory usage for k-NN