Skip to content

Commit 4815bc2

Browse files
committed
Class renames
1 parent 84f5bf4 commit 4815bc2

File tree

7 files changed

+137
-137
lines changed

7 files changed

+137
-137
lines changed

server/src/main/java/module-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,10 @@
466466
org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat,
467467
org.elasticsearch.index.codec.vectors.diskbbq.next.ESNextDiskBBQVectorsFormat,
468468
org.elasticsearch.index.codec.vectors.es93.ES93FlatVectorFormat,
469-
org.elasticsearch.index.codec.vectors.es93.ES93ScalarQuantizedFlatVectorsFormat,
469+
org.elasticsearch.index.codec.vectors.es93.ES93HnswVectorsFormat,
470+
org.elasticsearch.index.codec.vectors.es93.ES93ScalarQuantizedVectorsFormat,
470471
org.elasticsearch.index.codec.vectors.es93.ES93HnswScalarQuantizedVectorsFormat,
471472
org.elasticsearch.index.codec.vectors.es93.ES93BinaryQuantizedVectorsFormat,
472-
org.elasticsearch.index.codec.vectors.es93.ES93HnswVectorsFormat,
473473
org.elasticsearch.index.codec.vectors.es93.ES93HnswBinaryQuantizedVectorsFormat;
474474

475475
provides org.apache.lucene.codecs.Codec

server/src/main/java/org/elasticsearch/index/codec/vectors/es93/ES93HnswScalarQuantizedVectorsFormat.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ES93HnswScalarQuantizedVectorsFormat extends AbstractHnswVectorsFor
3131

