@@ -97,7 +97,7 @@ enum MergePolicyType {
9797 LOG_DOC
9898 }
9999
100- private static String formatIndexPath (CmdLineArgs args ) {
100+ private static String formatIndexPath (TestConfiguration args ) {
101101 List <String > suffix = new ArrayList <>();
102102 if (args .indexType () == IndexType .FLAT ) {
103103 suffix .add ("flat" );
@@ -116,7 +116,7 @@ private static String formatIndexPath(CmdLineArgs args) {
116116 return INDEX_DIR + "/" + args .docVectors ().get (0 ).getFileName () + "-" + String .join ("-" , suffix ) + ".index" ;
117117 }
118118
119- static Codec createCodec (CmdLineArgs args ) {
119+ static Codec createCodec (TestConfiguration args ) {
120120 final KnnVectorsFormat format ;
121121 int quantizeBits = args .quantizeBits ();
122122 if (args .indexType () == IndexType .IVF ) {
@@ -233,7 +233,7 @@ public static void main(String[] args) throws Exception {
233233 System .out .println ("Where <config-file> is a JSON file containing one or more configurations for the KNN index tester." );
234234 System .out .println ("--warnUp is the number of warm iterations " );
235235 System .out .println ("An example configuration object: " );
236- System .out .println (CmdLineArgs .exampleFormatForHelp ());
236+ System .out .println (TestConfiguration .exampleFormatForHelp ());
237237 return ;
238238 }
239239
@@ -244,83 +244,91 @@ public static void main(String[] args) throws Exception {
244244
245245 logger .info ("Using configuration file: " + jsonConfigPath );
246246 // Parse the JSON config file to get command line arguments
247- // This assumes that CmdLineArgs.fromXContent is implemented to parse the JSON file
248- List <CmdLineArgs > cmdLineArgsList = new ArrayList <>();
247+ // This assumes that the JSON file is the correct format
248+ List <TestConfiguration > testConfigurationList = new ArrayList <>();
249249 try (
250250 InputStream jsonStream = Files .newInputStream (jsonConfigPath );
251251 XContentParser parser = XContentType .JSON .xContent ().createParser (XContentParserConfiguration .EMPTY , jsonStream )
252252 ) {
253253 // check if the parser is at the start of an object if so, we only have one set of arguments
254254 if (parser .currentToken () == null && parser .nextToken () == XContentParser .Token .START_OBJECT ) {
255- cmdLineArgsList .add (CmdLineArgs .fromXContent (parser ));
255+ testConfigurationList .add (TestConfiguration .fromXContent (parser ));
256256 } else if (parser .currentToken () == XContentParser .Token .START_ARRAY ) {
257257 // if the parser is at the start of an array, we have multiple sets of arguments
258258 while (parser .nextToken () != XContentParser .Token .END_ARRAY ) {
259- cmdLineArgsList .add (CmdLineArgs .fromXContent (parser ));
259+ testConfigurationList .add (TestConfiguration .fromXContent (parser ));
260260 }
261261 } else {
262262 throw new IllegalArgumentException ("Invalid JSON format in config file: " + jsonConfigPath );
263263 }
264264 }
265265 FormattedResults formattedResults = new FormattedResults ();
266266
267- for (CmdLineArgs cmdLineArgs : cmdLineArgsList ) {
268- String indexType = cmdLineArgs .indexType ().name ().toLowerCase (Locale .ROOT );
269- Results indexResults = new Results (cmdLineArgs .docVectors ().get (0 ).getFileName ().toString (), indexType , cmdLineArgs .numDocs ());
270- Results [] results = new Results [cmdLineArgs .numberOfSearchRuns ()];
267+ for (TestConfiguration testConfiguration : testConfigurationList ) {
268+ String indexType = testConfiguration .indexType ().name ().toLowerCase (Locale .ROOT );
269+ Results indexResults = new Results (
270+ testConfiguration .docVectors ().get (0 ).getFileName ().toString (),
271+ indexType ,
272+ testConfiguration .numDocs ()
273+ );
274+ Results [] results = new Results [testConfiguration .numberOfSearchRuns ()];
271275 for (int i = 0 ; i < results .length ; i ++) {
272- results [i ] = new Results (cmdLineArgs .docVectors ().get (0 ).getFileName ().toString (), indexType , cmdLineArgs .numDocs ());
276+ results [i ] = new Results (
277+ testConfiguration .docVectors ().get (0 ).getFileName ().toString (),
278+ indexType ,
279+ testConfiguration .numDocs ()
280+ );
273281 }
274282 logger .info ("Running with Java: " + Runtime .version ());
275- logger .info ("Running KNN index tester with arguments: " + cmdLineArgs );
276- Codec codec = createCodec (cmdLineArgs );
277- Path indexPath = PathUtils .get (formatIndexPath (cmdLineArgs ));
278- MergePolicy mergePolicy = getMergePolicy (cmdLineArgs );
279- if (cmdLineArgs .reindex () || cmdLineArgs .forceMerge ()) {
283+ logger .info ("Running KNN index tester with arguments: " + testConfiguration );
284+ Codec codec = createCodec (testConfiguration );
285+ Path indexPath = PathUtils .get (formatIndexPath (testConfiguration ));
286+ MergePolicy mergePolicy = getMergePolicy (testConfiguration );
287+ if (testConfiguration .reindex () || testConfiguration .forceMerge ()) {
280288 KnnIndexer knnIndexer = new KnnIndexer (
281- cmdLineArgs .docVectors (),
289+ testConfiguration .docVectors (),
282290 indexPath ,
283291 codec ,
284- cmdLineArgs .indexThreads (),
285- cmdLineArgs .vectorEncoding (),
286- cmdLineArgs .dimensions (),
287- cmdLineArgs .vectorSpace (),
288- cmdLineArgs .numDocs (),
292+ testConfiguration .indexThreads (),
293+ testConfiguration .vectorEncoding (),
294+ testConfiguration .dimensions (),
295+ testConfiguration .vectorSpace (),
296+ testConfiguration .numDocs (),
289297 mergePolicy ,
290- cmdLineArgs .writerBufferSizeInMb (),
291- cmdLineArgs .writerMaxBufferedDocs ()
298+ testConfiguration .writerBufferSizeInMb (),
299+ testConfiguration .writerMaxBufferedDocs ()
292300 );
293- if (cmdLineArgs .reindex () == false && Files .exists (indexPath ) == false ) {
301+ if (testConfiguration .reindex () == false && Files .exists (indexPath ) == false ) {
294302 throw new IllegalArgumentException ("Index path does not exist: " + indexPath );
295303 }
296- if (cmdLineArgs .reindex ()) {
304+ if (testConfiguration .reindex ()) {
297305 knnIndexer .createIndex (indexResults );
298306 }
299- if (cmdLineArgs .forceMerge ()) {
300- knnIndexer .forceMerge (indexResults , cmdLineArgs .forceMergeMaxNumSegments ());
307+ if (testConfiguration .forceMerge ()) {
308+ knnIndexer .forceMerge (indexResults , testConfiguration .forceMergeMaxNumSegments ());
301309 }
302310 }
303311 numSegments (indexPath , indexResults );
304- if (cmdLineArgs .queryVectors () != null && cmdLineArgs .numQueries () > 0 ) {
312+ if (testConfiguration .queryVectors () != null && testConfiguration .numQueries () > 0 ) {
305313 if (parsedArgs .warmUpIterations () > 0 ) {
306314 logger .info ("Running the searches for " + parsedArgs .warmUpIterations () + " warm up iterations" );
307315 }
308316 // Warm up
309317 for (int warmUpCount = 0 ; warmUpCount < parsedArgs .warmUpIterations (); warmUpCount ++) {
310318 for (int i = 0 ; i < results .length ; i ++) {
311319 var ignoreResults = new Results (
312- cmdLineArgs .docVectors ().get (0 ).getFileName ().toString (),
320+ testConfiguration .docVectors ().get (0 ).getFileName ().toString (),
313321 indexType ,
314- cmdLineArgs .numDocs ()
322+ testConfiguration .numDocs ()
315323 );
316- KnnSearcher knnSearcher = new KnnSearcher (indexPath , cmdLineArgs );
317- knnSearcher .runSearch (ignoreResults , cmdLineArgs .searchParams ().get (i ));
324+ KnnSearcher knnSearcher = new KnnSearcher (indexPath , testConfiguration );
325+ knnSearcher .runSearch (ignoreResults , testConfiguration .searchParams ().get (i ));
318326 }
319327 }
320328
321329 for (int i = 0 ; i < results .length ; i ++) {
322- KnnSearcher knnSearcher = new KnnSearcher (indexPath , cmdLineArgs );
323- knnSearcher .runSearch (results [i ], cmdLineArgs .searchParams ().get (i ));
330+ KnnSearcher knnSearcher = new KnnSearcher (indexPath , testConfiguration );
331+ knnSearcher .runSearch (results [i ], testConfiguration .searchParams ().get (i ));
324332 }
325333 }
326334 formattedResults .queryResults .addAll (List .of (results ));
@@ -329,7 +337,7 @@ public static void main(String[] args) throws Exception {
329337 logger .info ("Results: \n " + formattedResults );
330338 }
331339
332- private static MergePolicy getMergePolicy (CmdLineArgs args ) {
340+ private static MergePolicy getMergePolicy (TestConfiguration args ) {
333341 MergePolicy mergePolicy = null ;
334342 if (args .mergePolicy () != null ) {
335343 if (args .mergePolicy () == MergePolicyType .TIERED ) {
0 commit comments