Skip to content

Commit

Permalink
[codegen] Update to latest API spec
Browse files Browse the repository at this point in the history
  • Loading branch information
swallez committed Mar 9, 2023
1 parent 527063a commit 85aec97
Show file tree
Hide file tree
Showing 8 changed files with 524 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import co.elastic.clients.util.ObjectBuilder;
import co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.lang.Double;
import java.lang.Float;
import java.lang.Long;
import java.lang.String;
Expand All @@ -55,7 +54,10 @@
public class KnnQuery implements JsonpSerializable {
private final String field;

private final List<Double> queryVector;
private final List<Float> queryVector;

@Nullable
private final QueryVectorBuilder queryVectorBuilder;

private final long k;

Expand All @@ -71,7 +73,8 @@ public class KnnQuery implements JsonpSerializable {
private KnnQuery(Builder builder) {

this.field = ApiTypeHelper.requireNonNull(builder.field, this, "field");
this.queryVector = ApiTypeHelper.unmodifiableRequired(builder.queryVector, this, "queryVector");
this.queryVector = ApiTypeHelper.unmodifiable(builder.queryVector);
this.queryVectorBuilder = builder.queryVectorBuilder;
this.k = ApiTypeHelper.requireNonNull(builder.k, this, "k");
this.numCandidates = ApiTypeHelper.requireNonNull(builder.numCandidates, this, "numCandidates");
this.boost = builder.boost;
Expand All @@ -93,14 +96,25 @@ public final String field() {
}

/**
* Required - The query vector
* The query vector
* <p>
* API name: {@code query_vector}
*/
public final List<Double> queryVector() {
public final List<Float> queryVector() {
return this.queryVector;
}

/**
* The query vector builder. You must provide a query_vector_builder or
* query_vector, but not both.
* <p>
* API name: {@code query_vector_builder}
*/
@Nullable
public final QueryVectorBuilder queryVectorBuilder() {
return this.queryVectorBuilder;
}

/**
* Required - The final number of nearest neighbors to return as top hits
* <p>
Expand Down Expand Up @@ -155,12 +169,17 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
if (ApiTypeHelper.isDefined(this.queryVector)) {
generator.writeKey("query_vector");
generator.writeStartArray();
for (Double item0 : this.queryVector) {
for (Float item0 : this.queryVector) {
generator.write(item0);

}
generator.writeEnd();

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

}
generator.writeKey("k");
generator.write(this.k);
Expand Down Expand Up @@ -200,7 +219,11 @@ public String toString() {
public static class Builder extends WithJsonObjectBuilderBase<Builder> implements ObjectBuilder<KnnQuery> {
private String field;

private List<Double> queryVector;
@Nullable
private List<Float> queryVector;

@Nullable
private QueryVectorBuilder queryVectorBuilder;

private Long k;

Expand All @@ -223,29 +246,51 @@ public final Builder field(String value) {
}

/**
* Required - The query vector
* The query vector
* <p>
* API name: {@code query_vector}
* <p>
* Adds all elements of <code>list</code> to <code>queryVector</code>.
*/
public final Builder queryVector(List<Double> list) {
public final Builder queryVector(List<Float> list) {
this.queryVector = _listAddAll(this.queryVector, list);
return this;
}

/**
* Required - The query vector
* The query vector
* <p>
* API name: {@code query_vector}
* <p>
* Adds one or more values to <code>queryVector</code>.
*/
public final Builder queryVector(Double value, Double... values) {
public final Builder queryVector(Float value, Float... values) {
this.queryVector = _listAdd(this.queryVector, value, values);
return this;
}

/**
* The query vector builder. You must provide a query_vector_builder or
* query_vector, but not both.
* <p>
* API name: {@code query_vector_builder}
*/
public final Builder queryVectorBuilder(@Nullable QueryVectorBuilder value) {
this.queryVectorBuilder = value;
return this;
}

/**
* The query vector builder. You must provide a query_vector_builder or
* query_vector, but not both.
* <p>
* API name: {@code query_vector_builder}
*/
public final Builder queryVectorBuilder(
Function<QueryVectorBuilder.Builder, ObjectBuilder<QueryVectorBuilder>> fn) {
return this.queryVectorBuilder(fn.apply(new QueryVectorBuilder.Builder()).build());
}

/**
* Required - The final number of nearest neighbors to return as top hits
* <p>
Expand Down Expand Up @@ -340,8 +385,9 @@ public KnnQuery build() {
protected static void setupKnnQueryDeserializer(ObjectDeserializer<KnnQuery.Builder> op) {

op.add(Builder::field, JsonpDeserializer.stringDeserializer(), "field");
op.add(Builder::queryVector, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.doubleDeserializer()),
op.add(Builder::queryVector, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.floatDeserializer()),
"query_vector");
op.add(Builder::queryVectorBuilder, QueryVectorBuilder._DESERIALIZER, "query_vector_builder");
op.add(Builder::k, JsonpDeserializer.longDeserializer(), "k");
op.add(Builder::numCandidates, JsonpDeserializer.longDeserializer(), "num_candidates");
op.add(Builder::boost, JsonpDeserializer.floatDeserializer(), "boost");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package co.elastic.clients.elasticsearch._types;

import co.elastic.clients.json.JsonEnum;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.JsonpSerializable;
import co.elastic.clients.json.JsonpUtils;
import co.elastic.clients.json.ObjectBuilderDeserializer;
import co.elastic.clients.json.ObjectDeserializer;
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import co.elastic.clients.util.TaggedUnion;
import co.elastic.clients.util.TaggedUnionUtils;
import co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.lang.Object;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;

// typedef: _types.QueryVectorBuilder

/**
*
* @see <a href="../doc-files/api-spec.html#_types.QueryVectorBuilder">API
* specification</a>
*/
@JsonpDeserializable
public class QueryVectorBuilder implements TaggedUnion<QueryVectorBuilder.Kind, Object>, JsonpSerializable {

/**
* {@link QueryVectorBuilder} variant kinds.
*
* @see <a href="../doc-files/api-spec.html#_types.QueryVectorBuilder">API
* specification</a>
*/

public enum Kind implements JsonEnum {
TextEmbedding("text_embedding"),

;

private final String jsonValue;

Kind(String jsonValue) {
this.jsonValue = jsonValue;
}

public String jsonValue() {
return this.jsonValue;
}

}

private final Kind _kind;
private final Object _value;

@Override
public final Kind _kind() {
return _kind;
}

@Override
public final Object _get() {
return _value;
}

public QueryVectorBuilder(QueryVectorBuilderVariant value) {

this._kind = ApiTypeHelper.requireNonNull(value._queryVectorBuilderKind(), this, "<variant kind>");
this._value = ApiTypeHelper.requireNonNull(value, this, "<variant value>");

}

private QueryVectorBuilder(Builder builder) {

this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>");
this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>");

}

public static QueryVectorBuilder of(Function<Builder, ObjectBuilder<QueryVectorBuilder>> fn) {
return fn.apply(new Builder()).build();
}

/**
* Is this variant instance of kind {@code text_embedding}?
*/
public boolean isTextEmbedding() {
return _kind == Kind.TextEmbedding;
}

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

@Override
@SuppressWarnings("unchecked")
public void serialize(JsonGenerator generator, JsonpMapper mapper) {

generator.writeStartObject();

generator.writeKey(_kind.jsonValue());
if (_value instanceof JsonpSerializable) {
((JsonpSerializable) _value).serialize(generator, mapper);
}

generator.writeEnd();

}

@Override
public String toString() {
return JsonpUtils.toString(this);
}

public static class Builder extends WithJsonObjectBuilderBase<Builder>
implements
ObjectBuilder<QueryVectorBuilder> {
private Kind _kind;
private Object _value;

@Override
protected Builder self() {
return this;
}
public ObjectBuilder<QueryVectorBuilder> textEmbedding(TextEmbedding v) {
this._kind = Kind.TextEmbedding;
this._value = v;
return this;
}

public ObjectBuilder<QueryVectorBuilder> textEmbedding(
Function<TextEmbedding.Builder, ObjectBuilder<TextEmbedding>> fn) {
return this.textEmbedding(fn.apply(new TextEmbedding.Builder()).build());
}

public QueryVectorBuilder build() {
_checkSingleUse();
return new QueryVectorBuilder(this);
}

}

protected static void setupQueryVectorBuilderDeserializer(ObjectDeserializer<Builder> op) {

op.add(Builder::textEmbedding, TextEmbedding._DESERIALIZER, "text_embedding");

}

public static final JsonpDeserializer<QueryVectorBuilder> _DESERIALIZER = ObjectBuilderDeserializer
.lazy(Builder::new, QueryVectorBuilder::setupQueryVectorBuilderDeserializer, Builder::build);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package co.elastic.clients.elasticsearch._types;

import co.elastic.clients.util.ObjectBuilder;
import java.util.function.Function;

/**
* Builders for {@link QueryVectorBuilder} variants.
*/
public class QueryVectorBuilderBuilders {
private QueryVectorBuilderBuilders() {
}

/**
* Creates a builder for the {@link TextEmbedding text_embedding}
* {@code QueryVectorBuilder} variant.
*/
public static TextEmbedding.Builder textEmbedding() {
return new TextEmbedding.Builder();
}

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

}
Loading

0 comments on commit 85aec97

Please sign in to comment.