use crate::grpc_macros::convert_option;
use crate::qdrant::*;
#[derive(Debug)]
pub struct CreateCollectionBuilder {
pub(crate) collection_name: Option<String>,
pub(crate) hnsw_config: Option<Option<HnswConfigDiff>>,
pub(crate) wal_config: Option<Option<WalConfigDiff>>,
pub(crate) optimizers_config: Option<Option<OptimizersConfigDiff>>,
pub(crate) shard_number: Option<Option<u32>>,
pub(crate) on_disk_payload: Option<Option<bool>>,
pub(crate) timeout: Option<Option<u64>>,
pub(crate) vectors_config: Option<Option<VectorsConfig>>,
pub(crate) replication_factor: Option<Option<u32>>,
pub(crate) write_consistency_factor: Option<Option<u32>>,
pub(crate) init_from_collection: Option<Option<String>>,
quantization_config: Option<quantization_config::Quantization>,
pub(crate) sharding_method: Option<Option<i32>>,
pub(crate) sparse_vectors_config: Option<Option<SparseVectorConfig>>,
pub(crate) strict_mode_config: Option<Option<StrictModeConfig>>,
}
#[allow(clippy::all)]
#[allow(clippy::derive_partial_eq_without_eq)]
impl CreateCollectionBuilder {
#[allow(unused_mut)]
pub fn collection_name<VALUE: Into<String>>(self, value: VALUE) -> Self {
let mut new = self;
new.collection_name = Option::Some(value.into());
new
}
#[allow(unused_mut)]
pub fn hnsw_config<VALUE: core::convert::Into<HnswConfigDiff>>(self, value: VALUE) -> Self {
let mut new = self;
new.hnsw_config = Option::Some(Option::Some(value.into()));
new
}
#[allow(unused_mut)]
pub fn wal_config<VALUE: core::convert::Into<WalConfigDiff>>(self, value: VALUE) -> Self {
let mut new = self;
new.wal_config = Option::Some(Option::Some(value.into()));
new
}
#[allow(unused_mut)]
pub fn optimizers_config<VALUE: core::convert::Into<OptimizersConfigDiff>>(
self,
value: VALUE,
) -> Self {
let mut new = self;
new.optimizers_config = Option::Some(Option::Some(value.into()));
new
}
#[allow(unused_mut)]
pub fn shard_number(self, value: u32) -> Self {
let mut new = self;
new.shard_number = Option::Some(Option::Some(value));
new
}
#[allow(unused_mut)]
pub fn on_disk_payload(self, value: bool) -> Self {
let mut new = self;
new.on_disk_payload = Option::Some(Option::Some(value));
new
}
#[allow(unused_mut)]
pub fn timeout(self, value: u64) -> Self {
let mut new = self;
new.timeout = Option::Some(Option::Some(value));
new
}
#[allow(unused_mut)]
pub fn vectors_config<VALUE: core::convert::Into<VectorsConfig>>(self, value: VALUE) -> Self {
let mut new = self;
new.vectors_config = Option::Some(Option::Some(value.into()));
new
}
#[allow(unused_mut)]
pub fn replication_factor(self, value: u32) -> Self {
let mut new = self;
new.replication_factor = Option::Some(Option::Some(value));
new
}
#[allow(unused_mut)]
pub fn write_consistency_factor(self, value: u32) -> Self {
let mut new = self;
new.write_consistency_factor = Option::Some(Option::Some(value));
new
}
#[allow(unused_mut)]
pub fn init_from_collection<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
let mut new = self;
new.init_from_collection = Option::Some(Option::Some(value.into()));
new
}
#[allow(unused_mut)]
pub fn quantization_config<VALUE: core::convert::Into<quantization_config::Quantization>>(
self,
value: VALUE,
) -> Self {
let mut new = self;
new.quantization_config = Option::Some(value.into());
new
}
#[allow(unused_mut)]
pub fn sharding_method(self, value: i32) -> Self {
let mut new = self;
new.sharding_method = Option::Some(Option::Some(value));
new
}
#[allow(unused_mut)]
pub fn sparse_vectors_config<VALUE: core::convert::Into<SparseVectorConfig>>(
self,
value: VALUE,
) -> Self {
let mut new = self;
new.sparse_vectors_config = Option::Some(Option::Some(value.into()));
new
}
#[allow(unused_mut)]
pub fn strict_mode_config<VALUE: core::convert::Into<StrictModeConfig>>(
self,
value: VALUE,
) -> Self {
let mut new = self;
new.strict_mode_config = Option::Some(Option::Some(value.into()));
new
}
fn build_inner(self) -> Result<CreateCollection, std::convert::Infallible> {
Ok(CreateCollection {
collection_name: match self.collection_name {
Some(value) => value,
None => core::default::Default::default(),
},
hnsw_config: match self.hnsw_config {
Some(value) => value,
None => core::default::Default::default(),
},
wal_config: match self.wal_config {
Some(value) => value,
None => core::default::Default::default(),
},
optimizers_config: match self.optimizers_config {
Some(value) => value,
None => core::default::Default::default(),
},
shard_number: match self.shard_number {
Some(value) => value,
None => core::default::Default::default(),
},
on_disk_payload: match self.on_disk_payload {
Some(value) => value,
None => core::default::Default::default(),
},
timeout: match self.timeout {
Some(value) => value,
None => core::default::Default::default(),
},
vectors_config: match self.vectors_config {
Some(value) => value,
None => core::default::Default::default(),
},
replication_factor: match self.replication_factor {
Some(value) => value,
None => core::default::Default::default(),
},
write_consistency_factor: match self.write_consistency_factor {
Some(value) => value,
None => core::default::Default::default(),
},
init_from_collection: match self.init_from_collection {
Some(value) => value,
None => core::default::Default::default(),
},
quantization_config: { convert_option(&self.quantization_config) },
sharding_method: match self.sharding_method {
Some(value) => value,
None => core::default::Default::default(),
},
sparse_vectors_config: match self.sparse_vectors_config {
Some(value) => value,
None => core::default::Default::default(),
},
strict_mode_config: match self.strict_mode_config {
Some(value) => value,
None => core::default::Default::default(),
},
})
}
fn create_empty() -> Self {
Self {
collection_name: core::default::Default::default(),
hnsw_config: core::default::Default::default(),
wal_config: core::default::Default::default(),
optimizers_config: core::default::Default::default(),
shard_number: core::default::Default::default(),
on_disk_payload: core::default::Default::default(),
timeout: core::default::Default::default(),
vectors_config: core::default::Default::default(),
replication_factor: core::default::Default::default(),
write_consistency_factor: core::default::Default::default(),
init_from_collection: core::default::Default::default(),
quantization_config: core::default::Default::default(),
sharding_method: core::default::Default::default(),
sparse_vectors_config: core::default::Default::default(),
strict_mode_config: core::default::Default::default(),
}
}
}
impl From<CreateCollectionBuilder> for CreateCollection {
fn from(value: CreateCollectionBuilder) -> Self {
value.build_inner().unwrap_or_else(|_| {
panic!(
"Failed to convert {0} to {1}",
"CreateCollectionBuilder", "CreateCollection"
)
})
}
}
impl CreateCollectionBuilder {
pub fn build(self) -> CreateCollection {
self.build_inner().unwrap_or_else(|_| {
panic!(
"Failed to build {0} into {1}",
"CreateCollectionBuilder", "CreateCollection"
)
})
}
}
impl Default for CreateCollectionBuilder {
fn default() -> Self {
Self::create_empty()
}
}