Skip to content

Commit

Permalink
Fix points
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Yuan <[email protected]>
  • Loading branch information
juntao committed Jan 28, 2024
1 parent 61f6b9c commit c96aefd
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,35 @@ use qdrant::*;
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let client = qdrant::Qdrant::new();
// Create a collection with 10-dimensional vectors
let r = client.create_collection("my_test", 10).await;
let r = client.create_collection("my_test", 4).await;
println!("Create collection result is {:?}", r);

let mut points = Vec::<Point>::new();
for i in 0..10 {
let p = Point {
id: PointId::Num(i),
vector: vec![i as f32; 10],
payload: json!({"text": i.to_string()}).as_object().map(|m| m.to_owned()),
};
points.push(p);
}
points.push(Point{
id: PointId::Num(1), vector: vec!(0.05, 0.61, 0.76, 0.74), payload: json!({"city": "Berlin"}).as_object().map(|m| m.to_owned())
});
points.push(Point{
id: PointId::Num(2), vector: vec!(0.19, 0.81, 0.75, 0.11), payload: json!({"city": "London"}).as_object().map(|m| m.to_owned())
});
points.push(Point{
id: PointId::Num(3), vector: vec!(0.36, 0.55, 0.47, 0.94), payload: json!({"city": "Moscow"}).as_object().map(|m| m.to_owned())
});
points.push(Point{
id: PointId::Num(4), vector: vec!(0.18, 0.01, 0.85, 0.80), payload: json!({"city": "New York"}).as_object().map(|m| m.to_owned())
});
points.push(Point{
id: PointId::Num(5), vector: vec!(0.24, 0.18, 0.22, 0.44), payload: json!({"city": "Beijing"}).as_object().map(|m| m.to_owned())
});
points.push(Point{
id: PointId::Num(6), vector: vec!(0.35, 0.08, 0.11, 0.44), payload: json!({"city": "Mumbai"}).as_object().map(|m| m.to_owned())
});

let r = client.upsert_points("my_test", points).await;
println!("Upsert points result is {:?}", r);

println!("The collection size is {}", client.collection_info("my_test").await);

let q = vec![1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 6.0, 7.0, 8.0, 9.0];
let q = vec![0.2, 0.1, 0.9, 0.7];
let r = client.search_points("my_test", q, 2).await;
println!("Search result points are {:?}", r);
Ok(())
Expand Down

0 comments on commit c96aefd

Please sign in to comment.