qdrant_client/grpc_conversions/
primitives.rs1use std::collections::HashMap;
2
3use crate::prelude::point_id::PointIdOptions;
4use crate::prelude::{DeleteCollection, Value};
5use crate::qdrant::value::Kind;
6use crate::qdrant::{
7 shard_key, with_payload_selector, with_vectors_selector, CollectionClusterInfoRequest,
8 CollectionExistsRequest, CreateSnapshotRequest, DeleteAlias, DeleteCollectionBuilder,
9 DeleteFullSnapshotRequest, GetCollectionInfoRequest, IsEmptyCondition, IsNullCondition,
10 ListCollectionAliasesRequest, ListSnapshotsRequest, PayloadExcludeSelector,
11 PayloadIncludeSelector, PointId, RepeatedIntegers, RepeatedStrings, ShardKey, ShardKeySelector,
12 SparseIndices, SparseVectorConfig, SparseVectorParams, Struct, VectorParams, VectorParamsDiff,
13 VectorParamsDiffMap, VectorParamsMap, VectorsSelector, WithPayloadSelector,
14 WithVectorsSelector,
15};
16
17impl From<bool> for WithPayloadSelector {
18 fn from(flag: bool) -> Self {
19 WithPayloadSelector {
20 selector_options: Some(with_payload_selector::SelectorOptions::Enable(flag)),
21 }
22 }
23}
24
25impl From<Vec<&str>> for WithPayloadSelector {
26 fn from(fields: Vec<&str>) -> Self {
27 WithPayloadSelector {
28 selector_options: Some(with_payload_selector::SelectorOptions::Include(
29 PayloadIncludeSelector {
30 fields: fields.into_iter().map(|f| f.to_string()).collect(),
31 },
32 )),
33 }
34 }
35}
36
37impl From<Vec<&str>> for WithVectorsSelector {
38 fn from(names: Vec<&str>) -> Self {
39 WithVectorsSelector {
40 selector_options: Some(with_vectors_selector::SelectorOptions::Include(
41 VectorsSelector {
42 names: names.into_iter().map(|name| name.to_string()).collect(),
43 },
44 )),
45 }
46 }
47}
48
49impl From<bool> for WithVectorsSelector {
50 fn from(flag: bool) -> Self {
51 WithVectorsSelector {
52 selector_options: Some(with_vectors_selector::SelectorOptions::Enable(flag)),
53 }
54 }
55}
56
57impl From<f32> for Value {
58 fn from(val: f32) -> Self {
59 Self {
60 kind: Some(Kind::DoubleValue(val as f64)),
61 }
62 }
63}
64
65impl From<f64> for Value {
66 fn from(val: f64) -> Self {
67 Self {
68 kind: Some(Kind::DoubleValue(val)),
69 }
70 }
71}
72
73impl From<i64> for Value {
74 fn from(val: i64) -> Self {
75 Self {
76 kind: Some(Kind::IntegerValue(val)),
77 }
78 }
79}
80
81impl From<bool> for Value {
82 fn from(val: bool) -> Self {
83 Self {
84 kind: Some(Kind::BoolValue(val)),
85 }
86 }
87}
88
89impl From<String> for Value {
90 fn from(val: String) -> Self {
91 Self {
92 kind: Some(Kind::StringValue(val)),
93 }
94 }
95}
96
97impl From<&str> for Value {
98 fn from(val: &str) -> Self {
99 Self {
100 kind: Some(Kind::StringValue(val.into())),
101 }
102 }
103}
104
105impl<T> From<Vec<(&str, T)>> for Value
106where
107 T: Into<Value>,
108{
109 fn from(val: Vec<(&str, T)>) -> Self {
110 Self {
111 kind: Some(Kind::StructValue(Struct {
112 fields: val
113 .into_iter()
114 .map(|(k, v)| (k.to_string(), v.into()))
115 .collect(),
116 })),
117 }
118 }
119}
120
121impl From<String> for shard_key::Key {
122 fn from(keyword: String) -> Self {
123 shard_key::Key::Keyword(keyword)
124 }
125}
126
127impl From<u64> for shard_key::Key {
128 fn from(number: u64) -> Self {
129 shard_key::Key::Number(number)
130 }
131}
132
133impl From<String> for ShardKey {
134 fn from(keyword: String) -> Self {
135 ShardKey {
136 key: Some(shard_key::Key::Keyword(keyword)),
137 }
138 }
139}
140
141impl From<u64> for ShardKey {
142 fn from(number: u64) -> Self {
143 ShardKey {
144 key: Some(shard_key::Key::Number(number)),
145 }
146 }
147}
148
149impl From<String> for ShardKeySelector {
150 fn from(keyword: String) -> Self {
151 ShardKeySelector {
152 shard_keys: vec![ShardKey::from(keyword)],
153 }
154 }
155}
156
157impl From<u64> for ShardKeySelector {
158 fn from(number: u64) -> Self {
159 ShardKeySelector {
160 shard_keys: vec![ShardKey::from(number)],
161 }
162 }
163}
164
165impl From<Vec<String>> for ShardKeySelector {
166 fn from(keywords: Vec<String>) -> Self {
167 ShardKeySelector {
168 shard_keys: keywords.into_iter().map(ShardKey::from).collect(),
169 }
170 }
171}
172
173impl From<Vec<u64>> for ShardKeySelector {
174 fn from(numbers: Vec<u64>) -> Self {
175 ShardKeySelector {
176 shard_keys: numbers.into_iter().map(ShardKey::from).collect(),
177 }
178 }
179}
180
181impl From<String> for PointId {
182 fn from(val: String) -> Self {
183 Self {
184 point_id_options: Some(PointIdOptions::Uuid(val)),
185 }
186 }
187}
188
189impl From<&str> for PointId {
190 fn from(val: &str) -> Self {
191 Self::from(val.to_string())
192 }
193}
194
195impl From<u64> for PointId {
196 fn from(val: u64) -> Self {
197 Self {
198 point_id_options: Some(PointIdOptions::Num(val)),
199 }
200 }
201}
202
203impl From<Vec<u32>> for SparseIndices {
204 fn from(value: Vec<u32>) -> Self {
205 Self { data: value }
206 }
207}
208
209impl From<HashMap<String, VectorParams>> for VectorParamsMap {
210 fn from(value: HashMap<String, VectorParams>) -> Self {
211 VectorParamsMap { map: value }
212 }
213}
214
215impl From<HashMap<String, VectorParamsDiff>> for VectorParamsDiffMap {
216 fn from(value: HashMap<String, VectorParamsDiff>) -> Self {
217 VectorParamsDiffMap { map: value }
218 }
219}
220
221impl From<HashMap<String, SparseVectorParams>> for SparseVectorConfig {
222 fn from(value: HashMap<String, SparseVectorParams>) -> Self {
223 Self { map: value }
224 }
225}
226
227impl From<Vec<String>> for PayloadIncludeSelector {
228 fn from(value: Vec<String>) -> Self {
229 Self { fields: value }
230 }
231}
232
233impl From<Vec<String>> for PayloadExcludeSelector {
234 fn from(value: Vec<String>) -> Self {
235 Self { fields: value }
236 }
237}
238
239impl From<Vec<String>> for RepeatedStrings {
240 fn from(value: Vec<String>) -> Self {
241 Self { strings: value }
242 }
243}
244
245impl From<Vec<i64>> for RepeatedIntegers {
246 fn from(value: Vec<i64>) -> Self {
247 Self { integers: value }
248 }
249}
250
251impl From<HashMap<String, Value>> for Struct {
252 fn from(value: HashMap<String, Value>) -> Self {
253 Self { fields: value }
254 }
255}
256
257impl From<Vec<String>> for VectorsSelector {
258 fn from(value: Vec<String>) -> Self {
259 VectorsSelector { names: value }
260 }
261}
262
263impl From<String> for IsEmptyCondition {
264 fn from(value: String) -> Self {
265 Self { key: value }
266 }
267}
268
269impl From<String> for IsNullCondition {
270 fn from(value: String) -> Self {
271 Self { key: value }
272 }
273}
274
275impl From<bool> for with_payload_selector::SelectorOptions {
276 fn from(value: bool) -> Self {
277 Self::Enable(value)
278 }
279}
280
281impl From<bool> for with_vectors_selector::SelectorOptions {
282 fn from(value: bool) -> Self {
283 Self::Enable(value)
284 }
285}
286
287impl<S: Into<String>> From<S> for DeleteCollection {
288 fn from(value: S) -> Self {
289 DeleteCollectionBuilder::new(value).build()
290 }
291}
292
293impl<S: Into<String>> From<S> for CollectionExistsRequest {
294 fn from(value: S) -> Self {
295 Self {
296 collection_name: value.into(),
297 }
298 }
299}
300
301impl<S: Into<String>> From<S> for GetCollectionInfoRequest {
302 fn from(value: S) -> Self {
303 Self {
304 collection_name: value.into(),
305 }
306 }
307}
308
309impl<S: Into<String>> From<S> for DeleteAlias {
310 fn from(value: S) -> Self {
311 Self {
312 alias_name: value.into(),
313 }
314 }
315}
316
317impl<S: Into<String>> From<S> for ListCollectionAliasesRequest {
318 fn from(value: S) -> Self {
319 Self {
320 collection_name: value.into(),
321 }
322 }
323}
324
325impl<S: Into<String>> From<S> for CollectionClusterInfoRequest {
326 fn from(value: S) -> Self {
327 Self {
328 collection_name: value.into(),
329 }
330 }
331}
332
333impl<S: Into<String>> From<S> for CreateSnapshotRequest {
334 fn from(value: S) -> Self {
335 Self {
336 collection_name: value.into(),
337 }
338 }
339}
340
341impl<S: Into<String>> From<S> for ListSnapshotsRequest {
342 fn from(value: S) -> Self {
343 Self {
344 collection_name: value.into(),
345 }
346 }
347}
348
349impl<S: Into<String>> From<S> for DeleteFullSnapshotRequest {
350 fn from(value: S) -> Self {
351 Self {
352 snapshot_name: value.into(),
353 }
354 }
355}