32
32
import jakarta .json .stream .JsonGenerator ;
33
33
import java .lang .Float ;
34
34
import java .lang .Integer ;
35
- import java .lang .String ;
36
35
import java .util .Objects ;
37
36
import java .util .function .Function ;
38
37
import javax .annotation .Nullable ;
62
61
*/
63
62
@ JsonpDeserializable
64
63
public class DenseVectorIndexOptions implements JsonpSerializable {
65
- private final String type ;
66
-
67
64
@ Nullable
68
- private final Integer m ;
65
+ private final Float confidenceInterval ;
69
66
70
67
@ Nullable
71
68
private final Integer efConstruction ;
72
69
73
70
@ Nullable
74
- private final Float confidenceInterval ;
71
+ private final Integer m ;
72
+
73
+ private final DenseVectorIndexOptionsType type ;
75
74
76
75
// ---------------------------------------------------------------------------------------------
77
76
78
77
private DenseVectorIndexOptions (Builder builder ) {
79
78
80
- this .type = ApiTypeHelper .requireNonNull (builder .type , this , "type" );
81
- this .m = builder .m ;
82
- this .efConstruction = builder .efConstruction ;
83
79
this .confidenceInterval = builder .confidenceInterval ;
80
+ this .efConstruction = builder .efConstruction ;
81
+ this .m = builder .m ;
82
+ this .type = ApiTypeHelper .requireNonNull (builder .type , this , "type" );
84
83
85
84
}
86
85
@@ -89,21 +88,37 @@ public static DenseVectorIndexOptions of(Function<Builder, ObjectBuilder<DenseVe
89
88
}
90
89
91
90
/**
92
- * Required - API name: {@code type}
93
- */
94
- public final String type () {
95
- return this .type ;
96
- }
97
-
98
- /**
99
- * API name: {@code m}
91
+ * The confidence interval to use when quantizing the vectors. Can be any value
92
+ * between and including <code>0.90</code> and <code>1.0</code> or exactly
93
+ * <code>0</code>. When the value is <code>0</code>, this indicates that dynamic
94
+ * quantiles should be calculated for optimized quantization. When between
95
+ * <code>0.90</code> and <code>1.0</code>, this value restricts the values used
96
+ * when calculating the quantization thresholds.
97
+ * <p>
98
+ * For example, a value of <code>0.95</code> will only use the middle
99
+ * <code>95%</code> of the values when calculating the quantization thresholds
100
+ * (e.g. the highest and lowest <code>2.5%</code> of values will be ignored).
101
+ * <p>
102
+ * Defaults to <code>1/(dims + 1)</code> for <code>int8</code> quantized vectors
103
+ * and <code>0</code> for <code>int4</code> for dynamic quantile calculation.
104
+ * <p>
105
+ * Only applicable to <code>int8_hnsw</code>, <code>int4_hnsw</code>,
106
+ * <code>int8_flat</code>, and <code>int4_flat</code> index types.
107
+ * <p>
108
+ * API name: {@code confidence_interval}
100
109
*/
101
110
@ Nullable
102
- public final Integer m () {
103
- return this .m ;
111
+ public final Float confidenceInterval () {
112
+ return this .confidenceInterval ;
104
113
}
105
114
106
115
/**
116
+ * The number of candidates to track while assembling the list of nearest
117
+ * neighbors for each new node.
118
+ * <p>
119
+ * Only applicable to <code>hnsw</code>, <code>int8_hnsw</code>, and
120
+ * <code>int4_hnsw</code> index types.
121
+ * <p>
107
122
* API name: {@code ef_construction}
108
123
*/
109
124
@ Nullable
@@ -112,11 +127,25 @@ public final Integer efConstruction() {
112
127
}
113
128
114
129
/**
115
- * API name: {@code confidence_interval}
130
+ * The number of neighbors each node will be connected to in the HNSW graph.
131
+ * <p>
132
+ * Only applicable to <code>hnsw</code>, <code>int8_hnsw</code>, and
133
+ * <code>int4_hnsw</code> index types.
134
+ * <p>
135
+ * API name: {@code m}
116
136
*/
117
137
@ Nullable
118
- public final Float confidenceInterval () {
119
- return this .confidenceInterval ;
138
+ public final Integer m () {
139
+ return this .m ;
140
+ }
141
+
142
+ /**
143
+ * Required - The type of kNN algorithm to use.
144
+ * <p>
145
+ * API name: {@code type}
146
+ */
147
+ public final DenseVectorIndexOptionsType type () {
148
+ return this .type ;
120
149
}
121
150
122
151
/**
@@ -130,24 +159,23 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) {
130
159
131
160
protected void serializeInternal (JsonGenerator generator , JsonpMapper mapper ) {
132
161
133
- generator .writeKey ("type" );
134
- generator .write (this .type );
135
-
136
- if (this .m != null ) {
137
- generator .writeKey ("m" );
138
- generator .write (this .m );
162
+ if (this .confidenceInterval != null ) {
163
+ generator .writeKey ("confidence_interval" );
164
+ generator .write (this .confidenceInterval );
139
165
140
166
}
141
167
if (this .efConstruction != null ) {
142
168
generator .writeKey ("ef_construction" );
143
169
generator .write (this .efConstruction );
144
170
145
171
}
146
- if (this .confidenceInterval != null ) {
147
- generator .writeKey ("confidence_interval " );
148
- generator .write (this .confidenceInterval );
172
+ if (this .m != null ) {
173
+ generator .writeKey ("m " );
174
+ generator .write (this .m );
149
175
150
176
}
177
+ generator .writeKey ("type" );
178
+ this .type .serialize (generator , mapper );
151
179
152
180
}
153
181
@@ -165,46 +193,76 @@ public String toString() {
165
193
public static class Builder extends WithJsonObjectBuilderBase <Builder >
166
194
implements
167
195
ObjectBuilder <DenseVectorIndexOptions > {
168
- private String type ;
169
-
170
196
@ Nullable
171
- private Integer m ;
197
+ private Float confidenceInterval ;
172
198
173
199
@ Nullable
174
200
private Integer efConstruction ;
175
201
176
202
@ Nullable
177
- private Float confidenceInterval ;
203
+ private Integer m ;
204
+
205
+ private DenseVectorIndexOptionsType type ;
178
206
179
207
/**
180
- * Required - API name: {@code type}
208
+ * The confidence interval to use when quantizing the vectors. Can be any value
209
+ * between and including <code>0.90</code> and <code>1.0</code> or exactly
210
+ * <code>0</code>. When the value is <code>0</code>, this indicates that dynamic
211
+ * quantiles should be calculated for optimized quantization. When between
212
+ * <code>0.90</code> and <code>1.0</code>, this value restricts the values used
213
+ * when calculating the quantization thresholds.
214
+ * <p>
215
+ * For example, a value of <code>0.95</code> will only use the middle
216
+ * <code>95%</code> of the values when calculating the quantization thresholds
217
+ * (e.g. the highest and lowest <code>2.5%</code> of values will be ignored).
218
+ * <p>
219
+ * Defaults to <code>1/(dims + 1)</code> for <code>int8</code> quantized vectors
220
+ * and <code>0</code> for <code>int4</code> for dynamic quantile calculation.
221
+ * <p>
222
+ * Only applicable to <code>int8_hnsw</code>, <code>int4_hnsw</code>,
223
+ * <code>int8_flat</code>, and <code>int4_flat</code> index types.
224
+ * <p>
225
+ * API name: {@code confidence_interval}
181
226
*/
182
- public final Builder type ( String value ) {
183
- this .type = value ;
227
+ public final Builder confidenceInterval ( @ Nullable Float value ) {
228
+ this .confidenceInterval = value ;
184
229
return this ;
185
230
}
186
231
187
232
/**
188
- * API name: {@code m}
233
+ * The number of candidates to track while assembling the list of nearest
234
+ * neighbors for each new node.
235
+ * <p>
236
+ * Only applicable to <code>hnsw</code>, <code>int8_hnsw</code>, and
237
+ * <code>int4_hnsw</code> index types.
238
+ * <p>
239
+ * API name: {@code ef_construction}
189
240
*/
190
- public final Builder m (@ Nullable Integer value ) {
191
- this .m = value ;
241
+ public final Builder efConstruction (@ Nullable Integer value ) {
242
+ this .efConstruction = value ;
192
243
return this ;
193
244
}
194
245
195
246
/**
196
- * API name: {@code ef_construction}
247
+ * The number of neighbors each node will be connected to in the HNSW graph.
248
+ * <p>
249
+ * Only applicable to <code>hnsw</code>, <code>int8_hnsw</code>, and
250
+ * <code>int4_hnsw</code> index types.
251
+ * <p>
252
+ * API name: {@code m}
197
253
*/
198
- public final Builder efConstruction (@ Nullable Integer value ) {
199
- this .efConstruction = value ;
254
+ public final Builder m (@ Nullable Integer value ) {
255
+ this .m = value ;
200
256
return this ;
201
257
}
202
258
203
259
/**
204
- * API name: {@code confidence_interval}
260
+ * Required - The type of kNN algorithm to use.
261
+ * <p>
262
+ * API name: {@code type}
205
263
*/
206
- public final Builder confidenceInterval ( @ Nullable Float value ) {
207
- this .confidenceInterval = value ;
264
+ public final Builder type ( DenseVectorIndexOptionsType value ) {
265
+ this .type = value ;
208
266
return this ;
209
267
}
210
268
@@ -237,10 +295,10 @@ public DenseVectorIndexOptions build() {
237
295
protected static void setupDenseVectorIndexOptionsDeserializer (
238
296
ObjectDeserializer <DenseVectorIndexOptions .Builder > op ) {
239
297
240
- op .add (Builder ::type , JsonpDeserializer .stringDeserializer (), "type" );
241
- op .add (Builder ::m , JsonpDeserializer .integerDeserializer (), "m" );
242
- op .add (Builder ::efConstruction , JsonpDeserializer .integerDeserializer (), "ef_construction" );
243
298
op .add (Builder ::confidenceInterval , JsonpDeserializer .floatDeserializer (), "confidence_interval" );
299
+ op .add (Builder ::efConstruction , JsonpDeserializer .integerDeserializer (), "ef_construction" );
300
+ op .add (Builder ::m , JsonpDeserializer .integerDeserializer (), "m" );
301
+ op .add (Builder ::type , DenseVectorIndexOptionsType ._DESERIALIZER , "type" );
244
302
245
303
}
246
304
0 commit comments