diff --git a/proto/common.proto b/proto/common.proto index 70da9172..48b391bc 100644 --- a/proto/common.proto +++ b/proto/common.proto @@ -2,7 +2,6 @@ syntax = "proto3"; package qdrant; option csharp_namespace = "Qdrant.Client.Grpc"; -option java_outer_classname = "Points"; import "google/protobuf/timestamp.proto"; diff --git a/src/qdrant.rs b/src/qdrant.rs index c3c87937..99c8f3ff 100644 --- a/src/qdrant.rs +++ b/src/qdrant.rs @@ -3437,9 +3437,7 @@ pub struct Vector { /// Vector data (flatten for multi vectors), deprecated #[deprecated] #[prost(float, repeated, packed = "false", tag = "1")] - /** -Deprecated since 1.16.0, use [`vector`](crate::qdrant::Vector::vector) field instead.*/ pub data: ::prost::alloc::vec::Vec, /// Sparse indices for sparse vectors, deprecated #[deprecated] diff --git a/src/qdrant_client/builders/vectors.rs b/src/qdrant_client/builders/vectors.rs index cb7362b4..a53a8824 100644 --- a/src/qdrant_client/builders/vectors.rs +++ b/src/qdrant_client/builders/vectors.rs @@ -1,5 +1,5 @@ use crate::qdrant::{ - DenseVectorBuilder, MultiDenseVector, NamedVectors, SparseVectorBuilder, Vector, + vector, DenseVectorBuilder, MultiDenseVector, NamedVectors, SparseVectorBuilder, Vector, }; use crate::QdrantError; @@ -26,69 +26,162 @@ impl Vector { #[expect(deprecated)] pub fn try_into_dense(self) -> Result, QdrantError> { - if self.indices.is_some() { + let Vector { + data, + indices, + vectors_count, + vector, + } = self; + + if let Some(v) = vector { + return match v { + vector::Vector::Dense(dense) => Ok(dense.data), + vector::Vector::Sparse(_) => Err(QdrantError::ConversionError( + "Cannot convert sparse vector to dense".to_string(), + )), + vector::Vector::MultiDense(_) => Err(QdrantError::ConversionError( + "Cannot convert multi-vector to dense".to_string(), + )), + vector::Vector::Document(_) => Err(QdrantError::ConversionError( + "Cannot convert document vector to dense".to_string(), + )), + vector::Vector::Image(_) => Err(QdrantError::ConversionError( + "Cannot convert image vector to dense".to_string(), + )), + vector::Vector::Object(_) => Err(QdrantError::ConversionError( + "Cannot convert object vector to dense".to_string(), + )), + }; + } + + if indices.is_some() { return Err(QdrantError::ConversionError( "Cannot convert sparse vector to dense".to_string(), )); } - if self.vectors_count.is_some() && self.vectors_count.unwrap() > 1 { + if vectors_count.is_some() && vectors_count.unwrap() > 1 { return Err(QdrantError::ConversionError( "Cannot convert multi vector to dense".to_string(), )); } - Ok(self.data) + Ok(data) } #[expect(deprecated)] pub fn try_into_sparse(self) -> Result<(Vec, Vec), QdrantError> { - if self.indices.is_none() { + let Vector { + data, + indices, + vectors_count, + vector, + } = self; + + if let Some(v) = vector { + return match v { + vector::Vector::Dense(_) => Err(QdrantError::ConversionError( + "Cannot convert dense vector to sparse".to_string(), + )), + vector::Vector::Sparse(sparse) => Ok((sparse.indices, sparse.values)), + vector::Vector::MultiDense(_) => Err(QdrantError::ConversionError( + "Cannot convert multi-vector to sparse".to_string(), + )), + vector::Vector::Document(_) => Err(QdrantError::ConversionError( + "Cannot convert document vector to sparse".to_string(), + )), + vector::Vector::Image(_) => Err(QdrantError::ConversionError( + "Cannot convert image vector to sparse".to_string(), + )), + vector::Vector::Object(_) => Err(QdrantError::ConversionError( + "Cannot convert object vector to sparse".to_string(), + )), + }; + } + + if indices.is_none() { return Err(QdrantError::ConversionError( "Cannot convert dense vector to sparse".to_string(), )); } - if self.vectors_count.is_some() && self.vectors_count.unwrap() > 1 { + if vectors_count.is_some() && vectors_count.unwrap() > 1 { return Err(QdrantError::ConversionError( "Cannot convert multi vector to sparse".to_string(), )); } - let indices = self.indices.unwrap().data; + let indices = indices.unwrap().data; - if indices.len() != self.data.len() { + if indices.len() != data.len() { return Err(QdrantError::ConversionError(format!( "Malformed sparse vector: indices length {} is not equal to data length {}", indices.len(), - self.data.len() + data.len() ))); } - Ok((indices, self.data)) + Ok((indices, data)) } #[expect(deprecated)] pub fn try_into_multi(self) -> Result>, QdrantError> { - if self.vectors_count.is_none() { + let Vector { + data, + indices, + vectors_count, + vector, + } = self; + + if let Some(v) = vector { + return match v { + vector::Vector::Dense(_) => Err(QdrantError::ConversionError( + "Cannot convert dense vector to multi-vector".to_string(), + )), + vector::Vector::Sparse(_) => Err(QdrantError::ConversionError( + "Cannot convert sparse vector to multi-vector".to_string(), + )), + vector::Vector::MultiDense(multivec) => Ok(multivec + .vectors + .into_iter() + .map(|v| v.data) + .collect::>()), + vector::Vector::Document(_) => Err(QdrantError::ConversionError( + "Cannot convert document vector to multi-vector".to_string(), + )), + vector::Vector::Image(_) => Err(QdrantError::ConversionError( + "Cannot convert image vector to multi-vector".to_string(), + )), + vector::Vector::Object(_) => Err(QdrantError::ConversionError( + "Cannot convert object vector to multi-vector".to_string(), + )), + }; + } + + if vectors_count.is_none() { return Err(QdrantError::ConversionError( "Cannot convert single vector to multi".to_string(), )); } - let vectors_count = self.vectors_count.unwrap(); + if indices.is_some() { + return Err(QdrantError::ConversionError( + "Cannot convert sparse vector to multi-vector".to_string(), + )); + } + + let vectors_count = vectors_count.unwrap(); - if !self.data.len().is_multiple_of(vectors_count as usize) { + if !data.len().is_multiple_of(vectors_count as usize) { return Err(QdrantError::ConversionError(format!( "Malformed multi vector: data length {} is not divisible by vectors count {}", - self.data.len(), + data.len(), vectors_count ))); } - Ok(self - .data - .chunks(self.data.len() / self.vectors_count.unwrap() as usize) + Ok(data + .chunks(data.len() / vectors_count as usize) .map(|v| v.to_vec()) .collect()) } @@ -102,6 +195,7 @@ impl NamedVectors { } impl From for Vector { + #[allow(deprecated)] fn from(vector: crate::qdrant::vector::Vector) -> Self { #[expect(deprecated)] Vector {