Skip to content

Commit

Permalink
feat: discover ops
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed Dec 14, 2023
1 parent 842dcc7 commit 71a50a5
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
75 changes: 71 additions & 4 deletions src/main/java/io/qdrant/client/QdrantClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.qdrant.client.grpc.CollectionsGrpc;
import io.qdrant.client.grpc.PointsGrpc;
import io.qdrant.client.grpc.SnapshotsGrpc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -34,6 +35,10 @@
import static io.qdrant.client.grpc.Collections.DeleteCollection;
import static io.qdrant.client.grpc.Collections.DeleteShardKeyRequest;
import static io.qdrant.client.grpc.Collections.DeleteShardKeyResponse;
import static io.qdrant.client.grpc.Points.DiscoverBatchPoints;
import static io.qdrant.client.grpc.Points.DiscoverBatchResponse;
import static io.qdrant.client.grpc.Points.DiscoverPoints;
import static io.qdrant.client.grpc.Points.DiscoverResponse;
import static io.qdrant.client.grpc.Collections.GetCollectionInfoRequest;
import static io.qdrant.client.grpc.Collections.GetCollectionInfoResponse;
import static io.qdrant.client.grpc.Collections.ListAliasesRequest;
Expand Down Expand Up @@ -675,7 +680,7 @@ public ListenableFuture<List<AliasDescription>> listAliasesAsync(@Nullable Durat
* Creates a shard key for a collection.
*
* @param createShardKey The request object for the operation.
* @return a new instance of {@link CreateShardKeyResponse}
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<CreateShardKeyResponse> createShardKeyAsync(CreateShardKeyRequest createShardKey) {
return createShardKeyAsync(createShardKey, null);
Expand All @@ -686,7 +691,7 @@ public ListenableFuture<CreateShardKeyResponse> createShardKeyAsync(CreateShardK
*
* @param createShardKey The request object for the operation.
* @param timeout The timeout for the call.
* @return a new instance of {@link CreateShardKeyResponse}
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<CreateShardKeyResponse> createShardKeyAsync(CreateShardKeyRequest createShardKey, @Nullable Duration timeout) {
String collectionName = createShardKey.getCollectionName();
Expand All @@ -708,7 +713,7 @@ public ListenableFuture<CreateShardKeyResponse> createShardKeyAsync(CreateShardK
* Deletes a shard key for a collection.
*
* @param deleteShardKey The request object for the operation.
* @return a new instance of {@link DeleteShardKeyResponse}
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<DeleteShardKeyResponse> deleteShardKeyAsync(DeleteShardKeyRequest deleteShardKey) {
return deleteShardKeyAsync(deleteShardKey, null);
Expand All @@ -719,7 +724,7 @@ public ListenableFuture<DeleteShardKeyResponse> deleteShardKeyAsync(DeleteShardK
*
* @param deleteShardKey The request object for the operation.
* @param timeout The timeout for the call.
* @return a new instance of {@link DeleteShardKeyResponse}
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<DeleteShardKeyResponse> deleteShardKeyAsync(DeleteShardKeyRequest deleteShardKey, @Nullable Duration timeout) {
String collectionName = deleteShardKey.getCollectionName();
Expand Down Expand Up @@ -2227,6 +2232,68 @@ public ListenableFuture<List<PointGroup>> recommendGroupsAsync(RecommendPointGro
MoreExecutors.directExecutor());
}

/**
* Use the context and a target to find the most similar points to the target.
* Constraints by the context.
*
* @param request The discover points request
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<List<ScoredPoint>> discoverAsync(DiscoverPoints request) {
return discoverAsync(request, null);
}

/**
* Use the context and a target to find the most similar points to the target.
* Constraints by the context.
*
* @param request The discover points request
* @param timeout The timeout for the call.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<List<ScoredPoint>> discoverAsync(DiscoverPoints request, @Nullable Duration timeout) {
String collectionName = request.getCollectionName();
Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
logger.debug("Discover on '{}'", collectionName);
ListenableFuture<DiscoverResponse> future = getPoints(timeout).discover(request);
addLogFailureCallback(future, "Discover");
return Futures.transform(
future,
response -> response.getResultList(),
MoreExecutors.directExecutor());
}

/**
* Use the context and a target to find the most similar points to the target in a batch.
* Constraints by the context.
*
* @param request The discover batch points request.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<List<BatchResult>> discoverBatchAsync(DiscoverBatchPoints request) {
return discoverBatchAsync(request, null);
}

/**
* Use the context and a target to find the most similar points to the target in a batch.
* Constraints by the context.
*
* @param request The discover batch points request.
* @param timeout The timeout for the call.
* @return a new instance of {@link ListenableFuture}
*/
public ListenableFuture<List<BatchResult>> discoverBatchAsync(DiscoverBatchPoints request, @Nullable Duration timeout) {
String collectionName = request.getCollectionName();
Preconditions.checkArgument(!collectionName.isEmpty(), "Collection name must not be empty");
logger.debug("Discover batch on '{}'", collectionName);
ListenableFuture<DiscoverBatchResponse> future = getPoints(timeout).discoverBatch(request);
addLogFailureCallback(future, "Discover batch");
return Futures.transform(
future,
response -> response.getResultList(),
MoreExecutors.directExecutor());
}

/**
* Count the points in a collection. The count is exact
*
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/qdrant/client/ShardKeySelectorFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

import java.util.Arrays;

/**
* Convenience methods for constructing {@link ShardKeySelector}
*/
public class ShardKeySelectorFactory {
private ShardKeySelectorFactory() {
}

/**
* Creates a {@link ShardKeySelector} with the given shard keys.
*
Expand Down

0 comments on commit 71a50a5

Please sign in to comment.