|
15 | 15 | import org.apache.lucene.codecs.KnnVectorsFormat;
|
16 | 16 | import org.apache.lucene.codecs.lucene101.Lucene101Codec;
|
17 | 17 | import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat;
|
| 18 | +import org.apache.lucene.index.DirectoryReader; |
| 19 | +import org.apache.lucene.index.IndexReader; |
18 | 20 | import org.apache.lucene.index.LogByteSizeMergePolicy;
|
19 | 21 | import org.apache.lucene.index.LogDocMergePolicy;
|
20 | 22 | import org.apache.lucene.index.MergePolicy;
|
21 | 23 | import org.apache.lucene.index.NoMergePolicy;
|
22 | 24 | import org.apache.lucene.index.TieredMergePolicy;
|
| 25 | +import org.apache.lucene.store.FSDirectory; |
23 | 26 | import org.elasticsearch.cli.ProcessInfo;
|
24 | 27 | import org.elasticsearch.common.Strings;
|
25 | 28 | import org.elasticsearch.common.logging.LogConfigurator;
|
|
37 | 40 | import org.elasticsearch.xcontent.XContentParserConfiguration;
|
38 | 41 | import org.elasticsearch.xcontent.XContentType;
|
39 | 42 |
|
| 43 | +import java.io.IOException; |
40 | 44 | import java.io.InputStream;
|
| 45 | +import java.io.UncheckedIOException; |
41 | 46 | import java.lang.management.ThreadInfo;
|
42 | 47 | import java.nio.file.Files;
|
43 | 48 | import java.nio.file.Path;
|
@@ -230,10 +235,9 @@ public static void main(String[] args) throws Exception {
|
230 | 235 | }
|
231 | 236 | if (cmdLineArgs.forceMerge()) {
|
232 | 237 | knnIndexer.forceMerge(indexResults);
|
233 |
| - } else { |
234 |
| - knnIndexer.numSegments(indexResults); |
235 | 238 | }
|
236 | 239 | }
|
| 240 | + numSegments(indexPath, indexResults); |
237 | 241 | if (cmdLineArgs.queryVectors() != null && cmdLineArgs.numQueries() > 0) {
|
238 | 242 | for (int i = 0; i < results.length; i++) {
|
239 | 243 | int nProbe = nProbes[i];
|
@@ -265,6 +269,14 @@ private static MergePolicy getMergePolicy(CmdLineArgs args) {
|
265 | 269 | return mergePolicy;
|
266 | 270 | }
|
267 | 271 |
|
| 272 | + static void numSegments(Path indexPath, KnnIndexTester.Results result) { |
| 273 | + try (FSDirectory dir = FSDirectory.open(indexPath); IndexReader reader = DirectoryReader.open(dir)) { |
| 274 | + result.numSegments = reader.leaves().size(); |
| 275 | + } catch (IOException e) { |
| 276 | + throw new UncheckedIOException("Failed to get segment count for index at " + indexPath, e); |
| 277 | + } |
| 278 | + } |
| 279 | + |
268 | 280 | static class FormattedResults {
|
269 | 281 | List<Results> indexResults = new ArrayList<>();
|
270 | 282 | List<Results> queryResults = new ArrayList<>();
|
|
0 commit comments