3232
public ES93HnswScalarQuantizedVectorsFormat() {
3333
super(NAME);
34-
this.flatVectorsFormat = new ES93ScalarQuantizedVectorsFormat(
34+
this.flatVectorsFormat = new ES93ScalarQuantizedFlatVectorsFormat(
3535
Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding.SEVEN_BIT,
3636
false,
3737
false
@@ -46,7 +46,7 @@ public ES93HnswScalarQuantizedVectorsFormat(
4646
boolean useDirectIO
4747
) {
4848
super(NAME, maxConn, beamWidth);
49-
this.flatVectorsFormat = new ES93ScalarQuantizedVectorsFormat(encoding, useBFloat16, useDirectIO);
49+
this.flatVectorsFormat = new ES93ScalarQuantizedFlatVectorsFormat(encoding, useBFloat16, useDirectIO);
5050
}
5151

5252
public ES93HnswScalarQuantizedVectorsFormat(
@@ -59,7 +59,7 @@ public ES93HnswScalarQuantizedVectorsFormat(
5959
ExecutorService mergeExec
6060
) {
6161
super(NAME, maxConn, beamWidth, numMergeWorkers, mergeExec);
62-
this.flatVectorsFormat = new ES93ScalarQuantizedVectorsFormat(encoding, useBFloat16, useDirectIO);
62+
this.flatVectorsFormat = new ES93ScalarQuantizedFlatVectorsFormat(encoding, useBFloat16, useDirectIO);
6363
}
6464

6565
@Override
@@ -69,7 +69,7 @@ protected FlatVectorsFormat flatVectorsFormat() {
6969

7070
@Override
7171
public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
72-
return new Lucene99HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state), numMergeWorkers, mergeExec);
72+
return new Lucene99HnswVectorsWriter(state, maxConn, beamWidth, flatVectorsFormat.fieldsWriter(state), numMergeWorkers, mergeExec, 0);
7373
}
7474

7575
@Override

server/src/main/java/org/elasticsearch/index/codec/vectors/es93/ES93ScalarQuantizedFlatVectorsFormat.java

Lines changed: 36 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,40 @@
99

1010
package org.elasticsearch.index.codec.vectors.es93;
1111

12-
import org.apache.lucene.codecs.KnnVectorsFormat;
13-
import org.apache.lucene.codecs.KnnVectorsReader;
14-
import org.apache.lucene.codecs.KnnVectorsWriter;
12+
import org.apache.lucene.codecs.hnsw.FlatVectorScorerUtil;
1513
import org.apache.lucene.codecs.hnsw.FlatVectorsFormat;
1614
import org.apache.lucene.codecs.hnsw.FlatVectorsReader;
15+
import org.apache.lucene.codecs.hnsw.FlatVectorsWriter;
16+
import org.apache.lucene.codecs.lucene104.Lucene104ScalarQuantizedVectorScorer;
1717
import org.apache.lucene.codecs.lucene104.Lucene104ScalarQuantizedVectorsFormat;
18-
import org.apache.lucene.index.ByteVectorValues;
19-
import org.apache.lucene.index.FieldInfo;
20-
import org.apache.lucene.index.FloatVectorValues;
18+
import org.apache.lucene.codecs.lucene104.Lucene104ScalarQuantizedVectorsReader;
19+
import org.apache.lucene.codecs.lucene104.Lucene104ScalarQuantizedVectorsWriter;
2120
import org.apache.lucene.index.SegmentReadState;
2221
import org.apache.lucene.index.SegmentWriteState;
23-
import org.apache.lucene.search.AcceptDocs;
24-
import org.apache.lucene.search.KnnCollector;
25-
import org.apache.lucene.util.Bits;
26-
import org.apache.lucene.util.hnsw.OrdinalTranslatedKnnCollector;
27-
import org.apache.lucene.util.hnsw.RandomVectorScorer;
2822

2923
import java.io.IOException;
30-
import java.util.Map;
3124

3225
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.MAX_DIMS_COUNT;
3326

34-
public class ES93ScalarQuantizedFlatVectorsFormat extends KnnVectorsFormat {
27+
public class ES93ScalarQuantizedFlatVectorsFormat extends FlatVectorsFormat {
3528

3629
static final String NAME = "ES93ScalarQuantizedFlatVectorsFormat";
3730

38-
private final FlatVectorsFormat format;
31+
static final Lucene104ScalarQuantizedVectorScorer flatVectorScorer = new Lucene104ScalarQuantizedVectorScorer(
32+
FlatVectorScorerUtil.getLucene99FlatVectorsScorer()
33+
);
3934

40-
public ES93ScalarQuantizedFlatVectorsFormat() {
41-
this(false, Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding.SEVEN_BIT);
42-
}
43-
44-
public ES93ScalarQuantizedFlatVectorsFormat(boolean useBFloat16) {
45-
this(useBFloat16, Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding.SEVEN_BIT);
46-
}
35+
private final Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding encoding;
36+
private final FlatVectorsFormat rawVectorFormat;
4737

48-
public ES93ScalarQuantizedFlatVectorsFormat(boolean useBFloat16, Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding encoding) {
38+
public ES93ScalarQuantizedFlatVectorsFormat(
39+
Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding encoding,
40+
boolean useBFloat16,
41+
boolean useDirectIO
42+
) {
4943
super(NAME);
50-
this.format = new ES93ScalarQuantizedVectorsFormat(encoding, useBFloat16, false);
51-
}
52-
53-
@Override
54-
public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
55-
return format.fieldsWriter(state);
56-
}
57-
58-
@Override
59-
public KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException {
60-
return new ES93FlatVectorsReader(format.fieldsReader(state));
44+
this.encoding = encoding;
45+
this.rawVectorFormat = new ES93GenericFlatVectorsFormat(useBFloat16, useDirectIO);
6146
}
6247

6348
@Override
@@ -67,64 +52,26 @@ public int getMaxDimensions(String fieldName) {
6752

6853
@Override
6954
public String toString() {
70-
return NAME + "(name=" + NAME + ", innerFormat=" + format + ")";
55+
return NAME
56+
+ "(name="
57+
+ NAME
58+
+ ", encoding="
59+
+ encoding
60+
+ ", flatVectorScorer="
61+
+ flatVectorScorer
62+
+ ", rawVectorFormat="
63+
+ rawVectorFormat
64+
+ ")";
7165
}
7266

73-
public static class ES93FlatVectorsReader extends KnnVectorsReader {
74-
75-
private final FlatVectorsReader reader;
76-
77-
public ES93FlatVectorsReader(FlatVectorsReader reader) {
78-
super();
79-
this.reader = reader;
80-
}
81-
82-
@Override
83-
public void checkIntegrity() throws IOException {
84-
reader.checkIntegrity();
85-
}
86-
87-
@Override
88-
public FloatVectorValues getFloatVectorValues(String field) throws IOException {
89-
return reader.getFloatVectorValues(field);
90-
}
91-
92-
@Override
93-
public ByteVectorValues getByteVectorValues(String field) throws IOException {
94-
return reader.getByteVectorValues(field);
95-
}
96-
97-
@Override
98-
public void search(String field, float[] target, KnnCollector knnCollector, AcceptDocs acceptDocs) throws IOException {
99-
collectAllMatchingDocs(knnCollector, acceptDocs, reader.getRandomVectorScorer(field, target));
100-
}
101-
102-
private void collectAllMatchingDocs(KnnCollector knnCollector, AcceptDocs acceptDocs, RandomVectorScorer scorer)
103-
throws IOException {
104-
OrdinalTranslatedKnnCollector collector = new OrdinalTranslatedKnnCollector(knnCollector, scorer::ordToDoc);
105-
Bits acceptedOrds = scorer.getAcceptOrds(acceptDocs.bits());
106-
for (int i = 0; i < scorer.maxOrd(); i++) {
107-
if (acceptedOrds == null || acceptedOrds.get(i)) {
108-
collector.collect(i, scorer.score(i));
109-
collector.incVisitedCount(1);
110-
}
111-
}
112-
assert collector.earlyTerminated() == false;
113-
}
114-
115-
@Override
116-
public void search(String field, byte[] target, KnnCollector knnCollector, AcceptDocs acceptDocs) throws IOException {
117-
collectAllMatchingDocs(knnCollector, acceptDocs, reader.getRandomVectorScorer(field, target));
118-
}
119-
120-
@Override
121-
public Map<String, Long> getOffHeapByteSize(FieldInfo fieldInfo) {
122-
return reader.getOffHeapByteSize(fieldInfo);
123-
}
67+
@Override
68+
public FlatVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
69+
return new Lucene104ScalarQuantizedVectorsWriter(state, encoding, rawVectorFormat.fieldsWriter(state), flatVectorScorer) {
70+
};
71+
}
12472

125-
@Override
126-
public void close() throws IOException {
127-
reader.close();
128-
}
73+
@Override
74+
public FlatVectorsReader fieldsReader(SegmentReadState state) throws IOException {
75+
return new Lucene104ScalarQuantizedVectorsReader(state, rawVectorFormat.fieldsReader(state), flatVectorScorer);
12976
}
13077
}

server/src/main/java/org/elasticsearch/index/codec/vectors/es93/ES93ScalarQuantizedVectorsFormat.java

Lines changed: 89 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,69 +9,122 @@
99

1010
package org.elasticsearch.index.codec.vectors.es93;
1111

12-
import org.apache.lucene.codecs.hnsw.FlatVectorScorerUtil;
12+
import org.apache.lucene.codecs.KnnVectorsFormat;
13+
import org.apache.lucene.codecs.KnnVectorsReader;
14+
import org.apache.lucene.codecs.KnnVectorsWriter;
1315
import org.apache.lucene.codecs.hnsw.FlatVectorsFormat;
1416
import org.apache.lucene.codecs.hnsw.FlatVectorsReader;
15-
import org.apache.lucene.codecs.hnsw.FlatVectorsWriter;
16-
import org.apache.lucene.codecs.lucene104.Lucene104ScalarQuantizedVectorScorer;
1717
import org.apache.lucene.codecs.lucene104.Lucene104ScalarQuantizedVectorsFormat;
18-
import org.apache.lucene.codecs.lucene104.Lucene104ScalarQuantizedVectorsReader;
19-
import org.apache.lucene.codecs.lucene104.Lucene104ScalarQuantizedVectorsWriter;
18+
import org.apache.lucene.index.ByteVectorValues;
19+
import org.apache.lucene.index.FieldInfo;
20+
import org.apache.lucene.index.FloatVectorValues;
2021
import org.apache.lucene.index.SegmentReadState;
2122
import org.apache.lucene.index.SegmentWriteState;
23+
import org.apache.lucene.search.AcceptDocs;
24+
import org.apache.lucene.search.KnnCollector;
25+
import org.apache.lucene.util.Bits;
26+
import org.apache.lucene.util.hnsw.OrdinalTranslatedKnnCollector;
27+
import org.apache.lucene.util.hnsw.RandomVectorScorer;
2228

2329
import java.io.IOException;
30+
import java.util.Map;
2431

2532
import static org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.MAX_DIMS_COUNT;
2633

27-
public class ES93ScalarQuantizedVectorsFormat extends FlatVectorsFormat {
34+
public class ES93ScalarQuantizedVectorsFormat extends KnnVectorsFormat {
2835

2936
static final String NAME = "ES93ScalarQuantizedVectorsFormat";
3037

31-
static final Lucene104ScalarQuantizedVectorScorer flatVectorScorer = new Lucene104ScalarQuantizedVectorScorer(
32-
FlatVectorScorerUtil.getLucene99FlatVectorsScorer()
33-
);
38+
private final FlatVectorsFormat format;
3439

35-
private final Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding encoding;
36-
private final FlatVectorsFormat rawVectorFormat;
40+
public ES93ScalarQuantizedVectorsFormat() {
41+
this(false, Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding.SEVEN_BIT);
42+
}
43+
44+
public ES93ScalarQuantizedVectorsFormat(boolean useBFloat16) {
45+
this(useBFloat16, Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding.SEVEN_BIT);
46+
}
3747

38-
public ES93ScalarQuantizedVectorsFormat(
39-
Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding encoding,
40-
boolean useBFloat16,
41-
boolean useDirectIO
42-
) {
48+
public ES93ScalarQuantizedVectorsFormat(boolean useBFloat16, Lucene104ScalarQuantizedVectorsFormat.ScalarEncoding encoding) {
4349
super(NAME);
44-
this.encoding = encoding;
45-
this.rawVectorFormat = new ES93GenericFlatVectorsFormat(useBFloat16, useDirectIO);
50+
this.format = new ES93ScalarQuantizedFlatVectorsFormat(encoding, useBFloat16, false);
4651
}
4752

4853
@Override
49-
public int getMaxDimensions(String fieldName) {
50-
return MAX_DIMS_COUNT;
54+
public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
55+
return format.fieldsWriter(state);
5156
}
5257

5358
@Override
54-
public String toString() {
55-
return NAME
56-
+ "(name="
57-
+ NAME
58-
+ ", encoding="
59-
+ encoding
60-
+ ", flatVectorScorer="
61-
+ flatVectorScorer
62-
+ ", rawVectorFormat="
63-
+ rawVectorFormat
64-
+ ")";
59+
public KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException {
60+
return new ES93FlatVectorsReader(format.fieldsReader(state));
6561
}
6662

6763
@Override
68-
public FlatVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException {
69-
return new Lucene104ScalarQuantizedVectorsWriter(state, encoding, rawVectorFormat.fieldsWriter(state), flatVectorScorer) {
70-
};
64+
public int getMaxDimensions(String fieldName) {
65+
return MAX_DIMS_COUNT;
7166
}
7267

7368
@Override
74-
public FlatVectorsReader fieldsReader(SegmentReadState state) throws IOException {
75-
return new Lucene104ScalarQuantizedVectorsReader(state, rawVectorFormat.fieldsReader(state), flatVectorScorer);
69+
public String toString() {
70+
return NAME + "(name=" + NAME + ", innerFormat=" + format + ")";
71+
}
72+
73+
public static class ES93FlatVectorsReader extends KnnVectorsReader {
74+
75+
private final FlatVectorsReader reader;
76+
77+
public ES93FlatVectorsReader(FlatVectorsReader reader) {
78+
super();
79+
this.reader = reader;
80+
}
81+
82+
@Override
83+
public void checkIntegrity() throws IOException {
84+
reader.checkIntegrity();
85+
}
86+
87+
@Override
88+
public FloatVectorValues getFloatVectorValues(String field) throws IOException {
89+
return reader.getFloatVectorValues(field);
90+
}
91+
92+
@Override
93+
public ByteVectorValues getByteVectorValues(String field) throws IOException {
94+
return reader.getByteVectorValues(field);
95+
}
96+
97+
@Override
98+
public void search(String field, float[] target, KnnCollector knnCollector, AcceptDocs acceptDocs) throws IOException {
99+
collectAllMatchingDocs(knnCollector, acceptDocs, reader.getRandomVectorScorer(field, target));
100+
}
101+
102+
private void collectAllMatchingDocs(KnnCollector knnCollector, AcceptDocs acceptDocs, RandomVectorScorer scorer)
103+
throws IOException {
104+
OrdinalTranslatedKnnCollector collector = new OrdinalTranslatedKnnCollector(knnCollector, scorer::ordToDoc);
105+
Bits acceptedOrds = scorer.getAcceptOrds(acceptDocs.bits());
106+
for (int i = 0; i < scorer.maxOrd(); i++) {
107+
if (acceptedOrds == null || acceptedOrds.get(i)) {
108+
collector.collect(i, scorer.score(i));
109+
collector.incVisitedCount(1);
110+
}
111+
}
112+
assert collector.earlyTerminated() == false;
113+
}
114+
115+
@Override
116+
public void search(String field, byte[] target, KnnCollector knnCollector, AcceptDocs acceptDocs) throws IOException {
117+
collectAllMatchingDocs(knnCollector, acceptDocs, reader.getRandomVectorScorer(field, target));
118+
}
119+
120+
@Override
121+
public Map<String, Long> getOffHeapByteSize(FieldInfo fieldInfo) {
122+
return reader.getOffHeapByteSize(fieldInfo);
123+
}
124+
125+
@Override
126+
public void close() throws IOException {
127+
reader.close();
128+
}
76129
}
77130
}

server/src/main/resources/META-INF/services/org.apache.lucene.codecs.KnnVectorsFormat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ org.elasticsearch.index.codec.vectors.es818.ES818HnswBinaryQuantizedVectorsForma
1010
org.elasticsearch.index.codec.vectors.diskbbq.ES920DiskBBQVectorsFormat
1111
org.elasticsearch.index.codec.vectors.diskbbq.next.ESNextDiskBBQVectorsFormat
1212
org.elasticsearch.index.codec.vectors.es93.ES93FlatVectorFormat
13-
org.elasticsearch.index.codec.vectors.es93.ES93ScalarQuantizedFlatVectorsFormat
13+
org.elasticsearch.index.codec.vectors.es93.ES93HnswVectorsFormat
14+
org.elasticsearch.index.codec.vectors.es93.ES93ScalarQuantizedVectorsFormat
1415
org.elasticsearch.index.codec.vectors.es93.ES93HnswScalarQuantizedVectorsFormat
1516
org.elasticsearch.index.codec.vectors.es93.ES93BinaryQuantizedVectorsFormat
16-
org.elasticsearch.index.codec.vectors.es93.ES93HnswVectorsFormat
1717
org.elasticsearch.index.codec.vectors.es93.ES93HnswBinaryQuantizedVectorsFormat
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import static org.hamcrest.Matchers.greaterThan;
3636
import static org.hamcrest.Matchers.hasEntry;
3737

38-
public class ES93ScalarQuantizedFlatBFloat16VectorFormatTests extends BaseBFloat16KnnVectorsFormatTestCase {
38+
public class ES93ScalarQuantizedBFloat16VectorFormatTests extends BaseBFloat16KnnVectorsFormatTestCase {
3939

4040
static {
4141
LogConfigurator.loadLog4jPlugins();
@@ -46,7 +46,7 @@ public class ES93ScalarQuantizedFlatBFloat16VectorFormatTests extends BaseBFloat
4646

4747
@Override
4848
public void setUp() throws Exception {
49-
format = new ES93ScalarQuantizedFlatVectorsFormat(true);
49+
format = new ES93ScalarQuantizedVectorsFormat(true);
5050
super.setUp();
5151
}
5252

0 commit comments

Comments
 (0)