forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
4,497 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...h/xpack/inference/external/action/alibabacloudsearch/AlibabaCloudSearchActionCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.external.action.alibabacloudsearch; | ||
|
||
import org.elasticsearch.inference.InputType; | ||
import org.elasticsearch.xpack.inference.external.action.ExecutableAction; | ||
import org.elasticsearch.xpack.inference.external.http.sender.Sender; | ||
import org.elasticsearch.xpack.inference.services.ServiceComponents; | ||
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.embeddings.AlibabaCloudSearchEmbeddingsModel; | ||
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.rerank.AlibabaCloudSearchRerankModel; | ||
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.sparse.AlibabaCloudSearchSparseModel; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Provides a way to construct an {@link ExecutableAction} using the visitor pattern based on the alibaba cloud search model type. | ||
*/ | ||
public class AlibabaCloudSearchActionCreator implements AlibabaCloudSearchActionVisitor { | ||
private final Sender sender; | ||
private final ServiceComponents serviceComponents; | ||
|
||
public AlibabaCloudSearchActionCreator(Sender sender, ServiceComponents serviceComponents) { | ||
this.sender = Objects.requireNonNull(sender); | ||
this.serviceComponents = Objects.requireNonNull(serviceComponents); | ||
} | ||
|
||
@Override | ||
public ExecutableAction create(AlibabaCloudSearchEmbeddingsModel model, Map<String, Object> taskSettings, InputType inputType) { | ||
var overriddenModel = AlibabaCloudSearchEmbeddingsModel.of(model, taskSettings, inputType); | ||
|
||
return new AlibabaCloudSearchEmbeddingsAction(sender, overriddenModel, serviceComponents); | ||
} | ||
|
||
@Override | ||
public ExecutableAction create(AlibabaCloudSearchSparseModel model, Map<String, Object> taskSettings, InputType inputType) { | ||
var overriddenModel = AlibabaCloudSearchSparseModel.of(model, taskSettings, inputType); | ||
|
||
return new AlibabaCloudSearchSparseAction(sender, overriddenModel, serviceComponents); | ||
} | ||
|
||
@Override | ||
public ExecutableAction create(AlibabaCloudSearchRerankModel model, Map<String, Object> taskSettings) { | ||
var overriddenModel = AlibabaCloudSearchRerankModel.of(model, taskSettings); | ||
|
||
return new AlibabaCloudSearchRerankAction(sender, overriddenModel, serviceComponents); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...h/xpack/inference/external/action/alibabacloudsearch/AlibabaCloudSearchActionVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.external.action.alibabacloudsearch; | ||
|
||
import org.elasticsearch.inference.InputType; | ||
import org.elasticsearch.xpack.inference.external.action.ExecutableAction; | ||
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.embeddings.AlibabaCloudSearchEmbeddingsModel; | ||
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.rerank.AlibabaCloudSearchRerankModel; | ||
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.sparse.AlibabaCloudSearchSparseModel; | ||
|
||
import java.util.Map; | ||
|
||
public interface AlibabaCloudSearchActionVisitor { | ||
ExecutableAction create(AlibabaCloudSearchEmbeddingsModel model, Map<String, Object> taskSettings, InputType inputType); | ||
|
||
ExecutableAction create(AlibabaCloudSearchSparseModel model, Map<String, Object> taskSettings, InputType inputType); | ||
|
||
ExecutableAction create(AlibabaCloudSearchRerankModel model, Map<String, Object> taskSettings); | ||
} |
67 changes: 67 additions & 0 deletions
67
...pack/inference/external/action/alibabacloudsearch/AlibabaCloudSearchEmbeddingsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.external.action.alibabacloudsearch; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.core.TimeValue; | ||
import org.elasticsearch.inference.InferenceServiceResults; | ||
import org.elasticsearch.xpack.inference.external.action.ExecutableAction; | ||
import org.elasticsearch.xpack.inference.external.alibabacloudsearch.AlibabaCloudSearchAccount; | ||
import org.elasticsearch.xpack.inference.external.http.sender.AlibabaCloudSearchEmbeddingsRequestManager; | ||
import org.elasticsearch.xpack.inference.external.http.sender.InferenceInputs; | ||
import org.elasticsearch.xpack.inference.external.http.sender.Sender; | ||
import org.elasticsearch.xpack.inference.services.ServiceComponents; | ||
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.embeddings.AlibabaCloudSearchEmbeddingsModel; | ||
|
||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.constructFailedToSendRequestMessage; | ||
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.createInternalServerError; | ||
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.wrapFailuresInElasticsearchException; | ||
|
||
public class AlibabaCloudSearchEmbeddingsAction implements ExecutableAction { | ||
private static final Logger logger = LogManager.getLogger(AlibabaCloudSearchEmbeddingsAction.class); | ||
|
||
private final AlibabaCloudSearchAccount account; | ||
private final AlibabaCloudSearchEmbeddingsModel model; | ||
private final String failedToSendRequestErrorMessage; | ||
private final Sender sender; | ||
private final AlibabaCloudSearchEmbeddingsRequestManager requestCreator; | ||
|
||
public AlibabaCloudSearchEmbeddingsAction(Sender sender, AlibabaCloudSearchEmbeddingsModel model, ServiceComponents serviceComponents) { | ||
this.model = Objects.requireNonNull(model); | ||
this.sender = Objects.requireNonNull(sender); | ||
this.account = new AlibabaCloudSearchAccount( | ||
this.model.getServiceSettings().getCommonSettings().getUri(), | ||
this.model.getSecretSettings().apiKey() | ||
); | ||
this.failedToSendRequestErrorMessage = constructFailedToSendRequestMessage( | ||
this.model.getServiceSettings().getCommonSettings().getUri(), | ||
"AlibabaCloud Search text embeddings" | ||
); | ||
this.requestCreator = AlibabaCloudSearchEmbeddingsRequestManager.of(account, model, serviceComponents.threadPool()); | ||
} | ||
|
||
@Override | ||
public void execute(InferenceInputs inferenceInputs, TimeValue timeout, ActionListener<InferenceServiceResults> listener) { | ||
try { | ||
ActionListener<InferenceServiceResults> wrappedListener = wrapFailuresInElasticsearchException( | ||
failedToSendRequestErrorMessage, | ||
listener | ||
); | ||
sender.send(requestCreator, inferenceInputs, timeout, wrappedListener); | ||
} catch (ElasticsearchException e) { | ||
listener.onFailure(e); | ||
} catch (Exception e) { | ||
listener.onFailure(createInternalServerError(e, failedToSendRequestErrorMessage)); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ch/xpack/inference/external/action/alibabacloudsearch/AlibabaCloudSearchRerankAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.external.action.alibabacloudsearch; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.core.TimeValue; | ||
import org.elasticsearch.inference.InferenceServiceResults; | ||
import org.elasticsearch.xpack.inference.external.action.ExecutableAction; | ||
import org.elasticsearch.xpack.inference.external.alibabacloudsearch.AlibabaCloudSearchAccount; | ||
import org.elasticsearch.xpack.inference.external.http.sender.AlibabaCloudSearchRerankRequestManager; | ||
import org.elasticsearch.xpack.inference.external.http.sender.InferenceInputs; | ||
import org.elasticsearch.xpack.inference.external.http.sender.Sender; | ||
import org.elasticsearch.xpack.inference.services.ServiceComponents; | ||
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.rerank.AlibabaCloudSearchRerankModel; | ||
|
||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.constructFailedToSendRequestMessage; | ||
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.createInternalServerError; | ||
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.wrapFailuresInElasticsearchException; | ||
|
||
public class AlibabaCloudSearchRerankAction implements ExecutableAction { | ||
private static final Logger logger = LogManager.getLogger(AlibabaCloudSearchRerankAction.class); | ||
|
||
private final AlibabaCloudSearchAccount account; | ||
private final AlibabaCloudSearchRerankModel model; | ||
private final String failedToSendRequestErrorMessage; | ||
private final Sender sender; | ||
private final AlibabaCloudSearchRerankRequestManager requestCreator; | ||
|
||
public AlibabaCloudSearchRerankAction(Sender sender, AlibabaCloudSearchRerankModel model, ServiceComponents serviceComponents) { | ||
this.model = Objects.requireNonNull(model); | ||
this.account = new AlibabaCloudSearchAccount( | ||
this.model.getServiceSettings().getCommonSettings().getUri(), | ||
this.model.getSecretSettings().apiKey() | ||
); | ||
this.failedToSendRequestErrorMessage = constructFailedToSendRequestMessage( | ||
this.model.getServiceSettings().getCommonSettings().getUri(), | ||
"AlibabaCloud Search rerank" | ||
); | ||
this.sender = Objects.requireNonNull(sender); | ||
this.requestCreator = AlibabaCloudSearchRerankRequestManager.of(account, model, serviceComponents.threadPool()); | ||
} | ||
|
||
@Override | ||
public void execute(InferenceInputs inferenceInputs, TimeValue timeout, ActionListener<InferenceServiceResults> listener) { | ||
try { | ||
ActionListener<InferenceServiceResults> wrappedListener = wrapFailuresInElasticsearchException( | ||
failedToSendRequestErrorMessage, | ||
listener | ||
); | ||
sender.send(requestCreator, inferenceInputs, timeout, wrappedListener); | ||
} catch (ElasticsearchException e) { | ||
listener.onFailure(e); | ||
} catch (Exception e) { | ||
listener.onFailure(createInternalServerError(e, failedToSendRequestErrorMessage)); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ch/xpack/inference/external/action/alibabacloudsearch/AlibabaCloudSearchSparseAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.inference.external.action.alibabacloudsearch; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.core.TimeValue; | ||
import org.elasticsearch.inference.InferenceServiceResults; | ||
import org.elasticsearch.xpack.inference.external.action.ExecutableAction; | ||
import org.elasticsearch.xpack.inference.external.alibabacloudsearch.AlibabaCloudSearchAccount; | ||
import org.elasticsearch.xpack.inference.external.http.sender.AlibabaCloudSearchSparseRequestManager; | ||
import org.elasticsearch.xpack.inference.external.http.sender.InferenceInputs; | ||
import org.elasticsearch.xpack.inference.external.http.sender.Sender; | ||
import org.elasticsearch.xpack.inference.services.ServiceComponents; | ||
import org.elasticsearch.xpack.inference.services.alibabacloudsearch.sparse.AlibabaCloudSearchSparseModel; | ||
|
||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.constructFailedToSendRequestMessage; | ||
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.createInternalServerError; | ||
import static org.elasticsearch.xpack.inference.external.action.ActionUtils.wrapFailuresInElasticsearchException; | ||
|
||
public class AlibabaCloudSearchSparseAction implements ExecutableAction { | ||
private static final Logger logger = LogManager.getLogger(AlibabaCloudSearchSparseAction.class); | ||
|
||
private final AlibabaCloudSearchAccount account; | ||
private final AlibabaCloudSearchSparseModel model; | ||
private final String failedToSendRequestErrorMessage; | ||
private final Sender sender; | ||
private final AlibabaCloudSearchSparseRequestManager requestCreator; | ||
|
||
public AlibabaCloudSearchSparseAction(Sender sender, AlibabaCloudSearchSparseModel model, ServiceComponents serviceComponents) { | ||
this.model = Objects.requireNonNull(model); | ||
this.account = new AlibabaCloudSearchAccount( | ||
this.model.getServiceSettings().getCommonSettings().getUri(), | ||
this.model.getSecretSettings().apiKey() | ||
); | ||
this.failedToSendRequestErrorMessage = constructFailedToSendRequestMessage( | ||
this.model.getServiceSettings().getCommonSettings().getUri(), | ||
"AlibabaCloud Search sparse embeddings" | ||
); | ||
this.sender = Objects.requireNonNull(sender); | ||
requestCreator = AlibabaCloudSearchSparseRequestManager.of(account, model, serviceComponents.threadPool()); | ||
} | ||
|
||
@Override | ||
public void execute(InferenceInputs inferenceInputs, TimeValue timeout, ActionListener<InferenceServiceResults> listener) { | ||
try { | ||
ActionListener<InferenceServiceResults> wrappedListener = wrapFailuresInElasticsearchException( | ||
failedToSendRequestErrorMessage, | ||
listener | ||
); | ||
sender.send(requestCreator, inferenceInputs, timeout, wrappedListener); | ||
} catch (ElasticsearchException e) { | ||
listener.onFailure(e); | ||
} catch (Exception e) { | ||
listener.onFailure(createInternalServerError(e, failedToSendRequestErrorMessage)); | ||
} | ||
} | ||
} |
Oops, something went wrong.