Skip to content

Commit

Permalink
Simplify LearnToRankRescorerBuilder serialization code.
Browse files Browse the repository at this point in the history
  • Loading branch information
afoucret committed Nov 21, 2023
1 parent 275c934 commit 5560737
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction;
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.InferenceConfig;
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.LearnToRankConfig;
import org.elasticsearch.xpack.ml.inference.loadingservice.LocalModel;

Expand Down Expand Up @@ -89,11 +90,7 @@ public LearnToRankRescorerBuilder(StreamInput input, LearnToRankService learnToR
super(input);
this.modelId = input.readString();
this.params = input.readMap();
if (input.readBoolean()) {
this.learnToRankConfig = new LearnToRankConfig(input);
} else {
this.learnToRankConfig = null;
}
this.learnToRankConfig = (LearnToRankConfig) input.readOptionalNamedWriteable(InferenceConfig.class);
this.learnToRankService = learnToRankService;

this.localModel = null;
Expand Down Expand Up @@ -258,13 +255,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
assert localModel == null || rescoreOccurred : "Unnecessarily populated local model object";
out.writeString(modelId);
out.writeGenericMap(params);

if (learnToRankConfig != null) {
out.writeBoolean(true);
learnToRankConfig.writeTo(out);
} else {
out.writeBoolean(false);
}
out.writeOptionalNamedWriteable(learnToRankConfig);
}

@Override
Expand Down

0 comments on commit 5560737

Please sign in to comment.