Skip to content

Commit 9243e90

Browse files
committed
deprecate old vector format for VectorStruct (#238)
* deprecate old vector format for VectorStruct * upd proto
1 parent 5665cf8 commit 9243e90

File tree

3 files changed

+111
-20
lines changed

3 files changed

+111
-20
lines changed

proto/common.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ syntax = "proto3";
22
package qdrant;
33

44
option csharp_namespace = "Qdrant.Client.Grpc";
5-
option java_outer_classname = "Points";
65

76
import "google/protobuf/timestamp.proto";
87

src/qdrant.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3437,9 +3437,7 @@ pub struct Vector {
34373437
/// Vector data (flatten for multi vectors), deprecated
34383438
#[deprecated]
34393439
#[prost(float, repeated, packed = "false", tag = "1")]
3440-
/**
34413440

3442-
Deprecated since 1.16.0, use [`vector`](crate::qdrant::Vector::vector) field instead.*/
34433441
pub data: ::prost::alloc::vec::Vec<f32>,
34443442
/// Sparse indices for sparse vectors, deprecated
34453443
#[deprecated]

src/qdrant_client/builders/vectors.rs

Lines changed: 111 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::qdrant::{
2-
DenseVectorBuilder, MultiDenseVector, NamedVectors, SparseVectorBuilder, Vector,
2+
vector, DenseVectorBuilder, MultiDenseVector, NamedVectors, SparseVectorBuilder, Vector,
33
};
44
use crate::QdrantError;
55

@@ -26,69 +26,162 @@ impl Vector {
2626

2727
#[expect(deprecated)]
2828
pub fn try_into_dense(self) -> Result<Vec<f32>, QdrantError> {
29-
if self.indices.is_some() {
29+
let Vector {
30+
data,
31+
indices,
32+
vectors_count,
33+
vector,
34+
} = self;
35+
36+
if let Some(v) = vector {
37+
return match v {
38+
vector::Vector::Dense(dense) => Ok(dense.data),
39+
vector::Vector::Sparse(_) => Err(QdrantError::ConversionError(
40+
"Cannot convert sparse vector to dense".to_string(),
41+
)),
42+
vector::Vector::MultiDense(_) => Err(QdrantError::ConversionError(
43+
"Cannot convert multi-vector to dense".to_string(),
44+
)),
45+
vector::Vector::Document(_) => Err(QdrantError::ConversionError(
46+
"Cannot convert document vector to dense".to_string(),
47+
)),
48+
vector::Vector::Image(_) => Err(QdrantError::ConversionError(
49+
"Cannot convert image vector to dense".to_string(),
50+
)),
51+
vector::Vector::Object(_) => Err(QdrantError::ConversionError(
52+
"Cannot convert object vector to dense".to_string(),
53+
)),
54+
};
55+
}
56+
57+
if indices.is_some() {
3058
return Err(QdrantError::ConversionError(
3159
"Cannot convert sparse vector to dense".to_string(),
3260
));
3361
}
3462

35-
if self.vectors_count.is_some() && self.vectors_count.unwrap() > 1 {
63+
if vectors_count.is_some() && vectors_count.unwrap() > 1 {
3664
return Err(QdrantError::ConversionError(
3765
"Cannot convert multi vector to dense".to_string(),
3866
));
3967
}
4068

41-
Ok(self.data)
69+
Ok(data)
4270
}
4371

4472
#[expect(deprecated)]
4573
pub fn try_into_sparse(self) -> Result<(Vec<u32>, Vec<f32>), QdrantError> {
46-
if self.indices.is_none() {
74+
let Vector {
75+
data,
76+
indices,
77+
vectors_count,
78+
vector,
79+
} = self;
80+
81+
if let Some(v) = vector {
82+
return match v {
83+
vector::Vector::Dense(_) => Err(QdrantError::ConversionError(
84+
"Cannot convert dense vector to sparse".to_string(),
85+
)),
86+
vector::Vector::Sparse(sparse) => Ok((sparse.indices, sparse.values)),
87+
vector::Vector::MultiDense(_) => Err(QdrantError::ConversionError(
88+
"Cannot convert multi-vector to sparse".to_string(),
89+
)),
90+
vector::Vector::Document(_) => Err(QdrantError::ConversionError(
91+
"Cannot convert document vector to sparse".to_string(),
92+
)),
93+
vector::Vector::Image(_) => Err(QdrantError::ConversionError(
94+
"Cannot convert image vector to sparse".to_string(),
95+
)),
96+
vector::Vector::Object(_) => Err(QdrantError::ConversionError(
97+
"Cannot convert object vector to sparse".to_string(),
98+
)),
99+
};
100+
}
101+
102+
if indices.is_none() {
47103
return Err(QdrantError::ConversionError(
48104
"Cannot convert dense vector to sparse".to_string(),
49105
));
50106
}
51107

52-
if self.vectors_count.is_some() && self.vectors_count.unwrap() > 1 {
108+
if vectors_count.is_some() && vectors_count.unwrap() > 1 {
53109
return Err(QdrantError::ConversionError(
54110
"Cannot convert multi vector to sparse".to_string(),
55111
));
56112
}
57113

58-
let indices = self.indices.unwrap().data;
114+
let indices = indices.unwrap().data;
59115

60-
if indices.len() != self.data.len() {
116+
if indices.len() != data.len() {
61117
return Err(QdrantError::ConversionError(format!(
62118
"Malformed sparse vector: indices length {} is not equal to data length {}",
63119
indices.len(),
64-
self.data.len()
120+
data.len()
65121
)));
66122
}
67123

68-
Ok((indices, self.data))
124+
Ok((indices, data))
69125
}
70126

71127
#[expect(deprecated)]
72128
pub fn try_into_multi(self) -> Result<Vec<Vec<f32>>, QdrantError> {
73-
if self.vectors_count.is_none() {
129+
let Vector {
130+
data,
131+
indices,
132+
vectors_count,
133+
vector,
134+
} = self;
135+
136+
if let Some(v) = vector {
137+
return match v {
138+
vector::Vector::Dense(_) => Err(QdrantError::ConversionError(
139+
"Cannot convert dense vector to multi-vector".to_string(),
140+
)),
141+
vector::Vector::Sparse(_) => Err(QdrantError::ConversionError(
142+
"Cannot convert sparse vector to multi-vector".to_string(),
143+
)),
144+
vector::Vector::MultiDense(multivec) => Ok(multivec
145+
.vectors
146+
.into_iter()
147+
.map(|v| v.data)
148+
.collect::<Vec<_>>()),
149+
vector::Vector::Document(_) => Err(QdrantError::ConversionError(
150+
"Cannot convert document vector to multi-vector".to_string(),
151+
)),
152+
vector::Vector::Image(_) => Err(QdrantError::ConversionError(
153+
"Cannot convert image vector to multi-vector".to_string(),
154+
)),
155+
vector::Vector::Object(_) => Err(QdrantError::ConversionError(
156+
"Cannot convert object vector to multi-vector".to_string(),
157+
)),
158+
};
159+
}
160+
161+
if vectors_count.is_none() {
74162
return Err(QdrantError::ConversionError(
75163
"Cannot convert single vector to multi".to_string(),
76164
));
77165
}
78166

79-
let vectors_count = self.vectors_count.unwrap();
167+
if indices.is_some() {
168+
return Err(QdrantError::ConversionError(
169+
"Cannot convert sparse vector to multi-vector".to_string(),
170+
));
171+
}
172+
173+
let vectors_count = vectors_count.unwrap();
80174

81-
if !self.data.len().is_multiple_of(vectors_count as usize) {
175+
if !data.len().is_multiple_of(vectors_count as usize) {
82176
return Err(QdrantError::ConversionError(format!(
83177
"Malformed multi vector: data length {} is not divisible by vectors count {}",
84-
self.data.len(),
178+
data.len(),
85179
vectors_count
86180
)));
87181
}
88182

89-
Ok(self
90-
.data
91-
.chunks(self.data.len() / self.vectors_count.unwrap() as usize)
183+
Ok(data
184+
.chunks(data.len() / vectors_count as usize)
92185
.map(|v| v.to_vec())
93186
.collect())
94187
}
@@ -102,6 +195,7 @@ impl NamedVectors {
102195
}
103196

104197
impl From<crate::qdrant::vector::Vector> for Vector {
198+
#[allow(deprecated)]
105199
fn from(vector: crate::qdrant::vector::Vector) -> Self {
106200
#[expect(deprecated)]
107201
Vector {

0 commit comments

Comments
 (0)