Skip to content

Commit 06b6c8d

Browse files
authored
refactor: Add request object overloads (#22)
1 parent 776b909 commit 06b6c8d

File tree

1 file changed

+182
-16
lines changed

1 file changed

+182
-16
lines changed

src/main/java/io/qdrant/client/QdrantClient.java

Lines changed: 182 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,23 @@ public ListenableFuture<List<RetrievedPoint>> retrieveAsync(
10581058
requestBuilder.setReadConsistency(readConsistency);
10591059
}
10601060

1061-
ListenableFuture<GetResponse> future = getPoints(timeout).get(requestBuilder.build());
1061+
return retrieveAsync(requestBuilder.build(), timeout);
1062+
}
1063+
1064+
/**
1065+
* Retrieves points.
1066+
*
1067+
* @param request The get points request
1068+
* @param timeout The timeout for the call.
1069+
* @return a new instance of {@link ListenableFuture}
1070+
*/
1071+
public ListenableFuture<List<RetrievedPoint>> retrieveAsync(
1072+
GetPoints request, @Nullable Duration timeout) {
1073+
Preconditions.checkArgument(
1074+
!request.getCollectionName().isEmpty(), "Collection name must not be empty");
1075+
1076+
logger.debug("Retrieve points from '{}'", request.getCollectionName());
1077+
ListenableFuture<GetResponse> future = getPoints(timeout).get(request);
10621078
addLogFailureCallback(future, "Retrieve");
10631079
return Futures.transform(future, GetResponse::getResultList, MoreExecutors.directExecutor());
10641080
}
@@ -1122,7 +1138,22 @@ public ListenableFuture<UpdateResult> updateVectorsAsync(
11221138
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
11231139
}
11241140

1125-
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).updateVectors(requestBuilder.build());
1141+
return updateVectorsAsync(requestBuilder.build(), timeout);
1142+
}
1143+
1144+
/**
1145+
* Update named vectors for point.
1146+
*
1147+
* @param request The update point vectors request
1148+
* @param timeout The timeout for the call.
1149+
* @return a new instance of {@link ListenableFuture}
1150+
*/
1151+
public ListenableFuture<UpdateResult> updateVectorsAsync(
1152+
UpdatePointVectors request,
1153+
@Nullable Duration timeout) {
1154+
Preconditions.checkArgument(!request.getCollectionName().isEmpty(), "Collection name must not be empty");
1155+
logger.debug("Update vectors in '{}'", request.getCollectionName());
1156+
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).updateVectors(request);
11261157
addLogFailureCallback(future, "Update vectors");
11271158
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
11281159
}
@@ -1291,7 +1322,18 @@ public ListenableFuture<UpdateResult> deleteVectorsAsync(
12911322
);
12921323
}
12931324

1294-
private ListenableFuture<UpdateResult> deleteVectorsAsync(
1325+
/**
1326+
* Delete named vectors for points.
1327+
*
1328+
* @param collectionName The name of the collection.
1329+
* @param vectors The list of vector names to delete.
1330+
* @param pointsSelector A selector for the points to be deleted.
1331+
* @param wait Whether to wait until the changes have been applied. Defaults to <code>true</code>.
1332+
* @param ordering Write ordering guarantees.
1333+
* @param timeout The timeout for the call.
1334+
* @return a new instance of {@link ListenableFuture}
1335+
*/
1336+
public ListenableFuture<UpdateResult> deleteVectorsAsync(
12951337
String collectionName,
12961338
List<String> vectors,
12971339
PointsSelector pointsSelector,
@@ -1312,7 +1354,24 @@ private ListenableFuture<UpdateResult> deleteVectorsAsync(
13121354
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
13131355
}
13141356

1315-
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).deleteVectors(requestBuilder.build());
1357+
return deleteVectorsAsync(requestBuilder.build(), timeout);
1358+
}
1359+
1360+
/**
1361+
* Delete named vectors for points.
1362+
*
1363+
* @param request The delete point vectors request
1364+
* @param timeout The timeout for the call.
1365+
* @return a new instance of {@link ListenableFuture}
1366+
*/
1367+
public ListenableFuture<UpdateResult> deleteVectorsAsync(
1368+
DeletePointVectors request,
1369+
@Nullable Duration timeout) {
1370+
Preconditions.checkArgument(
1371+
!request.getCollectionName().isEmpty(),
1372+
"Collection name must not be empty");
1373+
logger.debug("Delete vectors in '{}'", request.getCollectionName());
1374+
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).deleteVectors(request);
13161375
addLogFailureCallback(future, "Delete vectors");
13171376
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
13181377
}
@@ -1437,7 +1496,18 @@ public ListenableFuture<UpdateResult> setPayloadAsync(
14371496
);
14381497
}
14391498

