mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-09 21:08:31 +02:00
Create code snippets for distributed deployment.
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
This code snippet upserts a batch of points with a write `ordering` of `strong`. Qdrant routes the operation through the permanent shard leader so that all writes issued with the same ordering are applied and observed sequentially across replicas.
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
// @hide-start
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
// @hide-end
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "{collection_name}",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
Vectors = new[] { 0.9f, 0.1f, 0.1f },
|
||||
Payload = { ["color"] = "red" }
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 2,
|
||||
Vectors = new[] { 0.1f, 0.9f, 0.1f },
|
||||
Payload = { ["color"] = "green" }
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 3,
|
||||
Vectors = new[] { 0.1f, 0.1f, 0.9f },
|
||||
Payload = { ["color"] = "blue" }
|
||||
}
|
||||
},
|
||||
ordering: WriteOrderingType.Strong
|
||||
);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
await client.UpsertAsync(
|
||||
collectionName: "{collection_name}",
|
||||
points: new List<PointStruct>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
Vectors = new[] { 0.9f, 0.1f, 0.1f },
|
||||
Payload = { ["color"] = "red" }
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 2,
|
||||
Vectors = new[] { 0.1f, 0.9f, 0.1f },
|
||||
Payload = { ["color"] = "green" }
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 3,
|
||||
Vectors = new[] { 0.1f, 0.1f, 0.9f },
|
||||
Payload = { ["color"] = "blue" }
|
||||
}
|
||||
},
|
||||
ordering: WriteOrderingType.Strong
|
||||
);
|
||||
```
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client.Upsert(context.Background(), &qdrant.UpsertPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Points: []*qdrant.PointStruct{
|
||||
{
|
||||
Id: qdrant.NewIDNum(1),
|
||||
Vectors: qdrant.NewVectors(0.9, 0.1, 0.1),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"color": "red"}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(2),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.9, 0.1),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"color": "green"}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(3),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.1, 0.9),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"color": "blue"}),
|
||||
},
|
||||
},
|
||||
Ordering: &qdrant.WriteOrdering{
|
||||
Type: qdrant.WriteOrderingType_Strong,
|
||||
},
|
||||
})
|
||||
```
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
```java
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
import static io.qdrant.client.ValueFactory.value;
|
||||
import static io.qdrant.client.VectorsFactory.vectors;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.PointStruct;
|
||||
import io.qdrant.client.grpc.Points.UpsertPoints;
|
||||
import io.qdrant.client.grpc.Points.WriteOrdering;
|
||||
import io.qdrant.client.grpc.Points.WriteOrderingType;
|
||||
|
||||
client
|
||||
.upsertAsync(
|
||||
UpsertPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllPoints(
|
||||
List.of(
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(1))
|
||||
.setVectors(vectors(0.9f, 0.1f, 0.1f))
|
||||
.putAllPayload(Map.of("color", value("red")))
|
||||
.build(),
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(2))
|
||||
.setVectors(vectors(0.1f, 0.9f, 0.1f))
|
||||
.putAllPayload(Map.of("color", value("green")))
|
||||
.build(),
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(3))
|
||||
.setVectors(vectors(0.1f, 0.1f, 0.9f))
|
||||
.putAllPayload(Map.of("color", value("blue")))
|
||||
.build()))
|
||||
.setOrdering(WriteOrdering.newBuilder().setType(WriteOrderingType.Strong).build())
|
||||
.build())
|
||||
.get();
|
||||
```
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
```python
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client.upsert(
|
||||
collection_name="{collection_name}",
|
||||
points=models.Batch(
|
||||
ids=[1, 2, 3],
|
||||
payloads=[
|
||||
{"color": "red"},
|
||||
{"color": "green"},
|
||||
{"color": "blue"},
|
||||
],
|
||||
vectors=[
|
||||
[0.9, 0.1, 0.1],
|
||||
[0.1, 0.9, 0.1],
|
||||
[0.1, 0.1, 0.9],
|
||||
],
|
||||
),
|
||||
ordering=models.WriteOrdering.STRONG,
|
||||
)
|
||||
```
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
```rust
|
||||
use qdrant_client::qdrant::{
|
||||
PointStruct, UpsertPointsBuilder, WriteOrdering, WriteOrderingType,
|
||||
};
|
||||
use qdrant_client::Qdrant;
|
||||
|
||||
client
|
||||
.upsert_points(
|
||||
UpsertPointsBuilder::new(
|
||||
"{collection_name}",
|
||||
vec![
|
||||
PointStruct::new(1, vec![0.9, 0.1, 0.1], [("color", "red".into())]),
|
||||
PointStruct::new(2, vec![0.1, 0.9, 0.1], [("color", "green".into())]),
|
||||
PointStruct::new(3, vec![0.1, 0.1, 0.9], [("color", "blue".into())]),
|
||||
],
|
||||
)
|
||||
.ordering(WriteOrdering {
|
||||
r#type: WriteOrderingType::Strong.into(),
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
```
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
```typescript
|
||||
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
client.upsert("{collection_name}", {
|
||||
batch: {
|
||||
ids: [1, 2, 3],
|
||||
payloads: [{ color: "red" }, { color: "green" }, { color: "blue" }],
|
||||
vectors: [
|
||||
[0.9, 0.1, 0.1],
|
||||
[0.1, 0.9, 0.1],
|
||||
[0.1, 0.1, 0.9],
|
||||
],
|
||||
},
|
||||
ordering: "strong",
|
||||
});
|
||||
```
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package snippet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
// @hide-start
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "localhost",
|
||||
Port: 6334,
|
||||
})
|
||||
|
||||
if err != nil { panic(err) }
|
||||
// @hide-end
|
||||
|
||||
client.Upsert(context.Background(), &qdrant.UpsertPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Points: []*qdrant.PointStruct{
|
||||
{
|
||||
Id: qdrant.NewIDNum(1),
|
||||
Vectors: qdrant.NewVectors(0.9, 0.1, 0.1),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"color": "red"}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(2),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.9, 0.1),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"color": "green"}),
|
||||
},
|
||||
{
|
||||
Id: qdrant.NewIDNum(3),
|
||||
Vectors: qdrant.NewVectors(0.1, 0.1, 0.9),
|
||||
Payload: qdrant.NewValueMap(map[string]any{"color": "blue"}),
|
||||
},
|
||||
},
|
||||
Ordering: &qdrant.WriteOrdering{
|
||||
Type: qdrant.WriteOrderingType_Strong,
|
||||
},
|
||||
})
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
```http
|
||||
PUT /collections/{collection_name}/points?ordering=strong
|
||||
{
|
||||
"batch": {
|
||||
"ids": [1, 2, 3],
|
||||
"payloads": [
|
||||
{"color": "red"},
|
||||
{"color": "green"},
|
||||
{"color": "blue"}
|
||||
],
|
||||
"vectors": [
|
||||
[0.9, 0.1, 0.1],
|
||||
[0.1, 0.9, 0.1],
|
||||
[0.1, 0.1, 0.9]
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.qdrant.client.PointIdFactory.id;
|
||||
import static io.qdrant.client.ValueFactory.value;
|
||||
import static io.qdrant.client.VectorsFactory.vectors;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Points.PointStruct;
|
||||
import io.qdrant.client.grpc.Points.UpsertPoints;
|
||||
import io.qdrant.client.grpc.Points.WriteOrdering;
|
||||
import io.qdrant.client.grpc.Points.WriteOrderingType;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
// @hide-start
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
// @hide-end
|
||||
|
||||
client
|
||||
.upsertAsync(
|
||||
UpsertPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.addAllPoints(
|
||||
List.of(
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(1))
|
||||
.setVectors(vectors(0.9f, 0.1f, 0.1f))
|
||||
.putAllPayload(Map.of("color", value("red")))
|
||||
.build(),
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(2))
|
||||
.setVectors(vectors(0.1f, 0.9f, 0.1f))
|
||||
.putAllPayload(Map.of("color", value("green")))
|
||||
.build(),
|
||||
PointStruct.newBuilder()
|
||||
.setId(id(3))
|
||||
.setVectors(vectors(0.1f, 0.1f, 0.9f))
|
||||
.putAllPayload(Map.of("color", value("blue")))
|
||||
.build()))
|
||||
.setOrdering(WriteOrdering.newBuilder().setType(WriteOrderingType.Strong).build())
|
||||
.build())
|
||||
.get();
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
# @hide-start
|
||||
client = QdrantClient(url="http://localhost:6333")
|
||||
# @hide-end
|
||||
|
||||
client.upsert(
|
||||
collection_name="{collection_name}",
|
||||
points=models.Batch(
|
||||
ids=[1, 2, 3],
|
||||
payloads=[
|
||||
{"color": "red"},
|
||||
{"color": "green"},
|
||||
{"color": "blue"},
|
||||
],
|
||||
vectors=[
|
||||
[0.9, 0.1, 0.1],
|
||||
[0.1, 0.9, 0.1],
|
||||
[0.1, 0.1, 0.9],
|
||||
],
|
||||
),
|
||||
ordering=models.WriteOrdering.STRONG,
|
||||
)
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
use qdrant_client::qdrant::{
|
||||
PointStruct, UpsertPointsBuilder, WriteOrdering, WriteOrderingType,
|
||||
};
|
||||
use qdrant_client::Qdrant;
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
// @hide-start
|
||||
let client = Qdrant::from_url("http://localhost:6334").build()?;
|
||||
// @hide-end
|
||||
|
||||
client
|
||||
.upsert_points(
|
||||
UpsertPointsBuilder::new(
|
||||
"{collection_name}",
|
||||
vec![
|
||||
PointStruct::new(1, vec![0.9, 0.1, 0.1], [("color", "red".into())]),
|
||||
PointStruct::new(2, vec![0.1, 0.9, 0.1], [("color", "green".into())]),
|
||||
PointStruct::new(3, vec![0.1, 0.1, 0.9], [("color", "blue".into())]),
|
||||
],
|
||||
)
|
||||
.ordering(WriteOrdering {
|
||||
r#type: WriteOrderingType::Strong.into(),
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
// @hide-start
|
||||
const client = new QdrantClient({ host: "localhost", port: 6333 });
|
||||
// @hide-end
|
||||
|
||||
client.upsert("{collection_name}", {
|
||||
batch: {
|
||||
ids: [1, 2, 3],
|
||||
payloads: [{ color: "red" }, { color: "green" }, { color: "blue" }],
|
||||
vectors: [
|
||||
[0.9, 0.1, 0.1],
|
||||
[0.1, 0.9, 0.1],
|
||||
[0.1, 0.1, 0.9],
|
||||
],
|
||||
},
|
||||
ordering: "strong",
|
||||
});
|
||||
Reference in New Issue
Block a user