|
10 | 10 | import io.qdrant.client.grpc.CollectionsGrpc; |
11 | 11 | import io.qdrant.client.grpc.PointsGrpc; |
12 | 12 | import io.qdrant.client.grpc.SnapshotsGrpc; |
| 13 | + |
13 | 14 | import org.slf4j.Logger; |
14 | 15 | import org.slf4j.LoggerFactory; |
15 | 16 |
|
|
28 | 29 | import static io.qdrant.client.grpc.Collections.CollectionOperationResponse; |
29 | 30 | import static io.qdrant.client.grpc.Collections.CreateAlias; |
30 | 31 | import static io.qdrant.client.grpc.Collections.CreateCollection; |
| 32 | +import static io.qdrant.client.grpc.Collections.CreateShardKeyRequest; |
| 33 | +import static io.qdrant.client.grpc.Collections.CreateShardKeyResponse; |
31 | 34 | import static io.qdrant.client.grpc.Collections.DeleteAlias; |
32 | 35 | import static io.qdrant.client.grpc.Collections.DeleteCollection; |
| 36 | +import static io.qdrant.client.grpc.Collections.DeleteShardKeyRequest; |
| 37 | +import static io.qdrant.client.grpc.Collections.DeleteShardKeyResponse; |
| 38 | +import static io.qdrant.client.grpc.Points.DiscoverBatchPoints; |
| 39 | +import static io.qdrant.client.grpc.Points.DiscoverBatchResponse; |
| 40 | +import static io.qdrant.client.grpc.Points.DiscoverPoints; |
| 41 | +import static io.qdrant.client.grpc.Points.DiscoverResponse; |
33 | 42 | import static io.qdrant.client.grpc.Collections.GetCollectionInfoRequest; |
34 | 43 | import static io.qdrant.client.grpc.Collections.GetCollectionInfoResponse; |
35 | 44 | import static io.qdrant.client.grpc.Collections.ListAliasesRequest; |
|
40 | 49 | import static io.qdrant.client.grpc.Collections.PayloadIndexParams; |
41 | 50 | import static io.qdrant.client.grpc.Collections.PayloadSchemaType; |
42 | 51 | import static io.qdrant.client.grpc.Collections.RenameAlias; |
| 52 | +import static io.qdrant.client.grpc.Collections.ShardKey; |
43 | 53 | import static io.qdrant.client.grpc.Collections.UpdateCollection; |
44 | 54 | import static io.qdrant.client.grpc.Collections.VectorParams; |
45 | 55 | import static io.qdrant.client.grpc.Collections.VectorParamsMap; |
@@ -665,6 +675,78 @@ public ListenableFuture<List<AliasDescription>> listAliasesAsync(@Nullable Durat |
665 | 675 |
|
666 | 676 | //endregion |
667 | 677 |
|
| 678 | + //region ShardKey Management |
| 679 | + |
| 680 | + /** |
| 681 | + * Creates a shard key for a collection. |
| 682 | + * |
| 683 | + * @param createShardKey The request object for the operation. |
| 684 | + * @return a new instance of {@link ListenableFuture} |
| 685 | + */ |
| 686 | + public ListenableFuture<CreateShardKeyResponse> createShardKeyAsync(CreateShardKeyRequest createShardKey) { |
| 687 | + return createShardKeyAsync(createShardKey, null); |
| 688 | + } |
| 689 | + |
| 690 | + /** |
| 691 | + * Creates a shard key for a collection. |
| 692 | + * |
| 693 | + * @param createShardKey The request object for the operation. |
| 694 | + * @param timeout The timeout for the call. |
| 695 | + * @return a new instance of {@link ListenableFuture} |
| 696 | + */ |
| 697 | + public ListenableFuture<CreateShardKeyResponse> createShardKeyAsync(CreateShardKeyRequest createShardKey, @Nullable Duration timeout) { |
| 698 | + String collectionName = createShardKey.getCollectionName(); |
| 699 | + Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty"); |
| 700 | + ShardKey shardKey = createShardKey.getRequest().getShardKey(); |
| 701 | + logger.debug("Create shard key '{}' for '{}'", shardKey, collectionName); |
| 702 | + |
| 703 | + ListenableFuture<CreateShardKeyResponse> future = getCollections(timeout).createShardKey(createShardKey); |
| 704 | + addLogFailureCallback(future, "Create shard key"); |
| 705 | + return Futures.transform(future, response -> { |
| 706 | + if (!response.getResult()) { |
| 707 | + logger.error("Shard key could not be created for '{}'", collectionName); |
| 708 | + throw new QdrantException("Shard key " + shardKey + " could not be created for " + collectionName); |
| 709 | + } |
| 710 | + return response; |
| 711 | + }, MoreExecutors.directExecutor()); |
| 712 | + } |
| 713 | + |
| 714 | + /** |
| 715 | + * Deletes a shard key for a collection. |
| 716 | + * |
| 717 | + * @param deleteShardKey The request object for the operation. |
| 718 | + * @return a new instance of {@link ListenableFuture} |
| 719 | + */ |
| 720 | + public ListenableFuture<DeleteShardKeyResponse> deleteShardKeyAsync(DeleteShardKeyRequest deleteShardKey) { |
| 721 | + return deleteShardKeyAsync(deleteShardKey, null); |
| 722 | + } |
| 723 | + |
| 724 | + /** |
| 725 | + * Deletes a shard key for a collection. |
| 726 | + * |
| 727 | + * @param deleteShardKey The request object for the operation. |
| 728 | + * @param timeout The timeout for the call. |
| 729 | + * @return a new instance of {@link ListenableFuture} |
| 730 | + */ |
| 731 | + public ListenableFuture<DeleteShardKeyResponse> deleteShardKeyAsync(DeleteShardKeyRequest deleteShardKey, @Nullable Duration timeout) { |
| 732 | + String collectionName = deleteShardKey.getCollectionName(); |
| 733 | + Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty"); |
| 734 | + ShardKey shardKey = deleteShardKey.getRequest().getShardKey(); |
| 735 | + logger.debug("Delete shard key '{}' for '{}'", shardKey, collectionName); |
| 736 | + |
| 737 | + ListenableFuture<DeleteShardKeyResponse> future = getCollections(timeout).deleteShardKey(deleteShardKey); |
| 738 | + addLogFailureCallback(future, "Delete shard key"); |
| 739 | + return Futures.transform(future, response -> { |
| 740 | + if (!response.getResult()) { |
| 741 | + logger.error("Shard key '{}' could not be deleted for '{}'", shardKey, collectionName); |
| 742 | + throw new QdrantException("Shard key " + shardKey + " could not be created for " + collectionName); |
| 743 | + } |
| 744 | + return response; |
| 745 | + }, MoreExecutors.directExecutor()); |
| 746 | + } |
| 747 | + |
| 748 | + //endregion |
| 749 | + |
668 | 750 | //region Point Management |
669 | 751 |
|
670 | 752 | /** |
@@ -2153,6 +2235,88 @@ public ListenableFuture<List<PointGroup>> recommendGroupsAsync(RecommendPointGro |
2153 | 2235 | MoreExecutors.directExecutor()); |
2154 | 2236 | } |
2155 | 2237 |
|
| 2238 | + /** |
| 2239 | + * Use the context and a target to find the most similar points to the target. |
| 2240 | + * Constraints by the context. |
| 2241 | + * |
| 2242 | + * @param request The discover points request |
| 2243 | + * @return a new instance of {@link ListenableFuture} |
| 2244 | + */ |
| 2245 | + public ListenableFuture<List<ScoredPoint>> discoverAsync(DiscoverPoints request) { |
| 2246 | + return discoverAsync(request, null); |
| 2247 | + } |
| 2248 | + |
| 2249 | + /** |
| 2250 | + * Use the context and a target to find the most similar points to the target. |
| 2251 | + * Constraints by the context. |
| 2252 | + * |
| 2253 | + * @param request The discover points request |
| 2254 | + * @param timeout The timeout for the call. |
| 2255 | + * @return a new instance of {@link ListenableFuture} |
| 2256 | + */ |
| 2257 | + public ListenableFuture<List<ScoredPoint>> discoverAsync(DiscoverPoints request, @Nullable Duration timeout) { |
| 2258 | + String collectionName = request.getCollectionName(); |
| 2259 | + Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty"); |
| 2260 | + logger.debug("Discover on '{}'", collectionName); |
| 2261 | + ListenableFuture<DiscoverResponse> future = getPoints(timeout).discover(request); |
| 2262 | + addLogFailureCallback(future, "Discover"); |
| 2263 | + return Futures.transform( |
| 2264 | + future, |
| 2265 | + response -> response.getResultList(), |
| 2266 | + MoreExecutors.directExecutor()); |
| 2267 | + } |
| 2268 | + |
| 2269 | + /** |
| 2270 | + * Use the context and a target to find the most similar points to the target in |
| 2271 | + * a batch. |
| 2272 | + * Constrained by the context. |
| 2273 | + * |
| 2274 | + * @param collectionName The name of the collection |
| 2275 | + * @param discoverSearches The list for discover point searches |
| 2276 | + * @param readConsistency Options for specifying read consistency guarantees |
| 2277 | + * @return a new instance of {@link ListenableFuture} |
| 2278 | + */ |
| 2279 | + public ListenableFuture<List<BatchResult>> discoverBatchAsync( |
| 2280 | + String collectionName, |
| 2281 | + List<DiscoverPoints> discoverSearches, |
| 2282 | + @Nullable ReadConsistency readConsistency) { |
| 2283 | + return discoverBatchAsync(collectionName, discoverSearches, readConsistency, null); |
| 2284 | + } |
| 2285 | + |
| 2286 | + /** |
| 2287 | + * Use the context and a target to find the most similar points to the target in |
| 2288 | + * a batch. |
| 2289 | + * Constrained by the context. |
| 2290 | + * |
| 2291 | + * @param collectionName The name of the collection |
| 2292 | + * @param discoverSearches The list for discover point searches |
| 2293 | + * @param readConsistency Options for specifying read consistency guarantees |
| 2294 | + * @param timeout The timeout for the call. |
| 2295 | + * @return a new instance of {@link ListenableFuture} |
| 2296 | + */ |
| 2297 | + public ListenableFuture<List<BatchResult>> discoverBatchAsync( |
| 2298 | + String collectionName, |
| 2299 | + List<DiscoverPoints> discoverSearches, |
| 2300 | + @Nullable ReadConsistency readConsistency, |
| 2301 | + @Nullable Duration timeout) { |
| 2302 | + Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty"); |
| 2303 | + |
| 2304 | + DiscoverBatchPoints.Builder requestBuilder = DiscoverBatchPoints.newBuilder() |
| 2305 | + .setCollectionName(collectionName) |
| 2306 | + .addAllDiscoverPoints(discoverSearches); |
| 2307 | + |
| 2308 | + if (readConsistency != null) { |
| 2309 | + requestBuilder.setReadConsistency(readConsistency); |
| 2310 | + } |
| 2311 | + logger.debug("Discover batch on '{}'", collectionName); |
| 2312 | + ListenableFuture<DiscoverBatchResponse> future = getPoints(timeout).discoverBatch(requestBuilder.build()); |
| 2313 | + addLogFailureCallback(future, "Discover batch"); |
| 2314 | + return Futures.transform( |
| 2315 | + future, |
| 2316 | + response -> response.getResultList(), |
| 2317 | + MoreExecutors.directExecutor()); |
| 2318 | + } |
| 2319 | + |
2156 | 2320 | /** |
2157 | 2321 | * Count the points in a collection. The count is exact |
2158 | 2322 | * |
|
0 commit comments