|
| 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 | +package co.elastic.clients.elasticsearch._types; |
| 21 | + |
| 22 | +import co.elastic.clients.json.JsonpDeserializable; |
| 23 | +import co.elastic.clients.json.JsonpDeserializer; |
| 24 | +import co.elastic.clients.json.JsonpMapper; |
| 25 | +import co.elastic.clients.json.JsonpSerializable; |
| 26 | +import co.elastic.clients.json.JsonpUtils; |
| 27 | +import co.elastic.clients.json.ObjectBuilderDeserializer; |
| 28 | +import co.elastic.clients.json.ObjectDeserializer; |
| 29 | +import co.elastic.clients.util.ApiTypeHelper; |
| 30 | +import co.elastic.clients.util.ObjectBuilder; |
| 31 | +import co.elastic.clients.util.WithJsonObjectBuilderBase; |
| 32 | +import jakarta.json.stream.JsonGenerator; |
| 33 | +import java.lang.String; |
| 34 | +import java.util.Objects; |
| 35 | +import java.util.function.Function; |
| 36 | +import javax.annotation.Nullable; |
| 37 | + |
| 38 | +//---------------------------------------------------------------- |
| 39 | +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. |
| 40 | +//---------------------------------------------------------------- |
| 41 | +// |
| 42 | +// This code is generated from the Elasticsearch API specification |
| 43 | +// at https://github.com/elastic/elasticsearch-specification |
| 44 | +// |
| 45 | +// Manual updates to this file will be lost when the code is |
| 46 | +// re-generated. |
| 47 | +// |
| 48 | +// If you find a property that is missing or wrongly typed, please |
| 49 | +// open an issue or a PR on the API specification repository. |
| 50 | +// |
| 51 | +//---------------------------------------------------------------- |
| 52 | + |
| 53 | +// typedef: _types.Embedding |
| 54 | + |
| 55 | +/** |
| 56 | + * |
| 57 | + * @see <a href="../doc-files/api-spec.html#_types.Embedding">API |
| 58 | + * specification</a> |
| 59 | + */ |
| 60 | +@JsonpDeserializable |
| 61 | +public class Embedding implements QueryVectorBuilderVariant, JsonpSerializable { |
| 62 | + @Nullable |
| 63 | + private final String inferenceId; |
| 64 | + |
| 65 | + private final KnnEmbeddingInput input; |
| 66 | + |
| 67 | + @Nullable |
| 68 | + private final Time timeout; |
| 69 | + |
| 70 | + // --------------------------------------------------------------------------------------------- |
| 71 | + |
| 72 | + private Embedding(Builder builder) { |
| 73 | + |
| 74 | + this.inferenceId = builder.inferenceId; |
| 75 | + this.input = ApiTypeHelper.requireNonNull(builder.input, this, "input"); |
| 76 | + this.timeout = builder.timeout; |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + public static Embedding of(Function<Builder, ObjectBuilder<Embedding>> fn) { |
| 81 | + return fn.apply(new Builder()).build(); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * QueryVectorBuilder variant kind. |
| 86 | + */ |
| 87 | + @Override |
| 88 | + public QueryVectorBuilder.Kind _queryVectorBuilderKind() { |
| 89 | + return QueryVectorBuilder.Kind.Embedding; |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * API name: {@code inference_id} |
| 94 | + */ |
| 95 | + @Nullable |
| 96 | + public final String inferenceId() { |
| 97 | + return this.inferenceId; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Required - API name: {@code input} |
| 102 | + */ |
| 103 | + public final KnnEmbeddingInput input() { |
| 104 | + return this.input; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * API name: {@code timeout} |
| 109 | + */ |
| 110 | + @Nullable |
| 111 | + public final Time timeout() { |
| 112 | + return this.timeout; |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Serialize this object to JSON. |
| 117 | + */ |
| 118 | + public void serialize(JsonGenerator generator, JsonpMapper mapper) { |
| 119 | + generator.writeStartObject(); |
| 120 | + serializeInternal(generator, mapper); |
| 121 | + generator.writeEnd(); |
| 122 | + } |
| 123 | + |
| 124 | + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { |
| 125 | + |
| 126 | + if (this.inferenceId != null) { |
| 127 | + generator.writeKey("inference_id"); |
| 128 | + generator.write(this.inferenceId); |
| 129 | + |
| 130 | + } |
| 131 | + generator.writeKey("input"); |
| 132 | + this.input.serialize(generator, mapper); |
| 133 | + |
| 134 | + if (this.timeout != null) { |
| 135 | + generator.writeKey("timeout"); |
| 136 | + this.timeout.serialize(generator, mapper); |
| 137 | + |
| 138 | + } |
| 139 | + |
| 140 | + } |
| 141 | + |
| 142 | + @Override |
| 143 | + public String toString() { |
| 144 | + return JsonpUtils.toString(this); |
| 145 | + } |
| 146 | + |
| 147 | + // --------------------------------------------------------------------------------------------- |
| 148 | + |
| 149 | + /** |
| 150 | + * Builder for {@link Embedding}. |
| 151 | + */ |
| 152 | + |
| 153 | + public static class Builder extends WithJsonObjectBuilderBase<Builder> implements ObjectBuilder<Embedding> { |
| 154 | + @Nullable |
| 155 | + private String inferenceId; |
| 156 | + |
| 157 | + private KnnEmbeddingInput input; |
| 158 | + |
| 159 | + @Nullable |
| 160 | + private Time timeout; |
| 161 | + |
| 162 | + public Builder() { |
| 163 | + } |
| 164 | + private Builder(Embedding instance) { |
| 165 | + this.inferenceId = instance.inferenceId; |
| 166 | + this.input = instance.input; |
| 167 | + this.timeout = instance.timeout; |
| 168 | + |
| 169 | + } |
| 170 | + /** |
| 171 | + * API name: {@code inference_id} |
| 172 | + */ |
| 173 | + public final Builder inferenceId(@Nullable String value) { |
| 174 | + this.inferenceId = value; |
| 175 | + return this; |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * Required - API name: {@code input} |
| 180 | + */ |
| 181 | + public final Builder input(KnnEmbeddingInput value) { |
| 182 | + this.input = value; |
| 183 | + return this; |
| 184 | + } |
| 185 | + |
| 186 | + /** |
| 187 | + * Required - API name: {@code input} |
| 188 | + */ |
| 189 | + public final Builder input(Function<KnnEmbeddingInput.Builder, ObjectBuilder<KnnEmbeddingInput>> fn) { |
| 190 | + return this.input(fn.apply(new KnnEmbeddingInput.Builder()).build()); |
| 191 | + } |
| 192 | + |
| 193 | + /** |
| 194 | + * API name: {@code timeout} |
| 195 | + */ |
| 196 | + public final Builder timeout(@Nullable Time value) { |
| 197 | + this.timeout = value; |
| 198 | + return this; |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * API name: {@code timeout} |
| 203 | + */ |
| 204 | + public final Builder timeout(Function<Time.Builder, ObjectBuilder<Time>> fn) { |
| 205 | + return this.timeout(fn.apply(new Time.Builder()).build()); |
| 206 | + } |
| 207 | + |
| 208 | + @Override |
| 209 | + protected Builder self() { |
| 210 | + return this; |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * Builds a {@link Embedding}. |
| 215 | + * |
| 216 | + * @throws NullPointerException |
| 217 | + * if some of the required fields are null. |
| 218 | + */ |
| 219 | + public Embedding build() { |
| 220 | + _checkSingleUse(); |
| 221 | + |
| 222 | + return new Embedding(this); |
| 223 | + } |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * @return New {@link Builder} initialized with field values of this instance |
| 228 | + */ |
| 229 | + public Builder rebuild() { |
| 230 | + return new Builder(this); |
| 231 | + } |
| 232 | + // --------------------------------------------------------------------------------------------- |
| 233 | + |
| 234 | + /** |
| 235 | + * Json deserializer for {@link Embedding} |
| 236 | + */ |
| 237 | + public static final JsonpDeserializer<Embedding> _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new, |
| 238 | + Embedding::setupEmbeddingDeserializer); |
| 239 | + |
| 240 | + protected static void setupEmbeddingDeserializer(ObjectDeserializer<Embedding.Builder> op) { |
| 241 | + |
| 242 | + op.add(Builder::inferenceId, JsonpDeserializer.stringDeserializer(), "inference_id"); |
| 243 | + op.add(Builder::input, KnnEmbeddingInput._DESERIALIZER, "input"); |
| 244 | + op.add(Builder::timeout, Time._DESERIALIZER, "timeout"); |
| 245 | + |
| 246 | + } |
| 247 | + |
| 248 | +} |
0 commit comments