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