P java engine

I think I am missing something. Why do we need .mapToPair here?

Why the following doesn't work?
batchPredict(baseModel.asInstanceOf[M], indexedQueries.toJavaRDD()).rdd