Skip to main content

qdrant_client/qdrant_client/
sharding_keys.rs

1use crate::qdrant::{
2    CreateShardKeyRequest, CreateShardKeyResponse, DeleteShardKeyRequest, DeleteShardKeyResponse,
3    ListShardKeysRequest, ListShardKeysResponse,
4};
5use crate::qdrant_client::{Qdrant, QdrantResult};
6
7/// # Sharding key operations
8///
9/// Create or delete shard keys for collections.
10///
11/// Documentation: <https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding>
12impl Qdrant {
13    /// Create new shard key in a collection.
14    ///
15    /// ```no_run
16    ///# use qdrant_client::{Qdrant, QdrantError};
17    /// use qdrant_client::qdrant::shard_key::Key;
18    /// use qdrant_client::qdrant::{CreateShardKeyBuilder, CreateShardKeyRequestBuilder};
19    ///
20    ///# async fn create_shard_key(client: &Qdrant)
21    ///# -> Result<(), QdrantError> {
22    /// client
23    ///     .create_shard_key(
24    ///         CreateShardKeyRequestBuilder::new("my_collection").request(
25    ///             CreateShardKeyBuilder::default()
26    ///                 .shard_key(Key::Keyword("my_key".to_string())),
27    ///         ),
28    ///     )
29    ///     .await?;
30    ///# Ok(())
31    ///# }
32    /// ```
33    ///
34    /// Documentation: <https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding>
35    pub async fn create_shard_key(
36        &self,
37        request: impl Into<CreateShardKeyRequest>,
38    ) -> QdrantResult<CreateShardKeyResponse> {
39        let request = &request.into();
40
41        self.with_collections_client(|mut collection_api| async move {
42            let result = collection_api.create_shard_key(request.clone()).await?;
43            Ok(result.into_inner())
44        })
45        .await
46    }
47
48    /// List all shard keys in a collection.
49    ///
50    /// ```no_run
51    ///# use qdrant_client::{Qdrant, QdrantError};
52    ///# async fn list_shard_keys(client: &Qdrant)
53    ///# -> Result<(), QdrantError> {
54    /// let response = client.list_shard_keys("my_collection").await?;
55    ///# Ok(())
56    ///# }
57    /// ```
58    ///
59    /// Documentation: <https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding>
60    pub async fn list_shard_keys(
61        &self,
62        request: impl Into<ListShardKeysRequest>,
63    ) -> QdrantResult<ListShardKeysResponse> {
64        let request = &request.into();
65
66        self.with_collections_client(|mut collection_api| async move {
67            let result = collection_api.list_shard_keys(request.clone()).await?;
68            Ok(result.into_inner())
69        })
70        .await
71    }
72
73    /// Delete existing shard key from a collection.
74    ///
75    /// Deleting a shard key destroys all shards and data placed in it.
76    ///
77    /// ```no_run
78    ///# use qdrant_client::{Qdrant, QdrantError};
79    /// use qdrant_client::qdrant::shard_key::Key;
80    /// use qdrant_client::qdrant::DeleteShardKeyRequestBuilder;
81    ///
82    ///# async fn delete_shard_key(client: &Qdrant)
83    ///# -> Result<(), QdrantError> {
84    /// client
85    ///     .delete_shard_key(
86    ///         DeleteShardKeyRequestBuilder::new("my_collection")
87    ///             .key(Key::Keyword("my_key".to_string())),
88    ///     )
89    ///     .await?;
90    ///# Ok(())
91    ///# }
92    /// ```
93    ///
94    /// Documentation: <https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding>
95    pub async fn delete_shard_key(
96        &self,
97        request: impl Into<DeleteShardKeyRequest>,
98    ) -> QdrantResult<DeleteShardKeyResponse> {
99        let request = &request.into();
100
101        self.with_collections_client(|mut collection_api| async move {
102            let result = collection_api.delete_shard_key(request.clone()).await?;
103            Ok(result.into_inner())
104        })
105        .await
106    }
107}