feat: add rust snippets

This commit is contained in:
Daniel Boros
2025-12-04 12:03:46 +01:00
parent bc3dc0b0b3
commit 693f76f744
2 changed files with 90 additions and 0 deletions
@@ -0,0 +1,41 @@
```rust
use std::collections::HashMap;
use qdrant_client::{
Qdrant, QdrantError,
qdrant::{Document, PrefetchQueryBuilder, Query, QueryPointsBuilder, Value},
};
client
.query(
QueryPointsBuilder::new("{collection_name}")
.add_prefetch(
PrefetchQueryBuilder::default()
.query(Query::new_nearest(Document {
text: "How to bake cookies?".into(),
model: "openai/text-embedding-3-small".into(),
options: HashMap::<String, Value>::from_iter(vec![
(
"openai-api-key".to_string(),
Value::from("<YOUR_OPENAI_API_KEY>"),
),
("mrl".into(), Value::from(64)),
]),
}))
.using("small")
.limit(10_u64),
)
.query(Query::new_nearest(Document {
text: "How to bake cookies?".into(),
model: "openai/text-embedding-3-small".into(),
options: HashMap::from_iter(vec![(
"openai-api-key".into(),
"<YOUR_OPENAI_API_KEY>".into(),
)]),
}))
.using("large")
.limit(10_u64)
.build(),
)
.await?;
```
@@ -0,0 +1,49 @@
```rust
use std::collections::HashMap;
use qdrant_client::{
Payload, Qdrant, QdrantError,
qdrant::{Document, NamedVectors, PointStruct, UpsertPointsBuilder, Value},
};
let client = Qdrant::from_url("http://localhost:6334").build()?;
client
.upsert_points(
UpsertPointsBuilder::new(
"{collection_name}",
vec![PointStruct::new(
1,
NamedVectors::default()
.add_vector(
"large",
Document {
text: "Recipe for baking chocolate chip cookies".into(),
model: "openai/text-embedding-3-small".into(),
options: HashMap::<String, Value>::from_iter(vec![(
"openai-api-key".into(),
"<YOUR_OPENAI_API_KEY>".into(),
)]),
},
)
.add_vector(
"small",
Document {
text: "Mars, the red planet".into(),
model: "sentence-transformers/all-minilm-l6-v2".into(),
options: HashMap::<String, Value>::from_iter(vec![
(
"openai-api-key".into(),
Value::from("<YOUR_OPENAI_API_KEY>"),
),
("mrl".into(), Value::from(64)),
]),
},
),
Payload::default(),
)],
)
.wait(true),
)
.await?;
```