Skip to content

Commit 9298450

Browse files
committed
More flexible output builder.
1 parent 2068e91 commit 9298450

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/inference/InferenceOperator.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.esql.inference;
99

1010
import org.elasticsearch.action.ActionListener;
11+
import org.elasticsearch.compute.data.Block;
1112
import org.elasticsearch.compute.data.BlockFactory;
1213
import org.elasticsearch.compute.data.Page;
1314
import org.elasticsearch.compute.operator.AsyncOperator;
@@ -102,7 +103,7 @@ public Page getOutput() {
102103
return null;
103104
}
104105

105-
try (OutputBuilder outputBuilder = outputBuilder(ongoingInferenceResult.inputPage)) {
106+
try (OutputBuilder<Page> outputBuilder = outputBuilder(ongoingInferenceResult.inputPage)) {
106107
for (InferenceAction.Response response : ongoingInferenceResult.responses) {
107108
outputBuilder.addInferenceResponse(response);
108109
}
@@ -125,12 +126,12 @@ public Page getOutput() {
125126
*
126127
* @param input The corresponding input page used to generate the inference requests.
127128
*/
128-
protected abstract OutputBuilder outputBuilder(Page input);
129+
protected abstract OutputBuilder<Page> outputBuilder(Page input);
129130

130131
/**
131-
* An interface for accumulating inference responses and constructing a result {@link Page}.
132+
* An interface for accumulating inference responses and constructing a result (can be a {@link Page} or a {@link Block}).
132133
*/
133-
public interface OutputBuilder extends Releasable {
134+
public interface OutputBuilder<T> extends Releasable {
134135

135136
/**
136137
* Adds an inference response to the output.
@@ -144,11 +145,11 @@ public interface OutputBuilder extends Releasable {
144145
void addInferenceResponse(InferenceAction.Response inferenceResponse);
145146

146147
/**
147-
* Builds the final output page from accumulated inference responses.
148+
* Builds the final output from accumulated inference responses.
148149
*
149-
* @return The constructed output page.
150+
* @return The constructed output block.
150151
*/
151-
Page buildOutput();
152+
T buildOutput();
152153

153154
static <IR extends InferenceServiceResults> IR inferenceResults(InferenceAction.Response inferenceResponse, Class<IR> clazz) {
154155
InferenceServiceResults results = inferenceResponse.getResults();

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/inference/completion/CompletionOperatorOutputBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* {@link CompletionOperatorOutputBuilder} builds the output page for {@link CompletionOperator} by converting {@link ChatCompletionResults}
2121
* into a {@link BytesRefBlock}.
2222
*/
23-
public class CompletionOperatorOutputBuilder implements InferenceOperator.OutputBuilder {
23+
public class CompletionOperatorOutputBuilder implements InferenceOperator.OutputBuilder<Page> {
2424
private final Page inputPage;
2525
private final BytesRefBlock.Builder outputBlockBuilder;
2626
private final BytesRefBuilder bytesRefBuilder = new BytesRefBuilder();

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/inference/rerank/RerankOperatorOutputBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* * reranked relevance scores into the specified score channel of the input page.
2525
*/
2626

27-
public class RerankOperatorOutputBuilder implements InferenceOperator.OutputBuilder {
27+
public class RerankOperatorOutputBuilder implements InferenceOperator.OutputBuilder<Page> {
2828

2929
private final Page inputPage;
3030
private final DoubleBlock.Builder scoreBlockBuilder;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/inference/textembedding/TextEmbeddingOperatorOutputBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* {@link TextEmbeddingOperatorOutputBuilder} builds the output page for text embedding by converting
2222
* {@link TextEmbeddingResults} into a {@link FloatBlock} containing dense vector embeddings.
2323
*/
24-
public class TextEmbeddingOperatorOutputBuilder implements InferenceOperator.OutputBuilder {
24+
public class TextEmbeddingOperatorOutputBuilder implements InferenceOperator.OutputBuilder<Page> {
2525
private final Page inputPage;
2626
private final FloatBlock.Builder outputBlockBuilder;
2727

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbeddingTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static Iterable<Object[]> parameters() {
5050
List.of(inputTextDataType, inferenceIdDataType),
5151
() -> new TestCaseSupplier.TestCase(
5252
List.of(
53-
new TestCaseSupplier.TypedData(randomBytesReference(10).toBytesRef(), inputTextDataType, "inputText"),
53+
new TestCaseSupplier.TypedData(randomBytesReference(10).toBytesRef(), inputTextDataType, "text"),
5454
new TestCaseSupplier.TypedData(randomBytesReference(10).toBytesRef(), inferenceIdDataType, "inference_id")
5555
),
5656
Matchers.blankOrNullString(),

0 commit comments

Comments
 (0)