qdrant_client/builders/
strict_mode_sparse_config_builder.rs1use std::collections::HashMap;
2
3use crate::qdrant::{StrictModeSparse, StrictModeSparseConfig};
4
5#[derive(Clone)]
7pub struct StrictModeSparseConfigBuilder {
8 pub(crate) sparse_config: HashMap<String, StrictModeSparse>,
10}
11
12impl StrictModeSparseConfigBuilder {
13 pub fn new() -> Self {
15 Self {
16 sparse_config: HashMap::new(),
17 }
18 }
19
20 pub fn add_vector_config<S: Into<String>>(
22 self,
23 name: S,
24 strict_mode_multivector: StrictModeSparse,
25 ) -> Self {
26 let mut new = self;
27 new.sparse_config
28 .insert(name.into(), strict_mode_multivector);
29
30 new
31 }
32
33 pub fn sparse_config<M: Into<HashMap<String, StrictModeSparse>>>(self, config: M) -> Self {
35 let mut new = self;
36 new.sparse_config = config.into();
37 new
38 }
39
40 fn build_inner(self) -> Result<StrictModeSparseConfig, std::convert::Infallible> {
41 Ok(StrictModeSparseConfig {
42 sparse_config: self.sparse_config,
43 })
44 }
45
46 fn create_empty() -> Self {
48 Self {
49 sparse_config: core::default::Default::default(),
50 }
51 }
52}
53
54impl From<StrictModeSparseConfigBuilder> for StrictModeSparseConfig {
55 fn from(value: StrictModeSparseConfigBuilder) -> Self {
56 value.build_inner().unwrap_or_else(|_| {
57 panic!(
58 "Failed to convert {0} to {1}",
59 "StrictModeSparseConfigBuilder", "StrictModeSparseConfig"
60 )
61 })
62 }
63}
64
65impl StrictModeSparseConfigBuilder {
66 pub fn build(self) -> StrictModeSparseConfig {
68 self.build_inner().unwrap_or_else(|_| {
69 panic!(
70 "Failed to build {0} into {1}",
71 "StrictModeSparseConfigBuilder", "StrictModeSparseConfig"
72 )
73 })
74 }
75}
76
77impl Default for StrictModeSparseConfigBuilder {
78 fn default() -> Self {
79 Self::create_empty()
80 }
81}