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 runs a query with a read `consistency` of `majority`. Qdrant queries multiple replicas and returns only the points present on the majority of them, which helps avoid inconsistent results when replicas are concurrently updated.
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
using static Qdrant.Client.Grpc.Conditions;
|
||||
|
||||
public class Snippet
|
||||
{
|
||||
public static async Task Run()
|
||||
{
|
||||
// @hide-start
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
// @hide-end
|
||||
|
||||
await client.QueryAsync(
|
||||
collectionName: "{collection_name}",
|
||||
query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f },
|
||||
filter: MatchKeyword("city", "London"),
|
||||
searchParams: new SearchParams { HnswEf = 128, Exact = false },
|
||||
limit: 3,
|
||||
readConsistency: new ReadConsistency { Type = ReadConsistencyType.Majority }
|
||||
);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
using static Qdrant.Client.Grpc.Conditions;
|
||||
|
||||
await client.QueryAsync(
|
||||
collectionName: "{collection_name}",
|
||||
query: new float[] { 0.2f, 0.1f, 0.9f, 0.7f },
|
||||
filter: MatchKeyword("city", "London"),
|
||||
searchParams: new SearchParams { HnswEf = 128, Exact = false },
|
||||
limit: 3,
|
||||
readConsistency: new ReadConsistency { Type = ReadConsistencyType.Majority }
|
||||
);
|
||||
```
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
client.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
|
||||
Filter: &qdrant.Filter{
|
||||
Must: []*qdrant.Condition{
|
||||
qdrant.NewMatch("city", "London"),
|
||||
},
|
||||
},
|
||||
Params: &qdrant.SearchParams{
|
||||
HnswEf: qdrant.PtrOf(uint64(128)),
|
||||
},
|
||||
Limit: qdrant.PtrOf(uint64(3)),
|
||||
ReadConsistency: qdrant.NewReadConsistencyType(qdrant.ReadConsistencyType_Majority),
|
||||
})
|
||||
```
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
```java
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Common.Filter;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.ReadConsistency;
|
||||
import io.qdrant.client.grpc.Points.ReadConsistencyType;
|
||||
import io.qdrant.client.grpc.Points.SearchParams;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setFilter(Filter.newBuilder().addMust(matchKeyword("city", "London")).build())
|
||||
.setQuery(nearest(.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setParams(SearchParams.newBuilder().setHnswEf(128).setExact(false).build())
|
||||
.setLimit(3)
|
||||
.setReadConsistency(
|
||||
ReadConsistency.newBuilder().setType(ReadConsistencyType.Majority).build())
|
||||
.build())
|
||||
.get();
|
||||
```
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
```python
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
client.query_points(
|
||||
collection_name="{collection_name}",
|
||||
query=[0.2, 0.1, 0.9, 0.7],
|
||||
query_filter=models.Filter(
|
||||
must=[
|
||||
models.FieldCondition(
|
||||
key="city",
|
||||
match=models.MatchValue(
|
||||
value="London",
|
||||
),
|
||||
)
|
||||
]
|
||||
),
|
||||
search_params=models.SearchParams(hnsw_ef=128, exact=False),
|
||||
limit=3,
|
||||
consistency="majority",
|
||||
)
|
||||
```
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
```rust
|
||||
use qdrant_client::qdrant::{
|
||||
read_consistency::Value, Condition, Filter, QueryPointsBuilder, ReadConsistencyType,
|
||||
SearchParamsBuilder,
|
||||
};
|
||||
use qdrant_client::Qdrant;
|
||||
|
||||
client
|
||||
.query(
|
||||
QueryPointsBuilder::new("{collection_name}")
|
||||
.query(vec![0.2, 0.1, 0.9, 0.7])
|
||||
.limit(3)
|
||||
.filter(Filter::must([Condition::matches(
|
||||
"city",
|
||||
"London".to_string(),
|
||||
)]))
|
||||
.params(SearchParamsBuilder::default().hnsw_ef(128).exact(false))
|
||||
.read_consistency(Value::Type(ReadConsistencyType::Majority.into())),
|
||||
)
|
||||
.await?;
|
||||
```
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
```typescript
|
||||
import { QdrantClient } from "@qdrant/js-client-rest";
|
||||
|
||||
client.query("{collection_name}", {
|
||||
query: [0.2, 0.1, 0.9, 0.7],
|
||||
filter: {
|
||||
must: [{ key: "city", match: { value: "London" } }],
|
||||
},
|
||||
params: {
|
||||
hnsw_ef: 128,
|
||||
exact: false,
|
||||
},
|
||||
limit: 3,
|
||||
consistency: "majority",
|
||||
});
|
||||
```
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
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.Query(context.Background(), &qdrant.QueryPoints{
|
||||
CollectionName: "{collection_name}",
|
||||
Query: qdrant.NewQuery(0.2, 0.1, 0.9, 0.7),
|
||||
Filter: &qdrant.Filter{
|
||||
Must: []*qdrant.Condition{
|
||||
qdrant.NewMatch("city", "London"),
|
||||
},
|
||||
},
|
||||
Params: &qdrant.SearchParams{
|
||||
HnswEf: qdrant.PtrOf(uint64(128)),
|
||||
},
|
||||
Limit: qdrant.PtrOf(uint64(3)),
|
||||
ReadConsistency: qdrant.NewReadConsistencyType(qdrant.ReadConsistencyType_Majority),
|
||||
})
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
```http
|
||||
POST /collections/{collection_name}/points/query?consistency=majority
|
||||
{
|
||||
"query": [0.2, 0.1, 0.9, 0.7],
|
||||
"filter": {
|
||||
"must": [
|
||||
{
|
||||
"key": "city",
|
||||
"match": {
|
||||
"value": "London"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"hnsw_ef": 128,
|
||||
"exact": false
|
||||
},
|
||||
"limit": 3
|
||||
}
|
||||
```
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package com.example.snippets_amalgamation;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Common.Filter;
|
||||
import io.qdrant.client.grpc.Points.QueryPoints;
|
||||
import io.qdrant.client.grpc.Points.ReadConsistency;
|
||||
import io.qdrant.client.grpc.Points.ReadConsistencyType;
|
||||
import io.qdrant.client.grpc.Points.SearchParams;
|
||||
|
||||
import static io.qdrant.client.QueryFactory.nearest;
|
||||
import static io.qdrant.client.ConditionFactory.matchKeyword;
|
||||
|
||||
public class Snippet {
|
||||
public static void run() throws Exception {
|
||||
// @hide-start
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
// @hide-end
|
||||
|
||||
client.queryAsync(
|
||||
QueryPoints.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setFilter(Filter.newBuilder().addMust(matchKeyword("city", "London")).build())
|
||||
.setQuery(nearest(.2f, 0.1f, 0.9f, 0.7f))
|
||||
.setParams(SearchParams.newBuilder().setHnswEf(128).setExact(false).build())
|
||||
.setLimit(3)
|
||||
.setReadConsistency(
|
||||
ReadConsistency.newBuilder().setType(ReadConsistencyType.Majority).build())
|
||||
.build())
|
||||
.get();
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
# @hide-start
|
||||
# mypy: disable-error-code="arg-type"
|
||||
# @hide-end
|
||||
from qdrant_client import QdrantClient, models
|
||||
|
||||
# @hide-start
|
||||
client = QdrantClient(url="http://localhost:6333")
|
||||
# @hide-end
|
||||
|
||||
client.query_points(
|
||||
collection_name="{collection_name}",
|
||||
query=[0.2, 0.1, 0.9, 0.7],
|
||||
query_filter=models.Filter(
|
||||
must=[
|
||||
models.FieldCondition(
|
||||
key="city",
|
||||
match=models.MatchValue(
|
||||
value="London",
|
||||
),
|
||||
)
|
||||
]
|
||||
),
|
||||
search_params=models.SearchParams(hnsw_ef=128, exact=False),
|
||||
limit=3,
|
||||
consistency="majority",
|
||||
)
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
use qdrant_client::qdrant::{
|
||||
read_consistency::Value, Condition, Filter, QueryPointsBuilder, ReadConsistencyType,
|
||||
SearchParamsBuilder,
|
||||
};
|
||||
use qdrant_client::Qdrant;
|
||||
|
||||
pub async fn main() -> anyhow::Result<()> {
|
||||
// @hide-start
|
||||
let client = Qdrant::from_url("http://localhost:6334").build()?;
|
||||
// @hide-end
|
||||
|
||||
client
|
||||
.query(
|
||||
QueryPointsBuilder::new("{collection_name}")
|
||||
.query(vec![0.2, 0.1, 0.9, 0.7])
|
||||
.limit(3)
|
||||
.filter(Filter::must([Condition::matches(
|
||||
"city",
|
||||
"London".to_string(),
|
||||
)]))
|
||||
.params(SearchParamsBuilder::default().hnsw_ef(128).exact(false))
|
||||
.read_consistency(Value::Type(ReadConsistencyType::Majority.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.query("{collection_name}", {
|
||||
query: [0.2, 0.1, 0.9, 0.7],
|
||||
filter: {
|
||||
must: [{ key: "city", match: { value: "London" } }],
|
||||
},
|
||||
params: {
|
||||
hnsw_ef: 128,
|
||||
exact: false,
|
||||
},
|
||||
limit: 3,
|
||||
consistency: "majority",
|
||||
});
|
||||
Reference in New Issue
Block a user