1440-
private ListenableFuture<UpdateResult> setPayloadAsync(
1499+
/**
1500+
* Sets the payload for the points.
1501+
*
1502+
* @param collectionName The name of the collection.
1503+
* @param payload New payload values
1504+
* @param pointsSelector selector for the points whose payloads are to be set.
1505+
* @param wait Whether to wait until the changes have been applied. Defaults to <code>true</code>.
1506+
* @param ordering Write ordering guarantees.
1507+
* @param timeout The timeout for the call.
1508+
* @return a new instance of {@link ListenableFuture}
1509+
*/
1510+
public ListenableFuture<UpdateResult> setPayloadAsync(
14411511
String collectionName,
14421512
Map<String, Value> payload,
14431513
@Nullable PointsSelector pointsSelector,
@@ -1458,8 +1528,24 @@ private ListenableFuture<UpdateResult> setPayloadAsync(
14581528
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
14591529
}
14601530

1461-
logger.debug("Set payload in '{}'", collectionName);
1462-
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).setPayload(requestBuilder.build());
1531+
return setPayloadAsync(requestBuilder.build(), timeout);
1532+
}
1533+
1534+
/**
1535+
* Sets the payload for the points.
1536+
*
1537+
* @param request The set payload request.
1538+
* @param timeout The timeout for the call.
1539+
* @return a new instance of {@link ListenableFuture}
1540+
*/
1541+
public ListenableFuture<UpdateResult> setPayloadAsync(
1542+
SetPayloadPoints request,
1543+
@Nullable Duration timeout) {
1544+
Preconditions.checkArgument(
1545+
!request.getCollectionName().isEmpty(),
1546+
"Collection name must not be empty");
1547+
logger.debug("Set payload in '{}'", request.getCollectionName());
1548+
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).setPayload(request);
14631549
addLogFailureCallback(future, "Set payload");
14641550
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
14651551
}
@@ -1582,7 +1668,18 @@ public ListenableFuture<UpdateResult> overwritePayloadAsync(
15821668
);
15831669
}
15841670

1585-
private ListenableFuture<UpdateResult> overwritePayloadAsync(
1671+
/**
1672+
* Overwrites the payload for the points.
1673+
*
1674+
* @param collectionName The name of the collection.
1675+
* @param payload New payload values
1676+
* @param pointsSelector A selector for the points whose payloads are to be overwritten.
1677+
* @param wait Whether to wait until the changes have been applied. Defaults to <code>true</code>.
1678+
* @param ordering Write ordering guarantees.
1679+
* @param timeout The timeout for the call.
1680+
* @return a new instance of {@link ListenableFuture}
1681+
*/
1682+
public ListenableFuture<UpdateResult> overwritePayloadAsync(
15861683
String collectionName,
15871684
Map<String, Value> payload,
15881685
@Nullable PointsSelector pointsSelector,
@@ -1603,8 +1700,24 @@ private ListenableFuture<UpdateResult> overwritePayloadAsync(
16031700
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
16041701
}
16051702

1606-
logger.debug("Overwrite payload in '{}'", collectionName);
1607-
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).overwritePayload(requestBuilder.build());
1703+
return overwritePayloadAsync(requestBuilder.build(), timeout);
1704+
}
1705+
1706+
/**
1707+
* Overwrites the payload for the points.
1708+
*
1709+
* @param request The overwrite payload request
1710+
* @param timeout The timeout for the call.
1711+
* @return a new instance of {@link ListenableFuture}
1712+
*/
1713+
public ListenableFuture<UpdateResult> overwritePayloadAsync(
1714+
SetPayloadPoints request,
1715+
@Nullable Duration timeout) {
1716+
Preconditions.checkArgument(
1717+
!request.getCollectionName().isEmpty(),
1718+
"Collection name must not be empty");
1719+
logger.debug("Set payload in '{}'", request.getCollectionName());
1720+
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).overwritePayload(request);
16081721
addLogFailureCallback(future, "Overwrite payload");
16091722
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
16101723
}
@@ -1727,7 +1840,18 @@ public ListenableFuture<UpdateResult> deletePayloadAsync(
17271840
);
17281841
}
17291842

