Skip to content

Commit

Permalink
Integrate watsonx for re-ranking task
Browse files Browse the repository at this point in the history
  • Loading branch information
saikatsarkar056 committed Nov 21, 2024
1 parent 2bc243d commit 1e5c18e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ExecutableAction create(IbmWatsonxEmbeddingsModel model, Map<String, Obje
@Override
public ExecutableAction create(IbmWatsonxRerankModel model, Map<String, Object> taskSettings) {
var overriddenModel = IbmWatsonxRerankModel.of(model, taskSettings);
var requestCreator = IbmWatsonxRerankRequestManager.of(overriddenModel, serviceComponents.truncator(), serviceComponents.threadPool());
var requestCreator = IbmWatsonxRerankRequestManager.of(overriddenModel, serviceComponents.threadPool());
var failedToSendRequestErrorMessage = constructFailedToSendRequestMessage(
overriddenModel.getServiceSettings().uri(),
"Ibm Watsonx rerank"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.inference.InferenceServiceResults;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.inference.common.Truncator;
import org.elasticsearch.xpack.inference.external.http.retry.RequestSender;
import org.elasticsearch.xpack.inference.external.http.retry.ResponseHandler;
import org.elasticsearch.xpack.inference.external.ibmwatsonx.IbmWatsonxResponseHandler;
Expand All @@ -21,11 +20,9 @@

import org.elasticsearch.xpack.inference.services.ibmwatsonx.rerank.IbmWatsonxRerankModel;

import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;

import static org.elasticsearch.xpack.inference.common.Truncator.truncate;

public class IbmWatsonxRerankRequestManager extends IbmWatsonxRequestManager {
private static final Logger logger = LogManager.getLogger(IbmWatsonxRerankRequestManager.class);
Expand All @@ -35,17 +32,15 @@ private static ResponseHandler createIbmWatsonxResponseHandler() {
return new IbmWatsonxResponseHandler("ibm watsonx rerank", (request, response) -> IbmWatsonxRankedResponseEntity.fromResponse(response), false);
}

public static IbmWatsonxRerankRequestManager of(IbmWatsonxRerankModel model, Truncator truncator, ThreadPool threadPool) {
return new IbmWatsonxRerankRequestManager(Objects.requireNonNull(model), Objects.requireNonNull(truncator), Objects.requireNonNull(threadPool));
public static IbmWatsonxRerankRequestManager of(IbmWatsonxRerankModel model, ThreadPool threadPool) {
return new IbmWatsonxRerankRequestManager(Objects.requireNonNull(model), Objects.requireNonNull(threadPool));
}

private final IbmWatsonxRerankModel model;
private final Truncator truncator;

private IbmWatsonxRerankRequestManager(IbmWatsonxRerankModel model, Truncator truncator, ThreadPool threadPool) {
private IbmWatsonxRerankRequestManager(IbmWatsonxRerankModel model, ThreadPool threadPool) {
super(threadPool, model);
this.model = model;
this.truncator = Objects.requireNonNull(truncator);
}

@Override
Expand Down

0 comments on commit 1e5c18e

Please sign in to comment.