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 14, 2024
1 parent 062eb17 commit 7001d64
Show file tree
Hide file tree
Showing 67 changed files with 5,162 additions and 691 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,10 @@ public enum Kind implements JsonEnum {

Rrf("rrf"),

TextSimilarityReranker("text_similarity_reranker"),

Rule("rule"),

;

private final String jsonValue;
Expand Down Expand Up @@ -173,6 +177,41 @@ 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);
}

/**
* Is this variant instance of kind {@code rule}?
*/
public boolean isRule() {
return _kind == Kind.Rule;
}

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

@Override
@SuppressWarnings("unchecked")
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
Expand Down Expand Up @@ -232,6 +271,27 @@ 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 ObjectBuilder<Retriever> rule(RuleRetriever v) {
this._kind = Kind.Rule;
this._value = v;
return this;
}

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

public Retriever build() {
_checkSingleUse();
return new Retriever(this);
Expand All @@ -244,6 +304,8 @@ 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");
op.add(Builder::rule, RuleRetriever._DESERIALIZER, "rule");

}

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,41 @@ 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();
}

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

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

}
Loading

0 comments on commit 7001d64

Please sign in to comment.