|
| 1 | +package io.qdrant.example; |
| 2 | + |
| 3 | +import io.grpc.Grpc; |
| 4 | +import io.grpc.InsecureChannelCredentials; |
| 5 | +import io.grpc.ManagedChannel; |
| 6 | +import io.qdrant.client.QdrantClient; |
| 7 | +import io.qdrant.client.QdrantGrpcClient; |
| 8 | +import io.qdrant.client.grpc.Collections; |
| 9 | +import io.qdrant.client.grpc.Collections.CreateCollection; |
| 10 | +import io.qdrant.client.grpc.Collections.VectorParams; |
| 11 | +import io.qdrant.client.grpc.Collections.Distance; |
| 12 | +import java.util.List; |
| 13 | +import java.util.concurrent.ExecutionException; |
| 14 | + |
| 15 | +public class QdrantExample { |
| 16 | + public static void main(String[] args) { |
| 17 | + try { |
| 18 | + ManagedChannel channel = |
| 19 | + Grpc.newChannelBuilder( |
| 20 | + "localhost:6334", InsecureChannelCredentials.create()) |
| 21 | + .build(); |
| 22 | + QdrantGrpcClient grpcClient = QdrantGrpcClient.newBuilder(channel, true).build(); |
| 23 | + QdrantClient client = new QdrantClient(grpcClient); |
| 24 | + |
| 25 | + |
| 26 | + // Create a simple collection |
| 27 | + String collectionName = "example_collection"; |
| 28 | + |
| 29 | + client.createCollectionAsync( |
| 30 | + collectionName, |
| 31 | + VectorParams.newBuilder() |
| 32 | + .setDistance(Distance.Cosine) |
| 33 | + .setSize(128) |
| 34 | + .build() |
| 35 | + ).get(); |
| 36 | + |
| 37 | + |
| 38 | + List<String> collections = client.listCollectionsAsync().get(); |
| 39 | + |
| 40 | + for (String collection : collections) { |
| 41 | + System.out.println("- " + collection); |
| 42 | + } |
| 43 | + |
| 44 | + client.close(); |
| 45 | + |
| 46 | + } catch (Exception e) { |
| 47 | + System.err.println("Error occurred: " + e.getMessage()); |
| 48 | + e.printStackTrace(); |
| 49 | + System.exit(1); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments