code: public static List<Pair<Double,Integer>> queryAllWithDistances(INDArray toQuery,INDArray X,List<RPTree> trees,int n,String similarityFunction) {
          if(trees.isEmpty()) {
              throw new ND4JIllegalArgumentException("Trees is empty!");
          }
  
          List<Integer> candidates = getCandidates(toQuery, trees,similarityFunction);
          val sortedCandidates = sortCandidates(toQuery,X,candidates,similarityFunction);
          int numReturns = Math.min(n,sortedCandidates.size());
          List<Pair<Double,Integer>> ret = new ArrayList<>(numReturns);
          for(int i = 0; i < numReturns; i++) {
              ret.add(sortedCandidates.get(i));
          }
  
          return ret;
      }
docs: Query all trees using the given input and data
  @param toQuery the query vector
  @param X the input data to query
  @param trees the trees to query
  @param n the number of results to search for
  @param similarityFunction the similarity function to use
  @return the indices (in order) in the ndarray