Skip to content

Commit

Permalink
[codegen] update to latest spec
Browse files Browse the repository at this point in the history
  • Loading branch information
l-trotta committed Nov 19, 2024
1 parent da2d0d2 commit 0a255f1
Show file tree
Hide file tree
Showing 111 changed files with 5,957 additions and 1,494 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public enum Kind implements JsonEnum {

Rrf("rrf"),

TextSimilarityReranker("text_similarity_reranker"),

;

private final String jsonValue;
Expand Down Expand Up @@ -173,6 +175,24 @@ public RRFRetriever rrf() {
return TaggedUnionUtils.get(this, Kind.Rrf);
}

/**
* Is this variant instance of kind {@code text_similarity_reranker}?
*/
public boolean isTextSimilarityReranker() {
return _kind == Kind.TextSimilarityReranker;
}

/**
* Get the {@code text_similarity_reranker} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the
* {@code text_similarity_reranker} kind.
*/
public TextSimilarityReranker textSimilarityReranker() {
return TaggedUnionUtils.get(this, Kind.TextSimilarityReranker);
}

@Override
@SuppressWarnings("unchecked")
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
Expand Down Expand Up @@ -232,6 +252,17 @@ public ObjectBuilder<Retriever> rrf(Function<RRFRetriever.Builder, ObjectBuilder
return this.rrf(fn.apply(new RRFRetriever.Builder()).build());
}

public ObjectBuilder<Retriever> textSimilarityReranker(TextSimilarityReranker v) {
this._kind = Kind.TextSimilarityReranker;
this._value = v;
return this;
}

public ObjectBuilder<Retriever> textSimilarityReranker(
Function<TextSimilarityReranker.Builder, ObjectBuilder<TextSimilarityReranker>> fn) {
return this.textSimilarityReranker(fn.apply(new TextSimilarityReranker.Builder()).build());
}

public Retriever build() {
_checkSingleUse();
return new Retriever(this);
Expand All @@ -244,6 +275,7 @@ protected static void setupRetrieverDeserializer(ObjectDeserializer<Builder> op)
op.add(Builder::standard, StandardRetriever._DESERIALIZER, "standard");
op.add(Builder::knn, KnnRetriever._DESERIALIZER, "knn");
op.add(Builder::rrf, RRFRetriever._DESERIALIZER, "rrf");
op.add(Builder::textSimilarityReranker, TextSimilarityReranker._DESERIALIZER, "text_similarity_reranker");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import co.elastic.clients.util.ObjectBuilder;
import co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.lang.Float;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
Expand Down Expand Up @@ -62,11 +63,15 @@
public abstract class RetrieverBase implements JsonpSerializable {
private final List<Query> filter;

@Nullable
private final Float minScore;

// ---------------------------------------------------------------------------------------------

protected RetrieverBase(AbstractBuilder<?> builder) {

this.filter = ApiTypeHelper.unmodifiable(builder.filter);
this.minScore = builder.minScore;

}

Expand All @@ -79,6 +84,17 @@ public final List<Query> filter() {
return this.filter;
}

/**
* Minimum _score for matching documents. Documents with a lower _score are not
* included in the top documents.
* <p>
* API name: {@code min_score}
*/
@Nullable
public final Float minScore() {
return this.minScore;
}

/**
* Serialize this object to JSON.
*/
Expand All @@ -100,6 +116,11 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeEnd();

}
if (this.minScore != null) {
generator.writeKey("min_score");
generator.write(this.minScore);

}

}

Expand All @@ -114,6 +135,9 @@ public abstract static class AbstractBuilder<BuilderT extends AbstractBuilder<Bu
@Nullable
private List<Query> filter;

@Nullable
private Float minScore;

/**
* Query to filter the documents that can match.
* <p>
Expand Down Expand Up @@ -149,6 +173,17 @@ public final BuilderT filter(Function<Query.Builder, ObjectBuilder<Query>> fn) {
return filter(fn.apply(new Query.Builder()).build());
}

/**
* Minimum _score for matching documents. Documents with a lower _score are not
* included in the top documents.
* <p>
* API name: {@code min_score}
*/
public final BuilderT minScore(@Nullable Float value) {
this.minScore = value;
return self();
}

protected abstract BuilderT self();

}
Expand All @@ -158,6 +193,7 @@ protected static <BuilderT extends AbstractBuilder<BuilderT>> void setupRetrieve
ObjectDeserializer<BuilderT> op) {

op.add(AbstractBuilder::filter, JsonpDeserializer.arrayDeserializer(Query._DESERIALIZER), "filter");
op.add(AbstractBuilder::minScore, JsonpDeserializer.floatDeserializer(), "min_score");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,23 @@ public static Retriever rrf(Function<RRFRetriever.Builder, ObjectBuilder<RRFRetr
return builder.build();
}

/**
* Creates a builder for the {@link TextSimilarityReranker
* text_similarity_reranker} {@code Retriever} variant.
*/
public static TextSimilarityReranker.Builder textSimilarityReranker() {
return new TextSimilarityReranker.Builder();
}

/**
* Creates a Retriever of the {@link TextSimilarityReranker
* text_similarity_reranker} {@code Retriever} variant.
*/
public static Retriever textSimilarityReranker(
Function<TextSimilarityReranker.Builder, ObjectBuilder<TextSimilarityReranker>> fn) {
Retriever.Builder builder = new Retriever.Builder();
builder.textSimilarityReranker(fn.apply(new TextSimilarityReranker.Builder()).build());
return builder.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import jakarta.json.stream.JsonGenerator;
import java.lang.Float;
import java.lang.Integer;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -71,9 +70,6 @@ public class StandardRetriever extends RetrieverBase implements RetrieverVariant

private final List<SortOptions> sort;

@Nullable
private final Float minScore;

@Nullable
private final FieldCollapse collapse;

Expand All @@ -86,7 +82,6 @@ private StandardRetriever(Builder builder) {
this.searchAfter = ApiTypeHelper.unmodifiable(builder.searchAfter);
this.terminateAfter = builder.terminateAfter;
this.sort = ApiTypeHelper.unmodifiable(builder.sort);
this.minScore = builder.minScore;
this.collapse = builder.collapse;

}
Expand Down Expand Up @@ -141,17 +136,6 @@ public final List<SortOptions> sort() {
return this.sort;
}

/**
* Minimum _score for matching documents. Documents with a lower _score are not
* included in the top documents.
* <p>
* API name: {@code min_score}
*/
@Nullable
public final Float minScore() {
return this.minScore;
}

/**
* Collapses the top documents by a specified key into a single top document per
* key.
Expand Down Expand Up @@ -195,11 +179,6 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
}
generator.writeEnd();

}
if (this.minScore != null) {
generator.writeKey("min_score");
generator.write(this.minScore);

}
if (this.collapse != null) {
generator.writeKey("collapse");
Expand Down Expand Up @@ -230,9 +209,6 @@ public static class Builder extends RetrieverBase.AbstractBuilder<Builder>
@Nullable
private List<SortOptions> sort;

@Nullable
private Float minScore;

@Nullable
private FieldCollapse collapse;

Expand Down Expand Up @@ -403,17 +379,6 @@ public final Builder sort(Function<SortOptions.Builder, ObjectBuilder<SortOption
return sort(fn.apply(new SortOptions.Builder()).build());
}

/**
* Minimum _score for matching documents. Documents with a lower _score are not
* included in the top documents.
* <p>
* API name: {@code min_score}
*/
public final Builder minScore(@Nullable Float value) {
this.minScore = value;
return this;
}

/**
* Collapses the top documents by a specified key into a single top document per
* key.
Expand Down Expand Up @@ -467,7 +432,6 @@ protected static void setupStandardRetrieverDeserializer(ObjectDeserializer<Stan
op.add(Builder::searchAfter, JsonpDeserializer.arrayDeserializer(FieldValue._DESERIALIZER), "search_after");
op.add(Builder::terminateAfter, JsonpDeserializer.integerDeserializer(), "terminate_after");
op.add(Builder::sort, JsonpDeserializer.arrayDeserializer(SortOptions._DESERIALIZER), "sort");
op.add(Builder::minScore, JsonpDeserializer.floatDeserializer(), "min_score");
op.add(Builder::collapse, FieldCollapse._DESERIALIZER, "collapse");

}
Expand Down
Loading

0 comments on commit 0a255f1

Please sign in to comment.