weaviate_community/collections/schema.rs
1/// All schema associated type components
2/// https://weaviate.io/developers/weaviate/config-refs/schema#auto-schema
3use serde::{Deserialize, Serialize};
4
5/// Storage for multiple classes.
6#[derive(Serialize, Deserialize, Debug)]
7pub struct Classes {
8 pub classes: Vec<Class>,
9}
10
11impl Classes {
12 /// Create a new Classes object
13 ///
14 /// # Parameters
15 /// - classes: the classes to encapsulate
16 ///
17 /// # Example
18 /// ```rust
19 /// use weaviate_community::collections::schema::{Class, Classes};
20 ///
21 /// let classes = Classes::new(
22 /// vec![
23 /// Class::builder("Article").build(),
24 /// Class::builder("Journal").build()
25 /// ]
26 /// );
27 /// ```
28 pub fn new(classes: Vec<Class>) -> Classes {
29 Classes { classes }
30 }
31}
32
33/// Full class definition and configuration options.
34#[derive(Serialize, Deserialize, Debug)]
35#[serde(rename_all = "camelCase")]
36pub struct Class {
37 pub class: String,
38 #[serde(skip_serializing_if = "Option::is_none")]
39 #[serde(default)]
40 pub description: Option<String>,
41 #[serde(skip_serializing_if = "Option::is_none")]
42 #[serde(default)]
43 pub properties: Option<Properties>,
44 #[serde(skip_serializing_if = "Option::is_none")]
45 #[serde(default = "default_vector_index_type")]
46 pub vector_index_type: Option<VectorIndexType>,
47 #[serde(skip_serializing_if = "Option::is_none")]
48 #[serde(default)]
49 pub vector_index_config: Option<VectorIndexConfig>,
50 #[serde(skip_serializing_if = "Option::is_none")]
51 #[serde(default)]
52 pub vectorizer: Option<String>,
53 #[serde(skip_serializing_if = "Option::is_none")]
54 #[serde(default)]
55 pub module_config: Option<serde_json::Value>,
56 #[serde(skip_serializing_if = "Option::is_none")]
57 #[serde(default)]
58 pub inverted_index_config: Option<InvertedIndexConfig>,
59 #[serde(skip_serializing_if = "Option::is_none")]
60 pub sharding_config: Option<ShardingConfig>,
61 #[serde(skip_serializing_if = "Option::is_none")]
62 #[serde(default)]
63 pub multi_tenancy_config: Option<MultiTenancyConfig>,
64 #[serde(skip_serializing_if = "Option::is_none")]
65 #[serde(default)]
66 pub replication_config: Option<ReplicationConfig>,
67}
68
69impl Class {
70 /// Create a new builder for the class object.
71 ///
72 /// This is the same as `ClassBuilder::new()`.
73 ///
74 /// # Parameters
75 /// - class_name: the name of the class
76 /// - description: the description of the class
77 ///
78 /// # Example
79 /// ```rust
80 /// use weaviate_community::collections::schema::Class;
81 ///
82 /// let builder = Class::builder("Article");
83 /// ```
84 pub fn builder(class_name: &str) -> ClassBuilder {
85 ClassBuilder::new(class_name)
86 }
87}
88
89/// ClassBuilder for building new classes
90#[derive(Default)]
91pub struct ClassBuilder {
92 pub class: String,
93 pub description: Option<String>,
94 pub properties: Option<Properties>,
95 pub vector_index_type: Option<VectorIndexType>,
96 pub vector_index_config: Option<VectorIndexConfig>,
97 pub vectorizer: Option<String>,
98 pub module_config: Option<serde_json::Value>,
99 pub inverted_index_config: Option<InvertedIndexConfig>,
100 pub sharding_config: Option<ShardingConfig>,
101 pub multi_tenancy_config: Option<MultiTenancyConfig>,
102 pub replication_config: Option<ReplicationConfig>,
103}
104
105impl ClassBuilder {
106 /// Create a new builder for the class object.
107 ///
108 /// This is the same as `Class::builder()`.
109 ///
110 /// # Parameters
111 /// - class_name: the name of the class
112 ///
113 /// # Example
114 /// ```rust
115 /// use weaviate_community::collections::schema::ClassBuilder;
116 ///
117 /// let builder = ClassBuilder::new("Article");
118 /// ```
119 pub fn new(class: &str) -> ClassBuilder {
120 ClassBuilder {
121 class: class.into(),
122 description: None,
123 properties: None,
124 vector_index_type: None,
125 vector_index_config: None,
126 vectorizer: None,
127 module_config: None,
128 inverted_index_config: None,
129 sharding_config: None,
130 multi_tenancy_config: None,
131 replication_config: None,
132 }
133 }
134
135 /// Add a value to the optional `description` value of the class.
136 ///
137 /// # Parameters
138 /// - description: the description to set
139 ///
140 /// # Example
141 /// ```rust
142 /// use weaviate_community::collections::schema::ClassBuilder;
143 ///
144 /// let builder = ClassBuilder::new("Article")
145 /// .with_description("A news article");
146 /// ```
147 pub fn with_description(mut self, description: &str) -> ClassBuilder {
148 self.description = Some(description.into());
149 self
150 }
151
152 /// Add a value to the optional `properties` value of the class.
153 ///
154 /// # Parameters
155 /// - properties: the properties to set
156 ///
157 /// # Example
158 /// ```rust
159 /// use weaviate_community::collections::schema::{
160 /// ClassBuilder,
161 /// Properties,
162 /// Property
163 /// };
164 ///
165 /// let properties = Properties::new(vec![Property::builder("title", vec!["text"]).build()]);
166 /// let builder = ClassBuilder::new("Article")
167 /// .with_properties(properties);
168 /// ```
169 pub fn with_properties(mut self, properties: Properties) -> ClassBuilder {
170 self.properties = Some(properties);
171 self
172 }
173
174 /// Add a value to the optional `vector_index_type` value of the class.
175 ///
176 /// The vector_index_type defaults to `hnsw` if unset.
177 ///
178 /// # Parameters
179 /// - vector_index_type: the vector_index_type to set
180 ///
181 /// # Example
182 /// ```rust
183 /// use weaviate_community::collections::schema::{
184 /// ClassBuilder,
185 /// VectorIndexType
186 /// };
187 ///
188 /// let builder = ClassBuilder::new("Article")
189 /// .with_vector_index_type(VectorIndexType::HNSW);
190 /// ```
191 pub fn with_vector_index_type(mut self, vector_index_type: VectorIndexType) -> ClassBuilder {
192 self.vector_index_type = Some(vector_index_type);
193 self
194 }
195
196 /// Add a value to the optional `vector_index_config` value of the class.
197 ///
198 /// # Parameters
199 /// - vector_index_config: the vector_index_config to set
200 ///
201 /// # Example
202 /// ```rust
203 /// use weaviate_community::collections::schema::{
204 /// ClassBuilder,
205 /// VectorIndexConfig
206 /// };
207 ///
208 /// let config = VectorIndexConfig::builder().build();
209 /// let builder = ClassBuilder::new("Article")
210 /// .with_vector_index_config(config);
211 /// ```
212 pub fn with_vector_index_config(
213 mut self,
214 vector_index_config: VectorIndexConfig,
215 ) -> ClassBuilder {
216 self.vector_index_config = Some(vector_index_config);
217 self
218 }
219
220 /// Add a value to the optional `vectorizer` value of the class.
221 ///
222 /// Defaults to the vectorizer set in the database configuration if unset.
223 ///
224 /// # Parameters
225 /// - vectorizer: the vectorizer to set
226 ///
227 /// # Example
228 /// ```rust
229 /// use weaviate_community::collections::schema::ClassBuilder;
230 ///
231 /// let builder = ClassBuilder::new("Article")
232 /// .with_vectorizer("none");
233 /// ```
234 pub fn with_vectorizer(mut self, vectorizer: &str) -> ClassBuilder {
235 self.vectorizer = Some(vectorizer.into());
236 self
237 }
238
239 /// Add a value to the optional `module_config` value of the class.
240 ///
241 /// This parameter needs re-evaluating
242 ///
243 /// # Parameters
244 /// - module_config: the module_config to set
245 ///
246 /// # Example
247 /// ```rust
248 /// use weaviate_community::collections::schema::ClassBuilder;
249 ///
250 /// let builder = ClassBuilder::new("Article")
251 /// .with_module_config(serde_json::json!({}));
252 /// ```
253 pub fn with_module_config(mut self, module_config: serde_json::Value) -> ClassBuilder {
254 self.module_config = Some(module_config);
255 self
256 }
257
258 /// Add a value to the optional `inverted_index_config` value of the class.
259 ///
260 /// # Parameters
261 /// - inverted_index_config: the inverted_index_config to set
262 ///
263 /// # Example
264 /// ```rust
265 /// use weaviate_community::collections::schema::{ClassBuilder, InvertedIndexConfig};
266 ///
267 /// let config = InvertedIndexConfig::builder().build();
268 /// let builder = ClassBuilder::new("Article")
269 /// .with_inverted_index_config(config);
270 /// ```
271 pub fn with_inverted_index_config(
272 mut self,
273 inverted_index_config: InvertedIndexConfig,
274 ) -> ClassBuilder {
275 self.inverted_index_config = Some(inverted_index_config);
276 self
277 }
278
279 /// Add a value to the optional `sharding_config` value of the class.
280 ///
281 /// # Parameters
282 /// - sharding_config: the sharding_config to set
283 ///
284 /// # Example
285 /// ```rust
286 /// use weaviate_community::collections::schema::{ClassBuilder, ShardingConfig};
287 ///
288 /// let config = ShardingConfig::builder().build();
289 /// let builder = ClassBuilder::new("Article")
290 /// .with_sharding_config(config);
291 /// ```
292 pub fn with_sharding_config(mut self, sharding_config: ShardingConfig) -> ClassBuilder {
293 self.sharding_config = Some(sharding_config);
294 self
295 }
296
297 /// Add a value to the optional `multi_tenancy_config` value of the class.
298 ///
299 /// # Parameters
300 /// - multi_tenancy_config: the multi_tenancy_config to set
301 ///
302 /// # Example
303 /// ```rust
304 /// use weaviate_community::collections::schema::{ClassBuilder, MultiTenancyConfig};
305 ///
306 /// let config = MultiTenancyConfig::new(true);
307 /// let builder = ClassBuilder::new("Article")
308 /// .with_multi_tenancy_config(config);
309 /// ```
310 pub fn with_multi_tenancy_config(
311 mut self,
312 multi_tenancy_config: MultiTenancyConfig,
313 ) -> ClassBuilder {
314 self.multi_tenancy_config = Some(multi_tenancy_config);
315 self
316 }
317
318 /// Add a value to the optional `replication_config` value of the class.
319 ///
320 /// # Parameters
321 /// - replication_config: the replication_config to set
322 ///
323 /// # Example
324 /// ```rust
325 /// use weaviate_community::collections::schema::{ClassBuilder, ReplicationConfig};
326 ///
327 /// let config = ReplicationConfig::new(3);
328 /// let builder = ClassBuilder::new("Article")
329 /// .with_replication_config(config);
330 /// ```
331 pub fn with_replication_config(
332 mut self,
333 replication_config: ReplicationConfig,
334 ) -> ClassBuilder {
335 self.replication_config = Some(replication_config);
336 self
337 }
338
339 /// Build the Class from the ClassBuilder
340 ///
341 /// # Example
342 /// Using ClassBuilder
343 /// ```rust
344 /// use weaviate_community::collections::schema::ClassBuilder;
345 ///
346 /// let class = ClassBuilder::new("Article").build();
347 /// ```
348 ///
349 /// Using Class
350 /// ```rust
351 /// use weaviate_community::collections::schema::Class;
352 ///
353 /// let class = Class::builder("Article").build();
354 /// ```
355 pub fn build(self) -> Class {
356 Class {
357 class: self.class,
358 description: self.description,
359 properties: self.properties,
360 vector_index_type: self.vector_index_type,
361 vector_index_config: self.vector_index_config,
362 vectorizer: self.vectorizer,
363 module_config: self.module_config,
364 inverted_index_config: self.inverted_index_config,
365 sharding_config: self.sharding_config,
366 multi_tenancy_config: self.multi_tenancy_config,
367 replication_config: self.replication_config,
368 }
369 }
370}
371
372/// Strict definitions of Vector Index types.
373///
374/// Currently Weaviate only supports HNSW.
375#[derive(Serialize, Deserialize, Debug)]
376pub enum VectorIndexType {
377 #[serde(rename = "hnsw")]
378 HNSW,
379}
380
381/// Controls default for Class vector_index_type
382fn default_vector_index_type() -> Option<VectorIndexType> {
383 Some(VectorIndexType::HNSW)
384}
385
386/// Wrapper for multiple properties
387#[derive(Serialize, Deserialize, Debug, PartialEq)]
388#[serde(rename_all = "camelCase")]
389pub struct Properties(pub Vec<Property>);
390
391impl Properties {
392 /// Create a new Properties wrapper, to house multiple individual properties.
393 ///
394 /// # Parameters
395 /// - properties: the properties to set
396 ///
397 /// # Example
398 /// ```rust
399 /// use weaviate_community::collections::schema::{
400 /// Properties,
401 /// Property
402 /// };
403 ///
404 /// let properties = Properties::new(vec![Property::builder("title", vec!["text"]).build()]);
405 /// ```
406 pub fn new(properties: Vec<Property>) -> Properties {
407 Properties(properties)
408 }
409}
410
411/// Configuration options for a property
412#[derive(Serialize, Deserialize, Debug, PartialEq)]
413#[serde(rename_all = "camelCase")]
414pub struct Property {
415 pub name: String,
416 pub data_type: Vec<String>,
417 #[serde(skip_serializing_if = "Option::is_none")]
418 #[serde(default)]
419 pub description: Option<String>,
420 #[serde(skip_serializing_if = "Option::is_none")]
421 #[serde(default)]
422 pub tokenization: Option<Tokenization>,
423 #[serde(skip_serializing_if = "Option::is_none")]
424 #[serde(default)]
425 pub module_config: Option<serde_json::Value>,
426 #[serde(skip_serializing_if = "Option::is_none")]
427 #[serde(default)]
428 pub index_filterable: Option<bool>,
429 #[serde(skip_serializing_if = "Option::is_none")]
430 #[serde(default)]
431 pub index_searchable: Option<bool>,
432 #[serde(skip_serializing_if = "Option::is_none")]
433 #[serde(default)]
434 pub inverted_index_config: Option<InvertedIndexConfig>,
435}
436
437impl Property {
438 /// Create a new builder for the property object.
439 ///
440 /// This is the same as `PropertyBuilder::new()`.
441 ///
442 /// When creating cross-references, a property can have multiple data types.
443 ///
444 /// # Parameters
445 /// - name: the name of the property
446 /// - data_type: the data type of the property
447 ///
448 /// # Example
449 /// ```rust
450 /// use weaviate_community::collections::schema::Property;
451 ///
452 /// let builder = Property::builder("title", vec!["text"]);
453 /// ```
454 pub fn builder(name: &str, data_type: Vec<&str>) -> PropertyBuilder {
455 PropertyBuilder::new(name, data_type)
456 }
457}
458
459/// PropertyBuilder for building new properties
460#[derive(Default)]
461pub struct PropertyBuilder {
462 pub name: String,
463 pub data_type: Vec<String>,
464 pub description: Option<String>,
465 pub tokenization: Option<Tokenization>,
466 pub module_config: Option<serde_json::Value>,
467 pub index_filterable: Option<bool>,
468 pub index_searchable: Option<bool>,
469 pub inverted_index_config: Option<InvertedIndexConfig>,
470}
471
472impl PropertyBuilder {
473 /// Create a new builder for the property object.
474 ///
475 /// This is the same as `Property::builder()`.
476 ///
477 /// When creating cross-references, a property can have multiple data types.
478 ///
479 /// # Parameters
480 /// - name: the name of the property
481 /// - data_type: the data type of the property
482 ///
483 /// # Example
484 /// ```rust
485 /// use weaviate_community::collections::schema::PropertyBuilder;
486 ///
487 /// let builder = PropertyBuilder::new("title", vec!["text"]);
488 /// ```
489 pub fn new(name: &str, data_type: Vec<&str>) -> PropertyBuilder {
490 let data_type = data_type.iter().map(|field| field.to_string()).collect();
491 PropertyBuilder {
492 name: name.into(),
493 data_type,
494 description: None,
495 tokenization: None,
496 module_config: None,
497 index_filterable: None,
498 index_searchable: None,
499 inverted_index_config: None,
500 }
501 }
502
503 /// Add a value to the optional `description` value of the property.
504 ///
505 /// # Parameters
506 /// - description: the description of the property
507 ///
508 /// # Example
509 /// ```rust
510 /// use weaviate_community::collections::schema::PropertyBuilder;
511 ///
512 /// let builder = PropertyBuilder::new("title", vec!["text"])
513 /// .with_description("The title of the article");
514 /// ```
515 pub fn with_description(mut self, description: &str) -> PropertyBuilder {
516 self.description = Some(description.into());
517 self
518 }
519
520 /// Add a value to the optional `tokenization` value of the property.
521 ///
522 /// # Parameters
523 /// - tokenization: the tokenization to use for the property
524 ///
525 /// # Example
526 /// ```rust
527 /// use weaviate_community::collections::schema::{PropertyBuilder, Tokenization};
528 ///
529 /// let builder = PropertyBuilder::new("title", vec!["text"])
530 /// .with_tokenization(Tokenization::WORD);
531 /// ```
532 pub fn with_tokenization(mut self, tokenization: Tokenization) -> PropertyBuilder {
533 self.tokenization = Some(tokenization);
534 self
535 }
536
537 /// Add a value to the optional `module_config` value of the property.
538 ///
539 /// This needs to be revisited.
540 ///
541 /// # Parameters
542 /// - module_config: the module_config to use for the property
543 ///
544 /// # Example
545 /// ```rust
546 /// use weaviate_community::collections::schema::PropertyBuilder;
547 /// use std::collections::HashMap;
548 ///
549 /// let builder = PropertyBuilder::new("title", vec!["text"]);
550 /// ```
551 pub fn with_module_config(
552 mut self,
553 module_config: serde_json::Value,
554 ) -> PropertyBuilder {
555 self.module_config = Some(module_config);
556 self
557 }
558
559 /// Add a value to the optional `index_filterable` value of the property.
560 ///
561 /// # Parameters
562 /// - index_filterable: the index_filterable to use for the property
563 ///
564 /// # Example
565 /// ```rust
566 /// use weaviate_community::collections::schema::PropertyBuilder;
567 ///
568 /// let builder = PropertyBuilder::new("title", vec!["text"])
569 /// .with_index_filterable(true);
570 /// ```
571 pub fn with_index_filterable(mut self, index_filterable: bool) -> PropertyBuilder {
572 self.index_filterable = Some(index_filterable);
573 self
574 }
575
576 /// Add a value to the optional `index_searchable` value of the property.
577 ///
578 /// # Parameters
579 /// - index_searchable: the index_searchable to use for the property
580 ///
581 /// # Example
582 /// ```rust
583 /// use weaviate_community::collections::schema::PropertyBuilder;
584 ///
585 /// let builder = PropertyBuilder::new("title", vec!["text"])
586 /// .with_index_searchable(true);
587 /// ```
588 pub fn with_index_searchable(mut self, index_searchable: bool) -> PropertyBuilder {
589 self.index_searchable = Some(index_searchable);
590 self
591 }
592
593 /// Add a value to the optional `inverted_index_config` value of the property.
594 ///
595 /// # Parameters
596 /// - inverted_index_config: the inverted_index_config to use for the property
597 ///
598 /// # Example
599 /// ```rust
600 /// use weaviate_community::collections::schema::{PropertyBuilder, InvertedIndexConfig};
601 ///
602 /// let config = InvertedIndexConfig::builder().build();
603 /// let builder = PropertyBuilder::new("title", vec!["text"])
604 /// .with_inverted_index_config(config);
605 /// ```
606 pub fn with_inverted_index_config(
607 mut self,
608 inverted_index_config: InvertedIndexConfig,
609 ) -> PropertyBuilder {
610 self.inverted_index_config = Some(inverted_index_config);
611 self
612 }
613
614 /// Build the Property from the PropertyBuilder
615 ///
616 /// # Example
617 /// Using PropertyBuilder
618 /// ```rust
619 /// use weaviate_community::collections::schema::PropertyBuilder;
620 ///
621 /// let builder = PropertyBuilder::new("title", vec!["text"]).build();
622 /// ```
623 ///
624 /// Using Property
625 /// ```rust
626 /// use weaviate_community::collections::schema::Property;
627 ///
628 /// let builder = Property::builder("title", vec!["text"]).build();
629 /// ```
630 pub fn build(self) -> Property {
631 Property {
632 name: self.name,
633 data_type: self.data_type,
634 description: self.description,
635 tokenization: self.tokenization,
636 module_config: self.module_config,
637 index_filterable: self.index_filterable,
638 index_searchable: self.index_searchable,
639 inverted_index_config: self.inverted_index_config,
640 }
641 }
642}
643
644/// Configuration options for VectorIndexConfig
645#[derive(Serialize, Deserialize, Debug)]
646#[serde(rename_all = "camelCase")]
647pub struct VectorIndexConfig {
648 #[serde(skip_serializing_if = "Option::is_none")]
649 #[serde(default)]
650 pub distance: Option<DistanceMetric>,
651 #[serde(skip_serializing_if = "Option::is_none")]
652 #[serde(default)]
653 pub ef: Option<i64>,
654 #[serde(skip_serializing_if = "Option::is_none")]
655 #[serde(default)]
656 pub ef_construction: Option<u64>,
657 #[serde(skip_serializing_if = "Option::is_none")]
658 #[serde(default)]
659 pub max_connections: Option<u64>,
660 #[serde(skip_serializing_if = "Option::is_none")]
661 #[serde(default)]
662 pub dynamic_ef_min: Option<i64>,
663 #[serde(skip_serializing_if = "Option::is_none")]
664 #[serde(default)]
665 pub dynamic_ef_max: Option<i64>,
666 #[serde(skip_serializing_if = "Option::is_none")]
667 #[serde(default)]
668 pub dynamic_ef_factor: Option<i64>,
669 #[serde(skip_serializing_if = "Option::is_none")]
670 #[serde(default)]
671 pub vector_cache_max_objects: Option<u64>,
672 #[serde(skip_serializing_if = "Option::is_none")]
673 #[serde(default)]
674 pub flat_search_cut_off: Option<u64>,
675 #[serde(skip_serializing_if = "Option::is_none")]
676 #[serde(default)]
677 pub cleanup_interval_seconds: Option<u64>,
678 #[serde(skip_serializing_if = "Option::is_none")]
679 #[serde(default)]
680 pub pq: Option<PqConfig>,
681 #[serde(skip_serializing_if = "Option::is_none")]
682 #[serde(default)]
683 pub skip: Option<bool>,
684}
685
686impl VectorIndexConfig {
687 /// Create a new builder for the VectorIndexConfig object.
688 ///
689 /// This is the same as `VectorIndexConfigBuilder::new()`.
690 ///
691 /// # Example
692 /// ```rust
693 /// use weaviate_community::collections::schema::VectorIndexConfig;
694 ///
695 /// let builder = VectorIndexConfig::builder();
696 /// ```
697 pub fn builder() -> VectorIndexConfigBuilder {
698 VectorIndexConfigBuilder::default()
699 }
700}
701
702/// VectorIndexConfigBuilder for building a new VectorIndexConfig
703#[derive(Default)]
704pub struct VectorIndexConfigBuilder {
705 pub distance: Option<DistanceMetric>,
706 pub ef: Option<i64>,
707 pub ef_construction: Option<u64>,
708 pub max_connections: Option<u64>,
709 pub dynamic_ef_min: Option<i64>,
710 pub dynamic_ef_max: Option<i64>,
711 pub dynamic_ef_factor: Option<i64>,
712 pub vector_cache_max_objects: Option<u64>,
713 pub flat_search_cut_off: Option<u64>,
714 pub cleanup_interval_seconds: Option<u64>,
715 pub pq: Option<PqConfig>,
716 pub skip: Option<bool>,
717}
718
719impl VectorIndexConfigBuilder {
720 /// Create a new builder for the VectorIndexConfig object.
721 ///
722 /// This is the same as `VectorIndexConfig::builder()`.
723 ///
724 /// # Example
725 /// ```rust
726 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
727 ///
728 /// let builder = VectorIndexConfigBuilder::new();
729 /// ```
730 pub fn new() -> VectorIndexConfigBuilder {
731 VectorIndexConfigBuilder {
732 distance: None,
733 ef: None,
734 ef_construction: None,
735 max_connections: None,
736 dynamic_ef_min: None,
737 dynamic_ef_max: None,
738 dynamic_ef_factor: None,
739 vector_cache_max_objects: None,
740 flat_search_cut_off: None,
741 cleanup_interval_seconds: None,
742 pq: None,
743 skip: None,
744 }
745 }
746
747 /// Add a value to the optional `distance` value of the VectorIndexConfig.
748 ///
749 /// # Parameters
750 /// - distance: the distance to use for the vector index config
751 ///
752 /// # Example
753 /// ```rust
754 /// use weaviate_community::collections::schema::{VectorIndexConfigBuilder, DistanceMetric};
755 ///
756 /// let builder = VectorIndexConfigBuilder::new().with_distance(DistanceMetric::COSINE);
757 /// ```
758 pub fn with_distance(mut self, distance: DistanceMetric) -> VectorIndexConfigBuilder {
759 self.distance = Some(distance);
760 self
761 }
762
763 /// Add a value to the optional `ef` value of the VectorIndexConfig.
764 ///
765 /// # Parameters
766 /// - ef: the ef to use for the vector index config
767 ///
768 /// # Example
769 /// ```rust
770 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
771 ///
772 /// let builder = VectorIndexConfigBuilder::new().with_ef(10);
773 /// ```
774 pub fn with_ef(mut self, ef: i64) -> VectorIndexConfigBuilder {
775 self.ef = Some(ef);
776 self
777 }
778
779 /// Add a value to the optional `ef_construction` value of the VectorIndexConfig.
780 ///
781 /// # Parameters
782 /// - ef_construction: the ef_construction to use for the vector index config
783 ///
784 /// # Example
785 /// ```rust
786 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
787 ///
788 /// let builder = VectorIndexConfigBuilder::new().with_ef_construction(5);
789 /// ```
790 pub fn with_ef_construction(mut self, ef_construction: u64) -> VectorIndexConfigBuilder {
791 self.ef_construction = Some(ef_construction);
792 self
793 }
794
795 /// Add a value to the optional `max_connections` value of the VectorIndexConfig.
796 ///
797 /// # Parameters
798 /// - max_connections: the max_connections to use for the vector index config
799 ///
800 /// # Example
801 /// ```rust
802 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
803 ///
804 /// let builder = VectorIndexConfigBuilder::new().with_max_connections(5);
805 /// ```
806 pub fn with_max_connections(mut self, max_connections: u64) -> VectorIndexConfigBuilder {
807 self.max_connections = Some(max_connections);
808 self
809 }
810
811 /// Add a value to the optional `dynamic_ef_min` value of the VectorIndexConfig.
812 ///
813 /// # Parameters
814 /// - dynamic_ef_min: the dynamic_ef_min to use for the vector index config
815 ///
816 /// # Example
817 /// ```rust
818 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
819 ///
820 /// let builder = VectorIndexConfigBuilder::new().with_dynamic_ef_min(5);
821 /// ```
822 pub fn with_dynamic_ef_min(mut self, dynamic_ef_min: i64) -> VectorIndexConfigBuilder {
823 self.dynamic_ef_min = Some(dynamic_ef_min);
824 self
825 }
826
827 /// Add a value to the optional `dynamic_ef_max` value of the VectorIndexConfig.
828 ///
829 /// # Parameters
830 /// - dynamic_ef_max: the dynamic_ef_max to use for the vector index config
831 ///
832 /// # Example
833 /// ```rust
834 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
835 ///
836 /// let builder = VectorIndexConfigBuilder::new().with_dynamic_ef_max(10);
837 /// ```
838 pub fn with_dynamic_ef_max(mut self, dynamic_ef_max: i64) -> VectorIndexConfigBuilder {
839 self.dynamic_ef_max = Some(dynamic_ef_max);
840 self
841 }
842
843 /// Add a value to the optional `dynamic_ef_factor` value of the VectorIndexConfig.
844 ///
845 /// # Parameters
846 /// - dynamic_ef_factor: the dynamic_ef_factor to use for the vector index config
847 ///
848 /// # Example
849 /// ```rust
850 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
851 ///
852 /// let builder = VectorIndexConfigBuilder::new().with_dynamic_ef_factor(3);
853 /// ```
854 pub fn with_dynamic_ef_factor(mut self, dynamic_ef_factor: i64) -> VectorIndexConfigBuilder {
855 self.dynamic_ef_factor = Some(dynamic_ef_factor);
856 self
857 }
858
859 /// Add a value to the optional `vector_cache_max_objects` value of the VectorIndexConfig.
860 ///
861 /// # Parameters
862 /// - vector_cache_max_objects: the vector_cache_max_objects to use for the vector index config
863 ///
864 /// # Example
865 /// ```rust
866 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
867 ///
868 /// let builder = VectorIndexConfigBuilder::new().with_vector_cache_max_objects(3);
869 /// ```
870 pub fn with_vector_cache_max_objects(
871 mut self,
872 vector_cache_max_objects: u64,
873 ) -> VectorIndexConfigBuilder {
874 self.vector_cache_max_objects = Some(vector_cache_max_objects);
875 self
876 }
877
878 /// Add a value to the optional `flat_search_cut_off` value of the VectorIndexConfig.
879 ///
880 /// # Parameters
881 /// - flat_search_cut_off: the flat_search_cut_off to use for the vector index config
882 ///
883 /// # Example
884 /// ```rust
885 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
886 ///
887 /// let builder = VectorIndexConfigBuilder::new().with_flat_search_cut_off(3);
888 /// ```
889 pub fn with_flat_search_cut_off(
890 mut self,
891 flat_search_cut_off: u64,
892 ) -> VectorIndexConfigBuilder {
893 self.flat_search_cut_off = Some(flat_search_cut_off);
894 self
895 }
896
897 /// Add a value to the optional `cleanup_interval_seconds` value of the VectorIndexConfig.
898 ///
899 /// # Parameters
900 /// - cleanup_interval_seconds: the cleanup_interval_seconds to use for the vector index config
901 ///
902 /// # Example
903 /// ```rust
904 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
905 ///
906 /// let builder = VectorIndexConfigBuilder::new().with_cleanup_interval_seconds(3);
907 /// ```
908 pub fn with_cleanup_interval_seconds(
909 mut self,
910 cleanup_interval_seconds: u64,
911 ) -> VectorIndexConfigBuilder {
912 self.cleanup_interval_seconds = Some(cleanup_interval_seconds);
913 self
914 }
915
916 /// Add a value to the optional `pq` value of the VectorIndexConfig.
917 ///
918 /// # Parameters
919 /// - pq: the pq config to use for the vector index config
920 ///
921 /// # Example
922 /// ```rust
923 /// use weaviate_community::collections::schema::{
924 /// VectorIndexConfigBuilder,
925 /// PqConfig
926 /// };
927 ///
928 /// let pq_config = PqConfig::builder().build();
929 /// let builder = VectorIndexConfigBuilder::new().with_pq(pq_config);
930 /// ```
931 pub fn with_pq(mut self, pq: PqConfig) -> VectorIndexConfigBuilder {
932 self.pq = Some(pq);
933 self
934 }
935
936 /// Add a value to the optional `skip` value of the VectorIndexConfig.
937 ///
938 /// # Parameters
939 /// - skip: the skip to use for the vector index config
940 ///
941 /// # Example
942 /// ```rust
943 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
944 ///
945 /// let builder = VectorIndexConfigBuilder::new().with_skip(true);
946 /// ```
947 pub fn with_skip(mut self, skip: bool) -> VectorIndexConfigBuilder {
948 self.skip = Some(skip);
949 self
950 }
951
952 /// Build the VectorIndexConfig from the VectorIndexConfigBuilder
953 ///
954 /// # Example
955 /// Using VectorIndexConfigBuilder
956 /// ```rust
957 /// use weaviate_community::collections::schema::VectorIndexConfigBuilder;
958 ///
959 /// let config = VectorIndexConfigBuilder::new().build();
960 /// ```
961 ///
962 /// Using VectorIndexConfig
963 /// ```rust
964 /// use weaviate_community::collections::schema::VectorIndexConfig;
965 ///
966 /// let config = VectorIndexConfig::builder().build();
967 /// ```
968 pub fn build(self) -> VectorIndexConfig {
969 VectorIndexConfig {
970 distance: self.distance,
971 ef: self.ef,
972 ef_construction: self.ef_construction,
973 max_connections: self.max_connections,
974 dynamic_ef_min: self.dynamic_ef_min,
975 dynamic_ef_max: self.dynamic_ef_max,
976 dynamic_ef_factor: self.dynamic_ef_factor,
977 vector_cache_max_objects: self.vector_cache_max_objects,
978 flat_search_cut_off: self.flat_search_cut_off,
979 cleanup_interval_seconds: self.cleanup_interval_seconds,
980 pq: self.pq,
981 skip: self.skip,
982 }
983 }
984}
985
986/// The configuration options for pq
987#[derive(Serialize, Deserialize, Debug)]
988#[serde(rename_all = "camelCase")]
989pub struct PqConfig {
990 #[serde(skip_serializing_if = "Option::is_none")]
991 #[serde(default)]
992 pub enabled: Option<bool>,
993 #[serde(skip_serializing_if = "Option::is_none")]
994 #[serde(default)]
995 pub training_limit: Option<u64>,
996 #[serde(skip_serializing_if = "Option::is_none")]
997 #[serde(default)]
998 pub segments: Option<u64>,
999 #[serde(skip_serializing_if = "Option::is_none")]
1000 #[serde(default)]
1001 pub centroids: Option<u64>,
1002 #[serde(skip_serializing_if = "Option::is_none")]
1003 #[serde(default)]
1004 pub encoder: Option<EncoderConfig>,
1005 #[serde(skip_serializing_if = "Option::is_none")]
1006 #[serde(default)]
1007 pub bit_compression: Option<bool>,
1008}
1009
1010impl PqConfig {
1011 /// Create a new builder for the PqConfig object.
1012 ///
1013 /// This is the same as `PqConfigBuilder::new()`.
1014 ///
1015 /// # Example
1016 /// ```rust
1017 /// use weaviate_community::collections::schema::PqConfigBuilder;
1018 ///
1019 /// let builder = PqConfigBuilder::new();
1020 /// ```
1021 pub fn builder() -> PqConfigBuilder {
1022 PqConfigBuilder::default()
1023 }
1024}
1025
1026/// PqConfigBuilder for building a new PqConfig
1027#[derive(Default)]
1028pub struct PqConfigBuilder {
1029 pub enabled: Option<bool>,
1030 pub training_limit: Option<u64>,
1031 pub segments: Option<u64>,
1032 pub centroids: Option<u64>,
1033 pub encoder: Option<EncoderConfig>,
1034 pub bit_compression: Option<bool>,
1035}
1036
1037impl PqConfigBuilder {
1038 /// Create a new builder for the PqConfig object.
1039 ///
1040 /// This is the same as `PqConfig::builder()`.
1041 ///
1042 /// # Example
1043 /// ```rust
1044 /// use weaviate_community::collections::schema::PqConfigBuilder;
1045 ///
1046 /// let builder = PqConfigBuilder::new();
1047 /// ```
1048 pub fn new() -> PqConfigBuilder {
1049 PqConfigBuilder {
1050 enabled: None,
1051 training_limit: None,
1052 segments: None,
1053 centroids: None,
1054 encoder: None,
1055 bit_compression: None,
1056 }
1057 }
1058
1059 /// Add a value to the optional `enabled` value of the PqConfig.
1060 ///
1061 /// # Parameters
1062 /// - enabled: the enabled value to use for the pq config
1063 ///
1064 /// # Example
1065 /// ```rust
1066 /// use weaviate_community::collections::schema::PqConfigBuilder;
1067 ///
1068 /// let builder = PqConfigBuilder::new().with_enabled(true);
1069 /// ```
1070 pub fn with_enabled(mut self, enabled: bool) -> PqConfigBuilder {
1071 self.enabled = Some(enabled);
1072 self
1073 }
1074
1075 /// Add a value to the optional `training_limit` value of the PqConfig.
1076 ///
1077 /// # Parameters
1078 /// - training_limit: the training_limit value to use for the pq config
1079 ///
1080 /// # Example
1081 /// ```rust
1082 /// use weaviate_community::collections::schema::PqConfigBuilder;
1083 ///
1084 /// let builder = PqConfigBuilder::new().with_training_limit(100);
1085 /// ```
1086 pub fn with_training_limit(mut self, training_limit: u64) -> PqConfigBuilder {
1087 self.training_limit = Some(training_limit);
1088 self
1089 }
1090
1091 /// Add a value to the optional `segments` value of the PqConfig.
1092 ///
1093 /// # Parameters
1094 /// - segments: the segments value to use for the pq config
1095 ///
1096 /// # Example
1097 /// ```rust
1098 /// use weaviate_community::collections::schema::PqConfigBuilder;
1099 ///
1100 /// let builder = PqConfigBuilder::new().with_segments(100);
1101 /// ```
1102 pub fn with_segments(mut self, segments: u64) -> PqConfigBuilder {
1103 self.segments = Some(segments);
1104 self
1105 }
1106
1107 /// Add a value to the optional `centroids` value of the PqConfig.
1108 ///
1109 /// # Parameters
1110 /// - centroids: the centroids value to use for the pq config
1111 ///
1112 /// # Example
1113 /// ```rust
1114 /// use weaviate_community::collections::schema::PqConfigBuilder;
1115 ///
1116 /// let builder = PqConfigBuilder::new().with_centroids(20);
1117 /// ```
1118 pub fn with_centroids(mut self, centroids: u64) -> PqConfigBuilder {
1119 self.centroids = Some(centroids);
1120 self
1121 }
1122
1123 /// Add a value to the optional `encoder` value of the PqConfig.
1124 ///
1125 /// # Parameters
1126 /// - encoder: the encoder config to use for the pq config
1127 ///
1128 /// # Example
1129 /// ```rust
1130 /// use weaviate_community::collections::schema::{
1131 /// PqConfigBuilder,
1132 /// EncoderConfig,
1133 /// EncoderType
1134 /// };
1135 ///
1136 /// let encoder_config = EncoderConfig::builder(EncoderType::KMEANS).build();
1137 /// let builder = PqConfigBuilder::new().with_encoder(encoder_config);
1138 /// ```
1139 pub fn with_encoder(mut self, encoder: EncoderConfig) -> PqConfigBuilder {
1140 self.encoder = Some(encoder);
1141 self
1142 }
1143
1144 /// Add a value to the optional `bit_compression` value of the PqConfig.
1145 ///
1146 /// # Parameters
1147 /// - bit_compression: the bit compression value to use for the pq config
1148 ///
1149 /// # Example
1150 /// ```rust
1151 /// use weaviate_community::collections::schema::PqConfigBuilder;
1152 ///
1153 /// let builder = PqConfigBuilder::new().with_bit_compression(true);
1154 /// ```
1155 pub fn with_bit_compression(mut self, bit_compression: bool) -> PqConfigBuilder {
1156 self.bit_compression = Some(bit_compression);
1157 self
1158 }
1159
1160 /// Build the PqConfig from the PqConfigBuilder
1161 ///
1162 /// # Example
1163 /// Using PqConfigBuilder
1164 /// ```rust
1165 /// use weaviate_community::collections::schema::PqConfigBuilder;
1166 ///
1167 /// let config = PqConfigBuilder::new().build();
1168 /// ```
1169 ///
1170 /// Using PqConfig
1171 /// ```rust
1172 /// use weaviate_community::collections::schema::PqConfig;
1173 ///
1174 /// let config = PqConfig::builder().build();
1175 /// ```
1176 pub fn build(self) -> PqConfig {
1177 PqConfig {
1178 enabled: self.enabled,
1179 training_limit: self.training_limit,
1180 segments: self.segments,
1181 centroids: self.centroids,
1182 encoder: self.encoder,
1183 bit_compression: self.bit_compression,
1184 }
1185 }
1186}
1187
1188/// The configuration options for an encoder
1189///
1190/// - distribution
1191/// - encoder_type
1192#[derive(Serialize, Deserialize, Debug)]
1193pub struct EncoderConfig {
1194 #[serde(skip_serializing_if = "Option::is_none")]
1195 #[serde(default)]
1196 pub distribution: Option<Distribution>,
1197
1198 #[serde(rename = "type")]
1199 pub encoder_type: EncoderType,
1200}
1201
1202impl EncoderConfig {
1203 /// Create a new builder for the EncoderConfig object.
1204 ///
1205 /// This is the same as `EncoderConfigBuilder::new()`.
1206 ///
1207 /// # Parameters
1208 /// - encoder_type: the encoder type to use for the encoder config
1209 ///
1210 /// # Example
1211 /// ```rust
1212 /// use weaviate_community::collections::schema::{EncoderConfig, EncoderType};
1213 ///
1214 /// let builder = EncoderConfig::builder(EncoderType::KMEANS);
1215 /// ```
1216 pub fn builder(encoder_type: EncoderType) -> EncoderConfigBuilder {
1217 EncoderConfigBuilder::new(encoder_type)
1218 }
1219}
1220
1221/// PqConfigBuilder for building a new PqConfig
1222pub struct EncoderConfigBuilder {
1223 pub distribution: Option<Distribution>,
1224 pub encoder_type: EncoderType,
1225}
1226
1227impl EncoderConfigBuilder {
1228 /// Create a new builder for the EncoderConfig object.
1229 ///
1230 /// This is the same as `EncoderConfig::builder()`.
1231 ///
1232 /// # Parameters
1233 /// - encoder_type: the encoder type to use for the encoder config
1234 ///
1235 /// # Example
1236 /// ```rust
1237 /// use weaviate_community::collections::schema::{EncoderConfigBuilder, EncoderType};
1238 ///
1239 /// let builder = EncoderConfigBuilder::new(EncoderType::KMEANS);
1240 /// ```
1241 pub fn new(encoder_type: EncoderType) -> EncoderConfigBuilder {
1242 EncoderConfigBuilder {
1243 distribution: None,
1244 encoder_type,
1245 }
1246 }
1247
1248 /// Add a value to the optional `distribution` value of the EncoderConfig.
1249 ///
1250 /// # Parameters
1251 /// - distribution: the distribution to use for the encoder config
1252 ///
1253 /// # Example
1254 /// ```rust
1255 /// use weaviate_community::collections::schema::{
1256 /// EncoderConfigBuilder,
1257 /// EncoderType,
1258 /// Distribution
1259 /// };
1260 ///
1261 /// let builder = EncoderConfigBuilder::new(EncoderType::KMEANS)
1262 /// .with_distribution(Distribution::LOGNORMAL);
1263 /// ```
1264 pub fn with_distribution(mut self, distribution: Distribution) -> EncoderConfigBuilder {
1265 self.distribution = Some(distribution);
1266 self
1267 }
1268
1269 /// Build the PqConfig from the PqConfigBuilder
1270 ///
1271 /// # Example
1272 /// Using PqConfigBuilder
1273 /// ```rust
1274 /// use weaviate_community::collections::schema::{EncoderConfigBuilder, EncoderType};
1275 ///
1276 /// let config = EncoderConfigBuilder::new(EncoderType::KMEANS).build();
1277 /// ```
1278 ///
1279 /// Using PqConfig
1280 /// ```rust
1281 /// use weaviate_community::collections::schema::{EncoderConfig, EncoderType};
1282 ///
1283 /// let config = EncoderConfig::builder(EncoderType::KMEANS).build();
1284 /// ```
1285 pub fn build(self) -> EncoderConfig {
1286 EncoderConfig {
1287 distribution: self.distribution,
1288 encoder_type: self.encoder_type,
1289 }
1290 }
1291}
1292
1293/// Strict definitions of distributions.
1294///
1295/// Currently, Weaviate only allows log-normal and normal for kmeans
1296#[derive(Serialize, Deserialize, Debug)]
1297pub enum Distribution {
1298 #[serde(rename = "log-normal")]
1299 LOGNORMAL,
1300 #[serde(rename = "normal")]
1301 NORMAL,
1302}
1303
1304/// Strict definitions of encoders.
1305///
1306/// Currently only supports KMeans and Tile
1307#[derive(Serialize, Deserialize, Debug)]
1308pub enum EncoderType {
1309 #[serde(rename = "kmeans")]
1310 KMEANS,
1311 #[serde(rename = "tile")]
1312 TILE,
1313}
1314
1315/// Strict definitions of distance metrics.
1316///
1317/// Currently only supports the following:
1318/// - Cosine
1319/// - Dot
1320/// - L2 squared
1321/// - Hamming
1322/// - Manhattan
1323#[derive(Serialize, Deserialize, Debug)]
1324#[serde(rename_all = "camelCase")]
1325pub enum DistanceMetric {
1326 #[serde(rename = "cosine")]
1327 COSINE,
1328 #[serde(rename = "dot")]
1329 DOT,
1330 #[serde(rename = "l2-squared")]
1331 L2SQUARED,
1332 #[serde(rename = "hamming")]
1333 HAMMING,
1334 #[serde(rename = "manhattan")]
1335 MANHATTAN,
1336}
1337
1338/// The configuration options for ShardingConfig.
1339#[derive(Serialize, Deserialize, Debug)]
1340#[serde(rename_all = "camelCase")]
1341pub struct ShardingConfig {
1342 #[serde(skip_serializing_if = "Option::is_none")]
1343 #[serde(default)]
1344 pub virtual_per_physical: Option<u64>,
1345 #[serde(skip_serializing_if = "Option::is_none")]
1346 #[serde(default)]
1347 pub desired_count: Option<u64>,
1348 #[serde(skip_serializing_if = "Option::is_none")]
1349 #[serde(default)]
1350 pub actual_count: Option<u64>, // this could be problematic, it is read only
1351 #[serde(skip_serializing_if = "Option::is_none")]
1352 #[serde(default)]
1353 pub desired_virtual_count: Option<u64>,
1354 #[serde(skip_serializing_if = "Option::is_none")]
1355 #[serde(default)]
1356 pub actual_virtual_count: Option<u64>, // this could be problematic, it is read only
1357 #[serde(skip_serializing_if = "Option::is_none")]
1358 pub key: Option<ShardingKey>,
1359 #[serde(skip_serializing_if = "Option::is_none")]
1360 pub strategy: Option<ShardingStrategy>,
1361 #[serde(skip_serializing_if = "Option::is_none")]
1362 pub function: Option<ShardingFunction>,
1363}
1364
1365impl ShardingConfig {
1366 /// Create a new builder for the ShardingConfig object.
1367 ///
1368 /// This is the same as `ShardingConfigBuilder::new()`.
1369 ///
1370 /// # Example
1371 /// ```rust
1372 /// use weaviate_community::collections::schema::ShardingConfig;
1373 ///
1374 /// let builder = ShardingConfig::builder();
1375 /// ```
1376 pub fn builder() -> ShardingConfigBuilder {
1377 ShardingConfigBuilder::default()
1378 }
1379}
1380
1381/// ShardingConfigBuilder for building a new ShardingConfig
1382#[derive(Default)]
1383pub struct ShardingConfigBuilder {
1384 pub virtual_per_physical: Option<u64>,
1385 pub desired_count: Option<u64>,
1386 pub actual_count: Option<u64>, // this could be problematic, it is read only
1387 pub desired_virtual_count: Option<u64>,
1388 pub actual_virtual_count: Option<u64>, // this could be problematic, it is read only
1389 pub key: Option<ShardingKey>,
1390 pub strategy: Option<ShardingStrategy>,
1391 pub function: Option<ShardingFunction>,
1392}
1393
1394impl ShardingConfigBuilder {
1395 /// Create a new builder for the ShardingConfig object.
1396 ///
1397 /// This is the same as `ShardingConfig::builder()`.
1398 ///
1399 /// # Example
1400 /// ```rust
1401 /// use weaviate_community::collections::schema::ShardingConfigBuilder;
1402 ///
1403 /// let builder = ShardingConfigBuilder::new();
1404 /// ```
1405 pub fn new() -> ShardingConfigBuilder {
1406 ShardingConfigBuilder {
1407 virtual_per_physical: None,
1408 desired_count: None,
1409 actual_count: None,
1410 desired_virtual_count: None,
1411 actual_virtual_count: None,
1412 key: None,
1413 strategy: None,
1414 function: None,
1415 }
1416 }
1417
1418 /// Add a value to the optional `virtual_per_physical` value of the ShardingConfig.
1419 ///
1420 /// # Parameters
1421 /// - virtual_per_physical: the virtual per physical to use for the sharding config
1422 ///
1423 /// # Example
1424 /// ```rust
1425 /// use weaviate_community::collections::schema::ShardingConfigBuilder;
1426 ///
1427 /// let builder = ShardingConfigBuilder::new()
1428 /// .with_virtual_per_physical(10);
1429 /// ```
1430 pub fn with_virtual_per_physical(mut self, virtual_per_physical: u64) -> ShardingConfigBuilder {
1431 self.virtual_per_physical = Some(virtual_per_physical);
1432 self
1433 }
1434
1435 /// Add a value to the optional `desired_count` value of the ShardingConfig.
1436 ///
1437 /// # Parameters
1438 /// - desired_count: the desired count to use for the sharding config
1439 ///
1440 /// # Example
1441 /// ```rust
1442 /// use weaviate_community::collections::schema::ShardingConfigBuilder;
1443 ///
1444 /// let builder = ShardingConfigBuilder::new()
1445 /// .with_desired_count(10);
1446 /// ```
1447 pub fn with_desired_count(mut self, desired_count: u64) -> ShardingConfigBuilder {
1448 self.desired_count = Some(desired_count);
1449 self
1450 }
1451
1452 /// Add a value to the optional `actual_count` value of the ShardingConfig.
1453 ///
1454 /// # Parameters
1455 /// - actual_count: the actual count to use for the sharding config
1456 ///
1457 /// # Example
1458 /// ```rust
1459 /// use weaviate_community::collections::schema::ShardingConfigBuilder;
1460 ///
1461 /// let builder = ShardingConfigBuilder::new()
1462 /// .with_actual_count(10);
1463 /// ```
1464 pub fn with_actual_count(mut self, actual_count: u64) -> ShardingConfigBuilder {
1465 self.actual_count = Some(actual_count);
1466 self
1467 }
1468
1469 /// Add a value to the optional `desired_virtual_count` value of the ShardingConfig.
1470 ///
1471 /// # Parameters
1472 /// - desired_virtual_count: the desired virtual count to use for the sharding config
1473 ///
1474 /// # Example
1475 /// ```rust
1476 /// use weaviate_community::collections::schema::ShardingConfigBuilder;
1477 ///
1478 /// let builder = ShardingConfigBuilder::new()
1479 /// .with_desired_virtual_count(10);
1480 /// ```
1481 pub fn with_desired_virtual_count(
1482 mut self,
1483 desired_virtual_count: u64,
1484 ) -> ShardingConfigBuilder {
1485 self.desired_virtual_count = Some(desired_virtual_count);
1486 self
1487 }
1488
1489 /// Add a value to the optional `actual_virtual_count` value of the ShardingConfig.
1490 ///
1491 /// # Parameters
1492 /// - actual_virtual_count: the actual virtual count to use for the sharding config
1493 ///
1494 /// # Example
1495 /// ```rust
1496 /// use weaviate_community::collections::schema::ShardingConfigBuilder;
1497 ///
1498 /// let builder = ShardingConfigBuilder::new()
1499 /// .with_actual_virtual_count(10);
1500 /// ```
1501 pub fn with_actual_virtual_count(mut self, actual_virtual_count: u64) -> ShardingConfigBuilder {
1502 self.actual_virtual_count = Some(actual_virtual_count);
1503 self
1504 }
1505
1506 /// Add a value to the optional `key` value of the ShardingConfig.
1507 ///
1508 /// # Parameters
1509 /// - key: the sharding key to use for the sharding config
1510 ///
1511 /// # Example
1512 /// ```rust
1513 /// use weaviate_community::collections::schema::{ShardingConfigBuilder, ShardingKey};
1514 ///
1515 /// let builder = ShardingConfigBuilder::new()
1516 /// .with_key(ShardingKey::_ID);
1517 /// ```
1518 pub fn with_key(mut self, key: ShardingKey) -> ShardingConfigBuilder {
1519 self.key = Some(key);
1520 self
1521 }
1522
1523 /// Add a value to the optional `strategy` value of the ShardingConfig.
1524 ///
1525 /// # Parameters
1526 /// - strategy: the sharding strategy to use for the sharding config
1527 ///
1528 /// # Example
1529 /// ```rust
1530 /// use weaviate_community::collections::schema::{ShardingConfigBuilder, ShardingStrategy};
1531 ///
1532 /// let builder = ShardingConfigBuilder::new()
1533 /// .with_strategy(ShardingStrategy::HASH);
1534 /// ```
1535 pub fn with_strategy(mut self, strategy: ShardingStrategy) -> ShardingConfigBuilder {
1536 self.strategy = Some(strategy);
1537 self
1538 }
1539
1540 /// Add a value to the optional `function` value of the ShardingConfig.
1541 ///
1542 /// # Parameters
1543 /// - function: the sharding function to use for the sharding config
1544 ///
1545 /// # Example
1546 /// ```rust
1547 /// use weaviate_community::collections::schema::{ShardingConfigBuilder, ShardingFunction};
1548 ///
1549 /// let builder = ShardingConfigBuilder::new()
1550 /// .with_function(ShardingFunction::MURMUR3);
1551 /// ```
1552 pub fn with_function(mut self, function: ShardingFunction) -> ShardingConfigBuilder {
1553 self.function = Some(function);
1554 self
1555 }
1556
1557 /// Build the PqConfig from the PqConfigBuilder
1558 ///
1559 /// # Example
1560 /// Using PqConfigBuilder
1561 /// ```rust
1562 /// use weaviate_community::collections::schema::ShardingConfigBuilder;
1563 ///
1564 /// let config = ShardingConfigBuilder::new().build();
1565 /// ```
1566 ///
1567 /// Using PqConfig
1568 /// ```rust
1569 /// use weaviate_community::collections::schema::ShardingConfig;
1570 ///
1571 /// let config = ShardingConfig::builder().build();
1572 /// ```
1573 pub fn build(self) -> ShardingConfig {
1574 ShardingConfig {
1575 virtual_per_physical: self.virtual_per_physical,
1576 desired_count: self.desired_count,
1577 actual_count: self.actual_count,
1578 desired_virtual_count: self.desired_virtual_count,
1579 actual_virtual_count: self.actual_virtual_count,
1580 key: self.key,
1581 strategy: self.strategy,
1582 function: self.function,
1583 }
1584 }
1585}
1586
1587/// Strict definitions of sharding keys.
1588///
1589/// The default will usually be _ID, unless MultiTenancy is enabled, where the
1590/// default will be an empty string.
1591#[derive(Serialize, Deserialize, Debug)]
1592pub enum ShardingKey {
1593 #[serde(rename = "_id")]
1594 _ID,
1595 #[serde(rename = "")]
1596 MultiTenancyEnabled,
1597}
1598
1599/// Strict definitions of sharding strategies.
1600///
1601/// The default will usually be HASH, unless MultiTenancy is enabled, where the
1602/// default will be an empty string.
1603#[derive(Serialize, Deserialize, Debug)]
1604pub enum ShardingStrategy {
1605 #[serde(rename = "hash")]
1606 HASH,
1607 #[serde(rename = "")]
1608 MultiTenancyEnabled,
1609}
1610
1611/// Strict definitions of sharding functions.
1612///
1613/// The default will usually be MURMUR3, unless MultiTenancy is enabled, where the
1614/// default will be an empty string.
1615#[derive(Serialize, Deserialize, Debug)]
1616pub enum ShardingFunction {
1617 #[serde(rename = "murmur3")]
1618 MURMUR3,
1619 #[serde(rename = "")]
1620 MultiTenancyEnabled,
1621}
1622
1623/// MultiTenancyConfig holds the configuration options for multi tenancy.
1624#[derive(Serialize, Deserialize, Debug)]
1625pub struct MultiTenancyConfig {
1626 pub enabled: bool,
1627}
1628
1629impl MultiTenancyConfig {
1630 /// Create a new MultiTenancyConfig
1631 ///
1632 /// # Parameters
1633 /// - enabled: to enable multi tenancy or not
1634 ///
1635 /// # Example
1636 /// ```rust
1637 /// use weaviate_community::collections::schema::MultiTenancyConfig;
1638 ///
1639 /// let config = MultiTenancyConfig::new(true);
1640 /// ```
1641 pub fn new(enabled: bool) -> MultiTenancyConfig {
1642 MultiTenancyConfig { enabled }
1643 }
1644}
1645
1646/// The configuration options for InvertedIndexConfig
1647#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
1648#[serde(rename_all = "camelCase")]
1649pub struct InvertedIndexConfig {
1650 #[serde(skip_serializing_if = "Option::is_none")]
1651 #[serde(default)]
1652 pub stopwords: Option<StopwordsConfig>, // revisit
1653 #[serde(skip_serializing_if = "Option::is_none")]
1654 #[serde(default)]
1655 pub index_timestamps: Option<bool>,
1656 #[serde(skip_serializing_if = "Option::is_none")]
1657 #[serde(default)]
1658 pub index_null_state: Option<bool>,
1659 #[serde(skip_serializing_if = "Option::is_none")]
1660 #[serde(default)]
1661 pub index_property_length: Option<bool>,
1662 #[serde(skip_serializing_if = "Option::is_none")]
1663 #[serde(default)]
1664 pub bm25: Option<Bm25>,
1665 #[serde(skip_serializing_if = "Option::is_none")]
1666 #[serde(default)]
1667 pub cleanup_interval_seconds: Option<u64>,
1668}
1669
1670impl InvertedIndexConfig {
1671 /// Create a new builder for the InvertedIndexConfig object.
1672 ///
1673 /// This is the same as `InvertedIndexConfigBuilder::new()`.
1674 ///
1675 /// # Example
1676 /// ```rust
1677 /// use weaviate_community::collections::schema::InvertedIndexConfig;
1678 ///
1679 /// let builder = InvertedIndexConfig::builder();
1680 /// ```
1681 pub fn builder() -> InvertedIndexConfigBuilder {
1682 InvertedIndexConfigBuilder::default()
1683 }
1684}
1685
1686/// InvertedIndexConfigBuilder for building a new InvertedIndexConfig
1687#[derive(Default)]
1688pub struct InvertedIndexConfigBuilder {
1689 pub stopwords: Option<StopwordsConfig>, // revisit
1690 pub index_timestamps: Option<bool>,
1691 pub index_null_state: Option<bool>,
1692 pub index_property_length: Option<bool>,
1693 pub bm25: Option<Bm25>,
1694 pub cleanup_interval_seconds: Option<u64>,
1695}
1696
1697impl InvertedIndexConfigBuilder {
1698 /// Create a new builder for the InvertedIndexConfig object.
1699 ///
1700 /// This is the same as `InvertedIndexConfig::builder()`.
1701 ///
1702 /// # Example
1703 /// ```rust
1704 /// use weaviate_community::collections::schema::InvertedIndexConfigBuilder;
1705 ///
1706 /// let builder = InvertedIndexConfigBuilder::new();
1707 /// ```
1708 pub fn new() -> InvertedIndexConfigBuilder {
1709 InvertedIndexConfigBuilder {
1710 stopwords: None,
1711 index_timestamps: None,
1712 index_null_state: None,
1713 index_property_length: None,
1714 bm25: None,
1715 cleanup_interval_seconds: None,
1716 }
1717 }
1718
1719 /// Add a value to the optional `stopwords` value of the InvertedIndexConfig.
1720 ///
1721 /// # Parameters
1722 /// - stopwords: the stopwords to use for the inverted index config
1723 ///
1724 /// # Example
1725 /// ```rust
1726 /// use weaviate_community::collections::schema::{InvertedIndexConfigBuilder, StopwordsConfig};
1727 ///
1728 /// let stopwords = StopwordsConfig::builder().build();
1729 /// let builder = InvertedIndexConfigBuilder::new().with_stopwords(stopwords);
1730 /// ```
1731 pub fn with_stopwords(mut self, stopwords: StopwordsConfig) -> InvertedIndexConfigBuilder {
1732 self.stopwords = Some(stopwords);
1733 self
1734 }
1735
1736 /// Add a value to the optional `index_timestamps` value of the InvertedIndexConfig.
1737 ///
1738 /// # Parameters
1739 /// - index_timestamps: the index timestamps setting to use for the inverted index config
1740 ///
1741 /// # Example
1742 /// ```rust
1743 /// use weaviate_community::collections::schema::InvertedIndexConfigBuilder;
1744 ///
1745 /// let builder = InvertedIndexConfigBuilder::new().with_index_timestamps(true);
1746 /// ```
1747 pub fn with_index_timestamps(mut self, index_timestamps: bool) -> InvertedIndexConfigBuilder {
1748 self.index_timestamps = Some(index_timestamps);
1749 self
1750 }
1751
1752 /// Add a value to the optional `index_null_state` value of the InvertedIndexConfig.
1753 ///
1754 /// # Parameters
1755 /// - index_null_state: the index null state setting to use for the inverted index config
1756 ///
1757 /// # Example
1758 /// ```rust
1759 /// use weaviate_community::collections::schema::InvertedIndexConfigBuilder;
1760 ///
1761 /// let builder = InvertedIndexConfigBuilder::new().with_index_null_state(true);
1762 /// ```
1763 pub fn with_index_null_state(mut self, index_null_state: bool) -> InvertedIndexConfigBuilder {
1764 self.index_null_state = Some(index_null_state);
1765 self
1766 }
1767
1768 /// Add a value to the optional `index_property_length` value of the InvertedIndexConfig.
1769 ///
1770 /// # Parameters
1771 /// - index_property_length: the index prop state setting to use for the inverted index config
1772 ///
1773 /// # Example
1774 /// ```rust
1775 /// use weaviate_community::collections::schema::InvertedIndexConfigBuilder;
1776 ///
1777 /// let builder = InvertedIndexConfigBuilder::new().with_index_property_length(true);
1778 /// ```
1779 pub fn with_index_property_length(
1780 mut self,
1781 index_property_length: bool,
1782 ) -> InvertedIndexConfigBuilder {
1783 self.index_property_length = Some(index_property_length);
1784 self
1785 }
1786
1787 /// Add a value to the optional `bm25` value of the InvertedIndexConfig.
1788 ///
1789 /// # Parameters
1790 /// - bm25: the bm25 config to use for the inverted index config
1791 ///
1792 /// # Example
1793 /// ```rust
1794 /// use weaviate_community::collections::schema::{InvertedIndexConfigBuilder, Bm25};
1795 ///
1796 /// let bm25 = Bm25::new(10.0, 10.0);
1797 /// let builder = InvertedIndexConfigBuilder::new().with_bm25(bm25);
1798 /// ```
1799 pub fn with_bm25(mut self, bm25: Bm25) -> InvertedIndexConfigBuilder {
1800 self.bm25 = Some(bm25);
1801 self
1802 }
1803
1804 /// Add a value to the optional `cleanup_interval_seconds` value of the InvertedIndexConfig.
1805 ///
1806 /// # Parameters
1807 /// - cleanup_interval_seconds: the cleanup_interval_seconds for the inverted index config
1808 ///
1809 /// # Example
1810 /// ```rust
1811 /// use weaviate_community::collections::schema::InvertedIndexConfigBuilder;
1812 ///
1813 /// let builder = InvertedIndexConfigBuilder::new().with_cleanup_interval_seconds(60);
1814 /// ```
1815 pub fn with_cleanup_interval_seconds(
1816 mut self,
1817 cleanup_interval_seconds: u64,
1818 ) -> InvertedIndexConfigBuilder {
1819 self.cleanup_interval_seconds = Some(cleanup_interval_seconds);
1820 self
1821 }
1822
1823 /// Build the InvertedIndexConfig from the InvertedIndexConfigBuilder
1824 ///
1825 /// # Example
1826 /// Using InvertedIndexConfigBuilder
1827 /// ```rust
1828 /// use weaviate_community::collections::schema::InvertedIndexConfigBuilder;
1829 ///
1830 /// let config = InvertedIndexConfigBuilder::new().build();
1831 /// ```
1832 ///
1833 /// Using InvertedIndexConfig
1834 /// ```rust
1835 /// use weaviate_community::collections::schema::InvertedIndexConfig;
1836 ///
1837 /// let config = InvertedIndexConfig::builder().build();
1838 /// ```
1839 pub fn build(self) -> InvertedIndexConfig {
1840 InvertedIndexConfig {
1841 stopwords: self.stopwords,
1842 index_timestamps: self.index_timestamps,
1843 index_null_state: self.index_null_state,
1844 index_property_length: self.index_property_length,
1845 bm25: self.bm25,
1846 cleanup_interval_seconds: self.cleanup_interval_seconds,
1847 }
1848 }
1849}
1850
1851/// The configuration options for Stopwords.
1852#[derive(Serialize, Deserialize, Debug, PartialEq)]
1853#[serde(rename_all = "camelCase")]
1854pub struct StopwordsConfig {
1855 #[serde(skip_serializing_if = "Option::is_none")]
1856 #[serde(default)]
1857 pub preset: Option<StopwordPreset>,
1858 #[serde(skip_serializing_if = "Option::is_none")]
1859 #[serde(default)]
1860 pub additions: Option<Vec<String>>,
1861 #[serde(skip_serializing_if = "Option::is_none")]
1862 #[serde(default)]
1863 pub removals: Option<Vec<String>>,
1864}
1865
1866impl StopwordsConfig {
1867 /// Create a new builder for the StopwordsConfig object.
1868 ///
1869 /// This is the same as `StopwordsConfigBuilder::new()`.
1870 ///
1871 /// # Example
1872 /// ```rust
1873 /// use weaviate_community::collections::schema::StopwordsConfig;
1874 ///
1875 /// let builder = StopwordsConfig::builder();
1876 /// ```
1877 pub fn builder() -> StopwordsConfigBuilder {
1878 StopwordsConfigBuilder::default()
1879 }
1880}
1881
1882/// StopwordsConfigBuilder for building a new StopwordsConfig
1883#[derive(Default)]
1884pub struct StopwordsConfigBuilder {
1885 pub preset: Option<StopwordPreset>,
1886 pub additions: Option<Vec<String>>,
1887 pub removals: Option<Vec<String>>,
1888}
1889
1890impl StopwordsConfigBuilder {
1891 /// Create a new builder for the StopwordsConfig object.
1892 ///
1893 /// This is the same as `StopwordsConfig::builder()`.
1894 ///
1895 /// # Example
1896 /// ```rust
1897 /// use weaviate_community::collections::schema::StopwordsConfigBuilder;
1898 ///
1899 /// let builder = StopwordsConfigBuilder::new();
1900 /// ```
1901 pub fn new() -> StopwordsConfigBuilder {
1902 StopwordsConfigBuilder {
1903 preset: None,
1904 additions: None,
1905 removals: None,
1906 }
1907 }
1908
1909 /// Add a value to the optional `preset` value of the StopwordsConfig.
1910 ///
1911 /// # Parameters
1912 /// - preset: the preset for the stopwords config
1913 ///
1914 /// # Example
1915 /// ```rust
1916 /// use weaviate_community::collections::schema::{StopwordsConfigBuilder, StopwordPreset};
1917 ///
1918 /// let builder = StopwordsConfigBuilder::new().with_preset(StopwordPreset::EN);
1919 /// ```
1920 pub fn with_preset(mut self, preset: StopwordPreset) -> StopwordsConfigBuilder {
1921 self.preset = Some(preset);
1922 self
1923 }
1924
1925 /// Add a value to the optional `additions` value of the StopwordsConfig.
1926 ///
1927 /// # Parameters
1928 /// - additions: the additions for the stopwords config
1929 ///
1930 /// # Example
1931 /// ```rust
1932 /// use weaviate_community::collections::schema::StopwordsConfigBuilder;
1933 ///
1934 /// let builder = StopwordsConfigBuilder::new().with_additions(vec!["word"]);
1935 /// ```
1936 pub fn with_additions(mut self, additions: Vec<&str>) -> StopwordsConfigBuilder {
1937 let additions = additions.iter().map(|field| field.to_string()).collect();
1938 self.additions = Some(additions);
1939 self
1940 }
1941
1942 /// Add a value to the optional `removals` value of the StopwordsConfig.
1943 ///
1944 /// # Parameters
1945 /// - removals: the removals for the stopwords config
1946 ///
1947 /// # Example
1948 /// ```rust
1949 /// use weaviate_community::collections::schema::StopwordsConfigBuilder;
1950 ///
1951 /// let builder = StopwordsConfigBuilder::new().with_removals(vec!["word"]);
1952 /// ```
1953 pub fn with_removals(mut self, removals: Vec<&str>) -> StopwordsConfigBuilder {
1954 let removals = removals.iter().map(|field| field.to_string()).collect();
1955 self.removals = Some(removals);
1956 self
1957 }
1958
1959 /// Build the StopwordsConfig from the StopwordsConfigBuilder.
1960 ///
1961 /// # Example
1962 /// Using StopwordsConfigBuilder
1963 /// ```rust
1964 /// use weaviate_community::collections::schema::StopwordsConfigBuilder;
1965 ///
1966 /// let config = StopwordsConfigBuilder::new().build();
1967 /// ```
1968 ///
1969 /// Using StopwordsConfig
1970 /// ```rust
1971 /// use weaviate_community::collections::schema::StopwordsConfig;
1972 ///
1973 /// let config = StopwordsConfig::builder().build();
1974 /// ```
1975 pub fn build(self) -> StopwordsConfig {
1976 StopwordsConfig {
1977 preset: self.preset,
1978 additions: self.additions,
1979 removals: self.removals,
1980 }
1981 }
1982}
1983
1984/// Strict definitions of Stopword presets.
1985///
1986/// Weaviate supports EN and NONE
1987#[derive(Serialize, Deserialize, Debug, PartialEq)]
1988pub enum StopwordPreset {
1989 #[serde(rename = "en")]
1990 EN,
1991 #[serde(rename = "none")]
1992 NONE,
1993}
1994
1995/// The configuration options for the ReplicationConfig
1996#[derive(Serialize, Deserialize, Debug)]
1997pub struct ReplicationConfig {
1998 pub factor: u64,
1999}
2000
2001impl ReplicationConfig {
2002 /// Create a new ReplicationConfig
2003 ///
2004 /// # Parameters
2005 /// - factor: the replication factor
2006 ///
2007 /// # Example
2008 /// ```rust
2009 /// use weaviate_community::collections::schema::ReplicationConfig;
2010 ///
2011 /// let config = ReplicationConfig::new(3);
2012 /// ```
2013 pub fn new(factor: u64) -> ReplicationConfig {
2014 ReplicationConfig { factor }
2015 }
2016}
2017
2018/// Tenants struct for encapsulating multiple tenants.
2019#[derive(Serialize, Deserialize, Debug)]
2020#[serde(rename_all = "camelCase")]
2021pub struct Tenants {
2022 pub tenants: Vec<Tenant>,
2023}
2024
2025impl Tenants {
2026 /// Create a new Tenants object
2027 ///
2028 /// # Parameters
2029 /// - tenants: the tenants to encapsulate
2030 ///
2031 /// # Example
2032 /// ```rust
2033 /// use weaviate_community::collections::schema::{Tenants, Tenant};
2034 ///
2035 /// let config = Tenants::new(
2036 /// vec![
2037 /// Tenant::builder("abcde").build(),
2038 /// Tenant::builder("fghij").build(),
2039 /// ]
2040 /// );
2041 /// ```
2042 pub fn new(tenants: Vec<Tenant>) -> Tenants {
2043 Tenants { tenants }
2044 }
2045}
2046
2047/// The configuration options for a Tenant.
2048#[derive(Serialize, Deserialize, Debug)]
2049#[serde(rename_all = "camelCase")]
2050pub struct Tenant {
2051 pub name: String,
2052 #[serde(default = "default_activity_status")]
2053 pub activity_status: Option<ActivityStatus>,
2054}
2055
2056/// Default activity status for a tenant
2057///
2058/// The default activity status for a tenant is HOT.
2059fn default_activity_status() -> Option<ActivityStatus> {
2060 Some(ActivityStatus::HOT)
2061}
2062
2063impl Tenant {
2064 /// Create a new builder for the Tenant object.
2065 ///
2066 /// This is the same as `TenantBuilder::new()`.
2067 ///
2068 /// # Parameters
2069 /// - name: the name of the tenant
2070 ///
2071 /// # Example
2072 /// ```rust
2073 /// use weaviate_community::collections::schema::Tenant;
2074 ///
2075 /// let builder = Tenant::builder("abcde");
2076 /// ```
2077 pub fn builder(name: &str) -> TenantBuilder {
2078 TenantBuilder::new(name)
2079 }
2080}
2081
2082/// TenantBuilder for building a new Tenant
2083pub struct TenantBuilder {
2084 name: String,
2085 activity_status: Option<ActivityStatus>,
2086}
2087
2088impl TenantBuilder {
2089 /// Create a new builder for the Tenant object.
2090 ///
2091 /// This is the same as `Tenant::builder()`.
2092 ///
2093 /// # Parameters
2094 /// - name: the name of the tenant
2095 ///
2096 /// # Example
2097 /// ```rust
2098 /// use weaviate_community::collections::schema::TenantBuilder;
2099 ///
2100 /// let builder = TenantBuilder::new("abcde");
2101 /// ```
2102 pub fn new(name: &str) -> TenantBuilder {
2103 TenantBuilder {
2104 name: name.into(),
2105 activity_status: None,
2106 }
2107 }
2108
2109 /// Add a value to the optional `activity_status` value of the Tenant.
2110 ///
2111 /// # Parameters
2112 /// - activity_status: the activity_status of the tenant
2113 ///
2114 /// # Example
2115 /// ```rust
2116 /// use weaviate_community::collections::schema::{TenantBuilder, ActivityStatus};
2117 ///
2118 /// let builder = TenantBuilder::new("abcde").with_activity_status(ActivityStatus::HOT);
2119 /// ```
2120 pub fn with_activity_status(mut self, activity_status: ActivityStatus) -> TenantBuilder {
2121 self.activity_status = Some(activity_status);
2122 self
2123 }
2124
2125 /// Build the Tenant from the TenantBuilder.
2126 ///
2127 /// # Example
2128 /// Using TenantBuilder
2129 /// ```rust
2130 /// use weaviate_community::collections::schema::TenantBuilder;
2131 ///
2132 /// let config = TenantBuilder::new("abcde").build();
2133 /// ```
2134 ///
2135 /// Using Tenant
2136 /// ```rust
2137 /// use weaviate_community::collections::schema::Tenant;
2138 ///
2139 /// let config = Tenant::builder("abcde").build();
2140 /// ```
2141 pub fn build(self) -> Tenant {
2142 Tenant {
2143 name: self.name,
2144 activity_status: self.activity_status,
2145 }
2146 }
2147}
2148
2149/// Strict definitions of ActivityStatus of a tenant.
2150///
2151/// The activity status of a tenant can either be `hot` or `cold`.
2152#[derive(Serialize, Deserialize, Debug)]
2153pub enum ActivityStatus {
2154 HOT,
2155 COLD,
2156}
2157
2158/// The configuration options for BM25.
2159#[derive(Serialize, Deserialize, Debug, PartialEq)]
2160pub struct Bm25 {
2161 pub b: f64,
2162 pub k1: f64,
2163}
2164
2165impl Bm25 {
2166 /// Create a new Bm25 object
2167 ///
2168 /// # Parameters
2169 /// - b: the b value to set
2170 /// - k1: the k1 value to set
2171 ///
2172 /// # Example
2173 /// ```rust
2174 /// use weaviate_community::collections::schema::Bm25;
2175 ///
2176 /// let config = Bm25::new(10.0, 10.0);
2177 /// ```
2178 pub fn new(b: f64, k1: f64) -> Bm25 {
2179 Bm25 { b, k1 }
2180 }
2181}
2182
2183/// Strict definitions of tokenization methods.
2184///
2185/// Weaviate supports the following tokenization methods:
2186/// - Word
2187/// - Lowercase
2188/// - Whitespace
2189/// - Field
2190#[derive(Serialize, Deserialize, Debug, PartialEq)]
2191pub enum Tokenization {
2192 #[serde(rename = "word")]
2193 WORD,
2194 #[serde(rename = "lowercase")]
2195 LOWERCASE,
2196 #[serde(rename = "whitespace")]
2197 WHITESPACE,
2198 #[serde(rename = "field")]
2199 FIELD,
2200}
2201
2202/// Shards struct to hold multiple shards
2203#[derive(Serialize, Deserialize, Debug)]
2204pub struct Shards {
2205 pub shards: Vec<Shard>,
2206}
2207
2208impl Shards {
2209 /// Create a new Shards object
2210 ///
2211 /// # Parameters
2212 /// - shards: the shards to encapsulate
2213 ///
2214 /// # Example
2215 /// ```rust
2216 /// use weaviate_community::collections::schema::{Shards, Shard, ShardStatus};
2217 ///
2218 /// let shards = Shards::new(
2219 /// vec![
2220 /// Shard::new("abcd", ShardStatus::READY),
2221 /// Shard::new("efgh", ShardStatus::READONLY),
2222 /// ]
2223 /// );
2224 /// ```
2225 pub fn new(shards: Vec<Shard>) -> Shards {
2226 Shards { shards }
2227 }
2228}
2229
2230/// Shard struct to define the name and status of a shard.
2231///
2232/// Generally this wouldn't be created by a user, it would be automatically created in the schema,
2233/// and readable by the user.
2234#[derive(Serialize, Deserialize, Debug)]
2235pub struct Shard {
2236 pub name: String,
2237 pub status: ShardStatus,
2238}
2239
2240impl Shard {
2241 /// Create a new Shard object
2242 ///
2243 /// # Parameters
2244 /// - name: the name of the shard
2245 /// - status: the status of the shard
2246 ///
2247 /// # Example
2248 /// ```rust
2249 /// use weaviate_community::collections::schema::{Shard, ShardStatus};
2250 ///
2251 /// let shard = Shard::new("abcd", ShardStatus::READY);
2252 /// ```
2253 pub fn new(name: &str, status: ShardStatus) -> Shard {
2254 Shard {
2255 name: name.into(),
2256 status,
2257 }
2258 }
2259}
2260
2261/// Strict definitions of ShardStatus.
2262///
2263/// Weaviate supports READONLY and READY shard status.
2264#[derive(Serialize, Deserialize, Debug, PartialEq)]
2265pub enum ShardStatus {
2266 READONLY,
2267 READY,
2268}