diff --git a/pom.xml b/pom.xml index 393474d64..0adc6823e 100644 --- a/pom.xml +++ b/pom.xml @@ -264,7 +264,13 @@ @see: https://www.oracle.com/corporate/features/understanding-java-9-modules.html --> --add-opens=java.base/java.lang=ALL-UNNAMED - + + + + listener + io.weaviate.containers.TestListener + + @@ -334,12 +340,24 @@ + + add-test-source + process-resources + + add-test-source + + + + ${project.basedir}/src/it/java + + + org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 + 3.11.2 attach-javadocs diff --git a/src/it/java/io/weaviate/ConcurrentTest.java b/src/it/java/io/weaviate/ConcurrentTest.java new file mode 100644 index 000000000..2e2036d18 --- /dev/null +++ b/src/it/java/io/weaviate/ConcurrentTest.java @@ -0,0 +1,64 @@ +package io.weaviate; + +import java.util.Random; +import java.util.UUID; +import java.util.stream.IntStream; + +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.Rule; +import org.junit.rules.TestName; + +/** + * ConcurrentTest is the base class for integration tests, which provides + * utility methods to uniqualize collections and objects created in the + * database. + * + * Because we want to re-use the same database container across most of the + * test suites and (eventually) run them in parallel, + * test classes should extend this class and use its methods + * to avoid name clashes in the shared Weaviate instance. + */ +public abstract class ConcurrentTest { + @Rule + public TestName currentTest = new TestName(); + + protected static final Random rand = new Random(); + + /** + * Add unique namespace prefix to the string. + * + * @param value Collection name, object ID, etc., which has to be unique across + * all test suites. + * @return Value prefixed with the name of the current test suite + test method. + */ + protected String ns(String value) { + String cls = getClass().getSimpleName(); + String method = currentTest.getMethodName(); + return cls + "_" + method + "_" + value; + } + + /** Appends random characters to create unique value. */ + protected static String unique(String value) { + var randString = RandomStringUtils.insecure().next(8, true, false); + return value + "_" + randString; + } + + /** Generate random UUID. */ + protected static String randomUUID() { + return UUID.randomUUID().toString(); + } + + /** + * Generate a random vector. + * + * @param length Vector length. + * @param origin Value range lower bound. + * @param bound Value range upper bound. + * @return + */ + protected static Float[] randomVector(int length, float origin, float bound) { + return IntStream.range(0, length) + .mapToObj(f -> rand.nextFloat(origin, bound)) + .toArray(Float[]::new); + } +} diff --git a/src/it/java/io/weaviate/client6/internal/GRPCTest.java b/src/it/java/io/weaviate/client6/internal/GRPCTest.java new file mode 100644 index 000000000..ab14b6aaa --- /dev/null +++ b/src/it/java/io/weaviate/client6/internal/GRPCTest.java @@ -0,0 +1,48 @@ +package io.weaviate.client6.internal; + +import static org.junit.Assert.assertArrayEquals; + +import org.junit.Test; + +import com.google.protobuf.ByteString; + +/** + * Note: Java's {@code byte} is signed (int8) and is different from {@code byte} + * in Go, which is an alias for uint8. + * + * For this tests purposes the distinction is immaterial, as "want" arrays + * are "golden values" meant to be a readable respresentation for the test. + */ +public class GRPCTest { + @Test + public void test_toBytesString_1d() { + Float[] vector = { 1f, 2f, 3f }; + byte[] want = { 0, 0, -128, 63, 0, 0, 0, 64, 0, 0, 64, 64 }; + byte[] got = GRPC.toByteString(vector).toByteArray(); + assertArrayEquals(want, got); + } + + @Test + public void test_fromBytesString_1d() { + byte[] bytes = { 0, 0, -128, 63, 0, 0, 0, 64, 0, 0, 64, 64 }; + Float[] want = { 1f, 2f, 3f }; + Float[] got = GRPC.fromByteString(ByteString.copyFrom(bytes)); + assertArrayEquals(want, got); + } + + @Test + public void test_toBytesString_2d() { + Float[][] vector = { { 1f, 2f, 3f }, { 4f, 5f, 6f } }; + byte[] want = { 3, 0, 0, 0, -128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, -128, 64, 0, 0, -96, 64, 0, 0, -64, 64 }; + byte[] got = GRPC.toByteString(vector).toByteArray(); + assertArrayEquals(want, got); + } + + @Test + public void test_fromBytesString_2d() { + byte[] bytes = { 3, 0, 0, 0, -128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, -128, 64, 0, 0, -96, 64, 0, 0, -64, 64 }; + Float[][] want = { { 1f, 2f, 3f }, { 4f, 5f, 6f } }; + Float[][] got = GRPC.fromByteStringMulti(ByteString.copyFrom(bytes)); + assertArrayEquals(want, got); + } +} diff --git a/src/it/java/io/weaviate/client6/v1/DataITest.java b/src/it/java/io/weaviate/client6/v1/DataITest.java new file mode 100644 index 000000000..f64702f1e --- /dev/null +++ b/src/it/java/io/weaviate/client6/v1/DataITest.java @@ -0,0 +1,67 @@ +package io.weaviate.client6.v1; + +import java.io.IOException; +import java.util.Map; + +import org.assertj.core.api.Assertions; +import org.assertj.core.api.InstanceOfAssertFactories; +import org.junit.BeforeClass; +import org.junit.Test; + +import io.weaviate.ConcurrentTest; +import io.weaviate.client6.WeaviateClient; +import io.weaviate.client6.v1.collections.Property; +import io.weaviate.client6.v1.collections.VectorIndex; +import io.weaviate.client6.v1.collections.VectorIndex.IndexingStrategy; +import io.weaviate.client6.v1.collections.Vectorizer; +import io.weaviate.containers.Container; + +public class DataITest extends ConcurrentTest { + + private static WeaviateClient client = Container.WEAVIATE.getClient(); + private static final String COLLECTION = unique("Things"); + private static final String VECTOR_INDEX = "bring_your_own"; + + @BeforeClass + public static void beforeAll() throws IOException { + createTestCollection(); + } + + @Test + public void testCreateGetDelete() throws IOException { + var things = client.collections.use(COLLECTION); + var id = randomUUID(); + Float[] vector = { 1f, 2f, 3f }; + + things.data.insert(Map.of("username", "john doe"), metadata -> metadata + .id(id) + .vectors(Vectors.of(VECTOR_INDEX, vector))); + + var object = things.data.get(id, query -> query.withVector()); + Assertions.assertThat(object) + .as("object exists after insert").get() + .satisfies(obj -> { + Assertions.assertThat(obj.metadata().id()) + .as("object id").isEqualTo(id); + + Assertions.assertThat(obj.metadata().vectors()).extracting(Vectors::getSingle) + .asInstanceOf(InstanceOfAssertFactories.OPTIONAL).as("has single vector").get() + .asInstanceOf(InstanceOfAssertFactories.array(Float[].class)).containsExactly(vector); + + Assertions.assertThat(obj.properties()) + .as("has expected properties") + .containsEntry("username", "john doe"); + }); + + things.data.delete(id); + object = things.data.get(id); + Assertions.assertThat(object).isEmpty().as("object not exists after deletion"); + } + + private static void createTestCollection() throws IOException { + client.collections.create(COLLECTION, + col -> col + .properties(Property.text("username"), Property.integer("age")) + .vector(VECTOR_INDEX, new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.none()))); + } +} diff --git a/src/it/java/io/weaviate/client6/v1/collections/CollectionsITest.java b/src/it/java/io/weaviate/client6/v1/collections/CollectionsITest.java new file mode 100644 index 000000000..dd50d69e1 --- /dev/null +++ b/src/it/java/io/weaviate/client6/v1/collections/CollectionsITest.java @@ -0,0 +1,41 @@ +package io.weaviate.client6.v1.collections; + +import java.io.IOException; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +import io.weaviate.ConcurrentTest; +import io.weaviate.client6.WeaviateClient; +import io.weaviate.client6.v1.collections.VectorIndex.IndexType; +import io.weaviate.client6.v1.collections.VectorIndex.IndexingStrategy; +import io.weaviate.containers.Container; + +public class CollectionsITest extends ConcurrentTest { + private static WeaviateClient client = Container.WEAVIATE.getClient(); + + @Test + public void testCreateGetDelete() throws IOException { + var collectionName = ns("Things_1"); + client.collections.create(collectionName, + col -> col + .properties(Property.text("username"), Property.integer("age")) + .vector(new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.none()))); + + var thingsCollection = client.collections.getConfig(collectionName); + + Assertions.assertThat(thingsCollection).get() + .hasFieldOrPropertyWithValue("name", collectionName) + .extracting(CollectionDefinition::vectors).extracting(Vectors::getDefault) + .as("default vector").satisfies(defaultVector -> { + Assertions.assertThat(defaultVector).extracting(VectorIndex::vectorizer) + .as("has none vectorizer").isInstanceOf(NoneVectorizer.class); + Assertions.assertThat(defaultVector).extracting(VectorIndex::configuration) + .as("has hnsw index").returns(IndexType.HNSW, IndexingStrategy::type); + }); + + client.collections.delete(collectionName); + var noCollection = client.collections.getConfig(collectionName); + Assertions.assertThat(noCollection).as("after delete").isEmpty(); + } +} diff --git a/src/it/java/io/weaviate/client6/v1/query/NearVectorQueryITest.java b/src/it/java/io/weaviate/client6/v1/query/NearVectorQueryITest.java new file mode 100644 index 000000000..0b8693b75 --- /dev/null +++ b/src/it/java/io/weaviate/client6/v1/query/NearVectorQueryITest.java @@ -0,0 +1,88 @@ +package io.weaviate.client6.v1.query; + +import java.io.IOException; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; + +import org.assertj.core.api.Assertions; +import org.junit.BeforeClass; +import org.junit.Test; + +import io.weaviate.ConcurrentTest; +import io.weaviate.client6.WeaviateClient; +import io.weaviate.client6.v1.Vectors; +import io.weaviate.client6.v1.collections.VectorIndex; +import io.weaviate.client6.v1.collections.VectorIndex.IndexingStrategy; +import io.weaviate.client6.v1.collections.Vectorizer; +import io.weaviate.containers.Container; + +public class NearVectorQueryITest extends ConcurrentTest { + private static final WeaviateClient client = Container.WEAVIATE.getClient(); + + private static final String COLLECTION = unique("Things"); + private static final String VECTOR_INDEX = "bring_your_own"; + + /** + * One of the inserted vectors which will be used as target vector for search. + */ + private static Float[] searchVector; + + @BeforeClass + public static void beforeAll() throws IOException { + createTestCollection(); + var created = createVectors(10); + searchVector = created.values().iterator().next(); + } + + @Test + public void testNearVector() { + // TODO: test that we return the results in the expected order + // Because re-ranking should work correctly + var things = client.collections.use(COLLECTION); + QueryResult> result = things.query.nearVector(searchVector, + opt -> opt + .distance(2f) + .limit(3) + .returnMetadata(MetadataField.DISTANCE)); + + Assertions.assertThat(result.objects).hasSize(3); + float maxDistance = Collections.max(result.objects, + Comparator.comparing(obj -> obj.metadata.distance)).metadata.distance; + Assertions.assertThat(maxDistance).isLessThanOrEqualTo(2f); + } + + /** + * Insert 10 objects with random vectors. + * + * @returns IDs of inserted objects and their corresponding vectors. + */ + private static Map createVectors(int n) throws IOException { + var created = new HashMap(); + + var things = client.collections.use(COLLECTION); + for (int i = 0; i < n; i++) { + var vector = randomVector(10, -.01f, .001f); + var object = things.data.insert( + Map.of(), + metadata -> metadata + .id(randomUUID()) + .vectors(Vectors.of(VECTOR_INDEX, vector))); + + created.put(object.metadata().id(), vector); + } + + return created; + } + + /** + * Create {@link COLLECTION} with {@link VECTOR_INDEX} vector index. + * + * @throws IOException + */ + private static void createTestCollection() throws IOException { + client.collections.create(COLLECTION, cfg -> cfg + .vector(VECTOR_INDEX, new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.none()))); + } +} diff --git a/src/it/java/io/weaviate/containers/Container.java b/src/it/java/io/weaviate/containers/Container.java new file mode 100644 index 000000000..9ef69cfe8 --- /dev/null +++ b/src/it/java/io/weaviate/containers/Container.java @@ -0,0 +1,105 @@ +package io.weaviate.containers; + +import java.util.Arrays; +import java.util.List; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.lifecycle.Startable; + +import io.weaviate.client6.WeaviateClient; +import lombok.RequiredArgsConstructor; + +public class Container { + public static final Weaviate WEAVIATE = Weaviate.createDefault(); + public static final Contextionary CONTEXTIONARY = Contextionary.createDefault(); + + static { + startAll(); + } + + /** Start all shared Testcontainers. */ + // TODO: start lazily! + static void startAll() { + // WEAVIATE.start(); + } + + /** + * Stop all shared Testcontainers created in {@link #startAll}. + *

