|
| 1 | +use crate::qdrant::*; |
| 2 | + |
| 3 | +#[derive(Default)] |
| 4 | +pub struct MultiDenseVectorBuilder { |
| 5 | + pub(crate) vectors: Vec<DenseVector>, |
| 6 | +} |
| 7 | + |
| 8 | +impl MultiDenseVectorBuilder { |
| 9 | + pub fn new(vectors: impl Into<Vec<DenseVector>>) -> Self { |
| 10 | + Self { |
| 11 | + vectors: vectors.into(), |
| 12 | + } |
| 13 | + } |
| 14 | + |
| 15 | + pub fn single(vector: impl Into<DenseVector>) -> Self { |
| 16 | + Self::new(vec![vector.into()]) |
| 17 | + } |
| 18 | + |
| 19 | + #[allow(unused_mut)] |
| 20 | + pub fn vectors(mut self, vectors: impl Into<Vec<DenseVector>>) -> Self { |
| 21 | + self.vectors = vectors.into(); |
| 22 | + self |
| 23 | + } |
| 24 | + |
| 25 | + #[allow(unused_mut)] |
| 26 | + pub fn add_vector(mut self, vector: impl Into<DenseVector>) -> Self { |
| 27 | + self.vectors.push(vector.into()); |
| 28 | + self |
| 29 | + } |
| 30 | + |
| 31 | + /// Builds the desired type. Can often be omitted. |
| 32 | + pub fn build(self) -> MultiDenseVector { |
| 33 | + MultiDenseVector { |
| 34 | + vectors: self.vectors, |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +impl From<Vec<Vec<f32>>> for MultiDenseVector { |
| 40 | + fn from(vectors: Vec<Vec<f32>>) -> Self { |
| 41 | + Self::from( |
| 42 | + vectors |
| 43 | + .into_iter() |
| 44 | + .map(DenseVector::from) |
| 45 | + .collect::<Vec<_>>(), |
| 46 | + ) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +impl From<Vec<DenseVector>> for MultiDenseVector { |
| 51 | + fn from(vectors: Vec<DenseVector>) -> Self { |
| 52 | + MultiDenseVectorBuilder::new(vectors).build() |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +impl From<MultiDenseVector> for Vector { |
| 57 | + fn from(dense_vector: MultiDenseVector) -> Self { |
| 58 | + crate::qdrant::vector::Vector::from(dense_vector).into() |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +impl From<MultiDenseVectorBuilder> for Vector { |
| 63 | + fn from(dense_vector: MultiDenseVectorBuilder) -> Self { |
| 64 | + crate::qdrant::vector::Vector::from(dense_vector.build()).into() |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +impl From<MultiDenseVector> for crate::qdrant::vector::Vector { |
| 69 | + fn from(dense_vector: MultiDenseVector) -> Self { |
| 70 | + Self::MultiDense(dense_vector) |
| 71 | + } |
| 72 | +} |
0 commit comments