|
38 | 38 | import static java.lang.String.format; |
39 | 39 | import static org.elasticsearch.index.codec.vectors.IVFVectorsFormat.MAX_VECTORS_PER_CLUSTER; |
40 | 40 | import static org.elasticsearch.index.codec.vectors.IVFVectorsFormat.MIN_VECTORS_PER_CLUSTER; |
| 41 | +import static org.hamcrest.Matchers.anEmptyMap; |
| 42 | +import static org.hamcrest.Matchers.equalTo; |
41 | 43 | import static org.hamcrest.Matchers.is; |
42 | 44 | import static org.hamcrest.Matchers.oneOf; |
43 | 45 |
|
@@ -83,6 +85,25 @@ protected Codec getCodec() { |
83 | 85 | return TestUtil.alwaysKnnVectorsFormat(format); |
84 | 86 | } |
85 | 87 |
|
| 88 | + @Override |
| 89 | + protected void assertOffHeapByteSize(LeafReader r, String fieldName) throws IOException { |
| 90 | + var fieldInfo = r.getFieldInfos().fieldInfo(fieldName); |
| 91 | + |
| 92 | + if (r instanceof CodecReader codecReader) { |
| 93 | + KnnVectorsReader knnVectorsReader = codecReader.getVectorReader(); |
| 94 | + if (knnVectorsReader instanceof PerFieldKnnVectorsFormat.FieldsReader fieldsReader) { |
| 95 | + knnVectorsReader = fieldsReader.getFieldReader(fieldName); |
| 96 | + } |
| 97 | + var offHeap = knnVectorsReader.getOffHeapByteSize(fieldInfo); |
| 98 | + long totalByteSize = offHeap.values().stream().mapToLong(Long::longValue).sum(); |
| 99 | + // IVF doesn't report stats at the moment |
| 100 | + assertThat(offHeap, anEmptyMap()); |
| 101 | + assertThat(totalByteSize, equalTo(0L)); |
| 102 | + } else { |
| 103 | + throw new AssertionError("unexpected:" + r.getClass()); |
| 104 | + } |
| 105 | + } |
| 106 | + |
86 | 107 | @Override |
87 | 108 | public void testAdvance() throws Exception { |
88 | 109 | // TODO re-enable with hierarchical IVF, clustering as it is is flaky |
|
0 commit comments