Skip to main content

qdrant_client/qdrant_client/builders/
vectors_config.rs

1use std::collections::HashMap;
2
3use crate::qdrant::vectors_config::Config;
4use crate::qdrant::{
5    MultiVectorComparator, MultiVectorConfigBuilder, VectorParams, VectorParamsMap, VectorsConfig,
6};
7
8const DEFAULT_VECTOR_NAME: &str = "";
9
10#[derive(Debug, Clone, Default)]
11pub struct VectorsConfigBuilder {
12    params: HashMap<String, VectorParams>,
13}
14
15impl VectorsConfigBuilder {
16    /// Add a named vector with the given parameters
17    pub fn add_named_vector_params(
18        &mut self,
19        name: impl Into<String>,
20        params: impl Into<VectorParams>,
21    ) -> &mut Self {
22        self.params.insert(name.into(), params.into());
23        self
24    }
25
26    /// Add the default vector with the given parameters
27    pub fn add_vector_params(&mut self, params: impl Into<VectorParams>) -> &mut Self {
28        self.params
29            .insert(DEFAULT_VECTOR_NAME.to_string(), params.into());
30        self
31    }
32}
33
34impl From<VectorsConfigBuilder> for VectorsConfig {
35    fn from(mut builder: VectorsConfigBuilder) -> Self {
36        if builder.params.is_empty() {
37            return VectorsConfig::default();
38        }
39
40        if builder.params.len() == 1 && builder.params.contains_key(DEFAULT_VECTOR_NAME) {
41            return VectorsConfig {
42                config: Some(Config::from(
43                    builder.params.remove(DEFAULT_VECTOR_NAME).unwrap(),
44                )),
45            };
46        }
47
48        VectorsConfig {
49            config: Some(Config::from(VectorParamsMap::from(builder.params))),
50        }
51    }
52}
53
54impl MultiVectorConfigBuilder {
55    pub fn new(comparator: impl Into<MultiVectorComparator>) -> Self {
56        let builder = Self::empty();
57        builder.comparator(comparator.into() as i32)
58    }
59}