Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@
public class InnerRetriever implements JsonpSerializable {
private final Retriever retriever;

private final float weight;
@Nullable
private final Float weight;

@Nullable
private final ScoreNormalizer normalizer;

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

private InnerRetriever(Builder builder) {

this.retriever = ApiTypeHelper.requireNonNull(builder.retriever, this, "retriever");
this.weight = ApiTypeHelper.requireNonNull(builder.weight, this, "weight", 0);
this.normalizer = ApiTypeHelper.requireNonNull(builder.normalizer, this, "normalizer");
this.weight = builder.weight;
this.normalizer = builder.normalizer;

}

Expand All @@ -80,22 +82,33 @@ public static InnerRetriever of(Function<Builder, ObjectBuilder<InnerRetriever>>
}

/**
* Required - API name: {@code retriever}
* Required - The nested retriever configuration.
* <p>
* API name: {@code retriever}
*/
public final Retriever retriever() {
return this.retriever;
}

/**
* Required - API name: {@code weight}
* Weight multiplier for this retriever's contribution to the linear
* combination. Must be non-negative.
* <p>
* API name: {@code weight}
*/
public final float weight() {
@Nullable
public final Float weight() {
return this.weight;
}

/**
* Required - API name: {@code normalizer}
* Score normalizer to apply to this retriever's results before weighting. Falls
* back to the top-level <code>normalizer</code> on the linear retriever if
* unset, then to <code>none</code> (identity) if neither is set.
* <p>
* API name: {@code normalizer}
*/
@Nullable
public final ScoreNormalizer normalizer() {
return this.normalizer;
}
Expand All @@ -114,11 +127,15 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("retriever");
this.retriever.serialize(generator, mapper);

generator.writeKey("weight");
generator.write(this.weight);
if (this.weight != null) {
generator.writeKey("weight");
generator.write(this.weight);

generator.writeKey("normalizer");
this.normalizer.serialize(generator, mapper);
}
if (this.normalizer != null) {
generator.writeKey("normalizer");
this.normalizer.serialize(generator, mapper);
}

}

Expand All @@ -136,8 +153,10 @@ public String toString() {
public static class Builder extends WithJsonObjectBuilderBase<Builder> implements ObjectBuilder<InnerRetriever> {
private Retriever retriever;

@Nullable
private Float weight;

@Nullable
private ScoreNormalizer normalizer;

public Builder() {
Expand All @@ -149,40 +168,53 @@ private Builder(InnerRetriever instance) {

}
/**
* Required - API name: {@code retriever}
* Required - The nested retriever configuration.
* <p>
* API name: {@code retriever}
*/
public final Builder retriever(Retriever value) {
this.retriever = value;
return this;
}

/**
* Required - API name: {@code retriever}
* Required - The nested retriever configuration.
* <p>
* API name: {@code retriever}
*/
public final Builder retriever(Function<Retriever.Builder, ObjectBuilder<Retriever>> fn) {
return this.retriever(fn.apply(new Retriever.Builder()).build());
}

/**
* Required - API name: {@code retriever}
* Required - The nested retriever configuration.
* <p>
* API name: {@code retriever}
*/
public final Builder retriever(RetrieverVariant value) {
this.retriever = value._toRetriever();
return this;
}

/**
* Required - API name: {@code weight}
* Weight multiplier for this retriever's contribution to the linear
* combination. Must be non-negative.
* <p>
* API name: {@code weight}
*/
public final Builder weight(float value) {
public final Builder weight(@Nullable Float value) {
this.weight = value;
return this;
}

/**
* Required - API name: {@code normalizer}
* Score normalizer to apply to this retriever's results before weighting. Falls
* back to the top-level <code>normalizer</code> on the linear retriever if
* unset, then to <code>none</code> (identity) if neither is set.
* <p>
* API name: {@code normalizer}
*/
public final Builder normalizer(ScoreNormalizer value) {
public final Builder normalizer(@Nullable ScoreNormalizer value) {
this.normalizer = value;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public class KnnRetriever extends RetrieverBase implements RetrieverVariant {

private final int k;

private final int numCandidates;
@Nullable
private final Integer numCandidates;

@Nullable
private final Float visitPercentage;
Expand All @@ -88,7 +89,7 @@ private KnnRetriever(Builder builder) {
this.queryVector = ApiTypeHelper.unmodifiable(builder.queryVector);
this.queryVectorBuilder = builder.queryVectorBuilder;
this.k = ApiTypeHelper.requireNonNull(builder.k, this, "k", 0);
this.numCandidates = ApiTypeHelper.requireNonNull(builder.numCandidates, this, "numCandidates", 0);
this.numCandidates = builder.numCandidates;
this.visitPercentage = builder.visitPercentage;
this.similarity = builder.similarity;
this.rescoreVector = builder.rescoreVector;
Expand Down Expand Up @@ -147,11 +148,12 @@ public final int k() {
}

/**
* Required - Number of nearest neighbor candidates to consider per shard.
* Number of nearest neighbor candidates to consider per shard.
* <p>
* API name: {@code num_candidates}
*/
public final int numCandidates() {
@Nullable
public final Integer numCandidates() {
return this.numCandidates;
}

Expand Down Expand Up @@ -210,9 +212,11 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
generator.writeKey("k");
generator.write(this.k);

generator.writeKey("num_candidates");
generator.write(this.numCandidates);
if (this.numCandidates != null) {
generator.writeKey("num_candidates");
generator.write(this.numCandidates);

}
if (this.visitPercentage != null) {
generator.writeKey("visit_percentage");
generator.write(this.visitPercentage);
Expand Down Expand Up @@ -248,6 +252,7 @@ public static class Builder extends RetrieverBase.AbstractBuilder<Builder> imple

private Integer k;

@Nullable
private Integer numCandidates;

@Nullable
Expand Down Expand Up @@ -351,11 +356,11 @@ public final Builder k(int value) {
}

/**
* Required - Number of nearest neighbor candidates to consider per shard.
* Number of nearest neighbor candidates to consider per shard.
* <p>
* API name: {@code num_candidates}
*/
public final Builder numCandidates(int value) {
public final Builder numCandidates(@Nullable Integer value) {
this.numCandidates = value;
return this;
}
Expand Down
Loading
Loading