This is an issue about the onnx_nearest_neighbors_indices_k() function in nearest_neighbours.py when the keep_distances option is true.
The Mul operator created in line 141 converts distances (node[0]) from OnnxTopK_11 to negative values. The Mul operator is followed by a Max operator, which turns any negative value to 1e-6, so distances lose their effect in the downstream operation. I think this Mul operator should be removed, and node[0] can be connected to the Max operator directly.
Here is my suggested fix: https://github.com/onnx/sklearn-onnx/pull/1212/files.