mirror of
https://github.com/qdrant/landing_page.git
synced 2026-09-27 23:18:29 +02:00
feat: add rust snippets
This commit is contained in:
+41
@@ -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?;
|
||||
```
|
||||
Reference in New Issue
Block a user