forked from qdrant/rust-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.rs
91 lines (82 loc) · 2.7 KB
/
search.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use anyhow::Result;
use qdrant_client::prelude::*;
use qdrant_client::qdrant::vectors_config::Config;
use qdrant_client::qdrant::{CreateCollection, SearchPoints, VectorParams, VectorsConfig};
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<()> {
// Example of top level client
// You may also use tonic-generated client from `src/qdrant.rs`
let config = QdrantClientConfig::from_url("http://localhost:6334");
let client = QdrantClient::new(Some(config)).await?;
let collections_list = client.list_collections().await?;
dbg!(collections_list);
// collections_list = ListCollectionsResponse {
// collections: [
// CollectionDescription {
// name: "test",
// },
// ],
// time: 1.78e-6,
// }
let collection_name = "test";
client.delete_collection(collection_name).await?;
client
.create_collection(&CreateCollection {
collection_name: collection_name.into(),
vectors_config: Some(VectorsConfig {
config: Some(Config::Params(VectorParams {
size: 10,
distance: Distance::Cosine.into(),
})),
}),
..Default::default()
})
.await?;
let collection_info = client.collection_info(collection_name).await?;
dbg!(collection_info);
let payload: Payload = vec![("foo", "Bar".into()), ("bar", 12.into())]
.into_iter()
.collect::<HashMap<_, Value>>()
.into();
let points = vec![PointStruct::new(0, vec![12.; 10], payload)];
client
.upsert_points_blocking(collection_name, points, None)
.await?;
let search_result = client
.search_points(&SearchPoints {
collection_name: collection_name.into(),
vector: vec![11.; 10],
filter: None,
limit: 10,
with_vectors: None,
with_payload: None,
params: None,
score_threshold: None,
offset: None,
..Default::default()
})
.await?;
dbg!(search_result);
// search_result = SearchResponse {
// result: [
// ScoredPoint {
// id: Some(
// PointId {
// point_id_options: Some(
// Num(
// 0,
// ),
// ),
// },
// ),
// payload: {},
// score: 1.0000001,
// version: 0,
// vectors: None,
// },
// ],
// time: 5.312e-5,
// }
Ok(())
}