Skip to content

Commit 85aec97

Browse files
committed
[codegen] Update to latest API spec
1 parent 527063a commit 85aec97

File tree

8 files changed

+524
-26
lines changed

8 files changed

+524
-26
lines changed

java-client/src/main/java/co/elastic/clients/elasticsearch/_types/KnnQuery.java

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import co.elastic.clients.util.ObjectBuilder;
3636
import co.elastic.clients.util.WithJsonObjectBuilderBase;
3737
import jakarta.json.stream.JsonGenerator;
38-
import java.lang.Double;
3938
import java.lang.Float;
4039
import java.lang.Long;
4140
import java.lang.String;
@@ -55,7 +54,10 @@
5554
public class KnnQuery implements JsonpSerializable {
5655
private final String field;
5756

58-
private final List<Double> queryVector;
57+
private final List<Float> queryVector;
58+
59+
@Nullable
60+
private final QueryVectorBuilder queryVectorBuilder;
5961

6062
private final long k;
6163

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

7375
this.field = ApiTypeHelper.requireNonNull(builder.field, this, "field");
74-
this.queryVector = ApiTypeHelper.unmodifiableRequired(builder.queryVector, this, "queryVector");
76+
this.queryVector = ApiTypeHelper.unmodifiable(builder.queryVector);
77+
this.queryVectorBuilder = builder.queryVectorBuilder;
7578
this.k = ApiTypeHelper.requireNonNull(builder.k, this, "k");
7679
this.numCandidates = ApiTypeHelper.requireNonNull(builder.numCandidates, this, "numCandidates");
7780
this.boost = builder.boost;
@@ -93,14 +96,25 @@ public final String field() {
9396
}
9497

9598
/**
96-
* Required - The query vector
99+
* The query vector
97100
* <p>
98101
* API name: {@code query_vector}
99102
*/
100-
public final List<Double> queryVector() {
103+
public final List<Float> queryVector() {
101104
return this.queryVector;
102105
}
103106

107+
/**
108+
* The query vector builder. You must provide a query_vector_builder or
109+
* query_vector, but not both.
110+
* <p>
111+
* API name: {@code query_vector_builder}
112+
*/
113+
@Nullable
114+
public final QueryVectorBuilder queryVectorBuilder() {
115+
return this.queryVectorBuilder;
116+
}
117+
104118
/**
105119
* Required - The final number of nearest neighbors to return as top hits
106120
* <p>
@@ -155,12 +169,17 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
155169
if (ApiTypeHelper.isDefined(this.queryVector)) {
156170
generator.writeKey("query_vector");
157171
generator.writeStartArray();
158-
for (Double item0 : this.queryVector) {
172+
for (Float item0 : this.queryVector) {
159173
generator.write(item0);
160174

161175
}
162176
generator.writeEnd();
163177

178+
}
179+
if (this.queryVectorBuilder != null) {
180+
generator.writeKey("query_vector_builder");
181+
this.queryVectorBuilder.serialize(generator, mapper);
182+
164183
}
165184
generator.writeKey("k");
166185
generator.write(this.k);
@@ -200,7 +219,11 @@ public String toString() {
200219
public static class Builder extends WithJsonObjectBuilderBase<Builder> implements ObjectBuilder<KnnQuery> {
201220
private String field;
202221

203-
private List<Double> queryVector;
222+
@Nullable
223+
private List<Float> queryVector;
224+
225+
@Nullable
226+
private QueryVectorBuilder queryVectorBuilder;
204227

205228
private Long k;
206229

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

225248
/**
226-
* Required - The query vector
249+
* The query vector
227250
* <p>
228251
* API name: {@code query_vector}
229252
* <p>
230253
* Adds all elements of <code>list</code> to <code>queryVector</code>.
231254
*/
232-
public final Builder queryVector(List<Double> list) {
255+
public final Builder queryVector(List<Float> list) {
233256
this.queryVector = _listAddAll(this.queryVector, list);
234257
return this;
235258
}
236259

237260
/**
238-
* Required - The query vector
261+
* The query vector
239262
* <p>
240263
* API name: {@code query_vector}
241264
* <p>
242265
* Adds one or more values to <code>queryVector</code>.
243266
*/
244-
public final Builder queryVector(Double value, Double... values) {
267+
public final Builder queryVector(Float value, Float... values) {
245268
this.queryVector = _listAdd(this.queryVector, value, values);
246269
return this;
247270
}
248271

272+
/**
273+
* The query vector builder. You must provide a query_vector_builder or
274+
* query_vector, but not both.
275+
* <p>
276+
* API name: {@code query_vector_builder}
277+
*/
278+
public final Builder queryVectorBuilder(@Nullable QueryVectorBuilder value) {
279+
this.queryVectorBuilder = value;
280+
return this;
281+
}
282+
283+
/**
284+
* The query vector builder. You must provide a query_vector_builder or
285+
* query_vector, but not both.
286+
* <p>
287+
* API name: {@code query_vector_builder}
288+
*/
289+
public final Builder queryVectorBuilder(
290+
Function<QueryVectorBuilder.Builder, ObjectBuilder<QueryVectorBuilder>> fn) {
291+
return this.queryVectorBuilder(fn.apply(new QueryVectorBuilder.Builder()).build());
292+
}
293+
249294
/**
250295
* Required - The final number of nearest neighbors to return as top hits
251296
* <p>
@@ -340,8 +385,9 @@ public KnnQuery build() {
340385
protected static void setupKnnQueryDeserializer(ObjectDeserializer<KnnQuery.Builder> op) {
341386

342387
op.add(Builder::field, JsonpDeserializer.stringDeserializer(), "field");
343-
op.add(Builder::queryVector, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.doubleDeserializer()),
388+
op.add(Builder::queryVector, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.floatDeserializer()),
344389
"query_vector");
390+
op.add(Builder::queryVectorBuilder, QueryVectorBuilder._DESERIALIZER, "query_vector_builder");
345391
op.add(Builder::k, JsonpDeserializer.longDeserializer(), "k");
346392
op.add(Builder::numCandidates, JsonpDeserializer.longDeserializer(), "num_candidates");
347393
op.add(Builder::boost, JsonpDeserializer.floatDeserializer(), "boost");
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
//----------------------------------------------------
21+
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
22+
//----------------------------------------------------
23+
24+
package co.elastic.clients.elasticsearch._types;
25+
26+
import co.elastic.clients.json.JsonEnum;
27+
import co.elastic.clients.json.JsonpDeserializable;
28+
import co.elastic.clients.json.JsonpDeserializer;
29+
import co.elastic.clients.json.JsonpMapper;
30+
import co.elastic.clients.json.JsonpSerializable;
31+
import co.elastic.clients.json.JsonpUtils;
32+
import co.elastic.clients.json.ObjectBuilderDeserializer;
33+
import co.elastic.clients.json.ObjectDeserializer;
34+
import co.elastic.clients.util.ApiTypeHelper;
35+
import co.elastic.clients.util.ObjectBuilder;
36+
import co.elastic.clients.util.TaggedUnion;
37+
import co.elastic.clients.util.TaggedUnionUtils;
38+
import co.elastic.clients.util.WithJsonObjectBuilderBase;
39+
import jakarta.json.stream.JsonGenerator;
40+
import java.lang.Object;
41+
import java.util.Objects;
42+
import java.util.function.Function;
43+
import javax.annotation.Nullable;
44+
45+
// typedef: _types.QueryVectorBuilder
46+
47+
/**
48+
*
49+
* @see <a href="../doc-files/api-spec.html#_types.QueryVectorBuilder">API
50+
* specification</a>
51+
*/
52+
@JsonpDeserializable
53+
public class QueryVectorBuilder implements TaggedUnion<QueryVectorBuilder.Kind, Object>, JsonpSerializable {
54+
55+
/**
56+
* {@link QueryVectorBuilder} variant kinds.
57+
*
58+
* @see <a href="../doc-files/api-spec.html#_types.QueryVectorBuilder">API
59+
* specification</a>
60+
*/
61+
62+
public enum Kind implements JsonEnum {
63+
TextEmbedding("text_embedding"),
64+
65+
;
66+
67+
private final String jsonValue;
68+
69+
Kind(String jsonValue) {
70+
this.jsonValue = jsonValue;
71+
}
72+
73+
public String jsonValue() {
74+
return this.jsonValue;
75+
}
76+
77+
}
78+
79+
private final Kind _kind;
80+
private final Object _value;
81+
82+
@Override
83+
public final Kind _kind() {
84+
return _kind;
85+
}
86+
87+
@Override
88+
public final Object _get() {
89+
return _value;
90+
}
91+
92+
public QueryVectorBuilder(QueryVectorBuilderVariant value) {
93+
94+
this._kind = ApiTypeHelper.requireNonNull(value._queryVectorBuilderKind(), this, "<variant kind>");
95+
this._value = ApiTypeHelper.requireNonNull(value, this, "<variant value>");
96+
97+
}
98+
99+
private QueryVectorBuilder(Builder builder) {
100+
101+
this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "<variant kind>");
102+
this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "<variant value>");
103+
104+
}
105+
106+
public static QueryVectorBuilder of(Function<Builder, ObjectBuilder<QueryVectorBuilder>> fn) {
107+
return fn.apply(new Builder()).build();
108+
}
109+
110+
/**
111+
* Is this variant instance of kind {@code text_embedding}?
112+
*/
113+
public boolean isTextEmbedding() {
114+
return _kind == Kind.TextEmbedding;
115+
}
116+
117+
/**
118+
* Get the {@code text_embedding} variant value.
119+
*
120+
* @throws IllegalStateException
121+
* if the current variant is not of the {@code text_embedding} kind.
122+
*/
123+
public TextEmbedding textEmbedding() {
124+
return TaggedUnionUtils.get(this, Kind.TextEmbedding);
125+
}
126+
127+
@Override
128+
@SuppressWarnings("unchecked")
129+
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
130+
131+
generator.writeStartObject();
132+
133+
generator.writeKey(_kind.jsonValue());
134+
if (_value instanceof JsonpSerializable) {
135+
((JsonpSerializable) _value).serialize(generator, mapper);
136+
}
137+
138+
generator.writeEnd();
139+
140+
}
141+
142+
@Override
143+
public String toString() {
144+
return JsonpUtils.toString(this);
145+
}
146+
147+
public static class Builder extends WithJsonObjectBuilderBase<Builder>
148+
implements
149+
ObjectBuilder<QueryVectorBuilder> {
150+
private Kind _kind;
151+
private Object _value;
152+
153+
@Override
154+
protected Builder self() {
155+
return this;
156+
}
157+
public ObjectBuilder<QueryVectorBuilder> textEmbedding(TextEmbedding v) {
158+
this._kind = Kind.TextEmbedding;
159+
this._value = v;
160+
return this;
161+
}
162+
163+
public ObjectBuilder<QueryVectorBuilder> textEmbedding(
164+
Function<TextEmbedding.Builder, ObjectBuilder<TextEmbedding>> fn) {
165+
return this.textEmbedding(fn.apply(new TextEmbedding.Builder()).build());
166+
}
167+
168+
public QueryVectorBuilder build() {
169+
_checkSingleUse();
170+
return new QueryVectorBuilder(this);
171+
}
172+
173+
}
174+
175+
protected static void setupQueryVectorBuilderDeserializer(ObjectDeserializer<Builder> op) {
176+
177+
op.add(Builder::textEmbedding, TextEmbedding._DESERIALIZER, "text_embedding");
178+
179+
}
180+
181+
public static final JsonpDeserializer<QueryVectorBuilder> _DESERIALIZER = ObjectBuilderDeserializer
182+
.lazy(Builder::new, QueryVectorBuilder::setupQueryVectorBuilderDeserializer, Builder::build);
183+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
//----------------------------------------------------
21+
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
22+
//----------------------------------------------------
23+
24+
package co.elastic.clients.elasticsearch._types;
25+
26+
import co.elastic.clients.util.ObjectBuilder;
27+
import java.util.function.Function;
28+
29+
/**
30+
* Builders for {@link QueryVectorBuilder} variants.
31+
*/
32+
public class QueryVectorBuilderBuilders {
33+
private QueryVectorBuilderBuilders() {
34+
}
35+
36+
/**
37+
* Creates a builder for the {@link TextEmbedding text_embedding}
38+
* {@code QueryVectorBuilder} variant.
39+
*/
40+
public static TextEmbedding.Builder textEmbedding() {
41+
return new TextEmbedding.Builder();
42+
}
43+
44+
/**
45+
* Creates a QueryVectorBuilder of the {@link TextEmbedding text_embedding}
46+
* {@code QueryVectorBuilder} variant.
47+
*/
48+
public static QueryVectorBuilder textEmbedding(Function<TextEmbedding.Builder, ObjectBuilder<TextEmbedding>> fn) {
49+
QueryVectorBuilder.Builder builder = new QueryVectorBuilder.Builder();
50+
builder.textEmbedding(fn.apply(new TextEmbedding.Builder()).build());
51+
return builder.build();
52+
}
53+
54+
}

0 commit comments

Comments
 (0)