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