qdrant_client/builders/
strict_mode_sparse_config_builder.rs

1use std::collections::HashMap;
2
3use crate::qdrant::{StrictModeSparse, StrictModeSparseConfig};
4
5/// Builder for StrictModeSparseConfig, which defines sparse vector configuration for strict mode.
6#[derive(Clone)]
7pub struct StrictModeSparseConfigBuilder {
8    /// The sparse vectors configuration map, where keys are vector names and values are their configurations.
9    pub(crate) sparse_config: HashMap<String, StrictModeSparse>,
10}
11
12impl StrictModeSparseConfigBuilder {
13    /// Create a new builder with an empty sparse vectors configuration map.
14    pub fn new() -> Self {
15        Self {
16            sparse_config: HashMap::new(),
17        }
18    }
19
20    /// Add a configuration for a named vector, specifying its maximum number of vectors.
21    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    /// Set the entire sparse vectors configuration map at once.
34    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    /// Create an empty builder, with all fields set to `None` or default values.
47    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    /// Builds the desired StrictModeSparseConfig type.
67    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}