|
1 | 1 | package io.qdrant.example; |
2 | 2 |
|
3 | | -import io.grpc.Grpc; |
4 | | -import io.grpc.InsecureChannelCredentials; |
5 | | -import io.grpc.ManagedChannel; |
6 | 3 | import io.qdrant.client.QdrantClient; |
7 | 4 | import io.qdrant.client.QdrantGrpcClient; |
8 | | -import io.qdrant.client.grpc.Collections; |
9 | | -import io.qdrant.client.grpc.Collections.CreateCollection; |
10 | 5 | import io.qdrant.client.grpc.Collections.VectorParams; |
11 | 6 | import io.qdrant.client.grpc.Collections.Distance; |
12 | 7 | import java.util.List; |
13 | | -import java.util.concurrent.ExecutionException; |
14 | 8 |
|
15 | 9 | public class QdrantExample { |
16 | 10 | public static void main(String[] args) { |
17 | 11 | 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); |
| 12 | + QdrantClient client = new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false) |
| 13 | + .build()); |
24 | 14 |
|
25 | | - |
26 | | - // Create a simple collection |
27 | 15 | 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 | | - |
| 16 | + |
| 17 | + if (!client.collectionExistsAsync(collectionName).get()) { |
| 18 | + client.createCollectionAsync( |
| 19 | + collectionName, |
| 20 | + VectorParams.newBuilder() |
| 21 | + .setDistance(Distance.Cosine) |
| 22 | + .setSize(128) |
| 23 | + .build() |
| 24 | + ).get(); |
| 25 | + } |
37 | 26 |
|
38 | 27 | List<String> collections = client.listCollectionsAsync().get(); |
39 | 28 |
|
|
0 commit comments