+ * Testcontainer's Ryuk will reap any dangling containers after the tests + * finish. However, since {@link Weaviate} instances also hold a + * {@link WeaviateClient}, we want to stop them proactively to + * close client connections. + */ + static void stopAll() { + WEAVIATE.stop(); + } + + public static Group compose(Weaviate weaviate, GenericContainer... containers) { + return new Group(weaviate, containers); + } + + public static TestRule asTestRule(Startable container) { + return new PerTestSuite(container); + }; + + public static class Group implements Startable { + private final Weaviate weaviate; + private final List> containers; + + private Group(Weaviate weaviate, GenericContainer... containers) { + this.weaviate = weaviate; + this.containers = Arrays.asList(containers); + setSharedNetwork(); + } + + public WeaviateClient getClient() { + return weaviate.getClient(); + } + + @Override + public void start() { + containers.forEach(GenericContainer::start); + weaviate.start(); + } + + @Override + public void stop() { + weaviate.stop(); + containers.forEach(GenericContainer::stop); + } + + private void setSharedNetwork() { + weaviate.setNetwork(Network.SHARED); + containers.forEach(c -> c.setNetwork(Network.SHARED)); + } + + public TestRule asTestRule() { + return new PerTestSuite(this); + }; + } + + @RequiredArgsConstructor + public static class PerTestSuite implements TestRule { + private final Startable container; + + @Override + public Statement apply(Statement base, Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + try { + container.start(); + base.evaluate(); + } finally { + container.stop(); + } + } + }; + } + } +} diff --git a/src/it/java/io/weaviate/containers/Contextionary.java b/src/it/java/io/weaviate/containers/Contextionary.java new file mode 100644 index 000000000..76ec5aefd --- /dev/null +++ b/src/it/java/io/weaviate/containers/Contextionary.java @@ -0,0 +1,46 @@ +package io.weaviate.containers; + +import org.testcontainers.containers.GenericContainer; + +public class Contextionary extends GenericContainer { + public static final String VERSION = "en0.16.0-v1.2.1"; + public static final String DOCKER_IMAGE = "semitechnologies/contextionary"; + public static final String MODULE = "text2vec-contextionary"; + + public static final String HOST_NAME = "contextionary"; + public static final String URL = HOST_NAME + ":9999"; + + static Contextionary createDefault() { + return new Builder().build(); + } + + static Contextionary.Builder custom() { + return new Builder(); + } + + public static class Builder { + private String versionTag; + + public Builder() { + this.versionTag = VERSION; + } + + public Contextionary build() { + var container = new Contextionary(DOCKER_IMAGE + ":" + versionTag); + container + .withEnv("OCCURRENCE_WEIGHT_LINEAR_FACTOR", "true") + .withEnv("PERSISTENCE_DATA_PATH", "/var/lib/weaviate") + .withEnv("OCCURRENCE_WEIGHT_LINEAR_FACTOR", "0.75") + .withEnv("EXTENSIONS_STORAGE_MODE", "weaviate") + .withEnv("EXTENSIONS_STORAGE_ORIGIN", "http://weaviate:8080") + .withEnv("NEIGHBOR_OCCURRENCE_IGNORE_PERCENTILE", "5") + .withEnv("ENABLE_COMPOUND_SPLITTING", "'false'"); + container.withCreateContainerCmdModifier(cmd -> cmd.withHostName("contextionary")); + return container; + } + } + + public Contextionary(String image) { + super(image); + } +} diff --git a/src/it/java/io/weaviate/containers/TestListener.java b/src/it/java/io/weaviate/containers/TestListener.java new file mode 100644 index 000000000..72889125b --- /dev/null +++ b/src/it/java/io/weaviate/containers/TestListener.java @@ -0,0 +1,14 @@ +package io.weaviate.containers; + +import org.junit.runner.Result; +import org.junit.runner.notification.RunListener; + +public class TestListener extends RunListener { + + @Override + public void testRunFinished(Result result) throws Exception { + Container.stopAll(); + super.testRunFinished(result); + } + +} diff --git a/src/it/java/io/weaviate/containers/Weaviate.java b/src/it/java/io/weaviate/containers/Weaviate.java new file mode 100644 index 000000000..6126d5150 --- /dev/null +++ b/src/it/java/io/weaviate/containers/Weaviate.java @@ -0,0 +1,123 @@ +package io.weaviate.containers; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import org.testcontainers.weaviate.WeaviateContainer; + +import io.weaviate.client6.Config; +import io.weaviate.client6.WeaviateClient; + +public class Weaviate extends WeaviateContainer { + private static WeaviateClient clientInstance; + + public static final String VERSION = "1.29.0"; + public static final String DOCKER_IMAGE = "semitechnologies/weaviate"; + + /** + * Get a client for the current Weaviate container. + * As we aren't running tests in parallel at the moment, + * this is not made thread-safe. + */ + public WeaviateClient getClient() { + // FIXME: control from containers? + if (!isRunning()) { + start(); + } + if (clientInstance == null) { + var config = new Config("http", getHttpHostAddress(), getGrpcHostAddress()); + clientInstance = new WeaviateClient(config); + } + return clientInstance; + } + + public static Weaviate createDefault() { + return new Builder().build(); + } + + public static Weaviate.Builder custom() { + return new Builder(); + } + + public static class Builder { + private String versionTag; + private Set enableModules; + private String defaultVectorizerModule; + private String contextionaryUrl; + private boolean telemetry; + + public Builder() { + this.versionTag = VERSION; + this.enableModules = new HashSet<>(); + this.telemetry = false; + } + + public Builder withVersion(String version) { + this.versionTag = version; + return this; + } + + public Builder addModule(String module) { + enableModules.add(module); + return this; + } + + public Builder withDefaultVectorizer(String module) { + addModule(module); + defaultVectorizerModule = module; + return this; + } + + public Builder withContextionaryUrl(String url) { + contextionaryUrl = url; + return this; + } + + public Builder enableTelemetry() { + telemetry = true; + return this; + } + + public Weaviate build() { + var c = new Weaviate(DOCKER_IMAGE + ":" + versionTag); + + if (!enableModules.isEmpty()) { + c.withEnv("ENABLE_MODULES", String.join(",", enableModules)); + } + if (defaultVectorizerModule != null) { + c.withEnv("DEFAULT_VECTORIZER_MODULE", defaultVectorizerModule); + } + if (contextionaryUrl != null) { + c.withEnv("CONTEXTIONARY_URL", contextionaryUrl); + } + if (!telemetry) { + c.withEnv("DISABLE_TELEMETRY", "true"); + } + + c.withCreateContainerCmdModifier(cmd -> cmd.withHostName("weaviate")); + return c; + } + } + + private Weaviate(String dockerImageName) { + super(dockerImageName); + } + + @Override + public void stop() { + // Note: at the moment containers which are not created as a @TestRule + // will not be "stopped", so client's resources are also not being freed. + // This is fine in tests, but may produce warnings about the gRPC channel + // not shut down properly. + super.stop(); + if (clientInstance == null) { + return; + } + try { + clientInstance.close(); + } catch (IOException e) { + // TODO: log error + } + } +} diff --git a/src/main/java/io/weaviate/client6/Config.java b/src/main/java/io/weaviate/client6/Config.java new file mode 100644 index 000000000..8926c3aa8 --- /dev/null +++ b/src/main/java/io/weaviate/client6/Config.java @@ -0,0 +1,26 @@ +package io.weaviate.client6; + +public class Config { + private final String version = "v1"; + private final String scheme; + private final String httpHost; + private final String grpcHost; + + public Config(String scheme, String httpHost, String grpcHost) { + this.scheme = scheme; + this.httpHost = httpHost; + this.grpcHost = grpcHost; + } + + public String baseUrl() { + return scheme + "://" + httpHost + "/" + version; + } + + public String grpcAddress() { + if (grpcHost.contains(":")) { + return grpcHost; + } + // FIXME: use secure port (433) if scheme == https + return String.format("%s:80", grpcHost); + } +} diff --git a/src/main/java/io/weaviate/client6/WeaviateClient.java b/src/main/java/io/weaviate/client6/WeaviateClient.java new file mode 100644 index 000000000..8dba725a5 --- /dev/null +++ b/src/main/java/io/weaviate/client6/WeaviateClient.java @@ -0,0 +1,27 @@ +package io.weaviate.client6; + +import java.io.Closeable; +import java.io.IOException; + +import io.weaviate.client6.internal.GrpcClient; +import io.weaviate.client6.internal.HttpClient; +import io.weaviate.client6.v1.collections.Collections; + +public class WeaviateClient implements Closeable { + private final HttpClient http; + private final GrpcClient grpc; + + public final Collections collections; + + public WeaviateClient(Config config) { + this.http = new HttpClient(); + this.grpc = new GrpcClient(config); + this.collections = new Collections(config, http, grpc); + } + + @Override + public void close() throws IOException { + this.http.close(); + this.grpc.close(); + } +} diff --git a/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateGrpc.java b/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateGrpc.java deleted file mode 100644 index ed743de27..000000000 --- a/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateGrpc.java +++ /dev/null @@ -1,367 +0,0 @@ -package io.weaviate.client6.grpc.protocol.v0; - -import static io.grpc.MethodDescriptor.generateFullMethodName; - -/** - */ -@javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.58.0)", - comments = "Source: v0/weaviate.proto") -@io.grpc.stub.annotations.GrpcGenerated -public final class WeaviateGrpc { - - private WeaviateGrpc() {} - - public static final java.lang.String SERVICE_NAME = "weaviategrpc.Weaviate"; - - // Static method descriptors that strictly reflect the proto. - private static volatile io.grpc.MethodDescriptor getSearchMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "Search", - requestType = io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest.class, - responseType = io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getSearchMethod() { - io.grpc.MethodDescriptor getSearchMethod; - if ((getSearchMethod = WeaviateGrpc.getSearchMethod) == null) { - synchronized (WeaviateGrpc.class) { - if ((getSearchMethod = WeaviateGrpc.getSearchMethod) == null) { - WeaviateGrpc.getSearchMethod = getSearchMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "Search")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply.getDefaultInstance())) - .setSchemaDescriptor(new WeaviateMethodDescriptorSupplier("Search")) - .build(); - } - } - } - return getSearchMethod; - } - - private static volatile io.grpc.MethodDescriptor getBatchObjectsMethod; - - @io.grpc.stub.annotations.RpcMethod( - fullMethodName = SERVICE_NAME + '/' + "BatchObjects", - requestType = io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest.class, - responseType = io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply.class, - methodType = io.grpc.MethodDescriptor.MethodType.UNARY) - public static io.grpc.MethodDescriptor getBatchObjectsMethod() { - io.grpc.MethodDescriptor getBatchObjectsMethod; - if ((getBatchObjectsMethod = WeaviateGrpc.getBatchObjectsMethod) == null) { - synchronized (WeaviateGrpc.class) { - if ((getBatchObjectsMethod = WeaviateGrpc.getBatchObjectsMethod) == null) { - WeaviateGrpc.getBatchObjectsMethod = getBatchObjectsMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName(SERVICE_NAME, "BatchObjects")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply.getDefaultInstance())) - .setSchemaDescriptor(new WeaviateMethodDescriptorSupplier("BatchObjects")) - .build(); - } - } - } - return getBatchObjectsMethod; - } - - /** - * Creates a new async stub that supports all call types for the service - */ - public static WeaviateStub newStub(io.grpc.Channel channel) { - io.grpc.stub.AbstractStub.StubFactory factory = - new io.grpc.stub.AbstractStub.StubFactory() { - @java.lang.Override - public WeaviateStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new WeaviateStub(channel, callOptions); - } - }; - return WeaviateStub.newStub(factory, channel); - } - - /** - * Creates a new blocking-style stub that supports unary and streaming output calls on the service - */ - public static WeaviateBlockingStub newBlockingStub( - io.grpc.Channel channel) { - io.grpc.stub.AbstractStub.StubFactory factory = - new io.grpc.stub.AbstractStub.StubFactory() { - @java.lang.Override - public WeaviateBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new WeaviateBlockingStub(channel, callOptions); - } - }; - return WeaviateBlockingStub.newStub(factory, channel); - } - - /** - * Creates a new ListenableFuture-style stub that supports unary calls on the service - */ - public static WeaviateFutureStub newFutureStub( - io.grpc.Channel channel) { - io.grpc.stub.AbstractStub.StubFactory factory = - new io.grpc.stub.AbstractStub.StubFactory() { - @java.lang.Override - public WeaviateFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new WeaviateFutureStub(channel, callOptions); - } - }; - return WeaviateFutureStub.newStub(factory, channel); - } - - /** - */ - public interface AsyncService { - - /** - */ - default void search(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest request, - io.grpc.stub.StreamObserver responseObserver) { - io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getSearchMethod(), responseObserver); - } - - /** - */ - default void batchObjects(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest request, - io.grpc.stub.StreamObserver responseObserver) { - io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getBatchObjectsMethod(), responseObserver); - } - } - - /** - * Base class for the server implementation of the service Weaviate. - */ - public static abstract class WeaviateImplBase - implements io.grpc.BindableService, AsyncService { - - @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { - return WeaviateGrpc.bindService(this); - } - } - - /** - * A stub to allow clients to do asynchronous rpc calls to service Weaviate. - */ - public static final class WeaviateStub - extends io.grpc.stub.AbstractAsyncStub { - private WeaviateStub( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected WeaviateStub build( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new WeaviateStub(channel, callOptions); - } - - /** - */ - public void search(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest request, - io.grpc.stub.StreamObserver responseObserver) { - io.grpc.stub.ClientCalls.asyncUnaryCall( - getChannel().newCall(getSearchMethod(), getCallOptions()), request, responseObserver); - } - - /** - */ - public void batchObjects(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest request, - io.grpc.stub.StreamObserver responseObserver) { - io.grpc.stub.ClientCalls.asyncUnaryCall( - getChannel().newCall(getBatchObjectsMethod(), getCallOptions()), request, responseObserver); - } - } - - /** - * A stub to allow clients to do synchronous rpc calls to service Weaviate. - */ - public static final class WeaviateBlockingStub - extends io.grpc.stub.AbstractBlockingStub { - private WeaviateBlockingStub( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected WeaviateBlockingStub build( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new WeaviateBlockingStub(channel, callOptions); - } - - /** - */ - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply search(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest request) { - return io.grpc.stub.ClientCalls.blockingUnaryCall( - getChannel(), getSearchMethod(), getCallOptions(), request); - } - - /** - */ - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply batchObjects(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest request) { - return io.grpc.stub.ClientCalls.blockingUnaryCall( - getChannel(), getBatchObjectsMethod(), getCallOptions(), request); - } - } - - /** - * A stub to allow clients to do ListenableFuture-style rpc calls to service Weaviate. - */ - public static final class WeaviateFutureStub - extends io.grpc.stub.AbstractFutureStub { - private WeaviateFutureStub( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected WeaviateFutureStub build( - io.grpc.Channel channel, io.grpc.CallOptions callOptions) { - return new WeaviateFutureStub(channel, callOptions); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture search( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest request) { - return io.grpc.stub.ClientCalls.futureUnaryCall( - getChannel().newCall(getSearchMethod(), getCallOptions()), request); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture batchObjects( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest request) { - return io.grpc.stub.ClientCalls.futureUnaryCall( - getChannel().newCall(getBatchObjectsMethod(), getCallOptions()), request); - } - } - - private static final int METHODID_SEARCH = 0; - private static final int METHODID_BATCH_OBJECTS = 1; - - private static final class MethodHandlers implements - io.grpc.stub.ServerCalls.UnaryMethod, - io.grpc.stub.ServerCalls.ServerStreamingMethod, - io.grpc.stub.ServerCalls.ClientStreamingMethod, - io.grpc.stub.ServerCalls.BidiStreamingMethod { - private final AsyncService serviceImpl; - private final int methodId; - - MethodHandlers(AsyncService serviceImpl, int methodId) { - this.serviceImpl = serviceImpl; - this.methodId = methodId; - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - case METHODID_SEARCH: - serviceImpl.search((io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - case METHODID_BATCH_OBJECTS: - serviceImpl.batchObjects((io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - default: - throw new AssertionError(); - } - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public io.grpc.stub.StreamObserver invoke( - io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - default: - throw new AssertionError(); - } - } - } - - public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) { - return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) - .addMethod( - getSearchMethod(), - io.grpc.stub.ServerCalls.asyncUnaryCall( - new MethodHandlers< - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest, - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply>( - service, METHODID_SEARCH))) - .addMethod( - getBatchObjectsMethod(), - io.grpc.stub.ServerCalls.asyncUnaryCall( - new MethodHandlers< - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest, - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply>( - service, METHODID_BATCH_OBJECTS))) - .build(); - } - - private static abstract class WeaviateBaseDescriptorSupplier - implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { - WeaviateBaseDescriptorSupplier() {} - - @java.lang.Override - public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProto.getDescriptor(); - } - - @java.lang.Override - public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { - return getFileDescriptor().findServiceByName("Weaviate"); - } - } - - private static final class WeaviateFileDescriptorSupplier - extends WeaviateBaseDescriptorSupplier { - WeaviateFileDescriptorSupplier() {} - } - - private static final class WeaviateMethodDescriptorSupplier - extends WeaviateBaseDescriptorSupplier - implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { - private final java.lang.String methodName; - - WeaviateMethodDescriptorSupplier(java.lang.String methodName) { - this.methodName = methodName; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { - return getServiceDescriptor().findMethodByName(methodName); - } - } - - private static volatile io.grpc.ServiceDescriptor serviceDescriptor; - - public static io.grpc.ServiceDescriptor getServiceDescriptor() { - io.grpc.ServiceDescriptor result = serviceDescriptor; - if (result == null) { - synchronized (WeaviateGrpc.class) { - result = serviceDescriptor; - if (result == null) { - serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) - .setSchemaDescriptor(new WeaviateFileDescriptorSupplier()) - .addMethod(getSearchMethod()) - .addMethod(getBatchObjectsMethod()) - .build(); - } - } - } - return result; - } -} diff --git a/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateProto.java b/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateProto.java deleted file mode 100644 index 84447a78d..000000000 --- a/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateProto.java +++ /dev/null @@ -1,47 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: v0/weaviate.proto - -package io.weaviate.client6.grpc.protocol.v0; - -public final class WeaviateProto { - private WeaviateProto() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\021v0/weaviate.proto\022\014weaviategrpc\032\016v0/ba" + - "tch.proto\032\023v0/search_get.proto2\244\001\n\010Weavi" + - "ate\022B\n\006Search\022\033.weaviategrpc.SearchReque" + - "st\032\031.weaviategrpc.SearchReply\"\000\022T\n\014Batch" + - "Objects\022!.weaviategrpc.BatchObjectsReque" + - "st\032\037.weaviategrpc.BatchObjectsReply\"\000Bk\n" + - "$io.weaviate.client6.grpc.protocol.v0B\rW" + - "eaviateProtoZ4github.com/weaviate/weavia" + - "te/grpc/generated;protocolb\006proto3" - }; - descriptor = com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.getDescriptor(), - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.getDescriptor(), - }); - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.getDescriptor(); - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.getDescriptor(); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateProtoBatch.java b/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateProtoBatch.java deleted file mode 100644 index dd4254e7f..000000000 --- a/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateProtoBatch.java +++ /dev/null @@ -1,855 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: v0/batch.proto - -package io.weaviate.client6.grpc.protocol.v0; - -public final class WeaviateProtoBatch { - private WeaviateProtoBatch() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - public interface BatchObjectsRequestOrBuilder extends - // @@protoc_insertion_point(interface_extends:weaviategrpc.BatchObjectsRequest) - com.google.protobuf.MessageOrBuilder { - } - /** - * Protobuf type {@code weaviategrpc.BatchObjectsRequest} - */ - public static final class BatchObjectsRequest extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:weaviategrpc.BatchObjectsRequest) - BatchObjectsRequestOrBuilder { - private static final long serialVersionUID = 0L; - // Use BatchObjectsRequest.newBuilder() to construct. - private BatchObjectsRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private BatchObjectsRequest() { - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new BatchObjectsRequest(); - } - - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.internal_static_weaviategrpc_BatchObjectsRequest_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.internal_static_weaviategrpc_BatchObjectsRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest.class, io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest.Builder.class); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getUnknownFields().writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - size += getUnknownFields().getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest)) { - return super.equals(obj); - } - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest other = (io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest) obj; - - if (!getUnknownFields().equals(other.getUnknownFields())) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (29 * hash) + getUnknownFields().hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code weaviategrpc.BatchObjectsRequest} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:weaviategrpc.BatchObjectsRequest) - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequestOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.internal_static_weaviategrpc_BatchObjectsRequest_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.internal_static_weaviategrpc_BatchObjectsRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest.class, io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest.Builder.class); - } - - // Construct using io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest.newBuilder() - private Builder() { - - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - - } - @java.lang.Override - public Builder clear() { - super.clear(); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.internal_static_weaviategrpc_BatchObjectsRequest_descriptor; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest getDefaultInstanceForType() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest.getDefaultInstance(); - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest build() { - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest buildPartial() { - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest result = new io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest(this); - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest) { - return mergeFrom((io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest other) { - if (other == io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest.getDefaultInstance()) return this; - this.mergeUnknownFields(other.getUnknownFields()); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: - } // switch (tag) - } // while (!done) - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.unwrapIOException(); - } finally { - onChanged(); - } // finally - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:weaviategrpc.BatchObjectsRequest) - } - - // @@protoc_insertion_point(class_scope:weaviategrpc.BatchObjectsRequest) - private static final io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest(); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public BatchObjectsRequest parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - Builder builder = newBuilder(); - try { - builder.mergeFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(builder.buildPartial()); - } catch (com.google.protobuf.UninitializedMessageException e) { - throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException(e) - .setUnfinishedMessage(builder.buildPartial()); - } - return builder.buildPartial(); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsRequest getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface BatchObjectsReplyOrBuilder extends - // @@protoc_insertion_point(interface_extends:weaviategrpc.BatchObjectsReply) - com.google.protobuf.MessageOrBuilder { - } - /** - * Protobuf type {@code weaviategrpc.BatchObjectsReply} - */ - public static final class BatchObjectsReply extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:weaviategrpc.BatchObjectsReply) - BatchObjectsReplyOrBuilder { - private static final long serialVersionUID = 0L; - // Use BatchObjectsReply.newBuilder() to construct. - private BatchObjectsReply(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private BatchObjectsReply() { - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new BatchObjectsReply(); - } - - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.internal_static_weaviategrpc_BatchObjectsReply_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.internal_static_weaviategrpc_BatchObjectsReply_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply.class, io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply.Builder.class); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getUnknownFields().writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - size += getUnknownFields().getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply)) { - return super.equals(obj); - } - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply other = (io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply) obj; - - if (!getUnknownFields().equals(other.getUnknownFields())) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (29 * hash) + getUnknownFields().hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code weaviategrpc.BatchObjectsReply} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:weaviategrpc.BatchObjectsReply) - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReplyOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.internal_static_weaviategrpc_BatchObjectsReply_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.internal_static_weaviategrpc_BatchObjectsReply_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply.class, io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply.Builder.class); - } - - // Construct using io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply.newBuilder() - private Builder() { - - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - - } - @java.lang.Override - public Builder clear() { - super.clear(); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.internal_static_weaviategrpc_BatchObjectsReply_descriptor; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply getDefaultInstanceForType() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply.getDefaultInstance(); - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply build() { - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply buildPartial() { - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply result = new io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply(this); - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply) { - return mergeFrom((io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply other) { - if (other == io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply.getDefaultInstance()) return this; - this.mergeUnknownFields(other.getUnknownFields()); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: - } // switch (tag) - } // while (!done) - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.unwrapIOException(); - } finally { - onChanged(); - } // finally - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:weaviategrpc.BatchObjectsReply) - } - - // @@protoc_insertion_point(class_scope:weaviategrpc.BatchObjectsReply) - private static final io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply(); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public BatchObjectsReply parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - Builder builder = newBuilder(); - try { - builder.mergeFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(builder.buildPartial()); - } catch (com.google.protobuf.UninitializedMessageException e) { - throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException(e) - .setUnfinishedMessage(builder.buildPartial()); - } - return builder.buildPartial(); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoBatch.BatchObjectsReply getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_weaviategrpc_BatchObjectsRequest_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_weaviategrpc_BatchObjectsRequest_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_weaviategrpc_BatchObjectsReply_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_weaviategrpc_BatchObjectsReply_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\016v0/batch.proto\022\014weaviategrpc\"\025\n\023BatchO" + - "bjectsRequest\"\023\n\021BatchObjectsReplyBp\n$io" + - ".weaviate.client6.grpc.protocol.v0B\022Weav" + - "iateProtoBatchZ4github.com/weaviate/weav" + - "iate/grpc/generated;protocolb\006proto3" - }; - descriptor = com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }); - internal_static_weaviategrpc_BatchObjectsRequest_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_weaviategrpc_BatchObjectsRequest_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_weaviategrpc_BatchObjectsRequest_descriptor, - new java.lang.String[] { }); - internal_static_weaviategrpc_BatchObjectsReply_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_weaviategrpc_BatchObjectsReply_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_weaviategrpc_BatchObjectsReply_descriptor, - new java.lang.String[] { }); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateProtoSearchGet.java b/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateProtoSearchGet.java deleted file mode 100644 index 5a67dccfc..000000000 --- a/src/main/java/io/weaviate/client6/grpc/protocol/v0/WeaviateProtoSearchGet.java +++ /dev/null @@ -1,855 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: v0/search_get.proto - -package io.weaviate.client6.grpc.protocol.v0; - -public final class WeaviateProtoSearchGet { - private WeaviateProtoSearchGet() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - public interface SearchRequestOrBuilder extends - // @@protoc_insertion_point(interface_extends:weaviategrpc.SearchRequest) - com.google.protobuf.MessageOrBuilder { - } - /** - * Protobuf type {@code weaviategrpc.SearchRequest} - */ - public static final class SearchRequest extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:weaviategrpc.SearchRequest) - SearchRequestOrBuilder { - private static final long serialVersionUID = 0L; - // Use SearchRequest.newBuilder() to construct. - private SearchRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private SearchRequest() { - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new SearchRequest(); - } - - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.internal_static_weaviategrpc_SearchRequest_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.internal_static_weaviategrpc_SearchRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest.class, io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest.Builder.class); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getUnknownFields().writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - size += getUnknownFields().getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest)) { - return super.equals(obj); - } - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest other = (io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest) obj; - - if (!getUnknownFields().equals(other.getUnknownFields())) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (29 * hash) + getUnknownFields().hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code weaviategrpc.SearchRequest} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:weaviategrpc.SearchRequest) - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequestOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.internal_static_weaviategrpc_SearchRequest_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.internal_static_weaviategrpc_SearchRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest.class, io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest.Builder.class); - } - - // Construct using io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest.newBuilder() - private Builder() { - - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - - } - @java.lang.Override - public Builder clear() { - super.clear(); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.internal_static_weaviategrpc_SearchRequest_descriptor; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest getDefaultInstanceForType() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest.getDefaultInstance(); - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest build() { - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest buildPartial() { - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest result = new io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest(this); - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest) { - return mergeFrom((io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest other) { - if (other == io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest.getDefaultInstance()) return this; - this.mergeUnknownFields(other.getUnknownFields()); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: - } // switch (tag) - } // while (!done) - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.unwrapIOException(); - } finally { - onChanged(); - } // finally - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:weaviategrpc.SearchRequest) - } - - // @@protoc_insertion_point(class_scope:weaviategrpc.SearchRequest) - private static final io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest(); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public SearchRequest parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - Builder builder = newBuilder(); - try { - builder.mergeFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(builder.buildPartial()); - } catch (com.google.protobuf.UninitializedMessageException e) { - throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException(e) - .setUnfinishedMessage(builder.buildPartial()); - } - return builder.buildPartial(); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchRequest getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface SearchReplyOrBuilder extends - // @@protoc_insertion_point(interface_extends:weaviategrpc.SearchReply) - com.google.protobuf.MessageOrBuilder { - } - /** - * Protobuf type {@code weaviategrpc.SearchReply} - */ - public static final class SearchReply extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:weaviategrpc.SearchReply) - SearchReplyOrBuilder { - private static final long serialVersionUID = 0L; - // Use SearchReply.newBuilder() to construct. - private SearchReply(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private SearchReply() { - } - - @java.lang.Override - @SuppressWarnings({"unused"}) - protected java.lang.Object newInstance( - UnusedPrivateParameter unused) { - return new SearchReply(); - } - - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.internal_static_weaviategrpc_SearchReply_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.internal_static_weaviategrpc_SearchReply_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply.class, io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply.Builder.class); - } - - private byte memoizedIsInitialized = -1; - @java.lang.Override - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - @java.lang.Override - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getUnknownFields().writeTo(output); - } - - @java.lang.Override - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - size += getUnknownFields().getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply)) { - return super.equals(obj); - } - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply other = (io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply) obj; - - if (!getUnknownFields().equals(other.getUnknownFields())) return false; - return true; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (29 * hash) + getUnknownFields().hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - @java.lang.Override - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - @java.lang.Override - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code weaviategrpc.SearchReply} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:weaviategrpc.SearchReply) - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReplyOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.internal_static_weaviategrpc_SearchReply_descriptor; - } - - @java.lang.Override - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.internal_static_weaviategrpc_SearchReply_fieldAccessorTable - .ensureFieldAccessorsInitialized( - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply.class, io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply.Builder.class); - } - - // Construct using io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply.newBuilder() - private Builder() { - - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - - } - @java.lang.Override - public Builder clear() { - super.clear(); - return this; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.internal_static_weaviategrpc_SearchReply_descriptor; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply getDefaultInstanceForType() { - return io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply.getDefaultInstance(); - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply build() { - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply buildPartial() { - io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply result = new io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply(this); - onBuilt(); - return result; - } - - @java.lang.Override - public Builder clone() { - return super.clone(); - } - @java.lang.Override - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.setField(field, value); - } - @java.lang.Override - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return super.clearField(field); - } - @java.lang.Override - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return super.clearOneof(oneof); - } - @java.lang.Override - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return super.setRepeatedField(field, index, value); - } - @java.lang.Override - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return super.addRepeatedField(field, value); - } - @java.lang.Override - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply) { - return mergeFrom((io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply other) { - if (other == io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply.getDefaultInstance()) return this; - this.mergeUnknownFields(other.getUnknownFields()); - onChanged(); - return this; - } - - @java.lang.Override - public final boolean isInitialized() { - return true; - } - - @java.lang.Override - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!super.parseUnknownField(input, extensionRegistry, tag)) { - done = true; // was an endgroup tag - } - break; - } // default: - } // switch (tag) - } // while (!done) - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.unwrapIOException(); - } finally { - onChanged(); - } // finally - return this; - } - @java.lang.Override - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFields(unknownFields); - } - - @java.lang.Override - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:weaviategrpc.SearchReply) - } - - // @@protoc_insertion_point(class_scope:weaviategrpc.SearchReply) - private static final io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply(); - } - - public static io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - @java.lang.Override - public SearchReply parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - Builder builder = newBuilder(); - try { - builder.mergeFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(builder.buildPartial()); - } catch (com.google.protobuf.UninitializedMessageException e) { - throw e.asInvalidProtocolBufferException().setUnfinishedMessage(builder.buildPartial()); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException(e) - .setUnfinishedMessage(builder.buildPartial()); - } - return builder.buildPartial(); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - @java.lang.Override - public io.weaviate.client6.grpc.protocol.v0.WeaviateProtoSearchGet.SearchReply getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_weaviategrpc_SearchRequest_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_weaviategrpc_SearchRequest_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_weaviategrpc_SearchReply_descriptor; - private static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_weaviategrpc_SearchReply_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\023v0/search_get.proto\022\014weaviategrpc\"\017\n\rS" + - "earchRequest\"\r\n\013SearchReplyBt\n$io.weavia" + - "te.client6.grpc.protocol.v0B\026WeaviatePro" + - "toSearchGetZ4github.com/weaviate/weaviat" + - "e/grpc/generated;protocolb\006proto3" - }; - descriptor = com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }); - internal_static_weaviategrpc_SearchRequest_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_weaviategrpc_SearchRequest_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_weaviategrpc_SearchRequest_descriptor, - new java.lang.String[] { }); - internal_static_weaviategrpc_SearchReply_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_weaviategrpc_SearchReply_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_weaviategrpc_SearchReply_descriptor, - new java.lang.String[] { }); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/src/main/java/io/weaviate/client6/internal/DtoTypeAdapterFactory.java b/src/main/java/io/weaviate/client6/internal/DtoTypeAdapterFactory.java new file mode 100644 index 000000000..812f6dddd --- /dev/null +++ b/src/main/java/io/weaviate/client6/internal/DtoTypeAdapterFactory.java @@ -0,0 +1,108 @@ +package io.weaviate.client6.internal; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +/** + * DtoTypeAdapterFactory de-/serializes objects using their registerred DTOs. + * + *

+ * DTO classes must implement {@link Dto}, which produces the original model. + * Meanwhile, models do not need to be modified, to avoid leaking + * de-/serialization details. + * + *

+ * Usage: + * + *

{@code
+ * public class HttpHanlder {
+ *   static {
+ *     DtoTypeAdapterFactory.register(
+ *         MyDomainObject.class,
+ *         MyDtoObject.class,
+ *         domain -> new MyDtoObject(domain));
+ *   }
+ *   static final Gson gson = new GsonBuilder()
+ *       .registerTypeAdapterFactory(new DtoTypeAdapterFactory())
+ *       .create();
+ * }
+ * }
+ */ +public class DtoTypeAdapterFactory implements TypeAdapterFactory { + private static boolean locked = false; + private static final Map, Pair> registry = new HashMap<>(); + + /** + * Register a model-DTO pair. + * + *

+ * Only one DTO can be registerred per model. + * Subsequent registrations will be ignored. + */ + public static > void register(Class model, Class dto, + ModelConverter> convert) { + registry.putIfAbsent(model, new Pair(dto, convert)); + } + + /** + * Get model-DTO pair for the provided model class. Returns null if no pair is + * registerred. In this case {@link #create} should also return null. + * + *

+ * Conversion to {@code Pair} is safe, as entries to {@link #registry} + * can only be added via {@link #register}, which is type-safe. + */ + @SuppressWarnings("unchecked") + private static > Pair getPair(TypeToken type) { + var cls = type.getRawType(); + if (!registry.containsKey(cls)) { + return null; + } + return (Pair) registry.get(cls); + } + + /** Dto produces a domain model. */ + public interface Dto { + M toModel(); + } + + /** ModelConverter converts domain model to a DTO. */ + @FunctionalInterface + public interface ModelConverter> { + D toDTO(M model); + } + + record Pair>(Class dto, ModelConverter> convert) { + } + + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + var pair = getPair(type); + if (pair == null) { + return null; + } + var delegate = gson.getDelegateAdapter(this, TypeToken.get(pair.dto)); + return new TypeAdapter() { + + @Override + public T read(JsonReader in) throws IOException { + var dto = delegate.read(in); + return dto.toModel(); + } + + @Override + public void write(JsonWriter out, T value) throws IOException { + var dto = pair.convert.toDTO(value); + delegate.write(out, dto); + } + }; + } +} diff --git a/src/main/java/io/weaviate/client6/internal/GRPC.java b/src/main/java/io/weaviate/client6/internal/GRPC.java new file mode 100644 index 000000000..bd9bdd6c1 --- /dev/null +++ b/src/main/java/io/weaviate/client6/internal/GRPC.java @@ -0,0 +1,93 @@ +package io.weaviate.client6.internal; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.FloatBuffer; +import java.util.Arrays; + +import org.apache.commons.lang3.ArrayUtils; + +import com.google.protobuf.ByteString; + +public class GRPC { + private static final ByteOrder BYTE_ORDER = ByteOrder.LITTLE_ENDIAN; + + /** Encode Float[] to ByteString. */ + public static ByteString toByteString(Float[] vector) { + if (vector == null || vector.length == 0) { + return ByteString.EMPTY; + } + ByteBuffer buffer = ByteBuffer.allocate(vector.length * Float.BYTES).order(BYTE_ORDER); + Arrays.stream(vector).forEach(buffer::putFloat); + return ByteString.copyFrom(buffer.array()); + } + + /** Encode float[] to ByteString. */ + public static ByteString toByteString(float[] vector) { + ByteBuffer buffer = ByteBuffer.allocate(vector.length * Float.BYTES).order(BYTE_ORDER); + for (float f : vector) { + buffer.putFloat(f); + } + return ByteString.copyFrom(buffer.array()); + } + + /** + * Encode Float[][] to ByteString. + *

+ * The first 2 bytes of the resulting ByteString encode the number of dimensions + * (uint16 / short) followed by concatenated vectors (4 bytes per element). + */ + public static ByteString toByteString(Float[][] vectors) { + if (vectors == null || vectors.length == 0 || vectors[0].length == 0) { + return ByteString.EMPTY; + } + + int n = vectors.length; + short dimensions = (short) vectors[0].length; + int capacity = /* vector dimensions */ Short.BYTES + + /* concatenated elements */ (n * dimensions * Float.BYTES); + ByteBuffer buffer = ByteBuffer.allocate(capacity).order(BYTE_ORDER) + .putShort(dimensions); + Arrays.stream(vectors).forEach(v -> Arrays.stream(v).forEach(buffer::putFloat)); + return ByteString.copyFrom(buffer.array()); + } + + /** + * Decode ByteString into a Float[]. ByteString size must be a multiple of + * {@link Float#BYTES}, throws {@link IllegalArgumentException} otherwise. + */ + public static Float[] fromByteString(ByteString bs) { + if (bs.size() % Float.BYTES != 0) { + throw new IllegalArgumentException( + "byte string size not a multiple of " + String.valueOf(Float.BYTES) + " (Float.BYTES)"); + } + float[] vector = new float[bs.size() / Float.BYTES]; + bs.asReadOnlyByteBuffer().order(BYTE_ORDER).asFloatBuffer().get(vector); + return ArrayUtils.toObject(vector); + } + + /** Decode ByteString into a Float[][]. */ + public static Float[][] fromByteStringMulti(ByteString bs) { + if (bs == null || bs.size() == 0) { + return new Float[0][0]; + } + + ByteBuffer buf = bs.asReadOnlyByteBuffer().order(BYTE_ORDER); + + // Dimensions are encoded in the first 2 bytes. + short dimensions = buf.getShort(); // advances current position + + FloatBuffer fbuf = buf.asFloatBuffer(); + int n = fbuf.remaining() / dimensions; // fbuf size is buf / Float.BYTES + + // Reading from buffer advances current position, + // so we always read from offset=0. + Float[][] vectors = new Float[n][dimensions]; + for (int i = 0; i < n; i++) { + float[] v = new float[dimensions]; + fbuf.get(v, 0, dimensions); + vectors[i] = ArrayUtils.toObject(v); + } + return vectors; + } +} diff --git a/src/main/java/io/weaviate/client6/internal/GrpcClient.java b/src/main/java/io/weaviate/client6/internal/GrpcClient.java new file mode 100644 index 000000000..3e4045cc6 --- /dev/null +++ b/src/main/java/io/weaviate/client6/internal/GrpcClient.java @@ -0,0 +1,37 @@ +package io.weaviate.client6.internal; + +import java.io.Closeable; +import java.io.IOException; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import io.grpc.stub.MetadataUtils; +import io.weaviate.client6.Config; +import io.weaviate.client6.grpc.protocol.v1.WeaviateGrpc; +import io.weaviate.client6.grpc.protocol.v1.WeaviateGrpc.WeaviateBlockingStub; + +public class GrpcClient implements Closeable { + private final ManagedChannel channel; + public final WeaviateBlockingStub grpc; + + public GrpcClient(Config config) { + this.channel = buildChannel(config); + this.grpc = buildStub(channel); + } + + @Override + public void close() throws IOException { + channel.shutdown(); + } + + private static ManagedChannel buildChannel(Config config) { + ManagedChannelBuilder channelBuilder = ManagedChannelBuilder.forTarget(config.grpcAddress()); + channelBuilder.usePlaintext(); + return channelBuilder.build(); + } + + private static WeaviateBlockingStub buildStub(ManagedChannel channel) { + return WeaviateGrpc.newBlockingStub(channel) + .withInterceptors(MetadataUtils.newAttachHeadersInterceptor(new io.grpc.Metadata())); + } +} diff --git a/src/main/java/io/weaviate/client6/internal/HttpClient.java b/src/main/java/io/weaviate/client6/internal/HttpClient.java new file mode 100644 index 000000000..1d1122b37 --- /dev/null +++ b/src/main/java/io/weaviate/client6/internal/HttpClient.java @@ -0,0 +1,23 @@ +package io.weaviate.client6.internal; + +import java.io.Closeable; +import java.io.IOException; + +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; + +public class HttpClient implements Closeable { + // TODO: move somewhere + // public static final Gson GSON = + + public final CloseableHttpClient http; + + public HttpClient() { + http = HttpClients.createDefault(); + } + + @Override + public void close() throws IOException { + http.close(); + } +} diff --git a/src/main/java/io/weaviate/client6/v1/Collection.java b/src/main/java/io/weaviate/client6/v1/Collection.java new file mode 100644 index 000000000..e12f56915 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/Collection.java @@ -0,0 +1,17 @@ +package io.weaviate.client6.v1; + +import io.weaviate.client6.Config; +import io.weaviate.client6.internal.GrpcClient; +import io.weaviate.client6.internal.HttpClient; +import io.weaviate.client6.v1.data.Data; +import io.weaviate.client6.v1.query.Query; + +public class Collection { + public final Query query; + public final Data data; + + public Collection(String collectionName, Config config, GrpcClient grpc, HttpClient http) { + this.query = new Query<>(collectionName, grpc); + this.data = new Data<>(collectionName, config, http); + } +} diff --git a/src/main/java/io/weaviate/client6/v1/ObjectMetadata.java b/src/main/java/io/weaviate/client6/v1/ObjectMetadata.java new file mode 100644 index 000000000..d63b0225a --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/ObjectMetadata.java @@ -0,0 +1,55 @@ +package io.weaviate.client6.v1; + +import java.util.function.Consumer; + +public record ObjectMetadata(String id, Vectors vectors) { + + public static ObjectMetadata with(Consumer options) { + var opt = new Builder(options); + return new ObjectMetadata(opt.id, opt.vectors); + } + + public static class Builder { + public String id; + public Vectors vectors; + + public Builder id(String id) { + this.id = id; + return this; + } + + public Builder vectors(Vectors vectors) { + this.vectors = vectors; + return this; + } + + public Builder vectors(Float[] vector) { + this.vectors = Vectors.of(vector); + return this; + } + + public Builder vectors(Float[][] vector) { + this.vectors = Vectors.of(vector); + return this; + } + + public Builder vectors(String name, Float[] vector) { + this.vectors = Vectors.of(name, vector); + return this; + } + + public Builder vectors(String name, Float[][] vector) { + this.vectors = Vectors.of(name, vector); + return this; + } + + public Builder vectors(Consumer named) { + this.vectors = Vectors.with(named); + return this; + } + + private Builder(Consumer options) { + options.accept(this); + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/Vectors.java b/src/main/java/io/weaviate/client6/v1/Vectors.java new file mode 100644 index 000000000..9a69a5fa9 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/Vectors.java @@ -0,0 +1,126 @@ +package io.weaviate.client6.v1; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.Consumer; + +/** + * Vectors is an abstraction over named vectors. + * It may contain both 1-dimensional and 2-dimensional vectors. + */ +public class Vectors { + private static final String DEFAULT = "default"; + + private Float[] unnamedVector; + private Map namedVectors; + + public Float[] getSingle(String name) { + return (Float[]) namedVectors.get(name); + } + + public Float[] getDefaultSingle() { + return getSingle(DEFAULT); + } + + @SuppressWarnings("unchecked") + public Optional getSingle() { + return (Optional) getOnly(); + } + + public Float[][] getMulti(String name) { + return (Float[][]) namedVectors.get(name); + } + + public Float[][] getDefaultMulti() { + return getMulti(DEFAULT); + } + + @SuppressWarnings("unchecked") + public Optional getMulti() { + return (Optional) getOnly(); + } + + public Optional getUnnamed() { + return Optional.ofNullable(unnamedVector); + } + + private Optional getOnly() { + if (namedVectors == null || namedVectors.isEmpty() || namedVectors.size() > 1) { + return Optional.empty(); + } + return Optional.ofNullable(namedVectors.values().iterator().next()); + } + + public Map asMap() { + return Map.copyOf(namedVectors); + } + + /** Creates Vectors with a single unnamed vector. */ + private Vectors(Float[] vector) { + this(Map.of()); + this.unnamedVector = vector; + } + + /** Creates Vectors with one named vector. */ + private Vectors(String name, Object vector) { + this.namedVectors = Map.of(name, vector); + } + + /** Creates immutable set of vectors. */ + private Vectors(Map vectors) { + this.namedVectors = Collections.unmodifiableMap(vectors); + } + + static Vectors with(Consumer named) { + var vectors = new NamedVectors(named); + return new Vectors(vectors.namedVectors); + } + + /** + * Pass legacy unnamed vector. + * Multi-vectors can only be passed as named vectors. + */ + public static Vectors unnamed(Float[] vector) { + return new Vectors(vector); + } + + public static Vectors of(Float[] vector) { + return new Vectors(DEFAULT, vector); + } + + public static Vectors of(Float[][] vector) { + return new Vectors(DEFAULT, vector); + } + + public static Vectors of(String name, Float[] vector) { + return new Vectors(name, vector); + } + + public static Vectors of(String name, Float[][] vector) { + return new Vectors(name, vector); + } + + public static Vectors of(Map vectors) { + return new Vectors(vectors); + } + + public static class NamedVectors { + private Map namedVectors = new HashMap<>(); + + public NamedVectors vector(String name, Float[] vector) { + this.namedVectors.put(name, vector); + return this; + } + + public NamedVectors vector(String name, Float[][] vector) { + this.namedVectors.put(name, vector); + return this; + } + + NamedVectors(Consumer options) { + options.accept(this); + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/collections/CollectionDefinition.java b/src/main/java/io/weaviate/client6/v1/collections/CollectionDefinition.java new file mode 100644 index 000000000..b599f4ceb --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/collections/CollectionDefinition.java @@ -0,0 +1,51 @@ +package io.weaviate.client6.v1.collections; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; + +import io.weaviate.client6.v1.collections.Vectors.NamedVectors; + +public record CollectionDefinition(String name, List properties, Vectors vectors) { + + public static CollectionDefinition with(String name, Consumer options) { + var config = new Configuration(options); + return new CollectionDefinition(name, config.properties, config.vectors); + } + + // Tucked Builder for additional collection configuration. + public static class Configuration { + public List properties = new ArrayList<>(); + public Vectors vectors; + + public Configuration properties(Property... properties) { + this.properties = Arrays.asList(properties); + return this; + } + + public Configuration vectors(Vectors vectors) { + this.vectors = vectors; + return this; + } + + public Configuration vector(VectorIndex vector) { + this.vectors = Vectors.of(vector); + return this; + } + + public Configuration vector(String name, VectorIndex vector) { + this.vectors = new Vectors(name, vector); + return this; + } + + public Configuration vectors(Consumer named) { + this.vectors = Vectors.with(named); + return this; + } + + Configuration(Consumer options) { + options.accept(this); + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/collections/CollectionDefinitionDTO.java b/src/main/java/io/weaviate/client6/v1/collections/CollectionDefinitionDTO.java new file mode 100644 index 000000000..2c6cd5c85 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/collections/CollectionDefinitionDTO.java @@ -0,0 +1,45 @@ +package io.weaviate.client6.v1.collections; + +import java.util.List; + +import com.google.gson.annotations.SerializedName; + +import io.weaviate.client6.internal.DtoTypeAdapterFactory; + +class CollectionDefinitionDTO implements DtoTypeAdapterFactory.Dto { + @SerializedName("class") + String collection; + + @SerializedName("properties") + List properties; + + @SerializedName("vectorConfig") + Vectors vectors; + + @SerializedName("vectorIndexType") + private VectorIndex.IndexType vectorIndexType; + + @SerializedName("vectorIndexConfig") + private VectorIndex.IndexingStrategy vectorIndexConfig; + + @SerializedName("vectorizer") + private Vectorizer vectorizer; + + public CollectionDefinitionDTO(CollectionDefinition colDef) { + this.collection = colDef.name(); + this.properties = colDef.properties(); + this.vectors = colDef.vectors(); + + var unnamed = this.vectors.getUnnamed(); + if (unnamed.isPresent()) { + var index = unnamed.get(); + this.vectorIndexType = index.type(); + this.vectorIndexConfig = index.configuration(); + this.vectorizer = index.vectorizer(); + } + } + + public CollectionDefinition toModel() { + return new CollectionDefinition(collection, properties, vectors); + } +} diff --git a/src/main/java/io/weaviate/client6/v1/collections/Collections.java b/src/main/java/io/weaviate/client6/v1/collections/Collections.java new file mode 100644 index 000000000..0a2b8e97d --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/collections/Collections.java @@ -0,0 +1,164 @@ +package io.weaviate.client6.v1.collections; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.Type; +import java.util.Map; +import java.util.Optional; +import java.util.function.Consumer; + +import org.apache.hc.core5.http.ClassicHttpRequest; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpStatus; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import io.weaviate.client6.Config; +import io.weaviate.client6.internal.DtoTypeAdapterFactory; +import io.weaviate.client6.internal.GrpcClient; +import io.weaviate.client6.internal.HttpClient; +import io.weaviate.client6.v1.Collection; +import io.weaviate.client6.v1.collections.VectorIndex.IndexingStrategy; +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class Collections { + // TODO: hide befind an internal HttpClient + private final Config config; + + private final HttpClient httpClient; + private final GrpcClient grpcClient; + + static { + DtoTypeAdapterFactory.register( + CollectionDefinition.class, + CollectionDefinitionDTO.class, + m -> { + return new CollectionDefinitionDTO(m); + }); + } + + // Gson cannot deserialize interfaces: + // https://stackoverflow.com/a/49871339/14726116 + private static class IndexingStrategySerde + implements JsonDeserializer, JsonSerializer { + + @Override + public IndexingStrategy deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return IndexingStrategy.hnsw(); + } + + @Override + public JsonElement serialize(IndexingStrategy src, Type typeOfSrc, JsonSerializationContext context) { + return context.serialize(src); + } + } + + // Gson cannot deserialize interfaces: + // https://stackoverflow.com/a/49871339/14726116 + private static class VectorizerSerde + implements JsonDeserializer, JsonSerializer { + + @Override + public Vectorizer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return Vectorizer.none(); + } + + @Override + public JsonElement serialize(Vectorizer src, Type typeOfSrc, JsonSerializationContext context) { + return context.serialize(src); + } + } + + private static final Gson gson = new GsonBuilder() + .registerTypeAdapterFactory(new DtoTypeAdapterFactory()) + .registerTypeAdapter(Vectors.class, new TypeAdapter() { + Gson gson = new GsonBuilder() + .registerTypeAdapter(Vectorizer.class, new VectorizerSerde()) + .registerTypeAdapter(IndexingStrategy.class, new IndexingStrategySerde()) + .create(); + + @Override + public void write(JsonWriter out, Vectors value) throws IOException { + gson.toJson(value.asMap(), Map.class, out); + } + + @Override + public Vectors read(JsonReader in) throws IOException { + Map> vectors = gson.fromJson(in, + new TypeToken>>() { + }.getType()); + return Vectors.of(vectors); + } + }) + .create(); + + public void create(String name, Consumer options) throws IOException { + var collection = CollectionDefinition.with(name, options); + + ClassicHttpRequest httpPost = ClassicRequestBuilder + .post(config.baseUrl() + "/schema") + .setEntity(gson.toJson(collection), ContentType.APPLICATION_JSON) + .build(); + + // TODO: do not expose Apache HttpClient directly + httpClient.http.execute(httpPost, response -> { + var entity = response.getEntity(); + if (response.getCode() != HttpStatus.SC_SUCCESS) { // Does not return 201 + var message = EntityUtils.toString(entity); + throw new RuntimeException("HTTP " + response.getCode() + ": " + message); + } + return null; + }); + } + + public Optional getConfig(String name) throws IOException { + ClassicHttpRequest httpGet = ClassicRequestBuilder + .get(config.baseUrl() + "/schema/" + name) + .build(); + + return httpClient.http.execute(httpGet, response -> { + if (response.getCode() == HttpStatus.SC_NOT_FOUND) { + return Optional.empty(); + } + try (var r = new InputStreamReader(response.getEntity().getContent())) { + var collection = gson.fromJson(r, CollectionDefinition.class); + return Optional.ofNullable(collection); + } + }); + } + + public void delete(String name) throws IOException { + ClassicHttpRequest httpDelete = ClassicRequestBuilder + .delete(config.baseUrl() + "/schema/" + name) + .build(); + + httpClient.http.execute(httpDelete, response -> { + var entity = response.getEntity(); + if (response.getCode() != HttpStatus.SC_SUCCESS) { // Does not return 201 + var message = EntityUtils.toString(entity); + throw new RuntimeException("HTTP " + response.getCode() + ": " + message); + } + return null; + }); + } + + public Collection> use(String name) { + return new Collection<>(name, config, grpcClient, httpClient); + } +} diff --git a/src/main/java/io/weaviate/client6/v1/collections/DataType.java b/src/main/java/io/weaviate/client6/v1/collections/DataType.java new file mode 100644 index 000000000..8ec96470f --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/collections/DataType.java @@ -0,0 +1,10 @@ +package io.weaviate.client6.v1.collections; + +import com.google.gson.annotations.SerializedName; + +public enum DataType { + @SerializedName("text") + TEXT, + @SerializedName("int") + INT; +} diff --git a/src/main/java/io/weaviate/client6/v1/collections/HNSW.java b/src/main/java/io/weaviate/client6/v1/collections/HNSW.java new file mode 100644 index 000000000..cac6b45b4 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/collections/HNSW.java @@ -0,0 +1,43 @@ +package io.weaviate.client6.v1.collections; + +import java.util.function.Consumer; + +import io.weaviate.client6.v1.collections.VectorIndex.IndexType; + +public final record HNSW(Distance distance, Boolean skip) implements VectorIndex.IndexingStrategy { + public VectorIndex.IndexType type() { + return IndexType.HNSW; + } + + public enum Distance { + COSINE; + } + + HNSW() { + this(null, null); + } + + static HNSW with(Consumer options) { + var opt = new Options(options); + return new HNSW(opt.distance, opt.skip); + } + + public static class Options { + public Distance distance; + public Boolean skip; + + public Options distance(Distance distance) { + this.distance = distance; + return this; + } + + public Options disableIndexation() { + this.skip = true; + return this; + } + + public Options(Consumer options) { + options.accept(this); + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/collections/NoneVectorizer.java b/src/main/java/io/weaviate/client6/v1/collections/NoneVectorizer.java new file mode 100644 index 000000000..014ed7cca --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/collections/NoneVectorizer.java @@ -0,0 +1,10 @@ +package io.weaviate.client6.v1.collections; + +import java.util.Map; + +import com.google.gson.annotations.SerializedName; + +public class NoneVectorizer extends Vectorizer { + @SerializedName("none") + private final Map _configuration = Map.of(); +} diff --git a/src/main/java/io/weaviate/client6/v1/collections/Property.java b/src/main/java/io/weaviate/client6/v1/collections/Property.java new file mode 100644 index 000000000..81d23a5df --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/collections/Property.java @@ -0,0 +1,47 @@ +package io.weaviate.client6.v1.collections; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; + +import com.google.gson.annotations.SerializedName; + +public class Property { + @SerializedName("name") + public final String name; + + @SerializedName("dataType") + public final List dataTypes; + + /** Add text property with default configuration. */ + public static Property text(String name) { + return new Property(name, DataType.TEXT); + } + + /** Add integer property with default configuration. */ + public static Property integer(String name) { + return new Property(name, DataType.INT); + } + + public static final class Configuration { + private List dataTypes; + + public Configuration dataTypes(DataType... types) { + this.dataTypes = Arrays.asList(types); + return this; + } + } + + private Property(String name, DataType type) { + this.name = name; + this.dataTypes = List.of(type); + } + + public Property(String name, Consumer options) { + var config = new Configuration(); + options.accept(config); + + this.name = name; + this.dataTypes = config.dataTypes; + } +} diff --git a/src/main/java/io/weaviate/client6/v1/collections/VectorIndex.java b/src/main/java/io/weaviate/client6/v1/collections/VectorIndex.java new file mode 100644 index 000000000..ad1160dbf --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/collections/VectorIndex.java @@ -0,0 +1,36 @@ +package io.weaviate.client6.v1.collections; + +import java.util.function.Consumer; + +import com.google.gson.annotations.SerializedName; + +public record VectorIndex( + @SerializedName("vectorIndexType") IndexType type, + @SerializedName("vectorizer") V vectorizer, + @SerializedName("vectorIndexConfig") IndexingStrategy configuration) { + + public enum IndexType { + @SerializedName("hnsw") + HNSW; + } + + public VectorIndex(IndexingStrategy index, V vectorizer) { + this(index.type(), vectorizer, index); + } + + public VectorIndex(V vectorizer) { + this(null, vectorizer, null); + } + + public static sealed interface IndexingStrategy permits HNSW { + IndexType type(); + + public static IndexingStrategy hnsw() { + return new HNSW(); + } + + public static IndexingStrategy hnsw(Consumer options) { + return HNSW.with(options); + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/collections/Vectorizer.java b/src/main/java/io/weaviate/client6/v1/collections/Vectorizer.java new file mode 100644 index 000000000..ad9c4260f --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/collections/Vectorizer.java @@ -0,0 +1,8 @@ +package io.weaviate.client6.v1.collections; + +// This class is WIP, I haven't decided how to structure it yet. +public abstract class Vectorizer { + public static NoneVectorizer none() { + return new NoneVectorizer(); + } +} diff --git a/src/main/java/io/weaviate/client6/v1/collections/Vectors.java b/src/main/java/io/weaviate/client6/v1/collections/Vectors.java new file mode 100644 index 000000000..345442914 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/collections/Vectors.java @@ -0,0 +1,80 @@ +package io.weaviate.client6.v1.collections; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.function.Consumer; + +public class Vectors { + public static final String DEFAULT = "default"; + + private final VectorIndex unnamedVector; + private final Map> namedVectors; + + public static Vectors unnamed(VectorIndex vector) { + return new Vectors(vector); + } + + public static Vectors of(String name, VectorIndex vector) { + return new Vectors(name, vector); + } + + public static Vectors of(VectorIndex vector) { + return new Vectors(DEFAULT, vector); + } + + public static Vectors of(Map> vectors) { + return new Vectors(vectors); + } + + public static Vectors with(Consumer named) { + var vectors = new NamedVectors(named); + return new Vectors(vectors.namedVectors); + } + + public VectorIndex get(String name) { + return namedVectors.get(name); + } + + public Optional> getUnnamed() { + return Optional.ofNullable(unnamedVector); + } + + public VectorIndex getDefault() { + return namedVectors.get(DEFAULT); + } + + // This needs to document the fact that this only returns named vectors. + // Rename to "getNamedVectors()" + public Map asMap() { + return Map.copyOf(namedVectors); + } + + Vectors(VectorIndex vector) { + this.unnamedVector = vector; + this.namedVectors = Map.of(); + } + + Vectors(String name, VectorIndex vector) { + this.unnamedVector = null; + this.namedVectors = Map.of(name, vector); + } + + Vectors(Map> vectors) { + this.unnamedVector = null; + this.namedVectors = vectors; + } + + public static class NamedVectors { + private final Map> namedVectors = new HashMap<>(); + + public NamedVectors vector(String name, VectorIndex vector) { + this.namedVectors.put(name, vector); + return this; + } + + NamedVectors(Consumer options) { + options.accept(this); + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/data/ConsistencyLevel.java b/src/main/java/io/weaviate/client6/v1/data/ConsistencyLevel.java new file mode 100644 index 000000000..1011a7a02 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/data/ConsistencyLevel.java @@ -0,0 +1,5 @@ +package io.weaviate.client6.v1.data; + +public enum ConsistencyLevel { + ONE, QUORUM, ALL +} diff --git a/src/main/java/io/weaviate/client6/v1/data/Data.java b/src/main/java/io/weaviate/client6/v1/data/Data.java new file mode 100644 index 000000000..e5f457b23 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/data/Data.java @@ -0,0 +1,89 @@ +package io.weaviate.client6.v1.data; + +import java.io.IOException; +import java.util.Optional; +import java.util.function.Consumer; + +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.core5.http.ClassicHttpRequest; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpStatus; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; + +import com.google.gson.Gson; + +import io.weaviate.client6.Config; +import io.weaviate.client6.internal.HttpClient; +import io.weaviate.client6.v1.ObjectMetadata; +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class Data { + // TODO: inject singleton as dependency + private static final Gson gson = new Gson(); + + // TODO: this should be wrapped around in some TypeInspector etc. + private final String collectionName; + + // TODO: hide befind an internal HttpClient + private final Config config; + private final HttpClient httpClient; + + public WeaviateObject insert(T object, Consumer options) throws IOException { + var body = new WeaviateObject<>(collectionName, object, options); + ClassicHttpRequest httpPost = ClassicRequestBuilder + .post(config.baseUrl() + "/objects") + .setEntity(body.toJson(gson), ContentType.APPLICATION_JSON) + .build(); + + return httpClient.http.execute(httpPost, response -> { + var entity = response.getEntity(); + if (response.getCode() != HttpStatus.SC_SUCCESS) { // Does not return 201 + var message = EntityUtils.toString(entity); + throw new RuntimeException("HTTP " + response.getCode() + ": " + message); + } + + return WeaviateObject.fromJson(gson, entity.getContent()); + }); + } + + public Optional> get(String id) throws IOException { + return get(id, q -> { + }); + } + + public Optional> get(String id, Consumer query) throws IOException { + try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + ClassicHttpRequest httpGet = ClassicRequestBuilder + .get(config.baseUrl() + "/objects/" + collectionName + "/" + id + QueryParameters.encodeGet(query)) + .build(); + + return httpClient.http.execute(httpGet, response -> { + if (response.getCode() == HttpStatus.SC_NOT_FOUND) { + return Optional.empty(); + } + + WeaviateObject object = WeaviateObject.fromJson( + gson, response.getEntity().getContent()); + return Optional.ofNullable(object); + }); + } + } + + public void delete(String id) throws IOException { + try (CloseableHttpClient httpclient = HttpClients.createDefault()) { + ClassicHttpRequest httpGet = ClassicRequestBuilder + .delete(config.baseUrl() + "/objects/" + collectionName + "/" + id) + .build(); + + httpClient.http.execute(httpGet, response -> { + if (response.getCode() != HttpStatus.SC_NO_CONTENT) { + throw new RuntimeException(EntityUtils.toString(response.getEntity())); + } + return null; + }); + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/data/GetParameters.java b/src/main/java/io/weaviate/client6/v1/data/GetParameters.java new file mode 100644 index 000000000..819ffc09c --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/data/GetParameters.java @@ -0,0 +1,76 @@ +package io.weaviate.client6.v1.data; + +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.function.Consumer; + +public class GetParameters implements QueryParameters { + private enum Include { + VECTOR, CLASSIFICATION, INTERPRETATION; + + String toLowerCase() { + return this.name().toLowerCase(); + } + } + + private Set include = new LinkedHashSet<>(); // Preserves insertion order, helps testing + private ConsistencyLevel consistency; + private String nodeName; + private String tenant; + + GetParameters(Consumer options) { + options.accept(this); + } + + public GetParameters withVector() { + include.add(Include.VECTOR); + return this; + } + + public GetParameters withClassification() { + include.add(Include.CLASSIFICATION); + return this; + } + + public GetParameters withInterpretation() { + include.add(Include.INTERPRETATION); + return this; + } + + public GetParameters consistencyLevel(ConsistencyLevel consistency) { + this.consistency = consistency; + return this; + } + + public GetParameters nodeName(String name) { + this.nodeName = name; + return this; + } + + public GetParameters tenant(String name) { + this.tenant = name; + return this; + } + + @Override + public String encode() { + var sb = new StringBuilder(); + + if (!include.isEmpty()) { + List includeString = include.stream().map(Include::toLowerCase).toList(); + QueryParameters.addRaw(sb, "include", String.join(",", includeString)); + } + + if (consistency != null) { + QueryParameters.add(sb, "consistency_level", consistency.name()); + } + if (nodeName != null) { + QueryParameters.add(sb, "node_name", nodeName); + } + if (tenant != null) { + QueryParameters.add(sb, "tenant", tenant); + } + return sb.toString(); + } +} diff --git a/src/main/java/io/weaviate/client6/v1/data/QueryParameters.java b/src/main/java/io/weaviate/client6/v1/data/QueryParameters.java new file mode 100644 index 000000000..2b94c834c --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/data/QueryParameters.java @@ -0,0 +1,40 @@ +package io.weaviate.client6.v1.data; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.function.Consumer; + +interface QueryParameters { + /* Implementations must return an empty string if there're no parameters. */ + String encode(); + + static String encodeGet(Consumer options) { + return with(new GetParameters(options)); + } + + private static

String with(P parameters) { + var encoded = parameters.encode(); + return encoded.isEmpty() ? "" : "?" + encoded; + } + + static void add(StringBuilder sb, String key, String value) { + addRaw(sb, encode(key), encode(value)); + } + + static void addRaw(StringBuilder sb, String key, String value) { + if (!sb.isEmpty()) { + sb.append("&"); + } + sb.append(key).append("=").append(value); + } + + static String encode(String value) { + try { + return URLEncoder.encode(value, StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + // Will never happen, as we are using standard encoding. + return value; + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/data/WeaviateObject.java b/src/main/java/io/weaviate/client6/v1/data/WeaviateObject.java new file mode 100644 index 000000000..edc08d251 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/data/WeaviateObject.java @@ -0,0 +1,33 @@ +package io.weaviate.client6.v1.data; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.function.Consumer; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; + +import io.weaviate.client6.v1.ObjectMetadata; + +// TODO: unify this with collections.SearchObject + +public record WeaviateObject(String collection, T properties, ObjectMetadata metadata) { + + WeaviateObject(String collection, T properties, Consumer options) { + this(collection, properties, ObjectMetadata.with(options)); + } + + // JSON serialization ---------------- + public static WeaviateObject fromJson(Gson gson, InputStream input) throws IOException { + try (var r = new InputStreamReader(input)) { + WeaviateObjectDTO dto = gson.fromJson(r, new TypeToken>() { + }.getType()); + return dto.toWeaviateObject(); + } + } + + public String toJson(Gson gson) { + return gson.toJson(new WeaviateObjectDTO<>(this)); + } +} diff --git a/src/main/java/io/weaviate/client6/v1/data/WeaviateObjectDTO.java b/src/main/java/io/weaviate/client6/v1/data/WeaviateObjectDTO.java new file mode 100644 index 000000000..9d3e3fcc7 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/data/WeaviateObjectDTO.java @@ -0,0 +1,45 @@ +package io.weaviate.client6.v1.data; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import com.google.gson.annotations.SerializedName; + +import io.weaviate.client6.v1.ObjectMetadata; +import io.weaviate.client6.v1.Vectors; + +class WeaviateObjectDTO { + @SerializedName("class") + String collection; + @SerializedName("id") + String id; + @SerializedName("properties") + T properties; + @SerializedName("vectors") + Map vectors; + + WeaviateObjectDTO(WeaviateObject object) { + this.collection = object.collection(); + this.properties = object.properties(); + + if (object.metadata() != null) { + this.id = object.metadata().id(); + this.vectors = object.metadata().vectors().asMap(); + } + } + + WeaviateObject toWeaviateObject() { + Map arrayVectors = new HashMap<>(); + for (var entry : vectors.entrySet()) { + var value = (ArrayList) entry.getValue(); + var vector = new Float[value.size()]; + int i = 0; + for (var v : value) { + vector[i++] = v.floatValue(); + } + arrayVectors.put(entry.getKey(), vector); + } + return new WeaviateObject(collection, properties, new ObjectMetadata(id, Vectors.of(arrayVectors))); + } +} diff --git a/src/main/java/io/weaviate/client6/v1/query/Metadata.java b/src/main/java/io/weaviate/client6/v1/query/Metadata.java new file mode 100644 index 000000000..d490ee67f --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/query/Metadata.java @@ -0,0 +1,12 @@ +package io.weaviate.client6.v1.query; + +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoSearchGet.MetadataRequest; + +/** + * Metadata is the common base for all properties that are requestes as + * "_additional". It is an inteface all metadata properties MUST implement to be + * used in {@link QueryOptions}. + */ +public interface Metadata { + void appendTo(MetadataRequest.Builder metadata); +} diff --git a/src/main/java/io/weaviate/client6/v1/query/MetadataField.java b/src/main/java/io/weaviate/client6/v1/query/MetadataField.java new file mode 100644 index 000000000..fbec8a04c --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/query/MetadataField.java @@ -0,0 +1,28 @@ +package io.weaviate.client6.v1.query; + +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoSearchGet.MetadataRequest; + +/** + * MetadataField are collection properties that can be requested for any object. + */ +public enum MetadataField implements Metadata { + ID, + VECTOR, + DISTANCE; + + // FIXME: ideally, we don't want to surface this method in the public API + // But we might have to, if we want to implement that QueryAppender interface. + public void appendTo(MetadataRequest.Builder metadata) { + switch (this) { + case ID: + metadata.setUuid(true); + break; + case VECTOR: + metadata.setVector(true); + break; + case DISTANCE: + metadata.setDistance(true); + break; + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/query/NearVector.java b/src/main/java/io/weaviate/client6/v1/query/NearVector.java new file mode 100644 index 000000000..e479e8809 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/query/NearVector.java @@ -0,0 +1,54 @@ +package io.weaviate.client6.v1.query; + +import java.util.function.Consumer; + +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoBaseSearch; +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoSearchGet.SearchRequest; +import io.weaviate.client6.internal.GRPC; + +public class NearVector { + private final Float[] vector; + private final Options options; + + void appendTo(SearchRequest.Builder search) { + var nearVector = WeaviateProtoBaseSearch.NearVector.newBuilder(); + + // TODO: we should only add (named) Vectors. + // Since we do not force the users to supply a name when defining an index, + // we also need a way to "get default vector name" from the collection. + // For Map (untyped query handle) we always require the name. + nearVector.setVectorBytes(GRPC.toByteString(vector)); + options.append(search, nearVector); + search.setNearVector(nearVector.build()); + } + + public NearVector(Float[] vector, Consumer options) { + this.options = new Options(); + this.vector = vector; + options.accept(this.options); + } + + public static class Options extends QueryOptions { + private Float distance; + private Float certainty; + + public Options distance(float distance) { + this.distance = distance; + return this; + } + + public Options certainty(float certainty) { + this.certainty = certainty; + return this; + } + + void append(SearchRequest.Builder search, WeaviateProtoBaseSearch.NearVector.Builder nearVector) { + if (certainty != null) { + nearVector.setCertainty(certainty); + } else if (distance != null) { + nearVector.setDistance(distance); + } + super.appendTo(search); + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/query/Query.java b/src/main/java/io/weaviate/client6/v1/query/Query.java new file mode 100644 index 000000000..7ac1508c7 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/query/Query.java @@ -0,0 +1,104 @@ +package io.weaviate.client6.v1.query; + +import java.time.OffsetDateTime; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import com.google.gson.Gson; + +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoProperties.Value; +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoSearchGet.MetadataResult; +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoSearchGet.SearchReply; +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoSearchGet.SearchRequest; +import io.weaviate.client6.internal.GRPC; +import io.weaviate.client6.internal.GrpcClient; + +public class Query { + // TODO: inject singleton as dependency + private static final Gson gson = new Gson(); + + // TODO: this should be wrapped around in some TypeInspector etc. + private final String collectionName; + + // TODO: implement Closeable and call grpc.shutdown() on exit + // (probably on a "higher" level); + private final GrpcClient grpcClient; + + public Query(String collectionName, GrpcClient grpc) { + this.grpcClient = grpc; + this.collectionName = collectionName; + } + + public QueryResult nearVector(Float[] vector, Consumer options) { + var query = new NearVector(vector, options); + + // TODO: Since we always need to set these values, we migth want to move the + // next block to some factory method. + var req = SearchRequest.newBuilder(); + req.setCollection(collectionName); + req.setUses123Api(true); + req.setUses125Api(true); + req.setUses127Api(true); + + query.appendTo(req); + return search(req.build()); + } + + private QueryResult search(SearchRequest req) { + var reply = grpcClient.grpc.search(req); + return deserializeUntyped(reply); + } + + public QueryResult deserializeUntyped(SearchReply reply) { + List> objects = reply.getResultsList().stream() + .map(res -> { + Map properties = convertProtoMap(res.getProperties().getNonRefProps().getFieldsMap()); + + MetadataResult meta = res.getMetadata(); + var metadata = new QueryResult.SearchObject.QueryMetadata( + meta.getId(), + meta.getDistancePresent() ? meta.getDistance() : null, + GRPC.fromByteString(meta.getVectorBytes())); + // FIXME: rather than doing this unchecked cast, we should deal + // with the ORM and "untyped map" cases explicitly. + return new QueryResult.SearchObject((T) properties, metadata); + }).toList(); + + return new QueryResult(objects); + } + + /** + * Convert Map to Map such that can be + * (de-)serialized by {@link Gson}. + */ + private static Map convertProtoMap(Map map) { + return map.entrySet().stream().collect(Collectors.toMap( + Map.Entry::getKey, e -> convertProtoValue(e.getValue()))); + } + + /** + * Convert protobuf's Value stub to an Object by extracting the first available + * field. The checks are non-exhaustive and only cover text, boolean, and + * integer values. + */ + private static Object convertProtoValue(Value value) { + if (value.hasTextValue()) { + return value.getTextValue(); + } else if (value.hasBoolValue()) { + return value.getBoolValue(); + } else if (value.hasIntValue()) { + return value.getIntValue(); + } else if (value.hasNumberValue()) { + return value.getNumberValue(); + } else if (value.hasDateValue()) { + OffsetDateTime offsetDateTime = OffsetDateTime.parse(value.getDateValue()); + return Date.from(offsetDateTime.toInstant()); + } else { + assert false : "branch not covered"; + } + return null; + } +} diff --git a/src/main/java/io/weaviate/client6/v1/query/QueryOptions.java b/src/main/java/io/weaviate/client6/v1/query/QueryOptions.java new file mode 100644 index 000000000..5ae284953 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/query/QueryOptions.java @@ -0,0 +1,84 @@ +package io.weaviate.client6.v1.query; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; + +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoSearchGet.MetadataRequest; +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoSearchGet.PropertiesRequest; +import io.weaviate.client6.grpc.protocol.v1.WeaviateProtoSearchGet.SearchRequest; + +@SuppressWarnings("unchecked") +abstract class QueryOptions> { + private Integer limit; + private Integer offset; + private Integer autocut; + private String after; + private String consistencyLevel; + private List returnProperties = new ArrayList<>(); + private List returnMetadata = new ArrayList<>(); + + public final SELF limit(Integer limit) { + this.limit = limit; + return (SELF) this; + } + + public final SELF offset(Integer offset) { + this.offset = offset; + return (SELF) this; + } + + public final SELF autocut(Integer autocut) { + this.autocut = autocut; + return (SELF) this; + } + + public final SELF after(String after) { + this.after = after; + return (SELF) this; + } + + public final SELF consistencyLevel(String consistencyLevel) { + this.consistencyLevel = consistencyLevel; + return (SELF) this; + } + + public final SELF returnMetadata(Metadata... metadata) { + this.returnMetadata = Arrays.asList(metadata); + return (SELF) this; + } + + void appendTo(SearchRequest.Builder search) { + if (limit != null) { + search.setLimit(limit); + } + if (offset != null) { + search.setOffset(offset); + } + if (StringUtils.isNotBlank(after)) { + search.setAfter(after); + } + if (StringUtils.isNotBlank(consistencyLevel)) { + search.setConsistencyLevelValue(Integer.valueOf(consistencyLevel)); + } + if (autocut != null) { + search.setAutocut(autocut); + } + + if (!returnMetadata.isEmpty()) { + var metadata = MetadataRequest.newBuilder(); + returnMetadata.forEach(m -> m.appendTo(metadata)); + search.setMetadata(metadata); + } + + if (!returnProperties.isEmpty()) { + var properties = PropertiesRequest.newBuilder(); + for (String property : returnProperties) { + properties.addNonRefProperties(property); + } + search.setProperties(properties); + } + } +} diff --git a/src/main/java/io/weaviate/client6/v1/query/QueryResult.java b/src/main/java/io/weaviate/client6/v1/query/QueryResult.java new file mode 100644 index 000000000..24b0a91e2 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/query/QueryResult.java @@ -0,0 +1,26 @@ +package io.weaviate.client6.v1.query; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.ToString; + +@AllArgsConstructor +public class QueryResult { + public final List> objects; + + @AllArgsConstructor + public static class SearchObject { + public final T properties; + public final QueryMetadata metadata; + + @AllArgsConstructor + @ToString + public static class QueryMetadata { + String id; + Float distance; + // TODO: use Vectors (to handle both Float[] and Float[][]) + Float[] vector; + } + } +} diff --git a/src/main/proto/v0/batch.proto b/src/main/proto/v0/batch.proto deleted file mode 100644 index 425854711..000000000 --- a/src/main/proto/v0/batch.proto +++ /dev/null @@ -1,12 +0,0 @@ -syntax = "proto3"; - -package weaviategrpc; - -option go_package = "github.com/weaviate/weaviate/grpc/generated;protocol"; -option java_package = "io.weaviate.client6.grpc.protocol.v0"; -option java_outer_classname = "WeaviateProtoBatch"; - -message BatchObjectsRequest { -} -message BatchObjectsReply { -} diff --git a/src/main/proto/v0/search_get.proto b/src/main/proto/v0/search_get.proto deleted file mode 100644 index 0ef5105b0..000000000 --- a/src/main/proto/v0/search_get.proto +++ /dev/null @@ -1,12 +0,0 @@ -syntax = "proto3"; - -package weaviategrpc; - -option go_package = "github.com/weaviate/weaviate/grpc/generated;protocol"; -option java_package = "io.weaviate.client6.grpc.protocol.v0"; -option java_outer_classname = "WeaviateProtoSearchGet"; - -message SearchRequest { -} -message SearchReply { -} diff --git a/src/main/proto/v0/weaviate.proto b/src/main/proto/v0/weaviate.proto deleted file mode 100644 index e7fc3b822..000000000 --- a/src/main/proto/v0/weaviate.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -package weaviategrpc; - -import "v0/batch.proto"; -import "v0/search_get.proto"; - -option go_package = "github.com/weaviate/weaviate/grpc/generated;protocol"; -option java_package = "io.weaviate.client6.grpc.protocol.v0"; -option java_outer_classname = "WeaviateProto"; - -service Weaviate { - rpc Search(SearchRequest) returns (SearchReply) {}; - rpc BatchObjects(BatchObjectsRequest) returns (BatchObjectsReply) {}; -} diff --git a/src/test/java/io/weaviate/client6/v1/ObjectMetadataTest.java b/src/test/java/io/weaviate/client6/v1/ObjectMetadataTest.java new file mode 100644 index 000000000..542f5f7da --- /dev/null +++ b/src/test/java/io/weaviate/client6/v1/ObjectMetadataTest.java @@ -0,0 +1,93 @@ +package io.weaviate.client6.v1; + +import java.util.Optional; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +public class ObjectMetadataTest { + + @Test + public final void testMetadata_id() { + var metadata = ObjectMetadata.with(m -> m.id("object-1")); + Assertions.assertThat(metadata.id()) + .as("object id").isEqualTo("object-1"); + } + + @Test + public final void testVectorsMetadata_unnamed() { + Float[] vector = { 1f, 2f, 3f }; + var metadata = ObjectMetadata.with(m -> m.vectors(Vectors.unnamed(vector))); + + Assertions.assertThat(metadata.vectors()) + .as("unnamed vector").isNotNull() + .returns(Optional.of(vector), Vectors::getUnnamed) + .returns(Optional.empty(), Vectors::getSingle); + } + + @Test + public final void testVectorsMetadata_default() { + Float[] vector = { 1f, 2f, 3f }; + var metadata = ObjectMetadata.with(m -> m.vectors(vector)); + + Assertions.assertThat(metadata.vectors()) + .as("default vector").isNotNull() + .returns(vector, Vectors::getDefaultSingle) + .returns(Optional.of(vector), Vectors::getSingle) + .returns(Optional.empty(), Vectors::getUnnamed); + } + + @Test + public final void testVectorsMetadata_default_2d() { + Float[][] vector = { { 1f, 2f, 3f }, { 1f, 2f, 3f } }; + var metadata = ObjectMetadata.with(m -> m.vectors(vector)); + + Assertions.assertThat(metadata.vectors()) + .as("default 2d vector").isNotNull() + .returns(vector, Vectors::getDefaultMulti) + .returns(Optional.of(vector), Vectors::getMulti) + .returns(Optional.empty(), Vectors::getUnnamed); + } + + @Test + public final void testVectorsMetadata_named() { + Float[] vector = { 1f, 2f, 3f }; + var metadata = ObjectMetadata.with(m -> m.vectors("vector-1", vector)); + + Assertions.assertThat(metadata.vectors()) + .as("named vector").isNotNull() + .returns(vector, v -> v.getSingle("vector-1")) + .returns(Optional.of(vector), Vectors::getSingle) + .returns(null, Vectors::getDefaultSingle); + } + + @Test + public final void testVectorsMetadata_named_2d() { + Float[][] vector = { { 1f, 2f, 3f }, { 1f, 2f, 3f } }; + var metadata = ObjectMetadata.with(m -> m.vectors("vector-1", vector)); + + Assertions.assertThat(metadata.vectors()) + .as("named 2d vector").isNotNull() + .returns(vector, v -> v.getMulti("vector-1")) + .returns(Optional.of(vector), Vectors::getMulti) + .returns(null, Vectors::getDefaultMulti); + } + + @Test + public final void testVectorsMetadata_multiple_named() { + Float[][] vector_1 = { { 1f, 2f, 3f }, { 1f, 2f, 3f } }; + Float[] vector_2 = { 4f, 5f, 6f }; + var metadata = ObjectMetadata.with(m -> m.vectors( + named -> named + .vector("vector-1", vector_1) + .vector("vector-2", vector_2))); + + Assertions.assertThat(metadata.vectors()) + .as("multiple named vectors").isNotNull() + .returns(vector_1, v -> v.getMulti("vector-1")) + .returns(vector_2, v -> v.getSingle("vector-2")) + .returns(Optional.empty(), Vectors::getMulti) + .returns(Optional.empty(), Vectors::getSingle) + .returns(null, Vectors::getDefaultMulti); + } +} diff --git a/src/test/java/io/weaviate/client6/v1/collections/VectorsTest.java b/src/test/java/io/weaviate/client6/v1/collections/VectorsTest.java new file mode 100644 index 000000000..37426ac75 --- /dev/null +++ b/src/test/java/io/weaviate/client6/v1/collections/VectorsTest.java @@ -0,0 +1,127 @@ +package io.weaviate.client6.v1.collections; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParser; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.jparams.junit4.JParamsTestRunner; +import com.jparams.junit4.data.DataMethod; + +import io.weaviate.client6.internal.DtoTypeAdapterFactory; +import io.weaviate.client6.v1.collections.VectorIndex.IndexingStrategy; + +@RunWith(JParamsTestRunner.class) +public class VectorsTest { + // private static final Gson gson = new Gson(); + + static { + DtoTypeAdapterFactory.register(CollectionDefinition.class, CollectionDefinitionDTO.class, + m -> new CollectionDefinitionDTO(m)); + } + private static final Gson gson = new GsonBuilder() + .registerTypeAdapterFactory(new DtoTypeAdapterFactory()) + // TODO: create TypeAdapters via TypeAdapterFactory + .registerTypeAdapter(Vectors.class, new TypeAdapter() { + Gson gson = new Gson(); + + @Override + public void write(JsonWriter out, Vectors value) throws IOException { + gson.toJson(value.asMap(), Map.class, out); + } + + @Override + public Vectors read(JsonReader in) throws IOException { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'read'"); + } + + }) + .create(); + + public static Object[][] testCases() { + return new Object[][] { + { + """ + { + "vectorConfig": { + "default": { "vectorizer": { "none":{}}} + } + } + """, + collectionWithVectors(Vectors.of(new VectorIndex<>(Vectorizer.none()))), + new String[] { "vectorConfig" }, + }, + { + """ + { + "vectorConfig": { + "vector-1": { "vectorizer": { "none":{}}}, + "vector-2": { + "vectorizer": { "none":{}}, + "vectorIndexType": "hnsw", + "vectorIndexConfig": {} + } + } + } + """, + collectionWithVectors(Vectors.with(named -> named + .vector("vector-1", new VectorIndex<>(Vectorizer.none())) + .vector("vector-2", new VectorIndex<>(IndexingStrategy.hnsw(), Vectorizer.none())))), + new String[] { "vectorConfig" }, + }, + { + """ + { + "vectorizer": { "none": {}}, + "vectorIndexConfig": { "distance": "COSINE", "skip": true }, + "vectorIndexType": "hnsw" + } + """, + collectionWithVectors(Vectors.unnamed( + new VectorIndex<>( + IndexingStrategy.hnsw(opt -> opt + .distance(HNSW.Distance.COSINE) + .disableIndexation()), + Vectorizer.none()))), + new String[] { "vectorIndexType", "vectorIndexConfig", "vectorizer" }, + }, + }; + } + + @Test + @DataMethod(source = VectorsTest.class, method = "testCases") + public void test_toJson(String want, CollectionDefinition collection, String... compareKeys) { + var got = gson.toJson(collection); + assertEqual(want, got, compareKeys); + } + + private static CollectionDefinition collectionWithVectors(Vectors vectors) { + return new CollectionDefinition("Things", List.of(), vectors); + } + + private void assertEqual(String wantJson, String gotJson, String... compareKeys) { + var want = JsonParser.parseString(wantJson).getAsJsonObject(); + var got = JsonParser.parseString(gotJson).getAsJsonObject(); + + if (compareKeys == null || compareKeys.length == 0) { + Assertions.assertThat(got).isEqualTo(want); + return; + } + + for (var key : compareKeys) { + Assertions.assertThat(got.get(key)) + .isEqualTo(want.get(key)) + .as(key); + } + } +} diff --git a/src/test/java/io/weaviate/client6/v1/data/QueryParametersTest.java b/src/test/java/io/weaviate/client6/v1/data/QueryParametersTest.java new file mode 100644 index 000000000..6c6caa676 --- /dev/null +++ b/src/test/java/io/weaviate/client6/v1/data/QueryParametersTest.java @@ -0,0 +1,48 @@ +package io.weaviate.client6.v1.data; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.jparams.junit4.JParamsTestRunner; +import com.jparams.junit4.data.DataMethod; + +@RunWith(JParamsTestRunner.class) +public class QueryParametersTest { + + public static Object[][] testCases() { + return new Object[][] { + { + QueryParameters.encodeGet(q -> q + .withVector() + .nodeName("node-1")), + "?include=vector&node_name=node-1", + }, + { + QueryParameters.encodeGet(q -> q + .withVector() + .withClassification() + .tenant("JohnDoe")), + "?include=vector,classification&tenant=JohnDoe", + }, + { + QueryParameters.encodeGet(q -> q + .consistencyLevel(ConsistencyLevel.ALL) + .nodeName("node-1") + .tenant("JohnDoe")), + "?consistency_level=ALL&node_name=node-1&tenant=JohnDoe", + }, + { + QueryParameters.encodeGet(q -> { + }), + "", + }, + }; + } + + @Test + @DataMethod(source = QueryParametersTest.class, method = "testCases") + public void testEncode(String got, String want) { + Assertions.assertThat(got).isEqualTo(want).as("expected query parameters"); + } +} diff --git a/src/test/java/io/weaviate/internal/DtoTypeAdapterFactoryTest.java b/src/test/java/io/weaviate/internal/DtoTypeAdapterFactoryTest.java new file mode 100644 index 000000000..85cf85da6 --- /dev/null +++ b/src/test/java/io/weaviate/internal/DtoTypeAdapterFactoryTest.java @@ -0,0 +1,78 @@ +package io.weaviate.internal; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParser; +import com.jparams.junit4.JParamsTestRunner; +import com.jparams.junit4.data.DataMethod; + +import io.weaviate.client6.internal.DtoTypeAdapterFactory; + +@RunWith(JParamsTestRunner.class) +public class DtoTypeAdapterFactoryTest { + /** Person should be serialized to PersonDto. */ + record Person(String name) { + } + + record PersonDto(String nickname) implements DtoTypeAdapterFactory.Dto { + PersonDto(Person p) { + this(p.name); + } + + @Override + public Person toModel() { + return new Person(nickname); + } + } + + /** Car's DTO is a nested record. */ + record Car(String brand) { + record CarDto(String manufacturer, Integer version) implements DtoTypeAdapterFactory.Dto { + CarDto(Car c) { + this(c.brand, 1); + } + + @Override + public Car toModel() { + return new Car(manufacturer); + } + } + } + + /** Normal does not have a DTO and should be serialized as usual. */ + record Normal(String key, String value) { + } + + static { + DtoTypeAdapterFactory.register(Person.class, PersonDto.class, m -> new PersonDto(m)); + DtoTypeAdapterFactory.register(Car.class, Car.CarDto.class, m -> new Car.CarDto(m)); + } + + private static final Gson gson = new GsonBuilder() + .registerTypeAdapterFactory(new DtoTypeAdapterFactory()) + .create(); + + public static Object[][] testCases() { + return new Object[][] { + { new Person("Josh"), "{\"nickname\": \"Josh\"}" }, + { new Car("Porsche"), "{\"manufacturer\": \"Porsche\", \"version\": 1}" }, + { new Normal("foo", "bar"), "{\"key\": \"foo\", \"value\": \"bar\"}" }, + }; + } + + @Test + @DataMethod(source = DtoTypeAdapterFactoryTest.class, method = "testCases") + public void testRoundtrip(Object model, String wantJson) { + var gotJson = gson.toJson(model); + Assertions.assertThat(JsonParser.parseString(gotJson)) + .as("serialized") + .isEqualTo(JsonParser.parseString(wantJson)); + + var deserialized = gson.fromJson(gotJson, model.getClass()); + Assertions.assertThat(deserialized).as("deserialized").isEqualTo(model); + } +}