Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Added method overloads with request objects #22

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 182 additions & 16 deletions src/main/java/io/qdrant/client/QdrantClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,23 @@ public ListenableFuture<List<RetrievedPoint>> retrieveAsync(
requestBuilder.setReadConsistency(readConsistency);
}

ListenableFuture<GetResponse> 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<List<RetrievedPoint>> 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<GetResponse> future = getPoints(timeout).get(request);
addLogFailureCallback(future, "Retrieve");
return Futures.transform(future, GetResponse::getResultList, MoreExecutors.directExecutor());
}
Expand Down Expand Up @@ -1122,7 +1138,22 @@ public ListenableFuture<UpdateResult> updateVectorsAsync(
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
}

ListenableFuture<PointsOperationResponse> 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<UpdateResult> 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<PointsOperationResponse> future = getPoints(timeout).updateVectors(request);
addLogFailureCallback(future, "Update vectors");
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
}
Expand Down Expand Up @@ -1291,7 +1322,18 @@ public ListenableFuture<UpdateResult> deleteVectorsAsync(
);
}

private ListenableFuture<UpdateResult> 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 <code>true</code>.
* @param ordering Write ordering guarantees.
* @param timeout The timeout for the call.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<UpdateResult> deleteVectorsAsync(
String collectionName,
List<String> vectors,
PointsSelector pointsSelector,
Expand All @@ -1312,7 +1354,24 @@ private ListenableFuture<UpdateResult> deleteVectorsAsync(
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
}

ListenableFuture<PointsOperationResponse> 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<UpdateResult> 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<PointsOperationResponse> future = getPoints(timeout).deleteVectors(request);
addLogFailureCallback(future, "Delete vectors");
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
}
Expand Down Expand Up @@ -1437,7 +1496,18 @@ public ListenableFuture<UpdateResult> setPayloadAsync(
);
}

private ListenableFuture<UpdateResult> 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 <code>true</code>.
* @param ordering Write ordering guarantees.
* @param timeout The timeout for the call.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<UpdateResult> setPayloadAsync(
String collectionName,
Map<String, Value> payload,
@Nullable PointsSelector pointsSelector,
Expand All @@ -1458,8 +1528,24 @@ private ListenableFuture<UpdateResult> setPayloadAsync(
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
}

logger.debug("Set payload in '{}'", collectionName);
ListenableFuture<PointsOperationResponse> 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<UpdateResult> 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<PointsOperationResponse> future = getPoints(timeout).setPayload(request);
addLogFailureCallback(future, "Set payload");
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
}
Expand Down Expand Up @@ -1582,7 +1668,18 @@ public ListenableFuture<UpdateResult> overwritePayloadAsync(
);
}

private ListenableFuture<UpdateResult> 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 <code>true</code>.
* @param ordering Write ordering guarantees.
* @param timeout The timeout for the call.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<UpdateResult> overwritePayloadAsync(
String collectionName,
Map<String, Value> payload,
@Nullable PointsSelector pointsSelector,
Expand All @@ -1603,8 +1700,24 @@ private ListenableFuture<UpdateResult> overwritePayloadAsync(
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
}

logger.debug("Overwrite payload in '{}'", collectionName);
ListenableFuture<PointsOperationResponse> 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<UpdateResult> 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<PointsOperationResponse> future = getPoints(timeout).overwritePayload(request);
addLogFailureCallback(future, "Overwrite payload");
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
}
Expand Down Expand Up @@ -1727,7 +1840,18 @@ public ListenableFuture<UpdateResult> deletePayloadAsync(
);
}

private ListenableFuture<UpdateResult> 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 <code>true</code>.
* @param ordering Write ordering guarantees.
* @param timeout The timeout for the call.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<UpdateResult> deletePayloadAsync(
String collectionName,
List<String> keys,
@Nullable PointsSelector pointsSelector,
Expand All @@ -1748,8 +1872,24 @@ private ListenableFuture<UpdateResult> deletePayloadAsync(
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
}

logger.debug("Delete payload in '{}'", collectionName);
ListenableFuture<PointsOperationResponse> 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<UpdateResult> 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<PointsOperationResponse> future = getPoints(timeout).deletePayload(request);
addLogFailureCallback(future, "Delete payload");
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
}
Expand Down Expand Up @@ -1860,7 +2000,17 @@ public ListenableFuture<UpdateResult> clearPayloadAsync(
);
}

private ListenableFuture<UpdateResult> 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 <code>true</code>.
* @param ordering Write ordering guarantees.
* @param timeout The timeout for the call.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<UpdateResult> clearPayloadAsync(
String collectionName,
@Nullable PointsSelector pointsSelector,
@Nullable Boolean wait,
Expand All @@ -1879,8 +2029,24 @@ private ListenableFuture<UpdateResult> clearPayloadAsync(
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
}

logger.debug("Clear payload in '{}'", collectionName);
ListenableFuture<PointsOperationResponse> 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<UpdateResult> 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<PointsOperationResponse> future = getPoints(timeout).clearPayload(request);
addLogFailureCallback(future, "Clear payload");
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
}
Expand Down
Loading