Skip to content

Update TestSparseInferenceServiceExtension to not support text embeddings #126618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testGetServicesWithoutTaskType() throws IOException {
@SuppressWarnings("unchecked")
public void testGetServicesWithTextEmbeddingTaskType() throws IOException {
List<Object> services = getServices(TaskType.TEXT_EMBEDDING);
assertThat(services.size(), equalTo(16));
assertThat(services.size(), equalTo(15));

String[] providers = new String[services.size()];
for (int i = 0; i < services.size(); i++) {
Expand All @@ -86,7 +86,6 @@ public void testGetServicesWithTextEmbeddingTaskType() throws IOException {
"jinaai",
"mistral",
"openai",
"test_service",
"text_embedding_test_service",
"voyageai",
"watsonxai"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.inference.results.ChunkedInferenceEmbedding;
import org.elasticsearch.xpack.core.inference.results.SparseEmbeddingResults;
import org.elasticsearch.xpack.core.inference.results.TextEmbeddingFloatResults;
import org.elasticsearch.xpack.core.ml.search.WeightedToken;

import java.io.IOException;
Expand Down Expand Up @@ -64,7 +63,7 @@ public TestSparseModel(String inferenceEntityId, TestServiceSettings serviceSett
public static class TestInferenceService extends AbstractTestInferenceService {
public static final String NAME = "test_service";

private static final EnumSet<TaskType> supportedTaskTypes = EnumSet.of(TaskType.SPARSE_EMBEDDING, TaskType.TEXT_EMBEDDING);
private static final EnumSet<TaskType> supportedTaskTypes = EnumSet.of(TaskType.SPARSE_EMBEDDING);

public TestInferenceService(InferenceServiceExtension.InferenceServiceFactoryContext context) {}

Expand Down Expand Up @@ -115,8 +114,7 @@ public void infer(
ActionListener<InferenceServiceResults> listener
) {
switch (model.getConfigurations().getTaskType()) {
case ANY, SPARSE_EMBEDDING -> listener.onResponse(makeSparseEmbeddingResults(input));
case TEXT_EMBEDDING -> listener.onResponse(makeTextEmbeddingResults(input));
case ANY, SPARSE_EMBEDDING -> listener.onResponse(makeResults(input));
default -> listener.onFailure(
new ElasticsearchStatusException(
TaskType.unsupportedTaskTypeErrorMsg(model.getConfigurations().getTaskType(), name()),
Expand Down Expand Up @@ -157,7 +155,7 @@ public void chunkedInfer(
}
}

private SparseEmbeddingResults makeSparseEmbeddingResults(List<String> input) {
private SparseEmbeddingResults makeResults(List<String> input) {
var embeddings = new ArrayList<SparseEmbeddingResults.Embedding>();
for (int i = 0; i < input.size(); i++) {
var tokens = new ArrayList<WeightedToken>();
Expand All @@ -169,18 +167,6 @@ private SparseEmbeddingResults makeSparseEmbeddingResults(List<String> input) {
return new SparseEmbeddingResults(embeddings);
}

private TextEmbeddingFloatResults makeTextEmbeddingResults(List<String> input) {
var embeddings = new ArrayList<TextEmbeddingFloatResults.Embedding>();
for (int i = 0; i < input.size(); i++) {
var values = new float[5];
for (int j = 0; j < 5; j++) {
values[j] = random.nextFloat();
}
embeddings.add(new TextEmbeddingFloatResults.Embedding(values));
}
return new TextEmbeddingFloatResults(embeddings);
}

private List<ChunkedInference> makeChunkedResults(List<ChunkInferenceInput> inputs) {
List<ChunkedInference> results = new ArrayList<>();
for (ChunkInferenceInput chunkInferenceInput : inputs) {
Expand Down