-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathProperty.java
More file actions
648 lines (581 loc) · 19.4 KB
/
Copy pathProperty.java
File metadata and controls
648 lines (581 loc) · 19.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
package io.weaviate.client6.v1.api.collections;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import com.google.gson.annotations.SerializedName;
import io.weaviate.client6.v1.internal.ObjectBuilder;
public record Property(
@SerializedName("name") String propertyName,
@SerializedName("dataType") List<String> dataTypes,
@SerializedName("description") String description,
@SerializedName("indexInverted") Boolean indexInverted,
@SerializedName("indexFilterable") Boolean indexFilterable,
@SerializedName("indexRangeFilters") Boolean indexRangeFilters,
@SerializedName("indexSearchable") Boolean indexSearchable,
@SerializedName("tokenization") Tokenization tokenization,
@SerializedName("textAnalyzer") TextAnalyzer textAnalyzer,
@SerializedName("skipVectorization") Boolean skipVectorization,
@SerializedName("vectorizePropertyName") Boolean vectorizePropertyName,
@SerializedName("nestedProperties") List<Property> nestedProperties) {
/**
* Create a {@code text} property.
*
* @param name Property name.
*/
public static Property text(String name) {
return text(name, ObjectBuilder.identity());
}
/**
* Create a {@code text} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property text(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.TEXT, fn);
}
/**
* Create a {@code text} property.
*
* @param name Property name.
*/
public static Property textArray(String name) {
return textArray(name, ObjectBuilder.identity());
}
/**
* Create a {@code text[]} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property textArray(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.TEXT_ARRAY, fn);
}
/**
* Create a {@code int} property.
*
* @param name Property name.
*/
public static Property integer(String name) {
return integer(name, ObjectBuilder.identity());
}
/**
* Create a {@code int} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property integer(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.INT, fn);
}
/**
* Create a {@code int[]} property.
*
* @param name Property name.
*/
public static Property integerArray(String name) {
return integerArray(name, ObjectBuilder.identity());
}
/**
* Create a {@code int[]} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property integerArray(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.INT_ARRAY, fn);
}
/**
* Create a {@code blob} property.
*
* @param name Property name.
*/
public static Property blob(String name) {
return blob(name, ObjectBuilder.identity());
}
/**
* Create a {@code blob} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property blob(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.BLOB, fn);
}
/**
* Create a {@code blobHash} property.
*
* @param name Property name.
*/
public static Property blobHash(String name) {
return blobHash(name, ObjectBuilder.identity());
}
/**
* Create a {@code blobHash} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property blobHash(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.BLOB_HASH, fn);
}
/**
* Create a {@code bool} property.
*
* @param name Property name.
*/
public static Property bool(String name) {
return bool(name, ObjectBuilder.identity());
}
/**
* Create a {@code bool} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property bool(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.BOOL, fn);
}
/**
* Create a {@code bool[]} property.
*
* @param name Property name.
*/
public static Property boolArray(String name) {
return boolArray(name, ObjectBuilder.identity());
}
/**
* Create a {@code bool[]} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property boolArray(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.BOOL_ARRAY, fn);
}
/**
* Create a {@code date} property.
*
* @param name Property name.
*/
public static Property date(String name) {
return date(name, ObjectBuilder.identity());
}
/**
* Create a {@code date} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property date(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.DATE, fn);
}
/**
* Create a {@code date[]} property.
*
* @param name Property name.
*/
public static Property dateArray(String name) {
return dateArray(name, ObjectBuilder.identity());
}
/**
* Create a {@code date[]} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property dateArray(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.DATE_ARRAY, fn);
}
/**
* Create a {@code uuid} property.
*
* @param name Property name.
*/
public static Property uuid(String name) {
return uuid(name, ObjectBuilder.identity());
}
/**
* Create a {@code uuid} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property uuid(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.UUID, fn);
}
/**
* Create a {@code uuid[]} property.
*
* @param name Property name.
*/
public static Property uuidArray(String name) {
return uuidArray(name, ObjectBuilder.identity());
}
/**
* Create a {@code uuid[]} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property uuidArray(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.UUID_ARRAY, fn);
}
/**
* Create a {@code number} property.
*
* @param name Property name.
*/
public static Property number(String name) {
return number(name, ObjectBuilder.identity());
}
/**
* Create a {@code number} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property number(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.NUMBER, fn);
}
/**
* Create a {@code number[]} property.
*
* @param name Property name.
*/
public static Property numberArray(String name) {
return numberArray(name, ObjectBuilder.identity());
}
/**
* Create a {@code number[]} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property numberArray(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.NUMBER_ARRAY, fn);
}
/**
* Create a {@code object} property.
*
* @param name Property name.
*/
public static Property object(String name) {
return object(name, ObjectBuilder.identity());
}
/**
* Create a {@code object} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property object(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.OBJECT, fn);
}
/**
* Create a {@code object[]} property.
*
* @param name Property name.
*/
public static Property objectArray(String name) {
return objectArray(name, ObjectBuilder.identity());
}
/**
* Create a {@code object[]} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property objectArray(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.OBJECT_ARRAY, fn);
}
/**
* Create a {@code phoneNumber} property.
*
* @param name Property name.
*/
public static Property phoneNumber(String name) {
return phoneNumber(name, ObjectBuilder.identity());
}
/**
* Create a {@code phoneNumber} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property phoneNumber(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.PHONE_NUMBER, fn);
}
/**
* Create a {@code geoCoordinates} property.
*
* @param name Property name.
*/
public static Property geoCoordinates(String name) {
return geoCoordinates(name, ObjectBuilder.identity());
}
/**
* Create a {@code geoCoordinates} property with additional configuration.
*
* @param name Property name.
* @param fn Lambda expression for optional parameters.
*/
public static Property geoCoordinates(String name, Function<Builder, ObjectBuilder<Property>> fn) {
return newProperty(name, DataType.GEO_COORDINATES, fn);
}
private static Property newProperty(String name, String dataType, Function<Builder, ObjectBuilder<Property>> fn) {
return fn.apply(new Builder(name, dataType)).build();
}
/**
* Create a new "edit" builder from the property configuration. Consult the <a
* href=
* "https://docs.weaviate.io/weaviate/config-refs/collections#properties">documentation</a>
* to see which configuration is mutable before updating it.
*
* Example: Update property description.
*
* <pre>{@code
* Property updated = propertyHeight.edit()
* .description("How tall this building is.")
* .build();
* }</pre>
*
* @see #edit(Function)
*/
public Builder edit() {
return new Builder(propertyName, dataTypes)
.description(description)
.indexInverted(indexInverted)
.indexFilterable(indexFilterable)
.indexRangeFilters(indexRangeFilters)
.indexSearchable(indexSearchable)
.tokenization(tokenization)
.skipVectorization(skipVectorization)
.vectorizePropertyName(vectorizePropertyName);
}
/**
* Pass a lambda expression to update property configuration. Consult the <a
* href=
* "https://docs.weaviate.io/weaviate/config-refs/collections#properties">documentation</a>
* to see which configuration is mutable before updating it.
*
* Example: Update property description.
*
* <pre>{@code
* Property updated = propertyHeight.edit(
* p -> p.description("How tall this building is."));
* }</pre>
*
* @see #edit()
*/
public Property edit(Function<Builder, ObjectBuilder<Property>> fn) {
return fn.apply(edit()).build();
}
public Property(Builder builder) {
this(
builder.propertyName,
builder.dataTypes,
builder.description,
builder.indexInverted,
builder.indexFilterable,
builder.indexRangeFilters,
builder.indexSearchable,
builder.tokenization,
builder.textAnalyzer,
builder.skipVectorization,
builder.vectorizePropertyName,
builder.nestedProperties.isEmpty() ? null : builder.nestedProperties);
}
// All methods accepting a `boolean` should have a boxed overload
// to be used by Property::edit.
//
// There we can't just do:
// .indexInverted(indexInverted == null ? false : indexInverted)
// because that may change the value from `null` to Boolean.FALSE,
// effectively updating this setting. In the context of PUT /schema/{collection}
// call this becomes a problem because we're not allowed to update anything
// except for the description.
//
// The alternative (wrapping each call in an if-block) seems too verbose.
public static class Builder implements ObjectBuilder<Property> {
// Required parameters.
private final String propertyName;
private final List<String> dataTypes = new ArrayList<>();
// Optional parameters.
private String description;
private Boolean indexInverted;
private Boolean indexFilterable;
private Boolean indexRangeFilters;
private Boolean indexSearchable;
private Tokenization tokenization;
private TextAnalyzer textAnalyzer;
private Boolean skipVectorization;
private Boolean vectorizePropertyName;
private List<Property> nestedProperties = new ArrayList<>();
/**
* Create a scalar / array type property.
*
* @param dataType Property data type, see {@link DataType}.
*/
public Builder(String propertyName, String dataType) {
this.propertyName = propertyName;
this.dataTypes.add(dataType);
}
/**
* Create a cross-reference property.
*
* @param dataTypes List of collection names this property can reference.
*/
public Builder(String propertyName, List<String> dataTypes) {
this.propertyName = propertyName;
this.dataTypes.addAll(dataTypes);
}
/** Add property description. */
public Builder description(String description) {
this.description = description;
return this;
}
public Builder indexInverted(boolean indexInverted) {
this.indexInverted = indexInverted;
return this;
}
/** Convenience method to be used by {@link Property#edit}. */
Builder indexInverted(Boolean indexInverted) {
this.indexInverted = indexInverted;
return this;
}
/**
* Set to true to create a filtering index for this property.
*
* <p>
* Filterable indices are not applicable to {@code blob}, {@code object},
* {@code geoCoordinates}, and {@code phoneNumber} properties or arrays thereof.
*
* @see <a href=
* "https://docs.weaviate.io/weaviate/concepts/indexing/inverted-index#configure-inverted-indexes">Inverted
* Indexes</a>
*/
public Builder indexFilterable(boolean indexFilterable) {
this.indexFilterable = indexFilterable;
return this;
}
/** Convenience method to be used by {@link Property#edit}. */
Builder indexFilterable(Boolean indexFilterable) {
this.indexFilterable = indexFilterable;
return this;
}
/**
* Set to true to create a range-based filter for filtering
* by numerical ranges for this property.
*
* <p>
* Applicable to {code int}, {@code number}, and {@code date} properties.
*
* @see <a href=
* "https://docs.weaviate.io/weaviate/concepts/indexing/inverted-index#configure-inverted-indexes">Inverted
* Indexes</a>
*/
public Builder indexRangeFilters(boolean indexRangeFilters) {
this.indexRangeFilters = indexRangeFilters;
return this;
}
/** Convenience method to be used by {@link Property#edit}. */
Builder indexRangeFilters(Boolean indexRangeFilters) {
this.indexRangeFilters = indexRangeFilters;
return this;
}
/**
* Set to true to create a searchable index for this property.
*
* <p>
* This index type enables BM25/hybrid search and is only applicable to
* {@code text}/{@code text[]} fields. For those it is also created
* by default; you should set {@code indexInverted(false)} if you
* do not plan to run BM25/hybrid queries on this property.
*
* @see <a href=
* "https://docs.weaviate.io/weaviate/concepts/indexing/inverted-index#configure-inverted-indexes">Inverted
* Indexes</a>
*/
public Builder indexSearchable(boolean indexSearchable) {
this.indexSearchable = indexSearchable;
return this;
}
/** Convenience method to be used by {@link Property#edit}. */
Builder indexSearchable(Boolean indexSearchable) {
this.indexSearchable = indexSearchable;
return this;
}
/**
* Change tokenization method for this property.
*
* @see <a href=
* "https://docs.weaviate.io/academy/py/tokenization/options">Tokenization</a>
*/
public Builder tokenization(Tokenization tokenization) {
this.tokenization = tokenization;
return this;
}
/**
* Configures per-property text analysis for {@code text} and {@code text[]}
* properties that use an inverted index (searchable or filterable).
*
* <p>
* Supports ASCII folding (accent/diacritic handling) and selecting
* a stopword preset that overrides the collection-level
* {@code invertedIndexConfig.stopwords} setting for this property only.
*/
public Builder textAnalyzer(TextAnalyzer textAnalyzer) {
this.textAnalyzer = textAnalyzer;
return this;
}
public Builder skipVectorization(boolean skipVectorization) {
this.skipVectorization = skipVectorization;
return this;
}
/** Convenience method to be used by {@link Property#edit}. */
Builder skipVectorization(Boolean skipVectorization) {
this.skipVectorization = skipVectorization;
return this;
}
/** Include property name into the input for the vectorizer module. */
public Builder vectorizePropertyName(boolean vectorizePropertyName) {
this.vectorizePropertyName = vectorizePropertyName;
return this;
}
/**
* Defined nested properties. This configuration is only applicable to a
* property of type {@code object} and {@code object[]}.
*
* <pre>{@code
* Property.object("address",
* p -> p.nestedProperties(
* Property.text("street"),
* Property.integer("building_nr")))
* }</pre>
*/
public Builder nestedProperties(Property... properties) {
return nestedProperties(Arrays.asList(properties));
}
/**
* Defined nested properties. This configuration is only applicable to a
* property of type {@code object} and {@code object[]}.
*
* @see Builder#nestedProperties(Property...)
*/
public Builder nestedProperties(List<Property> properties) {
this.nestedProperties.addAll(properties);
return this;
}
/** Convenience method to be used by {@link Property#edit}. */
Builder vectorizePropertyName(Boolean vectorizePropertyName) {
this.vectorizePropertyName = vectorizePropertyName;
return this;
}
@Override
public Property build() {
return new Property(this);
}
}
}