From f7c1297dc3f58a52cd76c2c0bb4ad0d0b7764cb8 Mon Sep 17 00:00:00 2001 From: Anush008 Date: Thu, 22 Feb 2024 12:06:08 +0530 Subject: [PATCH] refactor: Add request object overloads --- .../java/io/qdrant/client/QdrantClient.java | 198 ++++++++++++++++-- 1 file changed, 182 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/qdrant/client/QdrantClient.java b/src/main/java/io/qdrant/client/QdrantClient.java index 9c057ff..deeea8b 100644 --- a/src/main/java/io/qdrant/client/QdrantClient.java +++ b/src/main/java/io/qdrant/client/QdrantClient.java @@ -1058,7 +1058,23 @@ public ListenableFuture> retrieveAsync( requestBuilder.setReadConsistency(readConsistency); } - ListenableFuture future = getPoints(timeout).get(requestBuilder.build()); + return retrieveAsync(requestBuilder.build(), timeout); + } + + /** + * Retrieves points. + * + * @param request The get points request + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture> retrieveAsync( + GetPoints request, @Nullable Duration timeout) { + Preconditions.checkArgument( + !request.getCollectionName().isEmpty(), "Collection name must not be empty"); + + logger.debug("Retrieve points from '{}'", request.getCollectionName()); + ListenableFuture future = getPoints(timeout).get(request); addLogFailureCallback(future, "Retrieve"); return Futures.transform(future, GetResponse::getResultList, MoreExecutors.directExecutor()); } @@ -1122,7 +1138,22 @@ public ListenableFuture updateVectorsAsync( requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build()); } - ListenableFuture future = getPoints(timeout).updateVectors(requestBuilder.build()); + return updateVectorsAsync(requestBuilder.build(), timeout); + } + + /** + * Update named vectors for point. + * + * @param request The update point vectors request + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture updateVectorsAsync( + UpdatePointVectors request, + @Nullable Duration timeout) { + Preconditions.checkArgument(!request.getCollectionName().isEmpty(), "Collection name must not be empty"); + logger.debug("Update vectors in '{}'", request.getCollectionName()); + ListenableFuture future = getPoints(timeout).updateVectors(request); addLogFailureCallback(future, "Update vectors"); return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor()); } @@ -1291,7 +1322,18 @@ public ListenableFuture deleteVectorsAsync( ); } - private ListenableFuture deleteVectorsAsync( + /** + * Delete named vectors for points. + * + * @param collectionName The name of the collection. + * @param vectors The list of vector names to delete. + * @param pointsSelector A selector for the points to be deleted. + * @param wait Whether to wait until the changes have been applied. Defaults to true. + * @param ordering Write ordering guarantees. + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture deleteVectorsAsync( String collectionName, List vectors, PointsSelector pointsSelector, @@ -1312,7 +1354,24 @@ private ListenableFuture deleteVectorsAsync( requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build()); } - ListenableFuture future = getPoints(timeout).deleteVectors(requestBuilder.build()); + return deleteVectorsAsync(requestBuilder.build(), timeout); + } + + /** + * Delete named vectors for points. + * + * @param request The delete point vectors request + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture deleteVectorsAsync( + DeletePointVectors request, + @Nullable Duration timeout) { + Preconditions.checkArgument( + !request.getCollectionName().isEmpty(), + "Collection name must not be empty"); + logger.debug("Delete vectors in '{}'", request.getCollectionName()); + ListenableFuture future = getPoints(timeout).deleteVectors(request); addLogFailureCallback(future, "Delete vectors"); return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor()); } @@ -1437,7 +1496,18 @@ public ListenableFuture setPayloadAsync( ); } - private ListenableFuture setPayloadAsync( + /** + * Sets the payload for the points. + * + * @param collectionName The name of the collection. + * @param payload New payload values + * @param pointsSelector selector for the points whose payloads are to be set. + * @param wait Whether to wait until the changes have been applied. Defaults to true. + * @param ordering Write ordering guarantees. + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture setPayloadAsync( String collectionName, Map payload, @Nullable PointsSelector pointsSelector, @@ -1458,8 +1528,24 @@ private ListenableFuture setPayloadAsync( requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build()); } - logger.debug("Set payload in '{}'", collectionName); - ListenableFuture future = getPoints(timeout).setPayload(requestBuilder.build()); + return setPayloadAsync(requestBuilder.build(), timeout); + } + + /** + * Sets the payload for the points. + * + * @param request The set payload request. + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture setPayloadAsync( + SetPayloadPoints request, + @Nullable Duration timeout) { + Preconditions.checkArgument( + !request.getCollectionName().isEmpty(), + "Collection name must not be empty"); + logger.debug("Set payload in '{}'", request.getCollectionName()); + ListenableFuture future = getPoints(timeout).setPayload(request); addLogFailureCallback(future, "Set payload"); return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor()); } @@ -1582,7 +1668,18 @@ public ListenableFuture overwritePayloadAsync( ); } - private ListenableFuture overwritePayloadAsync( + /** + * Overwrites the payload for the points. + * + * @param collectionName The name of the collection. + * @param payload New payload values + * @param pointsSelector A selector for the points whose payloads are to be overwritten. + * @param wait Whether to wait until the changes have been applied. Defaults to true. + * @param ordering Write ordering guarantees. + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture overwritePayloadAsync( String collectionName, Map payload, @Nullable PointsSelector pointsSelector, @@ -1603,8 +1700,24 @@ private ListenableFuture overwritePayloadAsync( requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build()); } - logger.debug("Overwrite payload in '{}'", collectionName); - ListenableFuture future = getPoints(timeout).overwritePayload(requestBuilder.build()); + return overwritePayloadAsync(requestBuilder.build(), timeout); + } + + /** + * Overwrites the payload for the points. + * + * @param request The overwrite payload request + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture overwritePayloadAsync( + SetPayloadPoints request, + @Nullable Duration timeout) { + Preconditions.checkArgument( + !request.getCollectionName().isEmpty(), + "Collection name must not be empty"); + logger.debug("Set payload in '{}'", request.getCollectionName()); + ListenableFuture future = getPoints(timeout).overwritePayload(request); addLogFailureCallback(future, "Overwrite payload"); return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor()); } @@ -1727,7 +1840,18 @@ public ListenableFuture deletePayloadAsync( ); } - private ListenableFuture deletePayloadAsync( + /** + * Delete specified key payload for the points. + * + * @param collectionName The name of the collection. + * @param keys List of keys to delete. + * @param pointsSelector selector for the points whose payloads are to be deleted. + * @param wait Whether to wait until the changes have been applied. Defaults to true. + * @param ordering Write ordering guarantees. + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture deletePayloadAsync( String collectionName, List keys, @Nullable PointsSelector pointsSelector, @@ -1748,8 +1872,24 @@ private ListenableFuture deletePayloadAsync( requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build()); } - logger.debug("Delete payload in '{}'", collectionName); - ListenableFuture future = getPoints(timeout).deletePayload(requestBuilder.build()); + return deletePayloadAsync(requestBuilder.build(), timeout); + } + + /** + * Delete specified key payload for the points. + * + * @param request The delete payload request + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture deletePayloadAsync( + DeletePayloadPoints request, + @Nullable Duration timeout) { + Preconditions.checkArgument( + !request.getCollectionName().isEmpty(), + "Collection name must not be empty"); + logger.debug("Delete payload in '{}'", request.getCollectionName()); + ListenableFuture future = getPoints(timeout).deletePayload(request); addLogFailureCallback(future, "Delete payload"); return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor()); } @@ -1860,7 +2000,17 @@ public ListenableFuture clearPayloadAsync( ); } - private ListenableFuture clearPayloadAsync( + /** + * Removes all payload for the points. + * + * @param collectionName The name of the collection. + * @param pointsSelector A selector for the points whose payloads are to be removed. + * @param wait Whether to wait until the changes have been applied. Defaults to true. + * @param ordering Write ordering guarantees. + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture clearPayloadAsync( String collectionName, @Nullable PointsSelector pointsSelector, @Nullable Boolean wait, @@ -1879,8 +2029,24 @@ private ListenableFuture clearPayloadAsync( requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build()); } - logger.debug("Clear payload in '{}'", collectionName); - ListenableFuture future = getPoints(timeout).clearPayload(requestBuilder.build()); + return clearPayloadAsync(requestBuilder.build(), timeout); + } + + /** + * Removes all payload for the points. + * + * @param request The clear payload request + * @param timeout The timeout for the call. + * @return a new instance of {@link ListenableFuture} + */ + public ListenableFuture clearPayloadAsync( + ClearPayloadPoints request, + @Nullable Duration timeout) { + Preconditions.checkArgument( + !request.getCollectionName().isEmpty(), + "Collection name must not be empty"); + logger.debug("Clear payload in '{}'", request.getCollectionName()); + ListenableFuture future = getPoints(timeout).clearPayload(request); addLogFailureCallback(future, "Clear payload"); return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor()); }