check(!pathSegmentsList.isEmpty(), "Need at least 1 user");
check(howMany > 0, "howMany must be positive");
check(offset >= 0, "offset must be non-negative");
ALSServingModel alsServingModel = getALSServingModel();
double[][] userFeaturesVectors = new double[pathSegmentsList.size()][];
ObjectSet<String> userKnownItems = new ObjectOpenHashSet<>();
for (int i = 0; i < userFeaturesVectors.length; i++) {
String userID = pathSegmentsList.get(i).getPath();
float[] userFeatureVector = alsServingModel.getUserVector(userID);
checkExists(userFeatureVector != null, userID);
userFeaturesVectors[i] = VectorMath.toDoubles(userFeatureVector);
if (!considerKnownItems) {
ObjectSet<String> knownItems = alsServingModel.getKnownItems(userID);
if (knownItems != null && !knownItems.isEmpty()) {
synchronized (knownItems) {
for (ObjectCursor<String> knownItem : knownItems) {
userKnownItems.add(knownItem.value);
}
}
}
}
}
List<Pair<String,Double>> topIDDots = alsServingModel.topN(
new DotsFunction(userFeaturesVectors),
howMany + offset,
new NotKnownPredicate(userKnownItems));
return toIDValueResponse(topIDDots, howMany, offset);