qdrant_client/builders/
sparse_vector_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone, Default)]
4pub struct SparseVectorBuilder {
5    pub(crate) indices: Vec<u32>,
6    pub(crate) values: Vec<f32>,
7}
8
9impl SparseVectorBuilder {
10    pub fn new(indices: impl Into<Vec<u32>>, values: impl Into<Vec<f32>>) -> Self {
11        Self {
12            indices: indices.into(),
13            values: values.into(),
14        }
15    }
16
17    pub fn indices(mut self, indices: impl Into<Vec<u32>>) -> Self {
18        self.indices = indices.into();
19        self
20    }
21
22    pub fn values(mut self, values: impl Into<Vec<f32>>) -> Self {
23        self.values = values.into();
24        self
25    }
26
27    /// Builds the desired type. Can often be omitted.
28    pub fn build(self) -> SparseVector {
29        SparseVector {
30            indices: self.indices,
31            values: self.values,
32        }
33    }
34}
35
36impl From<(Vec<u32>, Vec<f32>)> for SparseVector {
37    fn from((indices, values): (Vec<u32>, Vec<f32>)) -> Self {
38        SparseVectorBuilder::new(indices, values).build()
39    }
40}
41
42impl From<SparseVector> for Vector {
43    fn from(dense_vector: SparseVector) -> Self {
44        crate::qdrant::vector::Vector::from(dense_vector).into()
45    }
46}
47
48impl From<SparseVectorBuilder> for Vector {
49    fn from(dense_vector: SparseVectorBuilder) -> Self {
50        crate::qdrant::vector::Vector::from(dense_vector.build()).into()
51    }
52}
53
54impl From<SparseVector> for crate::qdrant::vector::Vector {
55    fn from(dense_vector: SparseVector) -> Self {
56        Self::Sparse(dense_vector)
57    }
58}