Skip to content

Commit d3db656

Browse files
Add yml rest test that can be called:
./gradlew ":x-pack:plugin:gpu:yamlRestTest" --tests "org.elasticsearch.xpack.gpu.GPUYamlTestSuiteIT.test {p0=gpu/10_basic/*}"
1 parent 34b0ce8 commit d3db656

File tree

6 files changed

+107
-15
lines changed

6 files changed

+107
-15
lines changed

server/src/main/java/org/elasticsearch/index/store/LuceneFilesExtensions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ public enum LuceneFilesExtensions {
8787
// ivf vectors format
8888
MIVF("mivf", "IVF Metadata", true, false),
8989
CENIVF("cenivf", "IVF Centroid Data", false, true),
90-
CLIVF("clivf", "IVF Cluster Data", false, true);
90+
CLIVF("clivf", "IVF Cluster Data", false, true),
91+
// GPU vectors format
92+
GPUIDX("gpuidx", "GPU Vector Index", false, true),
93+
MGPU("mgpu", "GPU Vector Metadata", true, false);
9194

9295
/**
9396
* Allow plugin developers of custom codecs to opt out of the assertion in {@link #fromExtension}

x-pack/plugin/gpu/build.gradle

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
apply plugin: 'elasticsearch.internal-es-plugin'
22
apply plugin: 'elasticsearch.internal-cluster-test'
3+
apply plugin: 'elasticsearch.internal-yaml-rest-test'
4+
35
esplugin {
46
name = 'gpu'
5-
description = 'A plugin for GPU functionality'
7+
description = 'A plugin for doing vector search in GPU'
68
classname = 'org.elasticsearch.xpack.gpu.GPUPlugin'
9+
extendedPlugins = ['x-pack-core']
710
}
811
base {
912
archivesName = 'x-pack-gpu'
1013
}
1114

1215
dependencies {
13-
// compileOnly project(path: xpackModule('core'))
14-
// testImplementation(testArtifact(project(xpackModule('core'))))
15-
16+
compileOnly project(path: xpackModule('core'))
1617
compileOnly project(':server')
17-
18-
implementation "org.apache.lucene:lucene-core:${versions.lucene}"
19-
20-
testImplementation project(':test:framework')
18+
testImplementation(testArtifact(project(xpackModule('core'))))
19+
testImplementation(testArtifact(project(':server')))
20+
clusterModules project(xpackModule('gpu'))
21+
}
22+
tasks.named("yamlRestTest") {
23+
usesDefaultDistribution("uses gpu plugin")
24+
}
25+
artifacts {
26+
restXpackTests(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test"))
2127
}

x-pack/plugin/gpu/src/test/java/org/elasticsearch/xpack/gpu/codec/GPUVectorsFormatTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
/*
22
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
5-
* Public License v 1"; you may not use this file except in compliance with, at
6-
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7-
* License v3.0 only", or the "Server Side Public License, v 1".
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.
86
*/
97
package org.elasticsearch.xpack.gpu.codec;
108

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
package org.elasticsearch.xpack.gpu;
8+
9+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
10+
11+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
12+
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
13+
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
14+
import org.junit.ClassRule;
15+
16+
public class GPUYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
17+
18+
@ClassRule
19+
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
20+
.nodes(1)
21+
.module("gpu")
22+
.setting("xpack.license.self_generated.type", "basic")
23+
.setting("xpack.security.enabled", "false")
24+
.build();
25+
26+
public GPUYamlTestSuiteIT(final ClientYamlTestCandidate testCandidate) {
27+
super(testCandidate);
28+
}
29+
30+
@ParametersFactory
31+
public static Iterable<Object[]> parameters() throws Exception {
32+
return ESClientYamlSuiteTestCase.createParameters();
33+
}
34+
35+
@Override
36+
protected String getTestRestCluster() {
37+
return cluster.getHttpAddresses();
38+
}
39+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
"Test GPU vector operations":
3+
- do:
4+
indices.create:
5+
index: gpu_vectors
6+
body:
7+
mappings:
8+
properties:
9+
embedding:
10+
type: dense_vector
11+
dims: 128
12+
similarity: l2_norm
13+
index_options:
14+
type: gpu
15+
16+
- do:
17+
bulk:
18+
index: gpu_vectors
19+
refresh: true
20+
body:
21+
- index:
22+
_id: "1"
23+
- text: "First document"
24+
embedding: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]
25+
- index:
26+
_id: "2"
27+
- text: "Second document"
28+
embedding: [0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85, 0.95, 1.05, 0.15, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.85]
29+
- index:
30+
_id: "3"
31+
- text: "Third document"
32+
embedding: [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 0.2, 0.3, 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.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]
42+
k: 3
43+
44+
- match: { hits.total.value: 3 }
45+
- match: { hits.hits.0._id: "1" }

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,8 @@ private static Mapper.Builder createEmbeddingsField(
10811081
case TEXT_EMBEDDING -> {
10821082
DenseVectorFieldMapper.Builder denseVectorMapperBuilder = new DenseVectorFieldMapper.Builder(
10831083
CHUNKED_EMBEDDINGS_FIELD,
1084-
indexVersionCreated
1084+
indexVersionCreated,
1085+
type -> DenseVectorFieldMapper.allBasicVectorIndexTypes().get(type)
10851086
);
10861087

10871088
SimilarityMeasure similarity = modelSettings.similarity();

0 commit comments

Comments
 (0)