Skip to content

Commit bd715c1

Browse files
author
Max Hniebergall
committed
Merge branch 'main' into ml-eis-integration-jbc
# Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/external/request/openai/OpenAiUnifiedChatCompletionRequestEntity.java # x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/external/request/openai/OpenAiUnifiedChatCompletionRequestEntityTests.java
2 parents 2a3faa4 + 21fe5a9 commit bd715c1

File tree

194 files changed

+3406
-1208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+3406
-1208
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/vector/VectorScorerBenchmark.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public class VectorScorerBenchmark {
8383

8484
RandomVectorScorer luceneDotScorerQuery;
8585
RandomVectorScorer nativeDotScorerQuery;
86+
RandomVectorScorer luceneSqrScorerQuery;
87+
RandomVectorScorer nativeSqrScorerQuery;
8688

8789
@Setup
8890
public void setup() throws IOException {
@@ -130,6 +132,8 @@ public void setup() throws IOException {
130132
}
131133
luceneDotScorerQuery = luceneScorer(values, VectorSimilarityFunction.DOT_PRODUCT, queryVec);
132134
nativeDotScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.DOT_PRODUCT, values, queryVec).get();
135+
luceneSqrScorerQuery = luceneScorer(values, VectorSimilarityFunction.EUCLIDEAN, queryVec);
136+
nativeSqrScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.EUCLIDEAN, values, queryVec).get();
133137

134138
// sanity
135139
var f1 = dotProductLucene();
@@ -157,6 +161,12 @@ public void setup() throws IOException {
157161
if (q1 != q2) {
158162
throw new AssertionError("query: lucene[" + q1 + "] != " + "native[" + q2 + "]");
159163
}
164+
165+
var sqr1 = squareDistanceLuceneQuery();
166+
var sqr2 = squareDistanceNativeQuery();
167+
if (sqr1 != sqr2) {
168+
throw new AssertionError("query: lucene[" + q1 + "] != " + "native[" + q2 + "]");
169+
}
160170
}
161171

162172
@TearDown
@@ -217,6 +227,16 @@ public float squareDistanceScalar() {
217227
return 1 / (1f + adjustedDistance);
218228
}
219229

