Skip to content

Commit

Permalink
chore: Added create collection overload
Browse files Browse the repository at this point in the history
  • Loading branch information
Anush008 committed Dec 8, 2023
1 parent 53420fd commit 2be9bc9
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/main/java/io/qdrant/client/QdrantClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/** Client for interfacing with the Qdrant service. */
public class QdrantClient {
public class QdrantClient implements AutoCloseable {
private QdrantGrpc.QdrantBlockingStub qdrantStub;
private CollectionsGrpc.CollectionsBlockingStub collectionsStub;
private PointsGrpc.PointsBlockingStub pointsStub;
private SnapshotsGrpc.SnapshotsBlockingStub snapshotStub;
private ManagedChannel channel;

/**
* Constructs a new QdrantClient with the specified URL and API key<br>
Expand Down Expand Up @@ -97,10 +99,11 @@ private ManagedChannel createManagedChannel(String url, TokenInterceptor interce
* @param channel The managed channel used for communication.
*/
private void initializeStubs(ManagedChannel channel) {
qdrantStub = QdrantGrpc.newBlockingStub(channel);
collectionsStub = CollectionsGrpc.newBlockingStub(channel);
pointsStub = PointsGrpc.newBlockingStub(channel);
snapshotStub = SnapshotsGrpc.newBlockingStub(channel);
this.qdrantStub = QdrantGrpc.newBlockingStub(channel);
this.collectionsStub = CollectionsGrpc.newBlockingStub(channel);
this.pointsStub = PointsGrpc.newBlockingStub(channel);
this.snapshotStub = SnapshotsGrpc.newBlockingStub(channel);
this.channel = channel;
}

/**
Expand Down Expand Up @@ -158,6 +161,24 @@ public Collections.CollectionOperationResponse createCollection(
return createCollection(details);
}

/**
* Creates a new collection with the specified name, vector size, and distance metric.
*
* @param collectionName The name of the collection to be created.
* @param vectorsConfig The vectors configuration of the collection.
* @return The response containing the operation status.
*/
public Collections.CollectionOperationResponse createCollection(
String collectionName, Collections.VectorsConfig vectorsConfig) {

Collections.CreateCollection details =
Collections.CreateCollection.newBuilder()
.setVectorsConfig(vectorsConfig)
.setCollectionName(collectionName)
.build();
return createCollection(details);
}

/**
* Creates a new collection with the specified details.
*
Expand Down Expand Up @@ -1228,5 +1249,10 @@ public SnapshotsService.DeleteSnapshotResponse deleteFullSnapshot(String snapsho
return snapshotStub.deleteFull(request);
}

@Override
public void close() throws InterruptedException {
this.channel.shutdown().awaitTermination(10, TimeUnit.SECONDS);
}

// TODO: Download snapshots REST
}

0 comments on commit 2be9bc9

Please sign in to comment.