Skip to content

Commit

Permalink
Address some PR feedback RE: optional values
Browse files Browse the repository at this point in the history
  • Loading branch information
kderusso committed Apr 2, 2024
1 parent d3ae94d commit f7a6a13
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public Object predictedValue() {
@Override
void doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.startObject(resultsField);
for (var vectorDimension : weightedTokens) {
vectorDimension.toXContent(builder, params);
for (var weightedToken : weightedTokens) {
weightedToken.toXContent(builder, params);
}
builder.endObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public SparseVectorQueryBuilder(

public SparseVectorQueryBuilder(
String fieldName,
String modelText,
@Nullable String modelText,
@Nullable String modelId,
@Nullable List<WeightedToken> weightedTokens,
@Nullable TokenPruningConfig tokenPruningConfig
Expand Down Expand Up @@ -97,7 +97,7 @@ public SparseVectorQueryBuilder(
public SparseVectorQueryBuilder(StreamInput in) throws IOException {
super(in);
this.fieldName = in.readString();
this.modelText = in.readString();
this.modelText = in.readOptionalString();
this.modelId = in.readOptionalString();
this.tokenPruningConfig = in.readOptionalWriteable(TokenPruningConfig::new);
this.weightedTokens = in.readOptionalCollectionAsList(WeightedToken::new);
Expand Down Expand Up @@ -134,7 +134,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
throw new IllegalStateException("supplier must be null, can't serialize suppliers, missing a rewriteAndFetch?");
}
out.writeString(fieldName);
out.writeString(modelText);
out.writeOptionalString(modelText);
out.writeOptionalString(modelId);
out.writeOptionalWriteable(tokenPruningConfig);
out.writeOptionalCollection(weightedTokens, StreamOutput::writeWriteable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected SparseVectorQueryBuilder doCreateTestQueryBuilder() {
TokenPruningConfig tokenPruningConfig = randomBoolean()
? new TokenPruningConfig(randomIntBetween(1, 100), randomFloat(), randomBoolean())
: null;
String modelText = randomAlphaOfLength(4);
String modelId = randomBoolean() ? randomAlphaOfLength(4) : null;
String modelText = modelId != null ? randomAlphaOfLength(4) : null;
List<TextExpansionResults.WeightedToken> weightedTokens = modelId == null ? VECTOR_DIMENSIONS : null;

var builder = new SparseVectorQueryBuilder(RANK_FEATURES_FIELD, modelText, modelId, weightedTokens, tokenPruningConfig);
Expand Down

0 comments on commit f7a6a13

Please sign in to comment.