230+
@Benchmark
231+
public float squareDistanceLuceneQuery() throws IOException {
232+
return luceneSqrScorerQuery.score(1);
233+
}
234+
235+
@Benchmark
236+
public float squareDistanceNativeQuery() throws IOException {
237+
return nativeSqrScorerQuery.score(1);
238+
}
239+
220240
QuantizedByteVectorValues vectorValues(int dims, int size, IndexInput in, VectorSimilarityFunction sim) throws IOException {
221241
var sq = new ScalarQuantizer(0.1f, 0.9f, (byte) 7);
222242
var slice = in.slice("values", 0, in.length());

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/GitInfoPlugin.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.gradle.internal.conventions;
1111

1212
import org.elasticsearch.gradle.internal.conventions.info.GitInfo;
13+
import org.elasticsearch.gradle.internal.conventions.info.GitInfoValueSource;
1314
import org.elasticsearch.gradle.internal.conventions.util.Util;
1415
import org.gradle.api.Plugin;
1516
import org.gradle.api.Project;
@@ -18,38 +19,28 @@
1819
import org.gradle.api.provider.Provider;
1920
import org.gradle.api.provider.ProviderFactory;
2021

21-
import javax.inject.Inject;
2222
import java.io.File;
2323

24-
class GitInfoPlugin implements Plugin<Project> {
24+
import javax.inject.Inject;
2525

26-
private ProviderFactory factory;
27-
private ObjectFactory objectFactory;
26+
public abstract class GitInfoPlugin implements Plugin<Project> {
2827

28+
private ProviderFactory factory;
2929
private Provider<String> revision;
30-
private Property<GitInfo> gitInfo;
3130

3231
@Inject
33-
GitInfoPlugin(ProviderFactory factory, ObjectFactory objectFactory) {
32+
public GitInfoPlugin(ProviderFactory factory) {
3433
this.factory = factory;
35-
this.objectFactory = objectFactory;
3634
}
3735

3836
@Override
3937
public void apply(Project project) {
4038
File rootDir = Util.locateElasticsearchWorkspace(project.getGradle());
41-
gitInfo = objectFactory.property(GitInfo.class).value(factory.provider(() ->
42-
GitInfo.gitInfo(rootDir)
43-
));
44-
gitInfo.disallowChanges();
45-
gitInfo.finalizeValueOnRead();
46-
47-
revision = gitInfo.map(info -> info.getRevision() == null ? info.getRevision() : "main");
39+
getGitInfo().convention(factory.of(GitInfoValueSource.class, spec -> { spec.getParameters().getPath().set(rootDir); }));
40+
revision = getGitInfo().map(info -> info.getRevision() == null ? info.getRevision() : "main");
4841
}
4942

50-
public Property<GitInfo> getGitInfo() {
51-
return gitInfo;
52-
}
43+
public abstract Property<GitInfo> getGitInfo();
5344

5445
public Provider<String> getRevision() {
5546
return revision;

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/LicensingPlugin.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
import org.gradle.api.provider.Provider;
1616
import org.gradle.api.provider.ProviderFactory;
1717

18-
import javax.inject.Inject;
1918
import java.util.Map;
2019

20+
import javax.inject.Inject;
21+
2122
public class LicensingPlugin implements Plugin<Project> {
2223
static final String ELASTIC_LICENSE_URL_PREFIX = "https://raw.githubusercontent.com/elastic/elasticsearch/";
2324
static final String ELASTIC_LICENSE_URL_POSTFIX = "/licenses/ELASTIC-LICENSE-2.0.txt";
@@ -33,24 +34,33 @@ public LicensingPlugin(ProviderFactory providerFactory) {
3334
@Override
3435
public void apply(Project project) {
3536
Provider<String> revision = project.getRootProject().getPlugins().apply(GitInfoPlugin.class).getRevision();
36-
Provider<String> licenseCommitProvider = providerFactory.provider(() ->
37-
isSnapshotVersion(project) ? revision.get() : "v" + project.getVersion()
37+
Provider<String> licenseCommitProvider = providerFactory.provider(
38+
() -> isSnapshotVersion(project) ? revision.get() : "v" + project.getVersion()
3839
);
3940

40-
Provider<String> elasticLicenseURL = licenseCommitProvider.map(licenseCommit -> ELASTIC_LICENSE_URL_PREFIX +
41-
licenseCommit + ELASTIC_LICENSE_URL_POSTFIX);
42-
Provider<String> agplLicenseURL = licenseCommitProvider.map(licenseCommit -> ELASTIC_LICENSE_URL_PREFIX +
43-
licenseCommit + AGPL_ELASTIC_LICENSE_URL_POSTFIX);
41+
Provider<String> elasticLicenseURL = licenseCommitProvider.map(
42+
licenseCommit -> ELASTIC_LICENSE_URL_PREFIX + licenseCommit + ELASTIC_LICENSE_URL_POSTFIX
43+
);
44+
Provider<String> agplLicenseURL = licenseCommitProvider.map(
45+
licenseCommit -> ELASTIC_LICENSE_URL_PREFIX + licenseCommit + AGPL_ELASTIC_LICENSE_URL_POSTFIX
46+
);
4447
// But stick the Elastic license url in project.ext so we can get it if we need to switch to it
4548
project.getExtensions().getExtraProperties().set("elasticLicenseUrl", elasticLicenseURL);
4649

47-
MapProperty<String, String> licensesProperty = project.getObjects().mapProperty(String.class, String.class).convention(
48-
providerFactory.provider(() -> Map.of(
49-
"Server Side Public License, v 1", "https://www.mongodb.com/licensing/server-side-public-license",
50-
"Elastic License 2.0", elasticLicenseURL.get(),
51-
"GNU Affero General Public License Version 3", agplLicenseURL.get())
50+
MapProperty<String, Provider<String>> licensesProperty = project.getObjects()
51+
.mapProperty(String.class, (Class<Provider<String>>) (Class<?>) Provider.class)
52+
.convention(
53+
providerFactory.provider(
54+
() -> Map.of(
55+
"Server Side Public License, v 1",
56+
providerFactory.provider(() -> "https://www.mongodb.com/licensing/server-side-public-license"),
57+
"Elastic License 2.0",
58+
elasticLicenseURL,
59+
"GNU Affero General Public License Version 3",
60+
agplLicenseURL
61+
)
5262
)
53-
);
63+
);
5464

5565
// Default to the SSPL+Elastic dual license
5666
project.getExtensions().getExtraProperties().set("projectLicenses", licensesProperty);

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.gradle.api.plugins.JavaLibraryPlugin;
2929
import org.gradle.api.plugins.JavaPlugin;
3030
import org.gradle.api.provider.MapProperty;
31+
import org.gradle.api.provider.Provider;
3132
import org.gradle.api.provider.ProviderFactory;
3233
import org.gradle.api.publish.PublishingExtension;
3334
import org.gradle.api.publish.maven.MavenPublication;
@@ -42,6 +43,7 @@
4243
import java.io.File;
4344
import java.util.Map;
4445
import java.util.concurrent.Callable;
46+
4547
import javax.inject.Inject;
4648

4749
public class PublishPlugin implements Plugin<Project> {
@@ -81,15 +83,15 @@ private void configurePublications(Project project) {
8183
}
8284
});
8385
@SuppressWarnings("unchecked")
84-
var projectLicenses = (MapProperty<String, String>) project.getExtensions().getExtraProperties().get("projectLicenses");
86+
var projectLicenses = (MapProperty<String, Provider<String>>) project.getExtensions().getExtraProperties().get("projectLicenses");
8587
publication.getPom().withXml(xml -> {
8688
var node = xml.asNode();
8789
node.appendNode("inceptionYear", "2009");
8890
var licensesNode = node.appendNode("licenses");
8991
projectLicenses.get().entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> {
9092
Node license = licensesNode.appendNode("license");
9193
license.appendNode("name", entry.getKey());
92-
license.appendNode("url", entry.getValue());
94+
license.appendNode("url", entry.getValue().get());
9395
license.appendNode("distribution", "repo");
9496
});
9597
var developer = node.appendNode("developers").appendNode("developer");
@@ -194,7 +196,6 @@ static void configureSourcesJar(Project project) {
194196
});
195197
}
196198

197-
198199
/**
199200
* Format the generated pom files to be in a sort of reproducible order.
200201
*/

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/info/GitInfo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.HashMap;
2323
import java.util.Iterator;
2424
import java.util.Map;
25+
import java.util.Objects;
2526
import java.util.regex.Matcher;
2627
import java.util.regex.Pattern;
2728
import java.util.stream.Collectors;
@@ -190,4 +191,15 @@ public String urlFromOrigin() {
190191
}
191192
}
192193

194+
@Override
195+
public boolean equals(Object o) {
196+
if (o == null || getClass() != o.getClass()) return false;
197+
GitInfo gitInfo = (GitInfo) o;
198+
return Objects.equals(revision, gitInfo.revision) && Objects.equals(origin, gitInfo.origin);
199+
}
200+
201+
@Override
202+
public int hashCode() {
203+
return Objects.hash(revision, origin);
204+
}
193205
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.elasticsearch.gradle.internal.conventions.info;
2+
3+
import org.gradle.api.provider.Property;
4+
import org.gradle.api.provider.ValueSource;
5+
import org.gradle.api.provider.ValueSourceParameters;
6+
import org.jetbrains.annotations.Nullable;
7+
8+
import java.io.File;
9+
10+
public abstract class GitInfoValueSource implements ValueSource<GitInfo, GitInfoValueSource.Parameters> {
11+
12+
@Nullable
13+
@Override
14+
public GitInfo obtain() {
15+
File path = getParameters().getPath().get();
16+
return GitInfo.gitInfo(path);
17+
}
18+
19+
public interface Parameters extends ValueSourceParameters {
20+
Property<File> getPath();
21+
}
22+
}

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
4545
file("build/distributions/hello-world-1.0-javadoc.jar").exists()
4646
file("build/distributions/hello-world-1.0-sources.jar").exists()
4747
file("build/distributions/hello-world-1.0.pom").exists()
48-
assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
48+
assertXmlEquals(
49+
file("build/distributions/hello-world-1.0.pom").text, """
4950
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5051
<!-- This module was also published with a richer model, Gradle metadata, -->
5152
<!-- which should be used instead. Do not delete the following line which -->
@@ -130,7 +131,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
130131
file("build/distributions/hello-world-1.0-javadoc.jar").exists()
131132
file("build/distributions/hello-world-1.0-sources.jar").exists()
132133
file("build/distributions/hello-world-1.0.pom").exists()
133-
assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
134+
assertXmlEquals(
135+
file("build/distributions/hello-world-1.0.pom").text, """
134136
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
135137
<modelVersion>4.0.0</modelVersion>
136138
<groupId>org.acme</groupId>
@@ -219,7 +221,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
219221
file("build/distributions/hello-world-1.0-javadoc.jar").exists()
220222
file("build/distributions/hello-world-1.0-sources.jar").exists()
221223
file("build/distributions/hello-world-1.0.pom").exists()
222-
assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
224+
assertXmlEquals(
225+
file("build/distributions/hello-world-1.0.pom").text, """
223226
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
224227
<modelVersion>4.0.0</modelVersion>
225228
<groupId>org.acme</groupId>
@@ -312,7 +315,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
312315
file("build/distributions/hello-world-plugin-1.0-javadoc.jar").exists()
313316
file("build/distributions/hello-world-plugin-1.0-sources.jar").exists()
314317
file("build/distributions/hello-world-plugin-1.0.pom").exists()
315-
assertXmlEquals(file("build/distributions/hello-world-plugin-1.0.pom").text, """
318+
assertXmlEquals(
319+
file("build/distributions/hello-world-plugin-1.0.pom").text, """
316320
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
317321
<!-- This module was also published with a richer model, Gradle metadata, -->
318322
<!-- which should be used instead. Do not delete the following line which -->
@@ -389,7 +393,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
389393
then:
390394
result.task(":generatePom").outcome == TaskOutcome.SUCCESS
391395
file("build/distributions/hello-world-plugin-2.0.pom").exists()
392-
assertXmlEquals(file("build/distributions/hello-world-plugin-2.0.pom").text, """
396+
assertXmlEquals(
397+
file("build/distributions/hello-world-plugin-2.0.pom").text, """
393398
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
394399
<!-- This module was also published with a richer model, Gradle metadata, -->
395400
<!-- which should be used instead. Do not delete the following line which -->
@@ -439,15 +444,15 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
439444
// scm info only added for internal builds
440445
internalBuild()
441446
buildFile << """
442-
buildParams.setGitOrigin("https://some-repo.com/repo.git")
447+
buildParams.setGitOrigin(project.providers.provider(() -> "https://some-repo.com/repo.git"))
443448
apply plugin:'elasticsearch.java'
444449
apply plugin:'elasticsearch.publish'
445450
446451
version = "1.0"
447452
group = 'org.acme'
448453
description = "just a test project"
449454
450-
ext.projectLicenses.set(['The Apache Software License, Version 2.0': 'http://www.apache.org/licenses/LICENSE-2.0'])
455+
ext.projectLicenses.set(['The Apache Software License, Version 2.0': project.providers.provider(() -> 'http://www.apache.org/licenses/LICENSE-2.0')])
451456
"""
452457

453458
when:
@@ -456,7 +461,8 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
456461
then:
457462
result.task(":generatePom").outcome == TaskOutcome.SUCCESS
458463
file("build/distributions/hello-world-1.0.pom").exists()
459-
assertXmlEquals(file("build/distributions/hello-world-1.0.pom").text, """
464+
assertXmlEquals(
465+
file("build/distributions/hello-world-1.0.pom").text, """
460466
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
461467
<!-- This module was also published with a richer model, Gradle metadata, -->
462468
<!-- which should be used instead. Do not delete the following line which -->
@@ -493,15 +499,15 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
493499

494500
private boolean assertXmlEquals(String toTest, String expected) {
495501
def diff = DiffBuilder.compare(Input.fromString(expected))
496-
.ignoreWhitespace()
497-
.ignoreComments()
498-
.normalizeWhitespace()
499-
.withTest(Input.fromString(toTest))
500-
.build()
502+
.ignoreWhitespace()
503+
.ignoreComments()
504+
.normalizeWhitespace()
505+
.withTest(Input.fromString(toTest))
506+
.build()
501507
diff.differences.each { difference ->
502508
println difference
503509
}
504-
if(diff.differences.size() > 0) {
510+
if (diff.differences.size() > 0) {
505511
println """ given:
506512
$toTest
507513
"""

0 commit comments

Comments
 (0)