77import java .util .Map ;
88import java .util .Objects ;
99
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+
1018public class QdrantOptions implements Serializable {
1119 private static final int DEFAULT_BATCH_SIZE = 64 ;
1220 private static final int DEFAULT_RETRIES = 3 ;
@@ -25,14 +33,14 @@ public class QdrantOptions implements Serializable {
2533 public final String [] vectorFields ;
2634 public final String [] vectorNames ;
2735 public final List <String > payloadFieldsToSkip ;
36+ public final ShardKeySelector shardKeySelector ;
2837
2938 public QdrantOptions (Map <String , String > options ) {
3039 Objects .requireNonNull (options );
3140
3241 qdrantUrl = options .get ("qdrant_url" );
3342 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 )));
3644 retries = Integer .parseInt (options .getOrDefault ("retries" , String .valueOf (DEFAULT_RETRIES )));
3745 idField = options .getOrDefault ("id_field" , "" );
3846 apiKey = options .getOrDefault ("api_key" , "" );
@@ -45,6 +53,8 @@ public QdrantOptions(Map<String, String> options) {
4553 vectorFields = parseArray (options .get ("vector_fields" ));
4654 vectorNames = parseArray (options .get ("vector_names" ));
4755
56+ shardKeySelector = parseShardKeys (options .get ("shard_key_selector" ));
57+
4858 validateSparseVectorFields ();
4959 validateVectorFields ();
5060
@@ -83,4 +93,33 @@ private void validateVectorFields() {
8393 throw new IllegalArgumentException ("Vector fields and names should have the same length" );
8494 }
8595 }
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+ }
86125}
0 commit comments