Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion proto/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ syntax = "proto3";
package qdrant;

option csharp_namespace = "Qdrant.Client.Grpc";
option java_outer_classname = "Points";

import "google/protobuf/timestamp.proto";

Expand Down
2 changes: 0 additions & 2 deletions src/qdrant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f32>,
/// Sparse indices for sparse vectors, deprecated
#[deprecated]
Expand Down
128 changes: 111 additions & 17 deletions src/qdrant_client/builders/vectors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::qdrant::{
DenseVectorBuilder, MultiDenseVector, NamedVectors, SparseVectorBuilder, Vector,
vector, DenseVectorBuilder, MultiDenseVector, NamedVectors, SparseVectorBuilder, Vector,
};
use crate::QdrantError;

Expand All @@ -26,69 +26,162 @@ impl Vector {

#[expect(deprecated)]
pub fn try_into_dense(self) -> Result<Vec<f32>, 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<u32>, Vec<f32>), 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<Vec<Vec<f32>>, 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::<Vec<_>>()),
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())
}
Expand All @@ -102,6 +195,7 @@ impl NamedVectors {
}

impl From<crate::qdrant::vector::Vector> for Vector {
#[allow(deprecated)]
fn from(vector: crate::qdrant::vector::Vector) -> Self {
#[expect(deprecated)]
Vector {
Expand Down