1730-
private ListenableFuture<UpdateResult> deletePayloadAsync(
1843+
/**
1844+
* Delete specified key payload for the points.
1845+
*
1846+
* @param collectionName The name of the collection.
1847+
* @param keys List of keys to delete.
1848+
* @param pointsSelector selector for the points whose payloads are to be deleted.
1849+
* @param wait Whether to wait until the changes have been applied. Defaults to <code>true</code>.
1850+
* @param ordering Write ordering guarantees.
1851+
* @param timeout The timeout for the call.
1852+
* @return a new instance of {@link ListenableFuture}
1853+
*/
1854+
public ListenableFuture<UpdateResult> deletePayloadAsync(
17311855
String collectionName,
17321856
List<String> keys,
17331857
@Nullable PointsSelector pointsSelector,
@@ -1748,8 +1872,24 @@ private ListenableFuture<UpdateResult> deletePayloadAsync(
17481872
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
17491873
}
17501874

1751-
logger.debug("Delete payload in '{}'", collectionName);
1752-
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).deletePayload(requestBuilder.build());
1875+
return deletePayloadAsync(requestBuilder.build(), timeout);
1876+
}
1877+
1878+
/**
1879+
* Delete specified key payload for the points.
1880+
*
1881+
* @param request The delete payload request
1882+
* @param timeout The timeout for the call.
1883+
* @return a new instance of {@link ListenableFuture}
1884+
*/
1885+
public ListenableFuture<UpdateResult> deletePayloadAsync(
1886+
DeletePayloadPoints request,
1887+
@Nullable Duration timeout) {
1888+
Preconditions.checkArgument(
1889+
!request.getCollectionName().isEmpty(),
1890+
"Collection name must not be empty");
1891+
logger.debug("Delete payload in '{}'", request.getCollectionName());
1892+
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).deletePayload(request);
17531893
addLogFailureCallback(future, "Delete payload");
17541894
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
17551895
}
@@ -1860,7 +2000,17 @@ public ListenableFuture<UpdateResult> clearPayloadAsync(
18602000
);
18612001
}
18622002

1863-
private ListenableFuture<UpdateResult> clearPayloadAsync(
2003+
/**
2004+
* Removes all payload for the points.
2005+
*
2006+
* @param collectionName The name of the collection.
2007+
* @param pointsSelector A selector for the points whose payloads are to be removed.
2008+
* @param wait Whether to wait until the changes have been applied. Defaults to <code>true</code>.
2009+
* @param ordering Write ordering guarantees.
2010+
* @param timeout The timeout for the call.
2011+
* @return a new instance of {@link ListenableFuture}
2012+
*/
2013+
public ListenableFuture<UpdateResult> clearPayloadAsync(
18642014
String collectionName,
18652015
@Nullable PointsSelector pointsSelector,
18662016
@Nullable Boolean wait,
@@ -1879,8 +2029,24 @@ private ListenableFuture<UpdateResult> clearPayloadAsync(
18792029
requestBuilder.setOrdering(WriteOrdering.newBuilder().setType(ordering).build());
18802030
}
18812031

1882-
logger.debug("Clear payload in '{}'", collectionName);
1883-
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).clearPayload(requestBuilder.build());
2032+
return clearPayloadAsync(requestBuilder.build(), timeout);
2033+
}
2034+
2035+
/**
2036+
* Removes all payload for the points.
2037+
*
2038+
* @param request The clear payload request
2039+
* @param timeout The timeout for the call.
2040+
* @return a new instance of {@link ListenableFuture}
2041+
*/
2042+
public ListenableFuture<UpdateResult> clearPayloadAsync(
2043+
ClearPayloadPoints request,
2044+
@Nullable Duration timeout) {
2045+
Preconditions.checkArgument(
2046+
!request.getCollectionName().isEmpty(),
2047+
"Collection name must not be empty");
2048+
logger.debug("Clear payload in '{}'", request.getCollectionName());
2049+
ListenableFuture<PointsOperationResponse> future = getPoints(timeout).clearPayload(request);
18842050
addLogFailureCallback(future, "Clear payload");
18852051
return Futures.transform(future, PointsOperationResponse::getResult, MoreExecutors.directExecutor());
18862052
}

0 commit comments

Comments
 (0)