use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Classes {
pub classes: Vec<Class>,
}
impl Classes {
pub fn new(classes: Vec<Class>) -> Classes {
Classes { classes }
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Class {
pub class: String,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub properties: Option<Properties>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "default_vector_index_type")]
pub vector_index_type: Option<VectorIndexType>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub vector_index_config: Option<VectorIndexConfig>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub vectorizer: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub module_config: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub inverted_index_config: Option<InvertedIndexConfig>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sharding_config: Option<ShardingConfig>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub multi_tenancy_config: Option<MultiTenancyConfig>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub replication_config: Option<ReplicationConfig>,
}
impl Class {
pub fn builder(class_name: &str) -> ClassBuilder {
ClassBuilder::new(class_name)
}
}
#[derive(Default)]
pub struct ClassBuilder {
pub class: String,
pub description: Option<String>,
pub properties: Option<Properties>,
pub vector_index_type: Option<VectorIndexType>,
pub vector_index_config: Option<VectorIndexConfig>,
pub vectorizer: Option<String>,
pub module_config: Option<serde_json::Value>,
pub inverted_index_config: Option<InvertedIndexConfig>,
pub sharding_config: Option<ShardingConfig>,
pub multi_tenancy_config: Option<MultiTenancyConfig>,
pub replication_config: Option<ReplicationConfig>,
}
impl ClassBuilder {
pub fn new(class: &str) -> ClassBuilder {
ClassBuilder {
class: class.into(),
description: None,
properties: None,
vector_index_type: None,
vector_index_config: None,
vectorizer: None,
module_config: None,
inverted_index_config: None,
sharding_config: None,
multi_tenancy_config: None,
replication_config: None,
}
}
pub fn with_description(mut self, description: &str) -> ClassBuilder {
self.description = Some(description.into());
self
}
pub fn with_properties(mut self, properties: Properties) -> ClassBuilder {
self.properties = Some(properties);
self
}
pub fn with_vector_index_type(mut self, vector_index_type: VectorIndexType) -> ClassBuilder {
self.vector_index_type = Some(vector_index_type);
self
}
pub fn with_vector_index_config(
mut self,
vector_index_config: VectorIndexConfig,
) -> ClassBuilder {
self.vector_index_config = Some(vector_index_config);
self
}
pub fn with_vectorizer(mut self, vectorizer: &str) -> ClassBuilder {
self.vectorizer = Some(vectorizer.into());
self
}
pub fn with_module_config(mut self, module_config: serde_json::Value) -> ClassBuilder {
self.module_config = Some(module_config);
self
}
pub fn with_inverted_index_config(
mut self,
inverted_index_config: InvertedIndexConfig,
) -> ClassBuilder {
self.inverted_index_config = Some(inverted_index_config);
self
}
pub fn with_sharding_config(mut self, sharding_config: ShardingConfig) -> ClassBuilder {
self.sharding_config = Some(sharding_config);
self
}
pub fn with_multi_tenancy_config(
mut self,
multi_tenancy_config: MultiTenancyConfig,
) -> ClassBuilder {
self.multi_tenancy_config = Some(multi_tenancy_config);
self
}
pub fn with_replication_config(
mut self,
replication_config: ReplicationConfig,
) -> ClassBuilder {
self.replication_config = Some(replication_config);
self
}
pub fn build(self) -> Class {
Class {
class: self.class,
description: self.description,
properties: self.properties,
vector_index_type: self.vector_index_type,
vector_index_config: self.vector_index_config,
vectorizer: self.vectorizer,
module_config: self.module_config,
inverted_index_config: self.inverted_index_config,
sharding_config: self.sharding_config,
multi_tenancy_config: self.multi_tenancy_config,
replication_config: self.replication_config,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub enum VectorIndexType {
#[serde(rename = "hnsw")]
HNSW,
}
fn default_vector_index_type() -> Option<VectorIndexType> {
Some(VectorIndexType::HNSW)
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Properties(pub Vec<Property>);
impl Properties {
pub fn new(properties: Vec<Property>) -> Properties {
Properties(properties)
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Property {
pub name: String,
pub data_type: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub tokenization: Option<Tokenization>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub module_config: Option<serde_json::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub index_filterable: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub index_searchable: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub inverted_index_config: Option<InvertedIndexConfig>,
}
impl Property {
pub fn builder(name: &str, data_type: Vec<&str>) -> PropertyBuilder {
PropertyBuilder::new(name, data_type)
}
}
#[derive(Default)]
pub struct PropertyBuilder {
pub name: String,
pub data_type: Vec<String>,
pub description: Option<String>,
pub tokenization: Option<Tokenization>,
pub module_config: Option<serde_json::Value>,
pub index_filterable: Option<bool>,
pub index_searchable: Option<bool>,
pub inverted_index_config: Option<InvertedIndexConfig>,
}
impl PropertyBuilder {
pub fn new(name: &str, data_type: Vec<&str>) -> PropertyBuilder {
let data_type = data_type.iter().map(|field| field.to_string()).collect();
PropertyBuilder {
name: name.into(),
data_type,
description: None,
tokenization: None,
module_config: None,
index_filterable: None,
index_searchable: None,
inverted_index_config: None,
}
}
pub fn with_description(mut self, description: &str) -> PropertyBuilder {
self.description = Some(description.into());
self
}
pub fn with_tokenization(mut self, tokenization: Tokenization) -> PropertyBuilder {
self.tokenization = Some(tokenization);
self
}
pub fn with_module_config(
mut self,
module_config: serde_json::Value,
) -> PropertyBuilder {
self.module_config = Some(module_config);
self
}
pub fn with_index_filterable(mut self, index_filterable: bool) -> PropertyBuilder {
self.index_filterable = Some(index_filterable);
self
}
pub fn with_index_searchable(mut self, index_searchable: bool) -> PropertyBuilder {
self.index_searchable = Some(index_searchable);
self
}
pub fn with_inverted_index_config(
mut self,
inverted_index_config: InvertedIndexConfig,
) -> PropertyBuilder {
self.inverted_index_config = Some(inverted_index_config);
self
}
pub fn build(self) -> Property {
Property {
name: self.name,
data_type: self.data_type,
description: self.description,
tokenization: self.tokenization,
module_config: self.module_config,
index_filterable: self.index_filterable,
index_searchable: self.index_searchable,
inverted_index_config: self.inverted_index_config,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct VectorIndexConfig {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub distance: Option<DistanceMetric>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub ef: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub ef_construction: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub max_connections: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub dynamic_ef_min: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub dynamic_ef_max: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub dynamic_ef_factor: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub vector_cache_max_objects: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub flat_search_cut_off: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub cleanup_interval_seconds: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub pq: Option<PqConfig>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub skip: Option<bool>,
}
impl VectorIndexConfig {
pub fn builder() -> VectorIndexConfigBuilder {
VectorIndexConfigBuilder::default()
}
}
#[derive(Default)]
pub struct VectorIndexConfigBuilder {
pub distance: Option<DistanceMetric>,
pub ef: Option<i64>,
pub ef_construction: Option<u64>,
pub max_connections: Option<u64>,
pub dynamic_ef_min: Option<i64>,
pub dynamic_ef_max: Option<i64>,
pub dynamic_ef_factor: Option<i64>,
pub vector_cache_max_objects: Option<u64>,
pub flat_search_cut_off: Option<u64>,
pub cleanup_interval_seconds: Option<u64>,
pub pq: Option<PqConfig>,
pub skip: Option<bool>,
}
impl VectorIndexConfigBuilder {
pub fn new() -> VectorIndexConfigBuilder {
VectorIndexConfigBuilder {
distance: None,
ef: None,
ef_construction: None,
max_connections: None,
dynamic_ef_min: None,
dynamic_ef_max: None,
dynamic_ef_factor: None,
vector_cache_max_objects: None,
flat_search_cut_off: None,
cleanup_interval_seconds: None,
pq: None,
skip: None,
}
}
pub fn with_distance(mut self, distance: DistanceMetric) -> VectorIndexConfigBuilder {
self.distance = Some(distance);
self
}
pub fn with_ef(mut self, ef: i64) -> VectorIndexConfigBuilder {
self.ef = Some(ef);
self
}
pub fn with_ef_construction(mut self, ef_construction: u64) -> VectorIndexConfigBuilder {
self.ef_construction = Some(ef_construction);
self
}
pub fn with_max_connections(mut self, max_connections: u64) -> VectorIndexConfigBuilder {
self.max_connections = Some(max_connections);
self
}
pub fn with_dynamic_ef_min(mut self, dynamic_ef_min: i64) -> VectorIndexConfigBuilder {
self.dynamic_ef_min = Some(dynamic_ef_min);
self
}
pub fn with_dynamic_ef_max(mut self, dynamic_ef_max: i64) -> VectorIndexConfigBuilder {
self.dynamic_ef_max = Some(dynamic_ef_max);
self
}
pub fn with_dynamic_ef_factor(mut self, dynamic_ef_factor: i64) -> VectorIndexConfigBuilder {
self.dynamic_ef_factor = Some(dynamic_ef_factor);
self
}
pub fn with_vector_cache_max_objects(
mut self,
vector_cache_max_objects: u64,
) -> VectorIndexConfigBuilder {
self.vector_cache_max_objects = Some(vector_cache_max_objects);
self
}
pub fn with_flat_search_cut_off(
mut self,
flat_search_cut_off: u64,
) -> VectorIndexConfigBuilder {
self.flat_search_cut_off = Some(flat_search_cut_off);
self
}
pub fn with_cleanup_interval_seconds(
mut self,
cleanup_interval_seconds: u64,
) -> VectorIndexConfigBuilder {
self.cleanup_interval_seconds = Some(cleanup_interval_seconds);
self
}
pub fn with_pq(mut self, pq: PqConfig) -> VectorIndexConfigBuilder {
self.pq = Some(pq);
self
}
pub fn with_skip(mut self, skip: bool) -> VectorIndexConfigBuilder {
self.skip = Some(skip);
self
}
pub fn build(self) -> VectorIndexConfig {
VectorIndexConfig {
distance: self.distance,
ef: self.ef,
ef_construction: self.ef_construction,
max_connections: self.max_connections,
dynamic_ef_min: self.dynamic_ef_min,
dynamic_ef_max: self.dynamic_ef_max,
dynamic_ef_factor: self.dynamic_ef_factor,
vector_cache_max_objects: self.vector_cache_max_objects,
flat_search_cut_off: self.flat_search_cut_off,
cleanup_interval_seconds: self.cleanup_interval_seconds,
pq: self.pq,
skip: self.skip,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct PqConfig {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub enabled: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub training_limit: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub segments: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub centroids: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub encoder: Option<EncoderConfig>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub bit_compression: Option<bool>,
}
impl PqConfig {
pub fn builder() -> PqConfigBuilder {
PqConfigBuilder::default()
}
}
#[derive(Default)]
pub struct PqConfigBuilder {
pub enabled: Option<bool>,
pub training_limit: Option<u64>,
pub segments: Option<u64>,
pub centroids: Option<u64>,
pub encoder: Option<EncoderConfig>,
pub bit_compression: Option<bool>,
}
impl PqConfigBuilder {
pub fn new() -> PqConfigBuilder {
PqConfigBuilder {
enabled: None,
training_limit: None,
segments: None,
centroids: None,
encoder: None,
bit_compression: None,
}
}
pub fn with_enabled(mut self, enabled: bool) -> PqConfigBuilder {
self.enabled = Some(enabled);
self
}
pub fn with_training_limit(mut self, training_limit: u64) -> PqConfigBuilder {
self.training_limit = Some(training_limit);
self
}
pub fn with_segments(mut self, segments: u64) -> PqConfigBuilder {
self.segments = Some(segments);
self
}
pub fn with_centroids(mut self, centroids: u64) -> PqConfigBuilder {
self.centroids = Some(centroids);
self
}
pub fn with_encoder(mut self, encoder: EncoderConfig) -> PqConfigBuilder {
self.encoder = Some(encoder);
self
}
pub fn with_bit_compression(mut self, bit_compression: bool) -> PqConfigBuilder {
self.bit_compression = Some(bit_compression);
self
}
pub fn build(self) -> PqConfig {
PqConfig {
enabled: self.enabled,
training_limit: self.training_limit,
segments: self.segments,
centroids: self.centroids,
encoder: self.encoder,
bit_compression: self.bit_compression,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EncoderConfig {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub distribution: Option<Distribution>,
#[serde(rename = "type")]
pub encoder_type: EncoderType,
}
impl EncoderConfig {
pub fn builder(encoder_type: EncoderType) -> EncoderConfigBuilder {
EncoderConfigBuilder::new(encoder_type)
}
}
pub struct EncoderConfigBuilder {
pub distribution: Option<Distribution>,
pub encoder_type: EncoderType,
}
impl EncoderConfigBuilder {
pub fn new(encoder_type: EncoderType) -> EncoderConfigBuilder {
EncoderConfigBuilder {
distribution: None,
encoder_type,
}
}
pub fn with_distribution(mut self, distribution: Distribution) -> EncoderConfigBuilder {
self.distribution = Some(distribution);
self
}
pub fn build(self) -> EncoderConfig {
EncoderConfig {
distribution: self.distribution,
encoder_type: self.encoder_type,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub enum Distribution {
#[serde(rename = "log-normal")]
LOGNORMAL,
#[serde(rename = "normal")]
NORMAL,
}
#[derive(Serialize, Deserialize, Debug)]
pub enum EncoderType {
#[serde(rename = "kmeans")]
KMEANS,
#[serde(rename = "tile")]
TILE,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub enum DistanceMetric {
#[serde(rename = "cosine")]
COSINE,
#[serde(rename = "dot")]
DOT,
#[serde(rename = "l2-squared")]
L2SQUARED,
#[serde(rename = "hamming")]
HAMMING,
#[serde(rename = "manhattan")]
MANHATTAN,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ShardingConfig {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub virtual_per_physical: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub desired_count: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub actual_count: Option<u64>, #[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub desired_virtual_count: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub actual_virtual_count: Option<u64>, #[serde(skip_serializing_if = "Option::is_none")]
pub key: Option<ShardingKey>,
#[serde(skip_serializing_if = "Option::is_none")]
pub strategy: Option<ShardingStrategy>,
#[serde(skip_serializing_if = "Option::is_none")]
pub function: Option<ShardingFunction>,
}
impl ShardingConfig {
pub fn builder() -> ShardingConfigBuilder {
ShardingConfigBuilder::default()
}
}
#[derive(Default)]
pub struct ShardingConfigBuilder {
pub virtual_per_physical: Option<u64>,
pub desired_count: Option<u64>,
pub actual_count: Option<u64>, pub desired_virtual_count: Option<u64>,
pub actual_virtual_count: Option<u64>, pub key: Option<ShardingKey>,
pub strategy: Option<ShardingStrategy>,
pub function: Option<ShardingFunction>,
}
impl ShardingConfigBuilder {
pub fn new() -> ShardingConfigBuilder {
ShardingConfigBuilder {
virtual_per_physical: None,
desired_count: None,
actual_count: None,
desired_virtual_count: None,
actual_virtual_count: None,
key: None,
strategy: None,
function: None,
}
}
pub fn with_virtual_per_physical(mut self, virtual_per_physical: u64) -> ShardingConfigBuilder {
self.virtual_per_physical = Some(virtual_per_physical);
self
}
pub fn with_desired_count(mut self, desired_count: u64) -> ShardingConfigBuilder {
self.desired_count = Some(desired_count);
self
}
pub fn with_actual_count(mut self, actual_count: u64) -> ShardingConfigBuilder {
self.actual_count = Some(actual_count);
self
}
pub fn with_desired_virtual_count(
mut self,
desired_virtual_count: u64,
) -> ShardingConfigBuilder {
self.desired_virtual_count = Some(desired_virtual_count);
self
}
pub fn with_actual_virtual_count(mut self, actual_virtual_count: u64) -> ShardingConfigBuilder {
self.actual_virtual_count = Some(actual_virtual_count);
self
}
pub fn with_key(mut self, key: ShardingKey) -> ShardingConfigBuilder {
self.key = Some(key);
self
}
pub fn with_strategy(mut self, strategy: ShardingStrategy) -> ShardingConfigBuilder {
self.strategy = Some(strategy);
self
}
pub fn with_function(mut self, function: ShardingFunction) -> ShardingConfigBuilder {
self.function = Some(function);
self
}
pub fn build(self) -> ShardingConfig {
ShardingConfig {
virtual_per_physical: self.virtual_per_physical,
desired_count: self.desired_count,
actual_count: self.actual_count,
desired_virtual_count: self.desired_virtual_count,
actual_virtual_count: self.actual_virtual_count,
key: self.key,
strategy: self.strategy,
function: self.function,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub enum ShardingKey {
#[serde(rename = "_id")]
_ID,
#[serde(rename = "")]
MultiTenancyEnabled,
}
#[derive(Serialize, Deserialize, Debug)]
pub enum ShardingStrategy {
#[serde(rename = "hash")]
HASH,
#[serde(rename = "")]
MultiTenancyEnabled,
}
#[derive(Serialize, Deserialize, Debug)]
pub enum ShardingFunction {
#[serde(rename = "murmur3")]
MURMUR3,
#[serde(rename = "")]
MultiTenancyEnabled,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct MultiTenancyConfig {
pub enabled: bool,
}
impl MultiTenancyConfig {
pub fn new(enabled: bool) -> MultiTenancyConfig {
MultiTenancyConfig { enabled }
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Default)]
#[serde(rename_all = "camelCase")]
pub struct InvertedIndexConfig {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub stopwords: Option<StopwordsConfig>, #[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub index_timestamps: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub index_null_state: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub index_property_length: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub bm25: Option<Bm25>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub cleanup_interval_seconds: Option<u64>,
}
impl InvertedIndexConfig {
pub fn builder() -> InvertedIndexConfigBuilder {
InvertedIndexConfigBuilder::default()
}
}
#[derive(Default)]
pub struct InvertedIndexConfigBuilder {
pub stopwords: Option<StopwordsConfig>, pub index_timestamps: Option<bool>,
pub index_null_state: Option<bool>,
pub index_property_length: Option<bool>,
pub bm25: Option<Bm25>,
pub cleanup_interval_seconds: Option<u64>,
}
impl InvertedIndexConfigBuilder {
pub fn new() -> InvertedIndexConfigBuilder {
InvertedIndexConfigBuilder {
stopwords: None,
index_timestamps: None,
index_null_state: None,
index_property_length: None,
bm25: None,
cleanup_interval_seconds: None,
}
}
pub fn with_stopwords(mut self, stopwords: StopwordsConfig) -> InvertedIndexConfigBuilder {
self.stopwords = Some(stopwords);
self
}
pub fn with_index_timestamps(mut self, index_timestamps: bool) -> InvertedIndexConfigBuilder {
self.index_timestamps = Some(index_timestamps);
self
}
pub fn with_index_null_state(mut self, index_null_state: bool) -> InvertedIndexConfigBuilder {
self.index_null_state = Some(index_null_state);
self
}
pub fn with_index_property_length(
mut self,
index_property_length: bool,
) -> InvertedIndexConfigBuilder {
self.index_property_length = Some(index_property_length);
self
}
pub fn with_bm25(mut self, bm25: Bm25) -> InvertedIndexConfigBuilder {
self.bm25 = Some(bm25);
self
}
pub fn with_cleanup_interval_seconds(
mut self,
cleanup_interval_seconds: u64,
) -> InvertedIndexConfigBuilder {
self.cleanup_interval_seconds = Some(cleanup_interval_seconds);
self
}
pub fn build(self) -> InvertedIndexConfig {
InvertedIndexConfig {
stopwords: self.stopwords,
index_timestamps: self.index_timestamps,
index_null_state: self.index_null_state,
index_property_length: self.index_property_length,
bm25: self.bm25,
cleanup_interval_seconds: self.cleanup_interval_seconds,
}
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct StopwordsConfig {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub preset: Option<StopwordPreset>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub additions: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub removals: Option<Vec<String>>,
}
impl StopwordsConfig {
pub fn builder() -> StopwordsConfigBuilder {
StopwordsConfigBuilder::default()
}
}
#[derive(Default)]
pub struct StopwordsConfigBuilder {
pub preset: Option<StopwordPreset>,
pub additions: Option<Vec<String>>,
pub removals: Option<Vec<String>>,
}
impl StopwordsConfigBuilder {
pub fn new() -> StopwordsConfigBuilder {
StopwordsConfigBuilder {
preset: None,
additions: None,
removals: None,
}
}
pub fn with_preset(mut self, preset: StopwordPreset) -> StopwordsConfigBuilder {
self.preset = Some(preset);
self
}
pub fn with_additions(mut self, additions: Vec<&str>) -> StopwordsConfigBuilder {
let additions = additions.iter().map(|field| field.to_string()).collect();
self.additions = Some(additions);
self
}
pub fn with_removals(mut self, removals: Vec<&str>) -> StopwordsConfigBuilder {
let removals = removals.iter().map(|field| field.to_string()).collect();
self.removals = Some(removals);
self
}
pub fn build(self) -> StopwordsConfig {
StopwordsConfig {
preset: self.preset,
additions: self.additions,
removals: self.removals,
}
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub enum StopwordPreset {
#[serde(rename = "en")]
EN,
#[serde(rename = "none")]
NONE,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ReplicationConfig {
pub factor: u64,
}
impl ReplicationConfig {
pub fn new(factor: u64) -> ReplicationConfig {
ReplicationConfig { factor }
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Tenants {
pub tenants: Vec<Tenant>,
}
impl Tenants {
pub fn new(tenants: Vec<Tenant>) -> Tenants {
Tenants { tenants }
}
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Tenant {
pub name: String,
#[serde(default = "default_activity_status")]
pub activity_status: Option<ActivityStatus>,
}
fn default_activity_status() -> Option<ActivityStatus> {
Some(ActivityStatus::HOT)
}
impl Tenant {
pub fn builder(name: &str) -> TenantBuilder {
TenantBuilder::new(name)
}
}
pub struct TenantBuilder {
name: String,
activity_status: Option<ActivityStatus>,
}
impl TenantBuilder {
pub fn new(name: &str) -> TenantBuilder {
TenantBuilder {
name: name.into(),
activity_status: None,
}
}
pub fn with_activity_status(mut self, activity_status: ActivityStatus) -> TenantBuilder {
self.activity_status = Some(activity_status);
self
}
pub fn build(self) -> Tenant {
Tenant {
name: self.name,
activity_status: self.activity_status,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub enum ActivityStatus {
HOT,
COLD,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Bm25 {
pub b: f64,
pub k1: f64,
}
impl Bm25 {
pub fn new(b: f64, k1: f64) -> Bm25 {
Bm25 { b, k1 }
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub enum Tokenization {
#[serde(rename = "word")]
WORD,
#[serde(rename = "lowercase")]
LOWERCASE,
#[serde(rename = "whitespace")]
WHITESPACE,
#[serde(rename = "field")]
FIELD,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Shards {
pub shards: Vec<Shard>,
}
impl Shards {
pub fn new(shards: Vec<Shard>) -> Shards {
Shards { shards }
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Shard {
pub name: String,
pub status: ShardStatus,
}
impl Shard {
pub fn new(name: &str, status: ShardStatus) -> Shard {
Shard {
name: name.into(),
status,
}
}
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub enum ShardStatus {
READONLY,
READY,
}