Skip to content

Commit 34b0ce8

Browse files
committed
move GPUIndexType to it's own top-level class, and spotless
1 parent d0da0d4 commit 34b0ce8

File tree

6 files changed

+114
-90
lines changed

6 files changed

+114
-90
lines changed

server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataVerifierTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,13 @@ private IndexMetadataVerifier getIndexMetadataVerifier() {
299299
Settings.EMPTY,
300300
null,
301301
xContentRegistry(),
302-
new MapperRegistry(Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), MapperPlugin.NOOP_FIELD_FILTER,
303-
Collections.emptyMap()),
302+
new MapperRegistry(
303+
Collections.emptyMap(),
304+
Collections.emptyMap(),
305+
Collections.emptyMap(),
306+
MapperPlugin.NOOP_FIELD_FILTER,
307+
Collections.emptyMap()
308+
),
304309
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
305310
null,
306311
MapperMetrics.NOOP

server/src/test/java/org/elasticsearch/index/IndexSettingsTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,13 @@ public void testIndexMapperDynamic() {
857857
Settings.EMPTY,
858858
null,
859859
xContentRegistry(),
860-
new MapperRegistry(Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), MapperPlugin.NOOP_FIELD_FILTER,
861-
Collections.emptyMap()),
860+
new MapperRegistry(
861+
Collections.emptyMap(),
862+
Collections.emptyMap(),
863+
Collections.emptyMap(),
864+
MapperPlugin.NOOP_FIELD_FILTER,
865+
Collections.emptyMap()
866+
),
862867
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
863868
null,
864869
MapperMetrics.NOOP

