7
7
import java .util .Map ;
8
8
import java .util .Objects ;
9
9
10
+ import javax .annotation .Nullable ;
11
+
12
+ import io .qdrant .client .grpc .Collections .ShardKey ;
13
+ import io .qdrant .client .grpc .Points .ShardKeySelector ;
14
+
15
+ import static io .qdrant .client .ShardKeySelectorFactory .shardKeySelector ;
16
+ import static io .qdrant .client .ShardKeyFactory .shardKey ;
17
+
10
18
public class QdrantOptions implements Serializable {
11
19
private static final int DEFAULT_BATCH_SIZE = 64 ;
12
20
private static final int DEFAULT_RETRIES = 3 ;
@@ -25,14 +33,14 @@ public class QdrantOptions implements Serializable {
25
33
public final String [] vectorFields ;
26
34
public final String [] vectorNames ;
27
35
public final List <String > payloadFieldsToSkip ;
36
+ public final ShardKeySelector shardKeySelector ;
28
37
29
38
public QdrantOptions (Map <String , String > options ) {
30
39
Objects .requireNonNull (options );
31
40
32
41
qdrantUrl = options .get ("qdrant_url" );
33
42
collectionName = options .get ("collection_name" );
34
- batchSize =
35
- Integer .parseInt (options .getOrDefault ("batch_size" , String .valueOf (DEFAULT_BATCH_SIZE )));
43
+ batchSize = Integer .parseInt (options .getOrDefault ("batch_size" , String .valueOf (DEFAULT_BATCH_SIZE )));
36
44
retries = Integer .parseInt (options .getOrDefault ("retries" , String .valueOf (DEFAULT_RETRIES )));
37
45
idField = options .getOrDefault ("id_field" , "" );
38
46
apiKey = options .getOrDefault ("api_key" , "" );
@@ -45,6 +53,8 @@ public QdrantOptions(Map<String, String> options) {
45
53
vectorFields = parseArray (options .get ("vector_fields" ));
46
54
vectorNames = parseArray (options .get ("vector_names" ));
47
55
56
+ shardKeySelector = parseShardKeys (options .get ("shard_key_selector" ));
57
+
48
58
validateSparseVectorFields ();
49
59
validateVectorFields ();
50
60
@@ -83,4 +93,33 @@ private void validateVectorFields() {
83
93
throw new IllegalArgumentException ("Vector fields and names should have the same length" );
84
94
}
85
95
}
96
+
97
+ private ShardKeySelector parseShardKeys (@ Nullable String shardKeys ) {
98
+ if (shardKeys == null ) {
99
+ return null ;
100
+ }
101
+ String [] keys = shardKeys .split ("," );
102
+
103
+ ShardKey [] shardKeysArray = new ShardKey [keys .length ];
104
+
105
+ for (int i = 0 ; i < keys .length ; i ++) {
106
+ String key = keys [i ];
107
+ if (isInt (key .trim ())) {
108
+ shardKeysArray [i ] = shardKey (Integer .parseInt (key .trim ()));
109
+ } else {
110
+ shardKeysArray [i ] = shardKey (key .trim ());
111
+ }
112
+ }
113
+
114
+ return shardKeySelector (shardKeysArray );
115
+ }
116
+
117
+ boolean isInt (String s ) {
118
+ try {
119
+ Integer .parseInt (s );
120
+ return true ;
121
+ } catch (NumberFormatException er ) {
122
+ return false ;
123
+ }
124
+ }
86
125
}
0 commit comments