3
3
import dev .langchain4j .data .segment .TextSegment ;
4
4
import dev .langchain4j .store .embedding .EmbeddingStore ;
5
5
import dev .langchain4j .store .embedding .qdrant .QdrantEmbeddingStore ;
6
+ import io .qdrant .client .QdrantClient ;
7
+ import io .qdrant .client .QdrantGrpcClient ;
8
+ import io .qdrant .client .grpc .Collections .CollectionOperationResponse ;
9
+ import io .qdrant .client .grpc .Collections .Distance ;
10
+ import io .qdrant .client .grpc .Collections .VectorParams ;
6
11
import jakarta .enterprise .inject .Produces ;
7
12
import org .eclipse .microprofile .config .inject .ConfigProperty ;
13
+ import org .slf4j .Logger ;
14
+ import org .slf4j .LoggerFactory ;
15
+
16
+ import com .google .common .util .concurrent .ListenableFuture ;
8
17
9
18
import java .net .URI ;
10
19
import java .net .URISyntaxException ;
11
20
12
21
public class EmbeddingStoreProducer {
13
22
23
+ private static final Logger log = LoggerFactory .getLogger (EmbeddingStoreProducer .class );
24
+
14
25
@ ConfigProperty (name = "AZURE_SEARCH_INDEX" , defaultValue = "kbindex" )
15
26
String azureSearchIndexName ;
16
27
@@ -21,10 +32,24 @@ public class EmbeddingStoreProducer {
21
32
public EmbeddingStore <TextSegment > embeddingStore () throws URISyntaxException {
22
33
String qdrantHostname = new URI (qdrantUrl ).getHost ();
23
34
int qdrantPort = new URI (qdrantUrl ).getPort ();
35
+
36
+ QdrantGrpcClient .Builder grpcClientBuilder = QdrantGrpcClient .newBuilder (qdrantHostname , qdrantPort , false );
37
+ QdrantClient qdrantClient = new QdrantClient (grpcClientBuilder .build ());
38
+
39
+ ListenableFuture <CollectionOperationResponse > futureCollection = qdrantClient .createCollectionAsync (azureSearchIndexName , VectorParams .newBuilder ().setSize (384 ).setDistance (Distance .Cosine ).build ());
40
+
41
+ while (!futureCollection .isDone ()) {
42
+ try {
43
+ log .info ("Creating collection {}" , azureSearchIndexName );
44
+ Thread .sleep (1000 );
45
+ } catch (InterruptedException e ) {
46
+ e .printStackTrace ();
47
+ }
48
+ }
49
+
24
50
return QdrantEmbeddingStore .builder ()
51
+ .client (qdrantClient )
25
52
.collectionName (azureSearchIndexName )
26
- .host (qdrantHostname )
27
- .port (qdrantPort )
28
53
.build ();
29
54
}
30
55
}
0 commit comments