Fix assertion failure on nearest neighbor