mirror of
https://github.com/qdrant/landing_page.git
synced 2026-09-28 23:48:31 +02:00
docs: Fix snippets (#868)
This commit is contained in:
@@ -633,26 +633,24 @@ client.createCollection("{collection_name}", {
|
||||
```rust
|
||||
use qdrant_client::{
|
||||
client::QdrantClient,
|
||||
qdrant::{
|
||||
vectors_config::Config, CreateCollection, Distance, SparseVectorParams, VectorParamsMap,
|
||||
VectorsConfig,
|
||||
},
|
||||
qdrant::{CreateCollection, SparseVectorConfig, SparseVectorParams},
|
||||
};
|
||||
|
||||
|
||||
let client = QdrantClient::from_url("http://localhost:6334").build()?;
|
||||
|
||||
client
|
||||
.create_collection(&CreateCollection {
|
||||
collection_name: "{collection_name}".to_string(),
|
||||
sparse_vectors_config: Some(SparseVectorsConfig {
|
||||
map: [
|
||||
(
|
||||
"text".to_string(),
|
||||
SparseVectorParams {},
|
||||
),
|
||||
]
|
||||
.into(),
|
||||
}),
|
||||
sparse_vectors_config: Some(SparseVectorConfig {
|
||||
map: [(
|
||||
"text".to_string(),
|
||||
SparseVectorParams {
|
||||
..Default::default()
|
||||
},
|
||||
)]
|
||||
.into(),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
})
|
||||
@@ -786,10 +784,10 @@ use qdrant_client::qdrant::OptimizersConfigDiff;
|
||||
client
|
||||
.update_collection(
|
||||
"{collection_name}",
|
||||
&OptimizersConfigDiff {
|
||||
Some(&OptimizersConfigDiff {
|
||||
indexing_threshold: Some(10000),
|
||||
..Default::default()
|
||||
},
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
@@ -1298,7 +1296,7 @@ use qdrant_client::qdrant::OptimizersConfigDiff;
|
||||
client
|
||||
.update_collection(
|
||||
"{collection_name}",
|
||||
&OptimizersConfigDiff::default(),
|
||||
Some(&OptimizersConfigDiff::default()),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
|
||||
@@ -139,6 +139,22 @@ client
|
||||
.get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
using static Qdrant.Client.Grpc.Conditions;
|
||||
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.RecommendAsync(
|
||||
"{collection_name}",
|
||||
positive: new ulong[] { 100, 231 },
|
||||
negative: new ulong[] { 718 },
|
||||
filter: MatchKeyword("city", "London"),
|
||||
limit: 3
|
||||
);
|
||||
```
|
||||
|
||||
Example result of this API would be
|
||||
|
||||
```json
|
||||
@@ -1012,6 +1028,31 @@ client
|
||||
.get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
using Qdrant.Client;
|
||||
using Qdrant.Client.Grpc;
|
||||
|
||||
var client = new QdrantClient("localhost", 6334);
|
||||
|
||||
await client.DiscoverAsync(
|
||||
collectionName: "{collection_name}",
|
||||
context:
|
||||
[
|
||||
new()
|
||||
{
|
||||
Positive = new VectorExample { Id = 100 },
|
||||
Negative = new VectorExample { Id = 718 }
|
||||
},
|
||||
new()
|
||||
{
|
||||
Positive = new VectorExample { Id = 200 },
|
||||
Negative = new VectorExample { Id = 300 }
|
||||
}
|
||||
],
|
||||
limit: 10
|
||||
);
|
||||
```
|
||||
|
||||
<aside role="status">
|
||||
Notes about context search:
|
||||
|
||||
|
||||
@@ -1719,9 +1719,11 @@ order_by: {
|
||||
```rust
|
||||
order_by: Some(OrderBy {
|
||||
key: "timestamp".to_string(),
|
||||
direction: Some(Direction::Desc) // default is Direction::Asc
|
||||
start_from: Some(123),
|
||||
})
|
||||
direction: Some(Direction::Desc as i32), // default is Direction::Asc
|
||||
start_from: Some(StartFrom {
|
||||
value: Some(Value::Integer(123)),
|
||||
}),
|
||||
});
|
||||
```
|
||||
|
||||
```java
|
||||
@@ -1825,6 +1827,7 @@ client
|
||||
"red".to_string(),
|
||||
)])),
|
||||
exact: Some(true),
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
```
|
||||
@@ -2070,16 +2073,18 @@ client.batchUpdate("{collection_name}", {
|
||||
```
|
||||
|
||||
```rust
|
||||
use std::collections::HashMap;
|
||||
|
||||
use qdrant_client::qdrant::{
|
||||
points_selector::PointsSelectorOneOf,
|
||||
points_update_operation::{
|
||||
DeletePayload, DeleteVectors, Operation, PointStructList, SetPayload, UpdateVectors,
|
||||
ClearPayload, DeletePayload, DeletePoints, DeleteVectors, Operation, PointStructList,
|
||||
SetPayload, UpdateVectors,
|
||||
},
|
||||
PointStruct, PointVectors, PointsIdsList, PointsSelector, PointsUpdateOperation,
|
||||
VectorsSelector,
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
|
||||
client
|
||||
.batch_updates_blocking(
|
||||
@@ -2092,6 +2097,7 @@ client
|
||||
vec![1.0, 2.0, 3.0, 4.0],
|
||||
json!({}).try_into().unwrap(),
|
||||
)],
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
@@ -2100,6 +2106,7 @@ client
|
||||
id: Some(1.into()),
|
||||
vectors: Some(vec![1.0, 2.0, 3.0, 4.0].into()),
|
||||
}],
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
@@ -2114,6 +2121,7 @@ client
|
||||
vectors: Some(VectorsSelector {
|
||||
names: vec!["".into()],
|
||||
}),
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
@@ -2126,6 +2134,7 @@ client
|
||||
)),
|
||||
}),
|
||||
payload: HashMap::from([("test_payload".to_string(), 1.into())]),
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
@@ -2141,6 +2150,7 @@ client
|
||||
("test_payload_2".to_string(), 2.into()),
|
||||
("test_payload_3".to_string(), 3.into()),
|
||||
]),
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
@@ -2153,20 +2163,31 @@ client
|
||||
)),
|
||||
}),
|
||||
keys: vec!["test_payload_2".to_string()],
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
operation: Some(Operation::ClearPayload(PointsSelector {
|
||||
points_selector_one_of: Some(PointsSelectorOneOf::Points(PointsIdsList {
|
||||
ids: vec![1.into()],
|
||||
})),
|
||||
operation: Some(Operation::ClearPayload(ClearPayload {
|
||||
points: Some(PointsSelector {
|
||||
points_selector_one_of: Some(PointsSelectorOneOf::Points(
|
||||
PointsIdsList {
|
||||
ids: vec![1.into()],
|
||||
},
|
||||
)),
|
||||
}),
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
PointsUpdateOperation {
|
||||
operation: Some(Operation::Delete(PointsSelector {
|
||||
points_selector_one_of: Some(PointsSelectorOneOf::Points(PointsIdsList {
|
||||
ids: vec![1.into()],
|
||||
})),
|
||||
operation: Some(Operation::DeletePoints(DeletePoints {
|
||||
points: Some(PointsSelector {
|
||||
points_selector_one_of: Some(PointsSelectorOneOf::Points(
|
||||
PointsIdsList {
|
||||
ids: vec![1.into()],
|
||||
},
|
||||
)),
|
||||
}),
|
||||
..Default::default()
|
||||
})),
|
||||
},
|
||||
],
|
||||
|
||||
@@ -346,7 +346,7 @@ client.create_collection(
|
||||
sharding_method=models.ShardingMethod.CUSTOM,
|
||||
# ... other collection parameters
|
||||
)
|
||||
client.create_shard_key("{collection_name}", "user_1")
|
||||
client.create_shard_key("{collection_name}", "{shard_key}")
|
||||
```
|
||||
|
||||
```typescript
|
||||
@@ -359,13 +359,17 @@ client.createCollection("{collection_name}", {
|
||||
sharding_method: "custom",
|
||||
// ... other collection parameters
|
||||
});
|
||||
|
||||
client.createShardKey("{collection_name}", {
|
||||
shard_key: "{shard_key}"
|
||||
});
|
||||
```
|
||||
|
||||
```rust
|
||||
|
||||
use qdrant_client::{
|
||||
client::QdrantClient,
|
||||
qdrant::{CreateCollection, ShardingMethod},
|
||||
qdrant::{CreateCollection, ShardingMethod, shard_key::Key}
|
||||
};
|
||||
|
||||
let client = QdrantClient::from_url("http://localhost:6334").build()?;
|
||||
@@ -379,13 +383,27 @@ client
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
|
||||
client
|
||||
.create_shard_key(
|
||||
"{collection_name}",
|
||||
&Key::Keyword("{shard_key".to_string()),
|
||||
None,
|
||||
None,
|
||||
&[],
|
||||
)
|
||||
.await?;
|
||||
```
|
||||
|
||||
```java
|
||||
import static io.qdrant.client.ShardKeyFactory.shardKey;
|
||||
|
||||
import io.qdrant.client.QdrantClient;
|
||||
import io.qdrant.client.QdrantGrpcClient;
|
||||
import io.qdrant.client.grpc.Collections.CreateCollection;
|
||||
import io.qdrant.client.grpc.Collections.ShardingMethod;
|
||||
import io.qdrant.client.grpc.Collections.CreateShardKey;
|
||||
import io.qdrant.client.grpc.Collections.CreateShardKeyRequest;
|
||||
|
||||
QdrantClient client =
|
||||
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build());
|
||||
@@ -399,6 +417,13 @@ client
|
||||
.setShardingMethod(ShardingMethod.Custom)
|
||||
.build())
|
||||
.get();
|
||||
|
||||
client.createShardKeyAsync(CreateShardKeyRequest.newBuilder()
|
||||
.setCollectionName("{collection_name}")
|
||||
.setRequest(CreateShardKey.newBuilder()
|
||||
.setShardKey(shardKey("{shard_key}"))
|
||||
.build())
|
||||
.build()).get();
|
||||
```
|
||||
|
||||
```csharp
|
||||
@@ -413,6 +438,11 @@ await client.CreateCollectionAsync(
|
||||
shardNumber: 1,
|
||||
shardingMethod: ShardingMethod.Custom
|
||||
);
|
||||
|
||||
await client.CreateShardKeyAsync(
|
||||
"{collection_name}",
|
||||
new CreateShardKey { ShardKey = new ShardKey { Keyword = "{shard_key}", } }
|
||||
);
|
||||
```
|
||||
|
||||
In this mode, the `shard_number` means the number of shards per shard key, where points will be distributed evenly. For example, if you have 10 shard keys and a collection config with these settings:
|
||||
|
||||
Reference in New Issue
Block a user