server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapperTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,11 @@ public void testValidateOnBuild() {
789789
final MapperBuilderContext context = MapperBuilderContext.root(false, false);
790790

791791
// Build a dense vector field mapper with float element type, which will trigger int8 HNSW index options
792-
DenseVectorFieldMapper mapper = new DenseVectorFieldMapper.Builder("test", IndexVersion.current(),
793-
type -> DenseVectorFieldMapper.allBasicVectorIndexTypes().get(type))
794-
.elementType(ElementType.FLOAT)
795-
.build(context);
792+
DenseVectorFieldMapper mapper = new DenseVectorFieldMapper.Builder(
793+
"test",
794+
IndexVersion.current(),
795+
type -> DenseVectorFieldMapper.allBasicVectorIndexTypes().get(type)
796+
).elementType(ElementType.FLOAT).build(context);
796797

797798
// Change the element type to byte, which is incompatible with int8 HNSW index options
798799
DenseVectorFieldMapper.Builder builder = (DenseVectorFieldMapper.Builder) mapper.getMergeBuilder();

test/framework/src/main/java/org/elasticsearch/index/mapper/AbstractDenseVectorFieldMapperTestcase.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
package org.elasticsearch.index.mapper;
1111

12-
1312
import org.apache.lucene.search.FieldExistsQuery;
1413
import org.apache.lucene.search.Query;
1514
import org.elasticsearch.index.IndexVersion;
@@ -1286,7 +1285,6 @@ protected void assertExistsQuery(MappedFieldType fieldType, Query query, LuceneD
12861285
@Override
12871286
public void testAggregatableConsistency() {}
12881287

1289-
12901288
@Override
12911289
protected void assertFetchMany(MapperService mapperService, String field, Object value, String format, int count) throws IOException {
12921290
assumeFalse("Dense vectors currently don't support multiple values in the same field", false);
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.gpu;
9+
10+
import org.apache.lucene.codecs.KnnVectorsFormat;
11+
import org.elasticsearch.index.IndexVersion;
12+
import org.elasticsearch.index.mapper.MappingParser;
13+
import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper;
14+
import org.elasticsearch.xcontent.XContentBuilder;
15+
import org.elasticsearch.xpack.gpu.codec.GPUVectorsFormat;
16+
17+
import java.io.IOException;
18+
import java.util.Map;
19+
import java.util.Objects;
20+
21+
class GPUIndexType implements DenseVectorFieldMapper.VectorIndexType {
22+
23+
static final String GPU_INDEX_TYPE_NAME = "gpu";
24+
25+
static final GPUIndexType GPU_INDEX_TYPE = new GPUIndexType();
26+
27+
@Override
28+
public String name() {
29+
return GPU_INDEX_TYPE_NAME;
30+
}
31+
32+
@Override
33+
public DenseVectorFieldMapper.IndexOptions parseIndexOptions(
34+
String fieldName,
35+
Map<String, ?> indexOptionsMap,
36+
IndexVersion indexVersion
37+
) {
38+
MappingParser.checkNoRemainingFields(fieldName, indexOptionsMap);
39+
return new GPUIndexOptions();
40+
}
41+
42+
@Override
43+
public boolean supportsElementType(DenseVectorFieldMapper.ElementType elementType) {
44+
return elementType == DenseVectorFieldMapper.ElementType.FLOAT;
45+
}
46+
47+
@Override
48+
public boolean supportsDimension(int dims) {
49+
return true;
50+
}
51+
52+
@Override
53+
public boolean isQuantized() {
54+
return false;
55+
}
56+
57+
static class GPUIndexOptions extends DenseVectorFieldMapper.IndexOptions {
58+
59+
GPUIndexOptions() {
60+
super(GPU_INDEX_TYPE);
61+
}
62+
63+
@Override
64+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
65+
builder.startObject();
66+
builder.field("type", type.name());
67+
builder.endObject();
68+
return builder;
69+
}
70+
71+
@Override
72+
public KnnVectorsFormat getVectorsFormat(DenseVectorFieldMapper.ElementType elementType) {
73+
assert elementType == DenseVectorFieldMapper.ElementType.FLOAT;
74+
return new GPUVectorsFormat();
75+
}
76+
77+
@Override
78+
public boolean updatableTo(DenseVectorFieldMapper.IndexOptions update) {
79+
return false;
80+
}
81+
82+
@Override
83+
protected boolean doEquals(DenseVectorFieldMapper.IndexOptions o) {
84+
return o instanceof GPUIndexOptions;
85+
}
86+
87+
@Override
88+
protected int doHashCode() {
89+
return Objects.hash(type);
90+
}
91+
}
92+
}

x-pack/plugin/gpu/src/main/java/org/elasticsearch/xpack/gpu/GPUPlugin.java

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66
*/
77
package org.elasticsearch.xpack.gpu;
88

9-
import org.apache.lucene.codecs.KnnVectorsFormat;
109
import org.elasticsearch.common.util.FeatureFlag;
11-
import org.elasticsearch.index.IndexVersion;
12-
import org.elasticsearch.index.mapper.MappingParser;
1310
import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper;
1411
import org.elasticsearch.plugins.MapperPlugin;
1512
import org.elasticsearch.plugins.Plugin;
16-
import org.elasticsearch.xcontent.XContentBuilder;
17-
import org.elasticsearch.xpack.gpu.codec.GPUVectorsFormat;
1813

19-
import java.io.IOException;
2014
import java.util.Map;
21-
import java.util.Objects;
15+
16+
import static org.elasticsearch.xpack.gpu.GPUIndexType.GPU_INDEX_TYPE;
17+
import static org.elasticsearch.xpack.gpu.GPUIndexType.GPU_INDEX_TYPE_NAME;
2218

2319
public class GPUPlugin extends Plugin implements MapperPlugin {
2420

@@ -31,77 +27,4 @@ public Map<String, DenseVectorFieldMapper.VectorIndexType> getDenseVectorIndexTy
3127
return Map.of();
3228
}
3329
}
34-
35-
static final String GPU_INDEX_TYPE_NAME = "gpu";
36-
37-
static final GPUIndexType GPU_INDEX_TYPE = new GPUIndexType();
38-
39-
static class GPUIndexType implements DenseVectorFieldMapper.VectorIndexType {
40-
41-
@Override
42-
public String name() {
43-
return GPU_INDEX_TYPE_NAME;
44-
}
45-
46-
@Override
47-
public DenseVectorFieldMapper.IndexOptions parseIndexOptions(
48-
String fieldName,
49-
Map<String, ?> indexOptionsMap,
50-
IndexVersion indexVersion
51-
) {
52-
MappingParser.checkNoRemainingFields(fieldName, indexOptionsMap);
53-
return new GPUIndexOptions();
54-
}
55-
56-
@Override
57-
public boolean supportsElementType(DenseVectorFieldMapper.ElementType elementType) {
58-
return elementType == DenseVectorFieldMapper.ElementType.FLOAT;
59-
}
60-
61-
@Override
62-
public boolean supportsDimension(int dims) {
63-
return true;
64-
}
65-
66-
@Override
67-
public boolean isQuantized() {
68-
return false;
69-
}
70-
}
71-
72-
static class GPUIndexOptions extends DenseVectorFieldMapper.IndexOptions {
73-
74-
GPUIndexOptions() {
75-
super(GPU_INDEX_TYPE);
76-
}
77-
78-
@Override
79-
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
80-
builder.startObject();
81-
builder.field("type", type.name());
82-
builder.endObject();
83-
return builder;
84-
}
85-
86-
@Override
87-
public KnnVectorsFormat getVectorsFormat(DenseVectorFieldMapper.ElementType elementType) {
88-
assert elementType == DenseVectorFieldMapper.ElementType.FLOAT;
89-
return new GPUVectorsFormat();
90-
}
91-
92-
@Override
93-
public boolean updatableTo(DenseVectorFieldMapper.IndexOptions update) {
94-
return false;
95-
}
96-
97-
@Override
98-
protected boolean doEquals(DenseVectorFieldMapper.IndexOptions o) {
99-
return o instanceof GPUIndexOptions;
100-
}
101-
102-
@Override
103-
protected int doHashCode() {
104-
return Objects.hash(type);
105-
}
106-
}
10730
}

0 commit comments

Comments
 (0)