Skip to content

Commit

Permalink
Merge branch 'main' into test/snapshot_v7_index_version
Browse files Browse the repository at this point in the history
  • Loading branch information
javanna authored Jan 6, 2025
2 parents e3535e4 + 23e7fe9 commit fde79ee
Show file tree
Hide file tree
Showing 1,393 changed files with 30,615 additions and 6,706 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public class VectorScorerBenchmark {

RandomVectorScorer luceneDotScorerQuery;
RandomVectorScorer nativeDotScorerQuery;
RandomVectorScorer luceneSqrScorerQuery;
RandomVectorScorer nativeSqrScorerQuery;

@Setup
public void setup() throws IOException {
Expand Down Expand Up @@ -130,6 +132,8 @@ public void setup() throws IOException {
}
luceneDotScorerQuery = luceneScorer(values, VectorSimilarityFunction.DOT_PRODUCT, queryVec);
nativeDotScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.DOT_PRODUCT, values, queryVec).get();
luceneSqrScorerQuery = luceneScorer(values, VectorSimilarityFunction.EUCLIDEAN, queryVec);
nativeSqrScorerQuery = factory.getInt7SQVectorScorer(VectorSimilarityFunction.EUCLIDEAN, values, queryVec).get();

// sanity
var f1 = dotProductLucene();
Expand Down Expand Up @@ -157,6 +161,12 @@ public void setup() throws IOException {
if (q1 != q2) {
throw new AssertionError("query: lucene[" + q1 + "] != " + "native[" + q2 + "]");
}

var sqr1 = squareDistanceLuceneQuery();
var sqr2 = squareDistanceNativeQuery();
if (sqr1 != sqr2) {
throw new AssertionError("query: lucene[" + q1 + "] != " + "native[" + q2 + "]");
}
}

@TearDown
Expand Down Expand Up @@ -217,6 +227,16 @@ public float squareDistanceScalar() {
return 1 / (1f + adjustedDistance);
}

@Benchmark
public float squareDistanceLuceneQuery() throws IOException {
return luceneSqrScorerQuery.score(1);
}

@Benchmark
public float squareDistanceNativeQuery() throws IOException {
return nativeSqrScorerQuery.score(1);
}

QuantizedByteVectorValues vectorValues(int dims, int size, IndexInput in, VectorSimilarityFunction sim) throws IOException {
var sq = new ScalarQuantizer(0.1f, 0.9f, (byte) 7);
var slice = in.slice("values", 0, in.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,45 @@
package org.elasticsearch.gradle.internal.conventions;

import org.elasticsearch.gradle.internal.conventions.info.GitInfo;
import org.elasticsearch.gradle.internal.conventions.info.GitInfoValueSource;
import org.elasticsearch.gradle.internal.conventions.util.Util;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;

import javax.inject.Inject;
import java.io.File;

class GitInfoPlugin implements Plugin<Project> {
import javax.inject.Inject;

private ProviderFactory factory;
private ObjectFactory objectFactory;
public abstract class GitInfoPlugin implements Plugin<Project> {

private ProviderFactory factory;
private Provider<String> revision;
private Property<GitInfo> gitInfo;

@Inject
GitInfoPlugin(ProviderFactory factory, ObjectFactory objectFactory) {
public GitInfoPlugin(ProviderFactory factory) {
this.factory = factory;
this.objectFactory = objectFactory;
}

@Override
public void apply(Project project) {
File rootDir = Util.locateElasticsearchWorkspace(project.getGradle());
gitInfo = objectFactory.property(GitInfo.class).value(factory.provider(() ->
GitInfo.gitInfo(rootDir)
));
gitInfo.disallowChanges();
gitInfo.finalizeValueOnRead();

revision = gitInfo.map(info -> info.getRevision() == null ? info.getRevision() : "main");
File rootDir = getGitRootDir(project);
getGitInfo().convention(factory.of(GitInfoValueSource.class, spec -> { spec.getParameters().getPath().set(rootDir); }));
revision = getGitInfo().map(info -> info.getRevision() == null ? info.getRevision() : "main");
}

public Property<GitInfo> getGitInfo() {
return gitInfo;
private static File getGitRootDir(Project project) {
File rootDir = project.getRootDir();
if (new File(rootDir, ".git").exists()) {
return rootDir;
}
return Util.locateElasticsearchWorkspace(project.getGradle());
}

public abstract Property<GitInfo> getGitInfo();

public Provider<String> getRevision() {
return revision;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;

import javax.inject.Inject;
import java.util.Map;

import javax.inject.Inject;

public class LicensingPlugin implements Plugin<Project> {
static final String ELASTIC_LICENSE_URL_PREFIX = "https://raw.githubusercontent.com/elastic/elasticsearch/";
static final String ELASTIC_LICENSE_URL_POSTFIX = "/licenses/ELASTIC-LICENSE-2.0.txt";
Expand All @@ -33,24 +34,33 @@ public LicensingPlugin(ProviderFactory providerFactory) {
@Override
public void apply(Project project) {
Provider<String> revision = project.getRootProject().getPlugins().apply(GitInfoPlugin.class).getRevision();
Provider<String> licenseCommitProvider = providerFactory.provider(() ->
isSnapshotVersion(project) ? revision.get() : "v" + project.getVersion()
Provider<String> licenseCommitProvider = providerFactory.provider(
() -> isSnapshotVersion(project) ? revision.get() : "v" + project.getVersion()
);

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

MapProperty<String, String> licensesProperty = project.getObjects().mapProperty(String.class, String.class).convention(
providerFactory.provider(() -> Map.of(
"Server Side Public License, v 1", "https://www.mongodb.com/licensing/server-side-public-license",
"Elastic License 2.0", elasticLicenseURL.get(),
"GNU Affero General Public License Version 3", agplLicenseURL.get())
MapProperty<String, Provider<String>> licensesProperty = project.getObjects()
.mapProperty(String.class, (Class<Provider<String>>) (Class<?>) Provider.class)
.convention(
providerFactory.provider(
() -> Map.of(
"Server Side Public License, v 1",
providerFactory.provider(() -> "https://www.mongodb.com/licensing/server-side-public-license"),
"Elastic License 2.0",
elasticLicenseURL,
"GNU Affero General Public License Version 3",
agplLicenseURL
)
)
);
);

// Default to the SSPL+Elastic dual license
project.getExtensions().getExtraProperties().set("projectLicenses", licensesProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.provider.Provider;
import org.gradle.api.provider.ProviderFactory;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
Expand All @@ -42,6 +43,7 @@
import java.io.File;
import java.util.Map;
import java.util.concurrent.Callable;

import javax.inject.Inject;

public class PublishPlugin implements Plugin<Project> {
Expand Down Expand Up @@ -81,15 +83,15 @@ private void configurePublications(Project project) {
}
});
@SuppressWarnings("unchecked")
var projectLicenses = (MapProperty<String, String>) project.getExtensions().getExtraProperties().get("projectLicenses");
var projectLicenses = (MapProperty<String, Provider<String>>) project.getExtensions().getExtraProperties().get("projectLicenses");
publication.getPom().withXml(xml -> {
var node = xml.asNode();
node.appendNode("inceptionYear", "2009");
var licensesNode = node.appendNode("licenses");
projectLicenses.get().entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> {
Node license = licensesNode.appendNode("license");
license.appendNode("name", entry.getKey());
license.appendNode("url", entry.getValue());
license.appendNode("url", entry.getValue().get());
license.appendNode("distribution", "repo");
});
var developer = node.appendNode("developers").appendNode("developer");
Expand Down Expand Up @@ -194,7 +196,6 @@ static void configureSourcesJar(Project project) {
});
}


/**
* Format the generated pom files to be in a sort of reproducible order.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -190,4 +191,15 @@ public String urlFromOrigin() {
}
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
GitInfo gitInfo = (GitInfo) o;
return Objects.equals(revision, gitInfo.revision) && Objects.equals(origin, gitInfo.origin);
}

@Override
public int hashCode() {
return Objects.hash(revision, origin);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.elasticsearch.gradle.internal.conventions.info;

import org.gradle.api.provider.Property;
import org.gradle.api.provider.ValueSource;
import org.gradle.api.provider.ValueSourceParameters;
import org.jetbrains.annotations.Nullable;

import java.io.File;

public abstract class GitInfoValueSource implements ValueSource<GitInfo, GitInfoValueSource.Parameters> {

@Nullable
@Override
public GitInfo obtain() {
File path = getParameters().getPath().get();
return GitInfo.gitInfo(path);
}

public interface Parameters extends ValueSourceParameters {
Property<File> getPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
import org.gradle.api.Project;
import org.gradle.api.file.FileTree;
import org.gradle.api.initialization.IncludedBuild;
import org.gradle.api.internal.GradleInternal;
import org.gradle.api.invocation.Gradle;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.util.PatternFilterable;

import javax.annotation.Nullable;
import java.io.File;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Supplier;

import javax.annotation.Nullable;

public class Util {

public static boolean getBooleanProperty(String property, boolean defaultValue) {
Expand Down Expand Up @@ -120,6 +121,14 @@ public static SourceSetContainer getJavaSourceSets(Project project) {
return project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
}

public static File getRootFolder(Gradle gradle) {
Gradle parent = gradle.getParent();
if (parent == null) {
return gradle.getRootProject().getRootDir();
}
return getRootFolder(parent);
}

public static File locateElasticsearchWorkspace(Gradle gradle) {
if (gradle.getRootProject().getName().startsWith("build-tools")) {
File buildToolsParent = gradle.getRootProject().getRootDir().getParentFile();
Expand Down
4 changes: 2 additions & 2 deletions build-tools-internal/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=89d4e70e4e84e2d2dfbb63e4daa53e21b25017cc70c37e4eea31ee51fb15098a
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
distributionSha256Sum=7ebdac923867a3cec0098302416d1e3c6c0c729fc4e2e05c10637a8af33a76c5
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Loading

0 comments on commit fde79ee

Please sign in to comment.