From 66a35744195c0b5d68f1dd3b38bc736c266e944a Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 25 Nov 2025 10:36:39 +0100 Subject: [PATCH 01/11] chore: remove unused builder parameter --- .../client6/v1/api/collections/data/WriteWeaviateObject.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java index 673157532..236322a36 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java @@ -44,7 +44,7 @@ public static WriteWeaviateObject of( public WriteWeaviateObject(Builder builder) { this( builder.uuid, - builder.collection, + null, // collection name is set on insert builder.tenant, builder.properties, builder.vectors, @@ -61,7 +61,6 @@ public static class Builder implements ObjectBuilder Date: Tue, 25 Nov 2025 13:51:17 +0100 Subject: [PATCH 02/11] spike: use a single WeaviateObject interface --- .../io/weaviate/integration/DataITest.java | 44 +++++++++++++++---- .../weaviate/integration/PaginationITest.java | 8 ++-- .../io/weaviate/integration/SearchITest.java | 34 +++++++------- .../v1/api/collections/IReference.java | 11 +++++ .../v1/api/collections/WeaviateObject.java | 27 +++++++++++- .../collections/data/InsertManyRequest.java | 17 ++++--- .../collections/data/InsertObjectRequest.java | 5 ++- .../v1/api/collections/data/Reference.java | 14 +++++- .../collections/data/WeaviateDataClient.java | 16 ++++--- .../data/WeaviateDataClientAsync.java | 13 +++--- .../collections/data/WriteWeaviateObject.java | 19 +++++--- .../generate/GenerativeResponse.java | 2 +- .../generate/GenerativeResponseGrouped.java | 2 +- .../api/collections/query/QueryMetadata.java | 20 ++++----- .../collections/query/QueryObjectGrouped.java | 2 +- .../api/collections/query/QueryResponse.java | 18 ++++---- .../collections/query/ReadWeaviateObject.java | 30 +++++++++++-- .../client6/v1/internal/json/JSON.java | 3 ++ 18 files changed, 200 insertions(+), 85 deletions(-) create mode 100644 src/main/java/io/weaviate/client6/v1/api/collections/IReference.java diff --git a/src/it/java/io/weaviate/integration/DataITest.java b/src/it/java/io/weaviate/integration/DataITest.java index 349ce5253..fa3f99f66 100644 --- a/src/it/java/io/weaviate/integration/DataITest.java +++ b/src/it/java/io/weaviate/integration/DataITest.java @@ -21,10 +21,10 @@ import io.weaviate.client6.v1.api.collections.ReferenceProperty; import io.weaviate.client6.v1.api.collections.VectorConfig; import io.weaviate.client6.v1.api.collections.Vectors; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.data.BatchReference; import io.weaviate.client6.v1.api.collections.data.DeleteManyResponse; import io.weaviate.client6.v1.api.collections.data.Reference; -import io.weaviate.client6.v1.api.collections.data.WriteWeaviateObject; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.Metadata; import io.weaviate.client6.v1.api.collections.query.Metadata.MetadataField; @@ -66,22 +66,48 @@ public void testCreateGetDelete() throws IOException { Assertions.assertThat(object) .as("object has correct properties").get() .satisfies(obj -> { - Assertions.assertThat(obj.metadata().uuid()) + Assertions.assertThat(obj.queryMetadata().uuid()) .as("object id").isEqualTo(id); - Assertions.assertThat(obj.metadata().vectors().getSingle(VECTOR_INDEX)) + Assertions.assertThat(obj.queryMetadata().vectors().getSingle(VECTOR_INDEX)) .containsExactly(vector); Assertions.assertThat(obj.properties()) .as("has expected properties") .containsEntry("name", "john doe"); - Assertions.assertThat(obj.metadata().creationTimeUnix()) - .as("creationTimeUnix").isNotNull(); - Assertions.assertThat(obj.metadata().lastUpdateTimeUnix()) - .as("lastUpdateTimeUnix").isNotNull(); + Assertions.assertThat(obj.queryMetadata().createdAt()) + .as("createdAt").isNotNull(); + Assertions.assertThat(obj.queryMetadata().lastUpdatedAt()) + .as("lastUpdatedAt").isNotNull(); }); + // var write = WriteWeaviateObject.of(null); + // write.tenant(); // can be null, but that's perfectly fine + // + // write.references().get("").getFirst().asWeaviateObject(); + // + // // Three key changes: + // var wv = WeaviateObject.write(null); // 1: you can use WeaviateObject, and + // not WriteWeaviateObject + // write.queryMetadata(); // 2: This should be called "queryMetadata" to avoid + // confusion + // wv.references().forEach((key, references) -> { + // references.forEach(ref -> { + // ref.collection(); + // ref.uuid(); + // + // // get "title" property from a referenced object + // var title = ref.asWeaviateObject().properties().get("title"); + // + // ref.asWeaviateObject().references().forEach((__, nestedRefs) -> { + // nestedRefs.forEach(nref -> { + // var n_title = ref.asWeaviateObject().properties().get("title"); + // }); + // }); + // }); + // }); + var deleted = artists.data.deleteById(id); Assertions.assertThat(deleted) .as("object was deleted").isTrue(); @@ -292,7 +318,7 @@ public void testUpdate() throws IOException { Assertions.assertThat(book) .as("has a vector") - .extracting(ReadWeaviateObject::metadata) + .extracting(ReadWeaviateObject::queryMetadata) .extracting(QueryMetadata::vectors) .returns(vector, Vectors::getDefaultSingle); }); @@ -557,6 +583,6 @@ public void test_multiTenant() throws IOException { var inserted = emails.data.insert(Map.of("subject", "McDonald's Xmas Bonanza")); // Assert - Assertions.assertThat(inserted).returns(johndoe, WriteWeaviateObject::tenant); + Assertions.assertThat(inserted).returns(johndoe, WeaviateObject::tenant); } } diff --git a/src/it/java/io/weaviate/integration/PaginationITest.java b/src/it/java/io/weaviate/integration/PaginationITest.java index b5e789e2b..16901e901 100644 --- a/src/it/java/io/weaviate/integration/PaginationITest.java +++ b/src/it/java/io/weaviate/integration/PaginationITest.java @@ -47,7 +47,7 @@ public void testIterateAll() throws IOException { // Act: stream var gotStream = allThings.stream() - .map(ReadWeaviateObject::metadata).map(QueryMetadata::uuid).toList(); + .map(ReadWeaviateObject::queryMetadata).map(QueryMetadata::uuid).toList(); // Assert Assertions.assertThat(gotStream) @@ -58,7 +58,7 @@ public void testIterateAll() throws IOException { // Act: for-loop var gotLoop = new ArrayList(); for (var thing : allThings) { - gotLoop.add(thing.metadata().uuid()); + gotLoop.add(thing.queryMetadata().uuid()); } // Assert @@ -89,7 +89,7 @@ public void testResumePagination() throws IOException { // Iterate over first 5 objects String lastId = things.paginate(p -> p.pageSize(5)).stream() - .limit(5).map(thing -> thing.metadata().uuid()) + .limit(5).map(thing -> thing.queryMetadata().uuid()) .reduce((prev, next) -> next).get(); // Act @@ -126,7 +126,7 @@ public void testWithQueryOptions() throws IOException { .as("uuid=" + thing.uuid()) .doesNotContainKey("dont_fetch"); - Assertions.assertThat(thing.metadata().creationTimeUnix()) + Assertions.assertThat(thing.queryMetadata().createdAt()) .isNotNull(); } } diff --git a/src/it/java/io/weaviate/integration/SearchITest.java b/src/it/java/io/weaviate/integration/SearchITest.java index d37a6718c..ecf9a97db 100644 --- a/src/it/java/io/weaviate/integration/SearchITest.java +++ b/src/it/java/io/weaviate/integration/SearchITest.java @@ -28,8 +28,8 @@ import io.weaviate.client6.v1.api.collections.VectorConfig; import io.weaviate.client6.v1.api.collections.Vectors; import io.weaviate.client6.v1.api.collections.WeaviateMetadata; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.data.Reference; -import io.weaviate.client6.v1.api.collections.data.WriteWeaviateObject; import io.weaviate.client6.v1.api.collections.generate.GenerativeObject; import io.weaviate.client6.v1.api.collections.generate.TaskOutput; import io.weaviate.client6.v1.api.collections.generative.DummyGenerative; @@ -91,7 +91,7 @@ public void testNearVector() { Assertions.assertThat(result.objects()).hasSize(3); float maxDistance = Collections.max(result.objects(), - Comparator.comparing(obj -> obj.metadata().distance())).metadata().distance(); + Comparator.comparing(obj -> obj.queryMetadata().distance())).queryMetadata().distance(); Assertions.assertThat(maxDistance).isLessThanOrEqualTo(2f); } @@ -265,7 +265,7 @@ public void testFetchObjectsWithFilters() throws IOException { Filter.property("size").lt(6))))); Assertions.assertThat(got.objects()) - .extracting(hat -> hat.metadata().uuid()) + .extracting(hat -> hat.queryMetadata().uuid()) .containsOnly( redHat.uuid(), greenHat.uuid(), @@ -331,7 +331,7 @@ public void testBm25() throws IOException, InterruptedException, ExecutionExcept Assertions.assertThat(dollarWorlds.objects()) .hasSize(1) - .extracting(ReadWeaviateObject::metadata).extracting(QueryMetadata::uuid) + .extracting(ReadWeaviateObject::queryMetadata).extracting(QueryMetadata::uuid) .containsOnly(want.uuid()); } @@ -363,7 +363,7 @@ public void testBm25_async() throws Exception, InterruptedException, ExecutionEx Assertions.assertThat(dollarWorlds.objects()) .hasSize(1) - .extracting(ReadWeaviateObject::metadata).extracting(QueryMetadata::uuid) + .extracting(ReadWeaviateObject::queryMetadata).extracting(QueryMetadata::uuid) .containsOnly(want.uuid()); } } @@ -393,7 +393,7 @@ public void testNearObject() throws IOException { // Assert Assertions.assertThat(terrestrial.objects()) .hasSize(1) - .extracting(ReadWeaviateObject::metadata).extracting(WeaviateMetadata::uuid) + .extracting(ReadWeaviateObject::queryMetadata).extracting(WeaviateMetadata::uuid) .containsOnly(lion.uuid()); } @@ -420,13 +420,13 @@ public void testHybrid() throws IOException { // Assert Assertions.assertThat(winterSport.objects()) .hasSize(1) - .extracting(ReadWeaviateObject::metadata).extracting(WeaviateMetadata::uuid) + .extracting(ReadWeaviateObject::queryMetadata).extracting(WeaviateMetadata::uuid) .containsOnly(skiing.uuid()); var first = winterSport.objects().get(0); - Assertions.assertThat(first.metadata().score()) + Assertions.assertThat(first.queryMetadata().score()) .as("metadata::score").isNotNull(); - Assertions.assertThat(first.metadata().explainScore()) + Assertions.assertThat(first.queryMetadata().explainScore()) .as("metadata::explainScore").isNotNull(); } @@ -519,23 +519,23 @@ public void testMetadataAll() throws IOException { // Assert var metadataHybrid = Assertions.assertThat(gotHybrid.objects()) .hasSize(1) - .extracting(ReadWeaviateObject::metadata) + .extracting(ReadWeaviateObject::queryMetadata) .first().actual(); Assertions.assertThat(metadataHybrid.uuid()).as("uuid").isNotNull().isEqualTo(frisbee.uuid()); - Assertions.assertThat(metadataHybrid.creationTimeUnix()).as("creationTimeUnix").isNotNull(); - Assertions.assertThat(metadataHybrid.lastUpdateTimeUnix()).as("lastUpdateTimeUnix").isNotNull(); + Assertions.assertThat(metadataHybrid.createdAt()).as("createdAt").isNotNull(); + Assertions.assertThat(metadataHybrid.lastUpdatedAt()).as("lastUpdateTimeUnix").isNotNull(); Assertions.assertThat(metadataHybrid.score()).as("score").isNotNull(); Assertions.assertThat(metadataHybrid.explainScore()).as("explainScore").isNotNull().isNotEqualTo(""); var metadataNearText = Assertions.assertThat(gotNearText.objects()) .hasSize(1) - .extracting(ReadWeaviateObject::metadata) + .extracting(ReadWeaviateObject::queryMetadata) .first().actual(); Assertions.assertThat(metadataNearText.uuid()).as("uuid").isNotNull().isEqualTo(frisbee.uuid()); - Assertions.assertThat(metadataNearText.creationTimeUnix()).as("creationTimeUnix").isNotNull(); - Assertions.assertThat(metadataNearText.lastUpdateTimeUnix()).as("lastUpdateTimeUnix").isNotNull(); + Assertions.assertThat(metadataNearText.createdAt()).as("createdAt").isNotNull(); + Assertions.assertThat(metadataNearText.lastUpdatedAt()).as("lastUpdateTimeUnix").isNotNull(); Assertions.assertThat(metadataNearText.distance()).as("distance").isNotNull(); Assertions.assertThat(metadataNearText.certainty()).as("certainty").isNotNull(); } @@ -558,7 +558,7 @@ public void testNearVector_targetVectors() throws IOException { Vectors.of("v2d", new float[][] { { 1, 2, 3 }, { 1, 2, 3 } }))); var thing456 = things.data.insertMany(List.of( - WriteWeaviateObject.of(thing -> thing + WeaviateObject.write(thing -> thing .vectors( Vectors.of("v1d", new float[] { 4, 5, 6 }), Vectors.of("v2d", new float[][] { { 4, 5, 6 }, { 4, 5, 6 } }))))); @@ -760,7 +760,7 @@ public void test_maxGrpcMessageSize() throws Exception { .vectorConfig(VectorConfig.selfProvided())); final var vector = randomVector(5000, -.01f, .01f); - final WriteWeaviateObject> hugeObject = WriteWeaviateObject.of( + final WeaviateObject> hugeObject = WeaviateObject.write( obj -> obj.vectors(Vectors.of(vector))); Assertions.assertThatThrownBy(() -> { diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java new file mode 100644 index 000000000..138843cf6 --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java @@ -0,0 +1,11 @@ +package io.weaviate.client6.v1.api.collections; + +import java.util.Map; + +public interface IReference { + String uuid(); + + String collection(); + + WeaviateObject> asWeaviateObject(); +} diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java index dedc38849..f9f98e312 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java @@ -1,9 +1,34 @@ package io.weaviate.client6.v1.api.collections; -public interface WeaviateObject { +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +import io.weaviate.client6.v1.api.collections.data.WriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.query.QueryMetadata; +import io.weaviate.client6.v1.internal.ObjectBuilder; + +public interface WeaviateObject { String uuid(); String collection(); Vectors vectors(); + + String tenant(); + + PropertiesT properties(); + + Map> references(); + + Long createdAt(); + + Long lastUpdatedAt(); + + QueryMetadata queryMetadata(); + + public static WeaviateObject write( + Function, ObjectBuilder>> fn) { + return fn.apply(new WriteWeaviateObject.Builder<>()).build(); + } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java index 843bdbb02..b471be340 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java @@ -10,6 +10,7 @@ import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; import io.weaviate.client6.v1.api.collections.GeoCoordinates; import io.weaviate.client6.v1.api.collections.PhoneNumber; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.MapUtil; import io.weaviate.client6.v1.internal.grpc.ByteStringUtil; import io.weaviate.client6.v1.internal.grpc.Rpc; @@ -20,10 +21,10 @@ import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoBatch; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; -public record InsertManyRequest(List> objects) { +public record InsertManyRequest(List> objects) { @SafeVarargs - public InsertManyRequest(WriteWeaviateObject... objects) { + public InsertManyRequest(WeaviateObject... objects) { this(Arrays.asList(objects)); } @@ -31,13 +32,13 @@ public InsertManyRequest(WriteWeaviateObject... objects) { @SafeVarargs public static final InsertManyRequest of(PropertiesT... properties) { var objects = Arrays.stream(properties) - .map(p -> (WriteWeaviateObject) WriteWeaviateObject.of(obj -> obj.properties(p))) + .map(p -> (WeaviateObject) WeaviateObject.write(obj -> obj.properties(p))) .toList(); return new InsertManyRequest<>(objects); } public static Rpc, WeaviateProtoBatch.BatchObjectsRequest, InsertManyResponse, WeaviateProtoBatch.BatchObjectsReply> rpc( - List> insertObjects, + List> insertObjects, CollectionDescriptor collection, CollectionHandleDefaults defaults) { return Rpc.insert( @@ -46,7 +47,7 @@ public static Rpc, WeaviateProtoBat var batch = request.objects.stream().map(obj -> { var batchObject = WeaviateProtoBatch.BatchObject.newBuilder(); - buildObject(batchObject, obj, collection, defaults); + buildObject(batchObject, (WriteWeaviateObject) obj, collection, defaults); return batchObject.build(); }).toList(); @@ -135,11 +136,13 @@ public static void buildObject(WeaviateProtoBatch.BatchObject.Builder object // is single- or multi-target? for (var ref : references) { if (ref.collection() == null) { - singleRef.add(WeaviateProtoBatch.BatchObject.SingleTargetRefProps.newBuilder().addAllUuids(ref.uuids()) + singleRef.add(WeaviateProtoBatch.BatchObject.SingleTargetRefProps.newBuilder() + .addAllUuids(((Reference) ref).uuids()) .setPropName(entry.getKey()).build()); } else { multiRef.add(WeaviateProtoBatch.BatchObject.MultiTargetRefProps.newBuilder() - .setTargetCollection(ref.collection()).addAllUuids(ref.uuids()).setPropName(entry.getKey()).build()); + .setTargetCollection(ref.collection()).addAllUuids(((Reference) ref).uuids()) + .setPropName(entry.getKey()).build()); } } }); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java index cf992eba7..38b0c63de 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java @@ -7,16 +7,17 @@ import com.google.gson.reflect.TypeToken; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.json.JSON; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; import io.weaviate.client6.v1.internal.rest.Endpoint; import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; -public record InsertObjectRequest(WriteWeaviateObject object) { +public record InsertObjectRequest(WeaviateObject object) { @SuppressWarnings("unchecked") - public static final Endpoint, WriteWeaviateObject> endpoint( + public static final Endpoint, WeaviateObject> endpoint( CollectionDescriptor collection, CollectionHandleDefaults defaults) { diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java index 097478788..135859fae 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java @@ -3,15 +3,27 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; +import java.util.Map; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; +import io.weaviate.client6.v1.api.collections.IReference; import io.weaviate.client6.v1.api.collections.WeaviateObject; -public record Reference(String collection, List uuids) { +public record Reference(String collection, List uuids) implements IReference { + + @Override + public String uuid() { + return uuids.get(0); + } + + @Override + public WeaviateObject> asWeaviateObject() { + throw new IllegalStateException("cannot convert to WeaviateObject"); + } public Reference(String collection, String uuid) { this(collection, List.of(uuid)); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java index 953a920d9..64272439f 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java @@ -6,9 +6,10 @@ import java.util.function.Function; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClient; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.FilterOperand; +import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClient; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.grpc.GrpcTransport; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; @@ -43,18 +44,18 @@ public WeaviateDataClient(WeaviateDataClient c, CollectionHandleDef this.defaults = defaults; } - public WriteWeaviateObject insert(PropertiesT properties) throws IOException { + public WeaviateObject insert(PropertiesT properties) throws IOException { return insert(InsertObjectRequest.of(properties)); } - public WriteWeaviateObject insert( + public WeaviateObject insert( PropertiesT properties, Function, ObjectBuilder>> fn) throws IOException { return insert(InsertObjectRequest.of(properties, fn)); } - public WriteWeaviateObject insert(InsertObjectRequest request) + public WeaviateObject insert(InsertObjectRequest request) throws IOException { return this.restTransport.performRequest(request, InsertObjectRequest.endpoint(collection, defaults)); } @@ -64,12 +65,12 @@ public final InsertManyResponse insertMany(PropertiesT... objects) { return insertMany(InsertManyRequest.of(objects)); } - public InsertManyResponse insertMany(List> objects) { + public InsertManyResponse insertMany(List> objects) { return insertMany(new InsertManyRequest<>(objects)); } @SafeVarargs - public final InsertManyResponse insertMany(WriteWeaviateObject... objects) { + public final InsertManyResponse insertMany(WeaviateObject... objects) { return insertMany(Arrays.asList(objects)); } @@ -102,7 +103,8 @@ public void replace( * Delete an object by its UUID. * * @param uuid The UUID of the object to delete. - * @return {@code true} if the object was deleted, {@code false} if there was no object to delete. + * @return {@code true} if the object was deleted, {@code false} if there was no + * object to delete. * @throws IOException in case the request was not sent successfully. */ public boolean deleteById(String uuid) throws IOException { diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java index 7ac560fc9..58a94ad7d 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java @@ -8,9 +8,10 @@ import java.util.function.Function; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClientAsync; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.FilterOperand; +import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClientAsync; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.grpc.GrpcTransport; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; @@ -45,17 +46,17 @@ public WeaviateDataClientAsync(WeaviateDataClientAsync c, Collectio this.defaults = defaults; } - public CompletableFuture> insert(PropertiesT properties) { + public CompletableFuture> insert(PropertiesT properties) { return insert(InsertObjectRequest.of(properties)); } - public CompletableFuture> insert( + public CompletableFuture> insert( PropertiesT properties, Function, ObjectBuilder>> fn) { return insert(InsertObjectRequest.of(properties, fn)); } - public CompletableFuture> insert( + public CompletableFuture> insert( InsertObjectRequest request) { return this.restTransport.performRequestAsync(request, InsertObjectRequest.endpoint(collection, defaults)); } @@ -66,11 +67,11 @@ public final CompletableFuture insertMany(PropertiesT... obj } @SafeVarargs - public final CompletableFuture insertMany(WriteWeaviateObject... objects) { + public final CompletableFuture insertMany(WeaviateObject... objects) { return insertMany(Arrays.asList(objects)); } - public CompletableFuture insertMany(List> objects) { + public CompletableFuture insertMany(List> objects) { return insertMany(new InsertManyRequest<>(objects)); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java index 236322a36..4538fd48d 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java @@ -21,8 +21,10 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; +import io.weaviate.client6.v1.api.collections.IReference; import io.weaviate.client6.v1.api.collections.Vectors; import io.weaviate.client6.v1.api.collections.WeaviateObject; +import io.weaviate.client6.v1.api.collections.query.QueryMetadata; import io.weaviate.client6.v1.internal.ObjectBuilder; public record WriteWeaviateObject( @@ -34,7 +36,12 @@ public record WriteWeaviateObject( @SerializedName("creationTimeUnix") Long createdAt, @SerializedName("lastUpdateTimeUnix") Long lastUpdatedAt, - Map> references) implements WeaviateObject { + Map> references) implements WeaviateObject { + + @Override + public QueryMetadata queryMetadata() { + return new QueryMetadata(uuid, vectors, createdAt, lastUpdatedAt, null, null, null, null); + } public static WriteWeaviateObject of( Function, ObjectBuilder>> fn) { @@ -64,7 +71,7 @@ public static class Builder implements ObjectBuilder> references = new HashMap<>(); + private Map> references = new HashMap<>(); public Builder uuid(String uuid) { this.uuid = uuid; @@ -85,19 +92,19 @@ public Builder properties(PropertiesT properties) { * Add a reference. Calls to {@link #reference} can be chained * to add multiple references. */ - public Builder reference(String property, Reference... references) { + public Builder reference(String property, IReference... references) { for (var ref : references) { addReference(property, ref); } return this; } - public Builder references(Map> references) { + public Builder references(Map> references) { this.references = references; return this; } - private void addReference(String property, Reference reference) { + private void addReference(String property, IReference reference) { if (!references.containsKey(property)) { references.put(property, new ArrayList<>()); } @@ -154,7 +161,7 @@ public void write(JsonWriter out, WriteWeaviateObject value) throws IOExcepti for (var refEntry : value.references().entrySet()) { var beacons = new JsonArray(); for (var reference : refEntry.getValue()) { - var beacon = referencesAdapter.toJsonTree(reference); + var beacon = referencesAdapter.toJsonTree((Reference) reference); beacons.add(beacon); } properties.add(refEntry.getKey(), beacons); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponse.java b/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponse.java index 275722e52..f762ba185 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponse.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponse.java @@ -41,7 +41,7 @@ static GenerativeResponse unmarshal( } return new GenerativeObject<>( object.properties(), - object.metadata(), + object.queryMetadata(), generative); }) .toList(); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGrouped.java b/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGrouped.java index 9c8504894..b73825bac 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGrouped.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGrouped.java @@ -37,7 +37,7 @@ static GenerativeResponseGrouped unmarshal( collection)) .map(object -> new QueryObjectGrouped<>( object.properties(), - object.metadata(), + object.queryMetadata(), groupName)) .toList(); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java index 03896895d..ba77e6b86 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java @@ -10,9 +10,9 @@ public record QueryMetadata( /** Vector embeddings associated with the object. */ Vectors vectors, /** Object creation time as a Unix timestamp. */ - Long creationTimeUnix, + Long createdAt, /** Unix timestamp of the latest object update. */ - Long lastUpdateTimeUnix, + Long lastUpdatedAt, /** Distances to the search vector. */ Float distance, /** Distance metric normalized to {@code 0 <= c <= 1} range. */ @@ -26,8 +26,8 @@ private QueryMetadata(Builder builder) { this( builder.uuid, builder.vectors, - builder.creationTimeUnix, - builder.lastUpdateTimeUnix, + builder.createdAt, + builder.lastUpdatedAt, builder.distance, builder.certainty, builder.score, @@ -37,8 +37,8 @@ private QueryMetadata(Builder builder) { static class Builder implements ObjectBuilder { private String uuid; private Vectors vectors; - private Long creationTimeUnix; - private Long lastUpdateTimeUnix; + private Long createdAt; + private Long lastUpdatedAt; private Float distance; private Float certainty; private Float score; @@ -58,13 +58,13 @@ public Builder vectors(Vectors... vectors) { return this; } - final Builder creationTimeUnix(Long creationTimeUnix) { - this.creationTimeUnix = creationTimeUnix; + final Builder createdAt(Long createdAt) { + this.createdAt = createdAt; return this; } - final Builder lastUpdateTimeUnix(Long lastUpdateTimeUnix) { - this.lastUpdateTimeUnix = lastUpdateTimeUnix; + final Builder lastUpdatedAt(Long lastUpdatedAt) { + this.lastUpdatedAt = lastUpdatedAt; return this; } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java index fb6b711d8..039557652 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java @@ -10,6 +10,6 @@ public record QueryObjectGrouped( QueryObjectGrouped(ReadWeaviateObject object, String belongsToGroup) { - this(object.properties(), object.metadata(), belongsToGroup); + this(object.properties(), object.queryMetadata(), belongsToGroup); } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java index af31ceb12..817994c83 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java @@ -3,10 +3,12 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.stream.Stream; import io.weaviate.client6.v1.api.collections.GeoCoordinates; +import io.weaviate.client6.v1.api.collections.IReference; import io.weaviate.client6.v1.api.collections.PhoneNumber; import io.weaviate.client6.v1.api.collections.Vectors; import io.weaviate.client6.v1.internal.DateUtil; @@ -36,14 +38,14 @@ public static ReadWeaviateObject unmarshalResultObjec CollectionDescriptor collection) { var object = unmarshalWithReferences(propertiesResult, metadataResult, collection); var metadata = new QueryMetadata.Builder() - .uuid(object.metadata().uuid()) - .vectors(object.metadata().vectors()); + .uuid(object.queryMetadata().uuid()) + .vectors(object.queryMetadata().vectors()); if (metadataResult.getCreationTimeUnixPresent()) { - metadata.creationTimeUnix(metadataResult.getCreationTimeUnix()); + metadata.createdAt(metadataResult.getCreationTimeUnix()); } if (metadataResult.getLastUpdateTimeUnixPresent()) { - metadata.lastUpdateTimeUnix(metadataResult.getLastUpdateTimeUnix()); + metadata.lastUpdatedAt(metadataResult.getLastUpdateTimeUnix()); } if (metadataResult.getDistancePresent()) { metadata.distance(metadataResult.getDistance()); @@ -76,18 +78,18 @@ static ReadWeaviateObject unmarshalWithReferences( // I.e. { "ref": A-1 } , { "ref": B-1 } => { "ref": [A-1, B-1] } var referenceProperties = propertiesResult.getRefPropsList() .stream().reduce( - new HashMap>>(), + new HashMap>(), (map, ref) -> { var refObjects = ref.getPropertiesList().stream() .map(property -> { var reference = unmarshalWithReferences( property, property.getMetadata(), CollectionDescriptor.ofMap(property.getTargetCollection())); - return new ReadWeaviateObject<>( + return (IReference) new ReadWeaviateObject<>( reference.collection(), (Object) reference.properties(), reference.references(), - reference.metadata()); + reference.queryMetadata()); }) .toList(); @@ -142,7 +144,7 @@ static ReadWeaviateObject unmarshalWithReferences( return new ReadWeaviateObject<>( descriptor.collectionName(), properties.build(), - referenceProperties, + (Map>) referenceProperties, metadata); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/ReadWeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/ReadWeaviateObject.java index 7f8505b79..d69c47ce2 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/ReadWeaviateObject.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/ReadWeaviateObject.java @@ -3,24 +3,46 @@ import java.util.List; import java.util.Map; +import io.weaviate.client6.v1.api.collections.IReference; import io.weaviate.client6.v1.api.collections.Vectors; import io.weaviate.client6.v1.api.collections.WeaviateObject; public record ReadWeaviateObject( String collection, PropertiesT properties, - Map>> references, - QueryMetadata metadata) implements WeaviateObject { + Map> references, + QueryMetadata queryMetadata) implements WeaviateObject, IReference { /** Shorthand for accesing objects's UUID from metadata. */ @Override public String uuid() { - return metadata.uuid(); + return queryMetadata.uuid(); } /** Shorthand for accesing objects's vectors from metadata. */ @Override public Vectors vectors() { - return metadata.vectors(); + return queryMetadata.vectors(); + } + + @Override + public Long createdAt() { + return queryMetadata.createdAt(); + } + + @Override + public Long lastUpdatedAt() { + return queryMetadata.lastUpdatedAt(); + } + + @Override + public String tenant() { + return null; + } + + @SuppressWarnings("unchecked") + @Override + public WeaviateObject> asWeaviateObject() { + return (WeaviateObject>) this; } } diff --git a/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java b/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java index d69e7fdaa..5907be70a 100644 --- a/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java +++ b/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java @@ -58,6 +58,9 @@ public final class JSON { gsonBuilder.registerTypeAdapter( io.weaviate.client6.v1.api.collections.data.Reference.class, io.weaviate.client6.v1.api.collections.data.Reference.TYPE_ADAPTER); + gsonBuilder.registerTypeAdapter( + io.weaviate.client6.v1.api.collections.IReference.class, + io.weaviate.client6.v1.api.collections.data.Reference.TYPE_ADAPTER); gsonBuilder.registerTypeAdapter( io.weaviate.client6.v1.api.collections.data.BatchReference.class, io.weaviate.client6.v1.api.collections.data.BatchReference.TYPE_ADAPTER); From 45efe7a3d50abaaaabf820de91a6c3afd14b0e3d Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 25 Nov 2025 15:47:15 +0100 Subject: [PATCH 03/11] refactor: re-unite Read-/WriteWeaviateObject Separate query-only metadata from the metadata that's always available. Retire Read- / Write- counterparts and use a single record. --- .../io/weaviate/integration/DataITest.java | 53 +++++----- .../io/weaviate/integration/ORMITest.java | 4 +- .../weaviate/integration/PaginationITest.java | 13 +-- .../weaviate/integration/ReferencesITest.java | 16 +-- .../io/weaviate/integration/SearchITest.java | 63 +++++------ .../v1/api/collections/IReference.java | 2 +- .../v1/api/collections/ObjectMetadata.java | 54 ---------- .../v1/api/collections/WeaviateMetadata.java | 9 -- .../v1/api/collections/WeaviateObject.java | 34 ------ ...eObject.java => XWriteWeaviateObject.java} | 74 ++++++++----- .../api/collections/data/BatchReference.java | 8 +- .../collections/data/InsertManyRequest.java | 14 +-- .../collections/data/InsertObjectRequest.java | 17 +-- .../v1/api/collections/data/Reference.java | 12 +-- .../data/ReplaceObjectRequest.java | 10 +- .../collections/data/UpdateObjectRequest.java | 10 +- .../collections/data/WeaviateDataClient.java | 14 +-- .../data/WeaviateDataClientAsync.java | 14 +-- .../generate/GenerativeObject.java | 26 ++--- .../generate/GenerativeResponse.java | 2 + .../api/collections/pagination/AsyncPage.java | 18 ++-- .../pagination/AsyncPaginator.java | 10 +- .../pagination/CursorSpliterator.java | 14 +-- .../api/collections/pagination/Paginator.java | 10 +- .../query/AbstractQueryClient.java | 3 +- .../api/collections/query/QueryMetadata.java | 45 +------- .../collections/query/QueryObjectGrouped.java | 4 +- .../api/collections/query/QueryResponse.java | 100 +++++++++++------- .../collections/query/ReadWeaviateObject.java | 48 --------- .../query/WeaviateQueryClient.java | 5 +- .../query/WeaviateQueryClientAsync.java | 5 +- .../client6/v1/internal/json/JSON.java | 2 +- .../client6/v1/internal/json/JSONTest.java | 9 +- 33 files changed, 290 insertions(+), 432 deletions(-) delete mode 100644 src/main/java/io/weaviate/client6/v1/api/collections/ObjectMetadata.java delete mode 100644 src/main/java/io/weaviate/client6/v1/api/collections/WeaviateMetadata.java delete mode 100644 src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java rename src/main/java/io/weaviate/client6/v1/api/collections/{data/WriteWeaviateObject.java => XWriteWeaviateObject.java} (70%) delete mode 100644 src/main/java/io/weaviate/client6/v1/api/collections/query/ReadWeaviateObject.java diff --git a/src/it/java/io/weaviate/integration/DataITest.java b/src/it/java/io/weaviate/integration/DataITest.java index fa3f99f66..8fb5c82bd 100644 --- a/src/it/java/io/weaviate/integration/DataITest.java +++ b/src/it/java/io/weaviate/integration/DataITest.java @@ -21,16 +21,14 @@ import io.weaviate.client6.v1.api.collections.ReferenceProperty; import io.weaviate.client6.v1.api.collections.VectorConfig; import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.WeaviateObject; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.api.collections.data.BatchReference; import io.weaviate.client6.v1.api.collections.data.DeleteManyResponse; import io.weaviate.client6.v1.api.collections.data.Reference; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.Metadata; import io.weaviate.client6.v1.api.collections.query.Metadata.MetadataField; -import io.weaviate.client6.v1.api.collections.query.QueryMetadata; import io.weaviate.client6.v1.api.collections.query.QueryReference; -import io.weaviate.client6.v1.api.collections.query.ReadWeaviateObject; import io.weaviate.client6.v1.api.collections.tenants.Tenant; import io.weaviate.containers.Container; @@ -66,19 +64,19 @@ public void testCreateGetDelete() throws IOException { Assertions.assertThat(object) .as("object has correct properties").get() .satisfies(obj -> { - Assertions.assertThat(obj.queryMetadata().uuid()) + Assertions.assertThat(obj.uuid()) .as("object id").isEqualTo(id); - Assertions.assertThat(obj.queryMetadata().vectors().getSingle(VECTOR_INDEX)) + Assertions.assertThat(obj.vectors().getSingle(VECTOR_INDEX)) .containsExactly(vector); Assertions.assertThat(obj.properties()) .as("has expected properties") .containsEntry("name", "john doe"); - Assertions.assertThat(obj.queryMetadata().createdAt()) + Assertions.assertThat(obj.createdAt()) .as("createdAt").isNotNull(); - Assertions.assertThat(obj.queryMetadata().lastUpdatedAt()) + Assertions.assertThat(obj.lastUpdatedAt()) .as("lastUpdatedAt").isNotNull(); }); @@ -140,7 +138,7 @@ public void testBlobData() throws IOException { cat -> cat.returnProperties("img")); Assertions.assertThat(got).get() - .extracting(ReadWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) .extractingByKey("img").isEqualTo(ragdollPng); } @@ -189,10 +187,10 @@ public void testReferences_AddReplaceDelete() throws IOException { Assertions.assertThat(johnWithFriends).get() .as("friends after ADD") - .extracting(ReadWeaviateObject::references).extracting("hasFriend") - .asInstanceOf(InstanceOfAssertFactories.list(ReadWeaviateObject.class)) + .extracting(XWriteWeaviateObject::references).extracting("hasFriend") + .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) .hasSize(1) - .first().extracting(ReadWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .first().extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) .returns("albie", friend -> friend.get("name")); // Act: replace reference @@ -209,10 +207,10 @@ public void testReferences_AddReplaceDelete() throws IOException { Assertions.assertThat(johnWithFriends).get() .as("friends after REPLACE") - .extracting(ReadWeaviateObject::references).extracting("hasFriend") - .asInstanceOf(InstanceOfAssertFactories.list(ReadWeaviateObject.class)) + .extracting(XWriteWeaviateObject::references).extracting("hasFriend") + .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) .hasSize(1) - .first().extracting(ReadWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .first().extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) .returns("barbara", friend -> friend.get("name")); // Act: delete reference @@ -228,8 +226,8 @@ public void testReferences_AddReplaceDelete() throws IOException { Assertions.assertThat(johnWithFriends).get() .as("friends after DELETE") - .extracting(ReadWeaviateObject::references).extracting("hasFriend") - .asInstanceOf(InstanceOfAssertFactories.list(ReadWeaviateObject.class)) + .extracting(XWriteWeaviateObject::references).extracting("hasFriend") + .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) .isEmpty(); } @@ -255,7 +253,7 @@ public void testReplace() throws IOException { Assertions.assertThat(replacedIvanhoe).get() .as("has ONLY year property") - .extracting(ReadWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) .doesNotContain(Map.entry("title", "ivanhoe")) .contains(Map.entry("year", 1819L)); } @@ -305,21 +303,20 @@ public void testUpdate() throws IOException { .satisfies(book -> { Assertions.assertThat(book) .as("has both year and title property") - .extracting(ReadWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) .contains(Map.entry("title", "ivanhoe"), Map.entry("year", 1819L)); Assertions.assertThat(book) .as("has reference to Authors") - .extracting(ReadWeaviateObject::references, InstanceOfAssertFactories.MAP) - .extractingByKey("writtenBy", InstanceOfAssertFactories.list(ReadWeaviateObject.class)) + .extracting(XWriteWeaviateObject::references, InstanceOfAssertFactories.MAP) + .extractingByKey("writtenBy", InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) .first() - .extracting(ReadWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) .contains(Map.entry("name", "walter scott")); Assertions.assertThat(book) .as("has a vector") - .extracting(ReadWeaviateObject::queryMetadata) - .extracting(QueryMetadata::vectors) + .extracting(XWriteWeaviateObject::vectors) .returns(vector, Vectors::getDefaultSingle); }); } @@ -430,10 +427,10 @@ public void testReferenceAddMany() throws IOException { Assertions.assertThat(goodburgAirports).get() .as("Goodburg has 3 airports") - .extracting(ReadWeaviateObject::references) + .extracting(XWriteWeaviateObject::references) .extracting(references -> references.get("hasAirports"), - InstanceOfAssertFactories.list(ReadWeaviateObject.class)) - .extracting(ReadWeaviateObject::uuid) + InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) + .extracting(XWriteWeaviateObject::uuid) .contains(alpha, bravo, charlie); } @@ -511,7 +508,7 @@ public void testDataTypes() throws IOException { // Assert Assertions.assertThat(got).get() - .extracting(ReadWeaviateObject::properties) + .extracting(XWriteWeaviateObject::properties) .asInstanceOf(InstanceOfAssertFactories.map(String.class, Object.class)) // Most of PhoneNumber fields are only present on read and are null on write. .usingRecursiveComparison() @@ -583,6 +580,6 @@ public void test_multiTenant() throws IOException { var inserted = emails.data.insert(Map.of("subject", "McDonald's Xmas Bonanza")); // Assert - Assertions.assertThat(inserted).returns(johndoe, WeaviateObject::tenant); + Assertions.assertThat(inserted).returns(johndoe, XWriteWeaviateObject::tenant); } } diff --git a/src/it/java/io/weaviate/integration/ORMITest.java b/src/it/java/io/weaviate/integration/ORMITest.java index a5e0984ed..e957ff8c1 100644 --- a/src/it/java/io/weaviate/integration/ORMITest.java +++ b/src/it/java/io/weaviate/integration/ORMITest.java @@ -17,10 +17,10 @@ import io.weaviate.client6.v1.api.collections.CollectionConfig; import io.weaviate.client6.v1.api.collections.GeoCoordinates; import io.weaviate.client6.v1.api.collections.PhoneNumber; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.api.collections.annotations.Collection; import io.weaviate.client6.v1.api.collections.annotations.Property; import io.weaviate.client6.v1.api.collections.data.InsertManyResponse.InsertObject; -import io.weaviate.client6.v1.api.collections.query.ReadWeaviateObject; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.containers.Container; @@ -358,7 +358,7 @@ public void test_partialScan() throws IOException { // Assert Assertions.assertThat(got).get() - .extracting(ReadWeaviateObject::properties) + .extracting(XWriteWeaviateObject::properties) .returns("Dystopia", Song::title) .returns(null, Song::album) .returns(0, Song::year) diff --git a/src/it/java/io/weaviate/integration/PaginationITest.java b/src/it/java/io/weaviate/integration/PaginationITest.java index 16901e901..abde63ca6 100644 --- a/src/it/java/io/weaviate/integration/PaginationITest.java +++ b/src/it/java/io/weaviate/integration/PaginationITest.java @@ -18,10 +18,9 @@ import io.weaviate.client6.v1.api.WeaviateClient; import io.weaviate.client6.v1.api.WeaviateException; import io.weaviate.client6.v1.api.collections.Property; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.api.collections.pagination.PaginationException; import io.weaviate.client6.v1.api.collections.query.Metadata; -import io.weaviate.client6.v1.api.collections.query.QueryMetadata; -import io.weaviate.client6.v1.api.collections.query.ReadWeaviateObject; import io.weaviate.containers.Container; public class PaginationITest extends ConcurrentTest { @@ -46,8 +45,7 @@ public void testIterateAll() throws IOException { var allThings = things.paginate(); // Act: stream - var gotStream = allThings.stream() - .map(ReadWeaviateObject::queryMetadata).map(QueryMetadata::uuid).toList(); + var gotStream = allThings.stream().map(XWriteWeaviateObject::uuid).toList(); // Assert Assertions.assertThat(gotStream) @@ -58,7 +56,7 @@ public void testIterateAll() throws IOException { // Act: for-loop var gotLoop = new ArrayList(); for (var thing : allThings) { - gotLoop.add(thing.queryMetadata().uuid()); + gotLoop.add(thing.uuid()); } // Assert @@ -89,7 +87,7 @@ public void testResumePagination() throws IOException { // Iterate over first 5 objects String lastId = things.paginate(p -> p.pageSize(5)).stream() - .limit(5).map(thing -> thing.queryMetadata().uuid()) + .limit(5).map(thing -> thing.uuid()) .reduce((prev, next) -> next).get(); // Act @@ -126,8 +124,7 @@ public void testWithQueryOptions() throws IOException { .as("uuid=" + thing.uuid()) .doesNotContainKey("dont_fetch"); - Assertions.assertThat(thing.queryMetadata().createdAt()) - .isNotNull(); + Assertions.assertThat(thing.createdAt()).isNotNull(); } } diff --git a/src/it/java/io/weaviate/integration/ReferencesITest.java b/src/it/java/io/weaviate/integration/ReferencesITest.java index c8b51acc3..418dbeb35 100644 --- a/src/it/java/io/weaviate/integration/ReferencesITest.java +++ b/src/it/java/io/weaviate/integration/ReferencesITest.java @@ -13,9 +13,9 @@ import io.weaviate.client6.v1.api.WeaviateClient; import io.weaviate.client6.v1.api.collections.Property; import io.weaviate.client6.v1.api.collections.ReferenceProperty; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.api.collections.data.Reference; import io.weaviate.client6.v1.api.collections.query.QueryReference; -import io.weaviate.client6.v1.api.collections.query.ReadWeaviateObject; import io.weaviate.containers.Container; /** @@ -99,9 +99,9 @@ public void testReferences() throws IOException { .as("Artists: fetch by id including hasAwards references") // Cast references to Map> - .extracting(ReadWeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) + .extracting(XWriteWeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) .as("hasAwards object reference").extractingByKey("hasAwards") - .asInstanceOf(InstanceOfAssertFactories.list(ReadWeaviateObject.class)) + .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) .extracting(object -> object.uuid()) .containsOnly( @@ -166,19 +166,19 @@ public void testNestedReferences() throws IOException { .as("Artists: fetch by id including nested references") // Cast references to Map> - .extracting(ReadWeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) + .extracting(XWriteWeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) .as("hasAwards object reference").extractingByKey("hasAwards") - .asInstanceOf(InstanceOfAssertFactories.list(ReadWeaviateObject.class)) + .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) .hasSize(1).allSatisfy(award -> Assertions.assertThat(award) .returns(grammy_1.uuid(), grammy -> grammy.uuid()) // Cast references to Map> - .extracting(ReadWeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) + .extracting(XWriteWeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) .as("presentedBy object reference").extractingByKey("presentedBy") - .asInstanceOf(InstanceOfAssertFactories.list(ReadWeaviateObject.class)) + .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) - .hasSize(1).extracting(ReadWeaviateObject::properties) + .hasSize(1).extracting(XWriteWeaviateObject::properties) .allSatisfy(properties -> Assertions.assertThat(properties) .asInstanceOf(InstanceOfAssertFactories.map(String.class, Object.class)) .containsEntry("ceo", "Harvy Mason"))); diff --git a/src/it/java/io/weaviate/integration/SearchITest.java b/src/it/java/io/weaviate/integration/SearchITest.java index ecf9a97db..bb0647d2b 100644 --- a/src/it/java/io/weaviate/integration/SearchITest.java +++ b/src/it/java/io/weaviate/integration/SearchITest.java @@ -27,8 +27,7 @@ import io.weaviate.client6.v1.api.collections.Reranker; import io.weaviate.client6.v1.api.collections.VectorConfig; import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.WeaviateMetadata; -import io.weaviate.client6.v1.api.collections.WeaviateObject; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.api.collections.data.Reference; import io.weaviate.client6.v1.api.collections.generate.GenerativeObject; import io.weaviate.client6.v1.api.collections.generate.TaskOutput; @@ -36,9 +35,7 @@ import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.GroupBy; import io.weaviate.client6.v1.api.collections.query.Metadata; -import io.weaviate.client6.v1.api.collections.query.QueryMetadata; import io.weaviate.client6.v1.api.collections.query.QueryResponseGroup; -import io.weaviate.client6.v1.api.collections.query.ReadWeaviateObject; import io.weaviate.client6.v1.api.collections.query.Rerank; import io.weaviate.client6.v1.api.collections.query.SortBy; import io.weaviate.client6.v1.api.collections.query.Target; @@ -172,7 +169,7 @@ public void testNearText() throws IOException { .returnProperties("title")); Assertions.assertThat(result.objects()).hasSize(2) - .extracting(ReadWeaviateObject::properties).allSatisfy( + .extracting(XWriteWeaviateObject::properties).allSatisfy( properties -> Assertions.assertThat(properties) .allSatisfy((_k, v) -> Assertions.assertThat((String) v).contains("Jungle"))); } @@ -235,7 +232,7 @@ public void testNearImage() throws IOException { opt -> opt.returnProperties("breed")); Assertions.assertThat(got.objects()).hasSize(1).first() - .extracting(ReadWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) .extractingByKey("breed").isEqualTo("ragdoll"); } @@ -265,7 +262,7 @@ public void testFetchObjectsWithFilters() throws IOException { Filter.property("size").lt(6))))); Assertions.assertThat(got.objects()) - .extracting(hat -> hat.queryMetadata().uuid()) + .extracting(XWriteWeaviateObject::uuid) .containsOnly( redHat.uuid(), greenHat.uuid(), @@ -294,7 +291,7 @@ public void testFetchObjectsWithSort() throws Exception { Assertions.assertThat(asc.objects()) .as("value asc") .hasSize(3) - .extracting(ReadWeaviateObject::properties) + .extracting(XWriteWeaviateObject::properties) .extracting(object -> object.get("value")) .containsExactly(1L, 2L, 3L); @@ -305,7 +302,7 @@ public void testFetchObjectsWithSort() throws Exception { Assertions.assertThat(desc.objects()) .as("value desc") .hasSize(3) - .extracting(ReadWeaviateObject::properties) + .extracting(XWriteWeaviateObject::properties) .extracting(object -> object.get("value")) .containsExactly(3L, 2L, 1L); } @@ -331,7 +328,7 @@ public void testBm25() throws IOException, InterruptedException, ExecutionExcept Assertions.assertThat(dollarWorlds.objects()) .hasSize(1) - .extracting(ReadWeaviateObject::queryMetadata).extracting(QueryMetadata::uuid) + .extracting(XWriteWeaviateObject::uuid) .containsOnly(want.uuid()); } @@ -363,7 +360,7 @@ public void testBm25_async() throws Exception, InterruptedException, ExecutionEx Assertions.assertThat(dollarWorlds.objects()) .hasSize(1) - .extracting(ReadWeaviateObject::queryMetadata).extracting(QueryMetadata::uuid) + .extracting(XWriteWeaviateObject::uuid) .containsOnly(want.uuid()); } } @@ -393,7 +390,7 @@ public void testNearObject() throws IOException { // Assert Assertions.assertThat(terrestrial.objects()) .hasSize(1) - .extracting(ReadWeaviateObject::queryMetadata).extracting(WeaviateMetadata::uuid) + .extracting(XWriteWeaviateObject::uuid) .containsOnly(lion.uuid()); } @@ -420,7 +417,7 @@ public void testHybrid() throws IOException { // Assert Assertions.assertThat(winterSport.objects()) .hasSize(1) - .extracting(ReadWeaviateObject::queryMetadata).extracting(WeaviateMetadata::uuid) + .extracting(XWriteWeaviateObject::uuid) .containsOnly(skiing.uuid()); var first = winterSport.objects().get(0); @@ -490,7 +487,7 @@ public void test_includeVectors() throws IOException { // Assert Assertions.assertThat(got).get() - .extracting(ReadWeaviateObject::vectors) + .extracting(XWriteWeaviateObject::vectors) .returns(true, v -> v.contains("v1")) .returns(true, v -> v.contains("v2")) .returns(false, v -> v.contains("v3")); @@ -517,25 +514,23 @@ public void testMetadataAll() throws IOException { .returnMetadata(Metadata.ALL)); // Assert - var metadataHybrid = Assertions.assertThat(gotHybrid.objects()) - .hasSize(1) - .extracting(ReadWeaviateObject::queryMetadata) - .first().actual(); + var hybridObject = Assertions.assertThat(gotHybrid.objects()) + .hasSize(1).first().actual(); + var hybridMetadata = hybridObject.queryMetadata(); - Assertions.assertThat(metadataHybrid.uuid()).as("uuid").isNotNull().isEqualTo(frisbee.uuid()); - Assertions.assertThat(metadataHybrid.createdAt()).as("createdAt").isNotNull(); - Assertions.assertThat(metadataHybrid.lastUpdatedAt()).as("lastUpdateTimeUnix").isNotNull(); - Assertions.assertThat(metadataHybrid.score()).as("score").isNotNull(); - Assertions.assertThat(metadataHybrid.explainScore()).as("explainScore").isNotNull().isNotEqualTo(""); + Assertions.assertThat(hybridObject.uuid()).as("uuid").isNotNull().isEqualTo(frisbee.uuid()); + Assertions.assertThat(hybridObject.createdAt()).as("createdAt").isNotNull(); + Assertions.assertThat(hybridObject.lastUpdatedAt()).as("lastUpdateTimeUnix").isNotNull(); + Assertions.assertThat(hybridMetadata.score()).as("score").isNotNull(); + Assertions.assertThat(hybridMetadata.explainScore()).as("explainScore").isNotNull().isNotEqualTo(""); - var metadataNearText = Assertions.assertThat(gotNearText.objects()) - .hasSize(1) - .extracting(ReadWeaviateObject::queryMetadata) - .first().actual(); + var nearTextObject = Assertions.assertThat(gotNearText.objects()) + .hasSize(1).first().actual(); + var metadataNearText = nearTextObject.queryMetadata(); - Assertions.assertThat(metadataNearText.uuid()).as("uuid").isNotNull().isEqualTo(frisbee.uuid()); - Assertions.assertThat(metadataNearText.createdAt()).as("createdAt").isNotNull(); - Assertions.assertThat(metadataNearText.lastUpdatedAt()).as("lastUpdateTimeUnix").isNotNull(); + Assertions.assertThat(nearTextObject.uuid()).as("uuid").isNotNull().isEqualTo(frisbee.uuid()); + Assertions.assertThat(nearTextObject.createdAt()).as("createdAt").isNotNull(); + Assertions.assertThat(nearTextObject.lastUpdatedAt()).as("lastUpdateTimeUnix").isNotNull(); Assertions.assertThat(metadataNearText.distance()).as("distance").isNotNull(); Assertions.assertThat(metadataNearText.certainty()).as("certainty").isNotNull(); } @@ -558,7 +553,7 @@ public void testNearVector_targetVectors() throws IOException { Vectors.of("v2d", new float[][] { { 1, 2, 3 }, { 1, 2, 3 } }))); var thing456 = things.data.insertMany(List.of( - WeaviateObject.write(thing -> thing + XWriteWeaviateObject.of(thing -> thing .vectors( Vectors.of("v1d", new float[] { 4, 5, 6 }), Vectors.of("v2d", new float[][] { { 4, 5, 6 }, { 4, 5, 6 } }))))); @@ -570,7 +565,7 @@ public void testNearVector_targetVectors() throws IOException { q -> q.limit(1)); Assertions.assertThat(got123.objects()) .as("search v1d") - .hasSize(1).extracting(ReadWeaviateObject::uuid) + .hasSize(1).extracting(XWriteWeaviateObject::uuid) .containsExactly(thing123.uuid()); var got456 = things.query.nearVector( @@ -578,7 +573,7 @@ public void testNearVector_targetVectors() throws IOException { q -> q.limit(1)); Assertions.assertThat(got456.objects()) .as("search v2d") - .hasSize(1).extracting(ReadWeaviateObject::uuid) + .hasSize(1).extracting(XWriteWeaviateObject::uuid) .containsExactly(thing456.uuids().get(0)); } @@ -760,7 +755,7 @@ public void test_maxGrpcMessageSize() throws Exception { .vectorConfig(VectorConfig.selfProvided())); final var vector = randomVector(5000, -.01f, .01f); - final WeaviateObject> hugeObject = WeaviateObject.write( + final XWriteWeaviateObject> hugeObject = XWriteWeaviateObject.of( obj -> obj.vectors(Vectors.of(vector))); Assertions.assertThatThrownBy(() -> { diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java index 138843cf6..e0aa0911f 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java @@ -7,5 +7,5 @@ public interface IReference { String collection(); - WeaviateObject> asWeaviateObject(); + XWriteWeaviateObject> asWeaviateObject(); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/ObjectMetadata.java b/src/main/java/io/weaviate/client6/v1/api/collections/ObjectMetadata.java deleted file mode 100644 index e467644c7..000000000 --- a/src/main/java/io/weaviate/client6/v1/api/collections/ObjectMetadata.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.weaviate.client6.v1.api.collections; - -import java.util.UUID; -import java.util.function.Function; - -import com.google.gson.annotations.SerializedName; - -import io.weaviate.client6.v1.internal.ObjectBuilder; - -public record ObjectMetadata( - @SerializedName("id") String uuid, - @SerializedName("vectors") Vectors vectors, - @SerializedName("creationTimeUnix") Long createdAt, - @SerializedName("lastUpdateTimeUnix") Long lastUpdatedAt) implements WeaviateMetadata { - - public ObjectMetadata(Builder builder) { - this(builder.uuid, builder.vectors, null, null); - } - - public static ObjectMetadata of() { - return of(ObjectBuilder.identity()); - } - - public static ObjectMetadata of(Function> fn) { - return fn.apply(new Builder()).build(); - } - - public static class Builder implements ObjectBuilder { - private String uuid = UUID.randomUUID().toString(); - private Vectors vectors; - - /** Assign a custom UUID for the object. */ - public Builder uuid(UUID uuid) { - return uuid(uuid.toString()); - } - - /** Assign a custom UUID for the object. */ - public Builder uuid(String uuid) { - this.uuid = uuid; - return this; - } - - /** Attach custom vectors to the object.. */ - public Builder vectors(Vectors... vectors) { - this.vectors = new Vectors(vectors); - return this; - } - - @Override - public ObjectMetadata build() { - return new ObjectMetadata(this); - } - } -} diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateMetadata.java b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateMetadata.java deleted file mode 100644 index a4b8cc05a..000000000 --- a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateMetadata.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.weaviate.client6.v1.api.collections; - -public interface WeaviateMetadata { - /** Object's UUID. */ - String uuid(); - - /** Object's associated vector embeddings. */ - Vectors vectors(); -} diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java deleted file mode 100644 index f9f98e312..000000000 --- a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.weaviate.client6.v1.api.collections; - -import java.util.List; -import java.util.Map; -import java.util.function.Function; - -import io.weaviate.client6.v1.api.collections.data.WriteWeaviateObject; -import io.weaviate.client6.v1.api.collections.query.QueryMetadata; -import io.weaviate.client6.v1.internal.ObjectBuilder; - -public interface WeaviateObject { - String uuid(); - - String collection(); - - Vectors vectors(); - - String tenant(); - - PropertiesT properties(); - - Map> references(); - - Long createdAt(); - - Long lastUpdatedAt(); - - QueryMetadata queryMetadata(); - - public static WeaviateObject write( - Function, ObjectBuilder>> fn) { - return fn.apply(new WriteWeaviateObject.Builder<>()).build(); - } -} diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/XWriteWeaviateObject.java similarity index 70% rename from src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java rename to src/main/java/io/weaviate/client6/v1/api/collections/XWriteWeaviateObject.java index 4538fd48d..e3e079d09 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WriteWeaviateObject.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/XWriteWeaviateObject.java @@ -1,4 +1,4 @@ -package io.weaviate.client6.v1.api.collections.data; +package io.weaviate.client6.v1.api.collections; import java.io.IOException; import java.lang.reflect.ParameterizedType; @@ -21,13 +21,11 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; -import io.weaviate.client6.v1.api.collections.IReference; -import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.WeaviateObject; +import io.weaviate.client6.v1.api.collections.data.Reference; import io.weaviate.client6.v1.api.collections.query.QueryMetadata; import io.weaviate.client6.v1.internal.ObjectBuilder; -public record WriteWeaviateObject( +public record XWriteWeaviateObject( @SerializedName("id") String uuid, @SerializedName("class") String collection, @SerializedName("tenant") String tenant, @@ -36,31 +34,59 @@ public record WriteWeaviateObject( @SerializedName("creationTimeUnix") Long createdAt, @SerializedName("lastUpdateTimeUnix") Long lastUpdatedAt, - Map> references) implements WeaviateObject { - + QueryMetadata queryMetadata, + Map> references) implements IReference { + + /** + * Cast {@code this} into an instance of {@link IWeaviateObject>}. Useful when working with references retrieved in a query. + * + *
{@code
+   *  var metalSongs = songs.query.fetchObjects(q -> q
+   *    .filters(Filter.property("genres").containsAll("metal")
+   *    .returnReferences(QueryReference.multi("performedBy"));
+   *
+   *  metalSongs.objects().forEach(song -> {
+   *    var songName = song.properties().get("name");
+   *    song.references().forEach(ref -> {
+   *      var artistName = ref.asWeaviateObject().properties().get("artistName");
+   *      System.out.printf("%s is performed by %s", songName, artistName);
+   *    });
+   *  });
+   * }
+ * + *

+ * Only call this method on objects returned from methods under {@code .query} + * namespace, as insert-references do not implement this interface. + * + * @throws IllegalStateException if reference object is an instance of + * {@link Reference}. See usage guidelines above. + */ + @SuppressWarnings("unchecked") @Override - public QueryMetadata queryMetadata() { - return new QueryMetadata(uuid, vectors, createdAt, lastUpdatedAt, null, null, null, null); + public XWriteWeaviateObject> asWeaviateObject() { + return (XWriteWeaviateObject>) this; } - public static WriteWeaviateObject of( - Function, ObjectBuilder>> fn) { + public static XWriteWeaviateObject of( + Function, ObjectBuilder>> fn) { return fn.apply(new Builder<>()).build(); } - public WriteWeaviateObject(Builder builder) { + public XWriteWeaviateObject(Builder builder) { this( builder.uuid, - null, // collection name is set on insert - builder.tenant, + null, // collection name is derived from CollectionHandle + builder.tenant, // tenant MAY be derived from CollectionHandle builder.properties, builder.vectors, - null, // creationTimeUnix is read-only - null, // lastUpdateTimeUnix is read-only + null, // createdAt is read-only + null, // lastUpdatedAt is read-only + null, // queryMetadata is read-only builder.references); } - public static class Builder implements ObjectBuilder> { + public static class Builder implements ObjectBuilder> { /** * The server should be providing default UUIDs, but it does not do that * during batch inserts and we have to provide our own. @@ -121,8 +147,8 @@ public Builder vectors(Vectors... vectors) { } @Override - public WriteWeaviateObject build() { - return new WriteWeaviateObject<>(this); + public XWriteWeaviateObject build() { + return new XWriteWeaviateObject<>(this); } } @@ -134,7 +160,7 @@ public static enum CustomTypeAdapterFactory implements TypeAdapterFactory { public TypeAdapter create(Gson gson, TypeToken typeToken) { var type = typeToken.getType(); var rawType = typeToken.getRawType(); - if (rawType != WriteWeaviateObject.class || + if (rawType != XWriteWeaviateObject.class || !(type instanceof ParameterizedType parameterized) || parameterized.getActualTypeArguments().length != 1) { return null; @@ -143,15 +169,15 @@ public TypeAdapter create(Gson gson, TypeToken typeToken) { var typeParams = parameterized.getActualTypeArguments(); final var propertiesType = typeParams[0]; - final var delegate = (TypeAdapter>) gson + final var delegate = (TypeAdapter>) gson .getDelegateAdapter(this, typeToken); final var propertiesAdapter = (TypeAdapter) gson.getAdapter(TypeToken.get(propertiesType)); final var referencesAdapter = gson.getAdapter(Reference.class); - return (TypeAdapter) new TypeAdapter>() { + return (TypeAdapter) new TypeAdapter>() { @Override - public void write(JsonWriter out, WriteWeaviateObject value) throws IOException { + public void write(JsonWriter out, XWriteWeaviateObject value) throws IOException { var json = delegate.toJsonTree(value).getAsJsonObject(); var properties = value.properties() != null ? propertiesAdapter.toJsonTree(value.properties()).getAsJsonObject() @@ -174,7 +200,7 @@ public void write(JsonWriter out, WriteWeaviateObject value) throws IOExcepti } @Override - public WriteWeaviateObject read(JsonReader in) throws IOException { + public XWriteWeaviateObject read(JsonReader in) throws IOException { var json = JsonParser.parseReader(in).getAsJsonObject(); var jsonProperties = json.get("properties").getAsJsonObject(); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java index 9854a57bc..616d564eb 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java @@ -7,12 +7,12 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; -import io.weaviate.client6.v1.api.collections.WeaviateObject; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; public record BatchReference(String fromCollection, String fromProperty, String fromUuid, Reference reference) { - public static BatchReference[] objects(WeaviateObject fromObject, String fromProperty, - WeaviateObject... toObjects) { + public static BatchReference[] objects(XWriteWeaviateObject fromObject, String fromProperty, + XWriteWeaviateObject... toObjects) { return Arrays.stream(toObjects) .map(to -> new BatchReference( fromObject.collection(), fromProperty, fromObject.uuid(), @@ -20,7 +20,7 @@ public static BatchReference[] objects(WeaviateObject fromObject, String fromPro .toArray(BatchReference[]::new); } - public static BatchReference[] uuids(WeaviateObject fromObject, String fromProperty, + public static BatchReference[] uuids(XWriteWeaviateObject fromObject, String fromProperty, String... toUuids) { return Arrays.stream(toUuids) .map(to -> new BatchReference( diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java index b471be340..4c31d1aff 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java @@ -10,7 +10,7 @@ import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; import io.weaviate.client6.v1.api.collections.GeoCoordinates; import io.weaviate.client6.v1.api.collections.PhoneNumber; -import io.weaviate.client6.v1.api.collections.WeaviateObject; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.internal.MapUtil; import io.weaviate.client6.v1.internal.grpc.ByteStringUtil; import io.weaviate.client6.v1.internal.grpc.Rpc; @@ -21,10 +21,10 @@ import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoBatch; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; -public record InsertManyRequest(List> objects) { +public record InsertManyRequest(List> objects) { @SafeVarargs - public InsertManyRequest(WeaviateObject... objects) { + public InsertManyRequest(XWriteWeaviateObject... objects) { this(Arrays.asList(objects)); } @@ -32,13 +32,13 @@ public InsertManyRequest(WeaviateObject... objects) { @SafeVarargs public static final InsertManyRequest of(PropertiesT... properties) { var objects = Arrays.stream(properties) - .map(p -> (WeaviateObject) WeaviateObject.write(obj -> obj.properties(p))) + .map(p -> (XWriteWeaviateObject) XWriteWeaviateObject.of(obj -> obj.properties(p))) .toList(); return new InsertManyRequest<>(objects); } public static Rpc, WeaviateProtoBatch.BatchObjectsRequest, InsertManyResponse, WeaviateProtoBatch.BatchObjectsReply> rpc( - List> insertObjects, + List> insertObjects, CollectionDescriptor collection, CollectionHandleDefaults defaults) { return Rpc.insert( @@ -47,7 +47,7 @@ public static Rpc, WeaviateProtoBat var batch = request.objects.stream().map(obj -> { var batchObject = WeaviateProtoBatch.BatchObject.newBuilder(); - buildObject(batchObject, (WriteWeaviateObject) obj, collection, defaults); + buildObject(batchObject, obj, collection, defaults); return batchObject.build(); }).toList(); @@ -93,7 +93,7 @@ public static Rpc, WeaviateProtoBat } public static void buildObject(WeaviateProtoBatch.BatchObject.Builder object, - WriteWeaviateObject insert, + XWriteWeaviateObject insert, CollectionDescriptor collection, CollectionHandleDefaults defaults) { object.setCollection(collection.collectionName()); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java index 38b0c63de..95aeb600c 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java @@ -7,22 +7,22 @@ import com.google.gson.reflect.TypeToken; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.WeaviateObject; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.json.JSON; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; import io.weaviate.client6.v1.internal.rest.Endpoint; import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; -public record InsertObjectRequest(WeaviateObject object) { +public record InsertObjectRequest(XWriteWeaviateObject object) { @SuppressWarnings("unchecked") - public static final Endpoint, WeaviateObject> endpoint( + public static final Endpoint, XWriteWeaviateObject> endpoint( CollectionDescriptor collection, CollectionHandleDefaults defaults) { - final var typeToken = (TypeToken>) TypeToken - .getParameterized(WriteWeaviateObject.class, collection.typeToken().getType()); + final var typeToken = (TypeToken>) TypeToken + .getParameterized(XWriteWeaviateObject.class, collection.typeToken().getType()); return new SimpleEndpoint<>( request -> "POST", @@ -31,7 +31,7 @@ public static final Endpoint, Wea ? Map.of("consistency_level", defaults.consistencyLevel()) : Collections.emptyMap(), request -> JSON.serialize( - new WriteWeaviateObject<>( + new XWriteWeaviateObject<>( request.object.uuid(), collection.collectionName(), defaults.tenant(), @@ -39,6 +39,7 @@ public static final Endpoint, Wea request.object.vectors(), request.object.createdAt(), request.object.lastUpdatedAt(), + null, // no queryMetadata no insert request.object.references()), typeToken), (statusCode, response) -> JSON.deserialize(response, typeToken)); @@ -50,7 +51,7 @@ static InsertObjectRequest of(PropertiesT properties) static InsertObjectRequest of( PropertiesT properties, - Function, ObjectBuilder>> fn) { - return new InsertObjectRequest<>(WriteWeaviateObject.of(ObjectBuilder.partial(fn, b -> b.properties(properties)))); + Function, ObjectBuilder>> fn) { + return new InsertObjectRequest<>(XWriteWeaviateObject.of(ObjectBuilder.partial(fn, b -> b.properties(properties)))); } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java index 135859fae..bd3808652 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java @@ -11,7 +11,7 @@ import com.google.gson.stream.JsonWriter; import io.weaviate.client6.v1.api.collections.IReference; -import io.weaviate.client6.v1.api.collections.WeaviateObject; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; public record Reference(String collection, List uuids) implements IReference { @@ -21,7 +21,7 @@ public String uuid() { } @Override - public WeaviateObject> asWeaviateObject() { + public XWriteWeaviateObject> asWeaviateObject() { throw new IllegalStateException("cannot convert to WeaviateObject"); } @@ -40,13 +40,13 @@ public static Reference uuids(String... uuids) { return new Reference(null, Arrays.asList(uuids)); } - /** Create references to single {@link WeaviateObject}. */ - public static Reference object(WeaviateObject object) { + /** Create references to single {@link XWriteWeaviateObject}. */ + public static Reference object(XWriteWeaviateObject object) { return new Reference(object.collection(), object.uuid()); } - /** Create references to multiple {@link WeaviateObject}. */ - public static Reference[] objects(WeaviateObject... objects) { + /** Create references to multiple {@link XWriteWeaviateObject}. */ + public static Reference[] objects(XWriteWeaviateObject... objects) { return Arrays.stream(objects) .map(o -> new Reference(o.collection(), o.uuid())) .toArray(Reference[]::new); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java index d3d1ec31f..6fb47d8eb 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java @@ -8,19 +8,20 @@ import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; import io.weaviate.client6.v1.api.collections.Vectors; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.json.JSON; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; import io.weaviate.client6.v1.internal.rest.Endpoint; import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; -public record ReplaceObjectRequest(WriteWeaviateObject object) { +public record ReplaceObjectRequest(XWriteWeaviateObject object) { static final Endpoint, Void> endpoint( CollectionDescriptor collection, CollectionHandleDefaults defaults) { - final var typeToken = TypeToken.getParameterized(WriteWeaviateObject.class, collection.typeToken().getType()); + final var typeToken = TypeToken.getParameterized(XWriteWeaviateObject.class, collection.typeToken().getType()); return SimpleEndpoint.sideEffect( request -> "PUT", @@ -29,7 +30,7 @@ static final Endpoint, Void> end ? Map.of("consistency_level", defaults.consistencyLevel()) : Collections.emptyMap(), request -> JSON.serialize( - new WriteWeaviateObject<>( + new XWriteWeaviateObject<>( request.object.uuid(), collection.collectionName(), defaults.tenant(), @@ -37,6 +38,7 @@ static final Endpoint, Void> end request.object.vectors(), request.object.createdAt(), request.object.lastUpdatedAt(), + null, request.object.references()), typeToken)); } @@ -52,7 +54,7 @@ public ReplaceObjectRequest(Builder builder) { } public static class Builder implements ObjectBuilder> { - private final WriteWeaviateObject.Builder object = new WriteWeaviateObject.Builder<>(); + private final XWriteWeaviateObject.Builder object = new XWriteWeaviateObject.Builder<>(); public Builder(String uuid) { this.object.uuid(uuid); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java index 3368468a7..4ca108c6d 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java @@ -8,19 +8,20 @@ import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; import io.weaviate.client6.v1.api.collections.Vectors; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.json.JSON; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; import io.weaviate.client6.v1.internal.rest.Endpoint; import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; -public record UpdateObjectRequest(WriteWeaviateObject object) { +public record UpdateObjectRequest(XWriteWeaviateObject object) { static final Endpoint, Void> endpoint( CollectionDescriptor collection, CollectionHandleDefaults defaults) { - final var typeToken = TypeToken.getParameterized(WriteWeaviateObject.class, collection.typeToken().getType()); + final var typeToken = TypeToken.getParameterized(XWriteWeaviateObject.class, collection.typeToken().getType()); return SimpleEndpoint.sideEffect( request -> "PATCH", @@ -29,7 +30,7 @@ static final Endpoint, Void> endp ? Map.of("consistency_level", defaults.consistencyLevel()) : Collections.emptyMap(), request -> JSON.serialize( - new WriteWeaviateObject<>( + new XWriteWeaviateObject<>( request.object.uuid(), collection.collectionName(), defaults.tenant(), @@ -37,6 +38,7 @@ static final Endpoint, Void> endp request.object.vectors(), request.object.createdAt(), request.object.lastUpdatedAt(), + null, request.object.references()), typeToken)); } @@ -51,7 +53,7 @@ public UpdateObjectRequest(Builder builder) { } public static class Builder implements ObjectBuilder> { - private final WriteWeaviateObject.Builder object = new WriteWeaviateObject.Builder<>(); + private final XWriteWeaviateObject.Builder object = new XWriteWeaviateObject.Builder<>(); public Builder(String uuid) { this.object.uuid(uuid); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java index 64272439f..3f8c0aac5 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java @@ -6,7 +6,7 @@ import java.util.function.Function; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.WeaviateObject; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.FilterOperand; import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClient; @@ -44,18 +44,18 @@ public WeaviateDataClient(WeaviateDataClient c, CollectionHandleDef this.defaults = defaults; } - public WeaviateObject insert(PropertiesT properties) throws IOException { + public XWriteWeaviateObject insert(PropertiesT properties) throws IOException { return insert(InsertObjectRequest.of(properties)); } - public WeaviateObject insert( + public XWriteWeaviateObject insert( PropertiesT properties, - Function, ObjectBuilder>> fn) + Function, ObjectBuilder>> fn) throws IOException { return insert(InsertObjectRequest.of(properties, fn)); } - public WeaviateObject insert(InsertObjectRequest request) + public XWriteWeaviateObject insert(InsertObjectRequest request) throws IOException { return this.restTransport.performRequest(request, InsertObjectRequest.endpoint(collection, defaults)); } @@ -65,12 +65,12 @@ public final InsertManyResponse insertMany(PropertiesT... objects) { return insertMany(InsertManyRequest.of(objects)); } - public InsertManyResponse insertMany(List> objects) { + public InsertManyResponse insertMany(List> objects) { return insertMany(new InsertManyRequest<>(objects)); } @SafeVarargs - public final InsertManyResponse insertMany(WeaviateObject... objects) { + public final InsertManyResponse insertMany(XWriteWeaviateObject... objects) { return insertMany(Arrays.asList(objects)); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java index 58a94ad7d..864e72a7f 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java @@ -8,7 +8,7 @@ import java.util.function.Function; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.WeaviateObject; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.FilterOperand; import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClientAsync; @@ -46,17 +46,17 @@ public WeaviateDataClientAsync(WeaviateDataClientAsync c, Collectio this.defaults = defaults; } - public CompletableFuture> insert(PropertiesT properties) { + public CompletableFuture> insert(PropertiesT properties) { return insert(InsertObjectRequest.of(properties)); } - public CompletableFuture> insert( + public CompletableFuture> insert( PropertiesT properties, - Function, ObjectBuilder>> fn) { + Function, ObjectBuilder>> fn) { return insert(InsertObjectRequest.of(properties, fn)); } - public CompletableFuture> insert( + public CompletableFuture> insert( InsertObjectRequest request) { return this.restTransport.performRequestAsync(request, InsertObjectRequest.endpoint(collection, defaults)); } @@ -67,11 +67,11 @@ public final CompletableFuture insertMany(PropertiesT... obj } @SafeVarargs - public final CompletableFuture insertMany(WeaviateObject... objects) { + public final CompletableFuture insertMany(XWriteWeaviateObject... objects) { return insertMany(Arrays.asList(objects)); } - public CompletableFuture insertMany(List> objects) { + public CompletableFuture insertMany(List> objects) { return insertMany(new InsertManyRequest<>(objects)); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeObject.java index 79f735b3c..b0e95dcc1 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeObject.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeObject.java @@ -4,20 +4,14 @@ import io.weaviate.client6.v1.api.collections.query.QueryMetadata; public record GenerativeObject( - /** Object properties. */ - PropertiesT properties, - /** Object metadata. */ - QueryMetadata metadata, - /** Generative task output. */ - TaskOutput generative) { - - /** Shorthand for accessing objects's UUID from metadata. */ - public String uuid() { - return metadata.uuid(); - } - - /** Shorthand for accessing objects's vectors from metadata. */ - public Vectors vectors() { - return metadata.vectors(); - } + /** Object UUID. */ + String uuid, + /** Retrieved object vectors. */ + Vectors vectors, + /** Object properties. */ + PropertiesT properties, + /** Object metadata. */ + QueryMetadata metadata, + /** Generative task output. */ + TaskOutput generative) { } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponse.java b/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponse.java index f762ba185..e4db43a9d 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponse.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponse.java @@ -40,6 +40,8 @@ static GenerativeResponse unmarshal( generative = GenerativeResponse.unmarshalTaskOutput(result.getGenerative()); } return new GenerativeObject<>( + object.uuid(), + object.vectors(), object.properties(), object.queryMetadata(), generative); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPage.java b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPage.java index 0e7046fbe..e23a6ad0e 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPage.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPage.java @@ -7,31 +7,31 @@ import java.util.concurrent.CompletableFuture; import java.util.function.BiFunction; -import io.weaviate.client6.v1.api.collections.query.ReadWeaviateObject; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; -public final class AsyncPage implements Iterable> { +public final class AsyncPage implements Iterable> { private final int pageSize; - private final BiFunction>>> fetch; + private final BiFunction>>> fetch; private final String cursor; - private List> currentPage = new ArrayList<>(); + private List> currentPage = new ArrayList<>(); AsyncPage(String cursor, int pageSize, - BiFunction>>> fetch) { + BiFunction>>> fetch) { this.cursor = cursor; this.pageSize = pageSize; this.fetch = fetch; } AsyncPage(String cursor, int pageSize, - BiFunction>>> fetch, - List> currentPage) { + BiFunction>>> fetch, + List> currentPage) { this(cursor, pageSize, fetch); this.currentPage = Collections.unmodifiableList(currentPage); } - List> items() { + List> items() { return currentPage; } @@ -68,7 +68,7 @@ public CompletableFuture> fetchNextPage() { } @Override - public Iterator> iterator() { + public Iterator> iterator() { return currentPage.iterator(); } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPaginator.java b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPaginator.java index c82c2df3e..a1b40eab7 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPaginator.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPaginator.java @@ -5,11 +5,11 @@ import java.util.function.Consumer; import java.util.function.Function; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.api.collections.query.FetchObjects; import io.weaviate.client6.v1.api.collections.query.Metadata; import io.weaviate.client6.v1.api.collections.query.QueryReference; import io.weaviate.client6.v1.api.collections.query.QueryResponse; -import io.weaviate.client6.v1.api.collections.query.ReadWeaviateObject; import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClientAsync; import io.weaviate.client6.v1.internal.ObjectBuilder; @@ -45,25 +45,25 @@ public AsyncPaginator(Builder builder) { this.resultSet = builder.prefetch ? rs.fetchNextPage() : CompletableFuture.completedFuture(rs); } - public CompletableFuture forEach(Consumer> action) { + public CompletableFuture forEach(Consumer> action) { return resultSet .thenCompose(rs -> rs.isEmpty() ? rs.fetchNextPage() : CompletableFuture.completedFuture(rs)) .thenCompose(processEachAndAdvance(action)); } - public CompletableFuture forPage(Consumer>> action) { + public CompletableFuture forPage(Consumer>> action) { return resultSet .thenCompose(rs -> rs.isEmpty() ? rs.fetchNextPage() : CompletableFuture.completedFuture(rs)) .thenCompose(processPageAndAdvance(action)); } private static Function, CompletableFuture> processEachAndAdvance( - Consumer> action) { + Consumer> action) { return processAndAdvanceFunc(rs -> rs.forEach(action)); } private static Function, CompletableFuture> processPageAndAdvance( - Consumer>> action) { + Consumer>> action) { return processAndAdvanceFunc(rs -> action.accept(rs.items())); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/CursorSpliterator.java b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/CursorSpliterator.java index eb45e0402..c2fc829af 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/CursorSpliterator.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/CursorSpliterator.java @@ -7,26 +7,26 @@ import java.util.function.BiFunction; import java.util.function.Consumer; -import io.weaviate.client6.v1.api.collections.query.ReadWeaviateObject; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; -public class CursorSpliterator implements Spliterator> { +public class CursorSpliterator implements Spliterator> { private final int pageSize; - private final BiFunction>> fetch; + private final BiFunction>> fetch; // Spliterators do not promise thread-safety, so there's no mechanism // to protect access to its internal state. private String cursor; - private Iterator> currentPage = Collections.emptyIterator(); + private Iterator> currentPage = Collections.emptyIterator(); public CursorSpliterator(String cursor, int pageSize, - BiFunction>> fetch) { + BiFunction>> fetch) { this.cursor = cursor; this.pageSize = pageSize; this.fetch = fetch; } @Override - public boolean tryAdvance(Consumer> action) { + public boolean tryAdvance(Consumer> action) { // Happy path: there are remaining objects in the current page. if (currentPage.hasNext()) { action.accept(currentPage.next()); @@ -53,7 +53,7 @@ public boolean tryAdvance(Consumer> acti } @Override - public Spliterator> trySplit() { + public Spliterator> trySplit() { // Do not support splitting just now; return null; } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java index f6893f58b..a2c3dce7d 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java @@ -8,15 +8,15 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.api.collections.query.FetchObjects; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.Metadata; import io.weaviate.client6.v1.api.collections.query.QueryReference; -import io.weaviate.client6.v1.api.collections.query.ReadWeaviateObject; import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClient; import io.weaviate.client6.v1.internal.ObjectBuilder; -public class Paginator implements Iterable> { +public class Paginator implements Iterable> { static final int DEFAULT_PAGE_SIZE = 100; private final WeaviateQueryClient query; @@ -25,15 +25,15 @@ public class Paginator implements Iterable> iterator() { + public Iterator> iterator() { return Spliterators.iterator(spliterator()); } - public Stream> stream() { + public Stream> stream() { return StreamSupport.stream(spliterator(), false); } - public Spliterator> spliterator() { + public Spliterator> spliterator() { return new CursorSpliterator(cursor, pageSize, (after, limit) -> { var fn = ObjectBuilder.partial(queryOptions, q -> q.after(after).limit(limit)); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java index b90c6d748..2083948d2 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java @@ -7,6 +7,7 @@ import io.weaviate.client6.v1.api.WeaviateApiException; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.grpc.GrpcTransport; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; @@ -72,7 +73,7 @@ public SingleT fetchObjectById(String uuid, Function Optional> optionalFirst(QueryResponse

response) { + protected final

Optional> optionalFirst(QueryResponse

response) { return response == null || response.objects().isEmpty() ? Optional.empty() : Optional.ofNullable(response.objects().get(0)); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java index ba77e6b86..dd8a54bfb 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryMetadata.java @@ -1,33 +1,18 @@ package io.weaviate.client6.v1.api.collections.query; -import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.WeaviateMetadata; import io.weaviate.client6.v1.internal.ObjectBuilder; public record QueryMetadata( - /** Object UUID. */ - String uuid, - /** Vector embeddings associated with the object. */ - Vectors vectors, - /** Object creation time as a Unix timestamp. */ - Long createdAt, - /** Unix timestamp of the latest object update. */ - Long lastUpdatedAt, - /** Distances to the search vector. */ Float distance, /** Distance metric normalized to {@code 0 <= c <= 1} range. */ Float certainty, /** BM25 ranking score. */ Float score, /** Components of the BM25 ranking score. */ - String explainScore) implements WeaviateMetadata { + String explainScore) { private QueryMetadata(Builder builder) { this( - builder.uuid, - builder.vectors, - builder.createdAt, - builder.lastUpdatedAt, builder.distance, builder.certainty, builder.score, @@ -35,39 +20,11 @@ private QueryMetadata(Builder builder) { } static class Builder implements ObjectBuilder { - private String uuid; - private Vectors vectors; - private Long createdAt; - private Long lastUpdatedAt; private Float distance; private Float certainty; private Float score; private String explainScore; - final Builder uuid(String uuid) { - this.uuid = uuid; - return this; - } - - public Builder vectors(Vectors... vectors) { - if (this.vectors == null) { - this.vectors = vectors.length == 1 ? vectors[0] : new Vectors(vectors); - } else { - this.vectors = this.vectors.withVectors(vectors); - } - return this; - } - - final Builder createdAt(Long createdAt) { - this.createdAt = createdAt; - return this; - } - - final Builder lastUpdatedAt(Long lastUpdatedAt) { - this.lastUpdatedAt = lastUpdatedAt; - return this; - } - final Builder distance(Float distance) { this.distance = distance; return this; diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java index 039557652..04b8aa476 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java @@ -1,5 +1,7 @@ package io.weaviate.client6.v1.api.collections.query; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; + public record QueryObjectGrouped( /** Object properties. */ PropertiesT properties, @@ -8,7 +10,7 @@ public record QueryObjectGrouped( /** Name of the group that the object belongs to. */ String belongsToGroup) { - QueryObjectGrouped(ReadWeaviateObject object, + QueryObjectGrouped(XWriteWeaviateObject object, String belongsToGroup) { this(object.properties(), object.queryMetadata(), belongsToGroup); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java index 817994c83..63d87c865 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java @@ -11,6 +11,7 @@ import io.weaviate.client6.v1.api.collections.IReference; import io.weaviate.client6.v1.api.collections.PhoneNumber; import io.weaviate.client6.v1.api.collections.Vectors; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.internal.DateUtil; import io.weaviate.client6.v1.internal.grpc.ByteStringUtil; import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoProperties; @@ -19,7 +20,7 @@ import io.weaviate.client6.v1.internal.orm.PropertiesBuilder; public record QueryResponse( - List> objects) { + List> objects) { static QueryResponse unmarshal(WeaviateProtoSearchGet.SearchReply reply, CollectionDescriptor collection) { @@ -32,20 +33,21 @@ static QueryResponse unmarshal(WeaviateProtoSearchGet return new QueryResponse<>(objects); } - public static ReadWeaviateObject unmarshalResultObject( + public static XWriteWeaviateObject unmarshalResultObject( WeaviateProtoSearchGet.PropertiesResult propertiesResult, WeaviateProtoSearchGet.MetadataResult metadataResult, CollectionDescriptor collection) { var object = unmarshalWithReferences(propertiesResult, metadataResult, collection); - var metadata = new QueryMetadata.Builder() - .uuid(object.queryMetadata().uuid()) - .vectors(object.queryMetadata().vectors()); + + Long createdAt = null; + Long lastUpdatedAt = null; + var metadata = new QueryMetadata.Builder(); if (metadataResult.getCreationTimeUnixPresent()) { - metadata.createdAt(metadataResult.getCreationTimeUnix()); + createdAt = metadataResult.getCreationTimeUnix(); } if (metadataResult.getLastUpdateTimeUnixPresent()) { - metadata.lastUpdatedAt(metadataResult.getLastUpdateTimeUnix()); + lastUpdatedAt = metadataResult.getLastUpdateTimeUnix(); } if (metadataResult.getDistancePresent()) { metadata.distance(metadataResult.getDistance()); @@ -59,11 +61,19 @@ public static ReadWeaviateObject unmarshalResultObjec if (metadataResult.getExplainScorePresent()) { metadata.explainScore(metadataResult.getExplainScore()); } - return new ReadWeaviateObject<>(collection.collectionName(), object.properties(), object.references(), - metadata.build()); + return new XWriteWeaviateObject<>( + object.uuid(), + collection.collectionName(), + null, // tenant is not reeturned in the query + object.properties(), + object.vectors(), + createdAt, + lastUpdatedAt, + metadata.build(), + object.references()); } - static ReadWeaviateObject unmarshalWithReferences( + static XWriteWeaviateObject unmarshalWithReferences( WeaviateProtoSearchGet.PropertiesResult propertiesResult, WeaviateProtoSearchGet.MetadataResult metadataResult, CollectionDescriptor descriptor) { @@ -85,11 +95,16 @@ static ReadWeaviateObject unmarshalWithReferences( var reference = unmarshalWithReferences( property, property.getMetadata(), CollectionDescriptor.ofMap(property.getTargetCollection())); - return (IReference) new ReadWeaviateObject<>( + return (IReference) new XWriteWeaviateObject<>( + reference.uuid(), reference.collection(), - (Object) reference.properties(), - reference.references(), - reference.queryMetadata()); + null, // tenant is not returned in the query + (Map) reference.properties(), + reference.vectors(), + reference.createdAt(), + reference.lastUpdatedAt(), + reference.queryMetadata(), + reference.references()); }) .toList(); @@ -110,42 +125,51 @@ static ReadWeaviateObject unmarshalWithReferences( return left; }); + String uuid = null; + Vectors vectors = null; QueryMetadata metadata = null; if (metadataResult != null) { - var metadataBuilder = new QueryMetadata.Builder() - .uuid(metadataResult.getId()); - - var vectors = new Vectors[metadataResult.getVectorsList().size()]; - var i = 0; - for (final var vector : metadataResult.getVectorsList()) { - var vectorName = vector.getName(); - var vbytes = vector.getVectorBytes(); - switch (vector.getType()) { - case VECTOR_TYPE_SINGLE_FP32: - vectors[i++] = Vectors.of(vectorName, ByteStringUtil.decodeVectorSingle(vbytes)); - break; - case VECTOR_TYPE_MULTI_FP32: - vectors[i++] = Vectors.of(vectorName, ByteStringUtil.decodeVectorMulti(vbytes)); - break; - default: - continue; - } - } - metadataBuilder.vectors(vectors); + var metadataBuilder = new QueryMetadata.Builder(); + uuid = metadataResult.getId(); + + // Read legacy (unnamed) vector. if (metadataResult.getVectorBytes() != null && !metadataResult.getVectorBytes().isEmpty()) { var unnamed = ByteStringUtil.decodeVectorSingle(metadataResult.getVectorBytes()); - metadataBuilder.vectors(Vectors.of(unnamed)); + vectors = Vectors.of(unnamed); + } else { + var namedVectors = new Vectors[metadataResult.getVectorsList().size()]; + var i = 0; + for (final var vector : metadataResult.getVectorsList()) { + var vectorName = vector.getName(); + var vbytes = vector.getVectorBytes(); + switch (vector.getType()) { + case VECTOR_TYPE_SINGLE_FP32: + namedVectors[i++] = Vectors.of(vectorName, ByteStringUtil.decodeVectorSingle(vbytes)); + break; + case VECTOR_TYPE_MULTI_FP32: + namedVectors[i++] = Vectors.of(vectorName, ByteStringUtil.decodeVectorMulti(vbytes)); + break; + default: + continue; + } + } + vectors = new Vectors(namedVectors); } metadata = metadataBuilder.build(); } - return new ReadWeaviateObject<>( + return new XWriteWeaviateObject<>( + uuid, descriptor.collectionName(), + null, // tenant is not returned in the query properties.build(), - (Map>) referenceProperties, - metadata); + vectors, + null, + null, + metadata, + referenceProperties); } static void setProperty(String property, WeaviateProtoProperties.Value value, diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/ReadWeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/ReadWeaviateObject.java deleted file mode 100644 index d69c47ce2..000000000 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/ReadWeaviateObject.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.weaviate.client6.v1.api.collections.query; - -import java.util.List; -import java.util.Map; - -import io.weaviate.client6.v1.api.collections.IReference; -import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.WeaviateObject; - -public record ReadWeaviateObject( - String collection, - PropertiesT properties, - Map> references, - QueryMetadata queryMetadata) implements WeaviateObject, IReference { - - /** Shorthand for accesing objects's UUID from metadata. */ - @Override - public String uuid() { - return queryMetadata.uuid(); - } - - /** Shorthand for accesing objects's vectors from metadata. */ - @Override - public Vectors vectors() { - return queryMetadata.vectors(); - } - - @Override - public Long createdAt() { - return queryMetadata.createdAt(); - } - - @Override - public Long lastUpdatedAt() { - return queryMetadata.lastUpdatedAt(); - } - - @Override - public String tenant() { - return null; - } - - @SuppressWarnings("unchecked") - @Override - public WeaviateObject> asWeaviateObject() { - return (WeaviateObject>) this; - } -} diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java index 24c53b753..680ba5298 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java @@ -3,12 +3,13 @@ import java.util.Optional; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.internal.grpc.GrpcTransport; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; public class WeaviateQueryClient extends - AbstractQueryClient>, QueryResponse, QueryResponseGrouped> { + AbstractQueryClient>, QueryResponse, QueryResponseGrouped> { public WeaviateQueryClient( CollectionDescriptor collection, @@ -23,7 +24,7 @@ public WeaviateQueryClient(WeaviateQueryClient c, CollectionHandleD } @Override - protected Optional> fetchObjectById(FetchObjectById byId) { + protected Optional> fetchObjectById(FetchObjectById byId) { var request = new QueryRequest(byId, null); var result = this.grpcTransport.performRequest(request, QueryRequest.rpc(collection, defaults)); return optionalFirst(result); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java index 13bf9ce6d..19aae5a16 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java @@ -4,12 +4,13 @@ import java.util.concurrent.CompletableFuture; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.internal.grpc.GrpcTransport; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; public class WeaviateQueryClientAsync extends - AbstractQueryClient>>, CompletableFuture>, CompletableFuture>> { + AbstractQueryClient>>, CompletableFuture>, CompletableFuture>> { public WeaviateQueryClientAsync( CollectionDescriptor collection, @@ -24,7 +25,7 @@ public WeaviateQueryClientAsync(WeaviateQueryClientAsync qc, Collec } @Override - protected CompletableFuture>> fetchObjectById( + protected CompletableFuture>> fetchObjectById( FetchObjectById byId) { var request = new QueryRequest(byId, null); var result = this.grpcTransport.performRequestAsync(request, QueryRequest.rpc(collection, defaults)); diff --git a/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java b/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java index 5907be70a..bfebae199 100644 --- a/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java +++ b/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java @@ -23,7 +23,7 @@ public final class JSON { gsonBuilder.registerTypeAdapterFactory( io.weaviate.client6.v1.api.rbac.Role.CustomTypeAdapterFactory.INSTANCE); gsonBuilder.registerTypeAdapterFactory( - io.weaviate.client6.v1.api.collections.data.WriteWeaviateObject.CustomTypeAdapterFactory.INSTANCE); + io.weaviate.client6.v1.api.collections.XWriteWeaviateObject.CustomTypeAdapterFactory.INSTANCE); gsonBuilder.registerTypeAdapterFactory( io.weaviate.client6.v1.api.collections.CollectionConfig.CustomTypeAdapterFactory.INSTANCE); gsonBuilder.registerTypeAdapterFactory( diff --git a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java index 1439e9a00..460590d53 100644 --- a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java +++ b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java @@ -25,10 +25,10 @@ import io.weaviate.client6.v1.api.collections.Tokenization; import io.weaviate.client6.v1.api.collections.VectorConfig; import io.weaviate.client6.v1.api.collections.Vectors; +import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; import io.weaviate.client6.v1.api.collections.data.BatchReference; import io.weaviate.client6.v1.api.collections.data.Reference; import io.weaviate.client6.v1.api.collections.data.ReferenceAddManyResponse; -import io.weaviate.client6.v1.api.collections.data.WriteWeaviateObject; import io.weaviate.client6.v1.api.collections.quantizers.PQ; import io.weaviate.client6.v1.api.collections.rerankers.CohereReranker; import io.weaviate.client6.v1.api.collections.vectorindex.Distance; @@ -413,11 +413,11 @@ public static Object[][] testCases() { "{\"beacon\": \"weaviate://localhost/Doodlebops/id-1\"}", }, - // WriteWeaviateObject.CustomTypeAdapterFactory.INSTANCE + // XWriteWeaviateObject.CustomTypeAdapterFactory.INSTANCE { - new TypeToken>>() { + new TypeToken>>() { }, - new WriteWeaviateObject<>( + new XWriteWeaviateObject<>( "thing-1", "Things", /* tenant */ null, @@ -425,6 +425,7 @@ public static Object[][] testCases() { /* vectors */ null, /* creationTimeUnix */ null, /* lastUpdateTimeUnix */ null, + /* queryMetadata */ null, Map.of("hasRef", List.of(Reference.uuids("ref-1")))), """ From c53dca96aa8a9aed8a51decb5e9d9eba717e1c40 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 25 Nov 2025 15:50:14 +0100 Subject: [PATCH 04/11] chore: rename XWriteWeaviateObject -> WeaviateObject --- .../io/weaviate/integration/DataITest.java | 42 +++++++++---------- .../io/weaviate/integration/ORMITest.java | 4 +- .../weaviate/integration/PaginationITest.java | 4 +- .../weaviate/integration/ReferencesITest.java | 16 +++---- .../io/weaviate/integration/SearchITest.java | 30 ++++++------- .../v1/api/collections/IReference.java | 2 +- .../v1/api/collections/IWeaviateObject.java | 26 ++++++++++++ ...eaviateObject.java => WeaviateObject.java} | 28 ++++++------- .../api/collections/data/BatchReference.java | 8 ++-- .../collections/data/InsertManyRequest.java | 12 +++--- .../collections/data/InsertObjectRequest.java | 16 +++---- .../v1/api/collections/data/Reference.java | 12 +++--- .../data/ReplaceObjectRequest.java | 10 ++--- .../collections/data/UpdateObjectRequest.java | 10 ++--- .../collections/data/WeaviateDataClient.java | 14 +++---- .../data/WeaviateDataClientAsync.java | 14 +++---- .../api/collections/pagination/AsyncPage.java | 18 ++++---- .../pagination/AsyncPaginator.java | 10 ++--- .../pagination/CursorSpliterator.java | 14 +++---- .../api/collections/pagination/Paginator.java | 10 ++--- .../query/AbstractQueryClient.java | 4 +- .../collections/query/QueryObjectGrouped.java | 4 +- .../api/collections/query/QueryResponse.java | 14 +++---- .../query/WeaviateQueryClient.java | 6 +-- .../query/WeaviateQueryClientAsync.java | 6 +-- .../client6/v1/internal/json/JSON.java | 2 +- .../client6/v1/internal/json/JSONTest.java | 6 +-- 27 files changed, 184 insertions(+), 158 deletions(-) create mode 100644 src/main/java/io/weaviate/client6/v1/api/collections/IWeaviateObject.java rename src/main/java/io/weaviate/client6/v1/api/collections/{XWriteWeaviateObject.java => WeaviateObject.java} (89%) diff --git a/src/it/java/io/weaviate/integration/DataITest.java b/src/it/java/io/weaviate/integration/DataITest.java index 8fb5c82bd..1ccd4203b 100644 --- a/src/it/java/io/weaviate/integration/DataITest.java +++ b/src/it/java/io/weaviate/integration/DataITest.java @@ -21,7 +21,7 @@ import io.weaviate.client6.v1.api.collections.ReferenceProperty; import io.weaviate.client6.v1.api.collections.VectorConfig; import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.data.BatchReference; import io.weaviate.client6.v1.api.collections.data.DeleteManyResponse; import io.weaviate.client6.v1.api.collections.data.Reference; @@ -138,7 +138,7 @@ public void testBlobData() throws IOException { cat -> cat.returnProperties("img")); Assertions.assertThat(got).get() - .extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .extracting(WeaviateObject::properties, InstanceOfAssertFactories.MAP) .extractingByKey("img").isEqualTo(ragdollPng); } @@ -187,10 +187,10 @@ public void testReferences_AddReplaceDelete() throws IOException { Assertions.assertThat(johnWithFriends).get() .as("friends after ADD") - .extracting(XWriteWeaviateObject::references).extracting("hasFriend") - .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) + .extracting(WeaviateObject::references).extracting("hasFriend") + .asInstanceOf(InstanceOfAssertFactories.list(WeaviateObject.class)) .hasSize(1) - .first().extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .first().extracting(WeaviateObject::properties, InstanceOfAssertFactories.MAP) .returns("albie", friend -> friend.get("name")); // Act: replace reference @@ -207,10 +207,10 @@ public void testReferences_AddReplaceDelete() throws IOException { Assertions.assertThat(johnWithFriends).get() .as("friends after REPLACE") - .extracting(XWriteWeaviateObject::references).extracting("hasFriend") - .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) + .extracting(WeaviateObject::references).extracting("hasFriend") + .asInstanceOf(InstanceOfAssertFactories.list(WeaviateObject.class)) .hasSize(1) - .first().extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .first().extracting(WeaviateObject::properties, InstanceOfAssertFactories.MAP) .returns("barbara", friend -> friend.get("name")); // Act: delete reference @@ -226,8 +226,8 @@ public void testReferences_AddReplaceDelete() throws IOException { Assertions.assertThat(johnWithFriends).get() .as("friends after DELETE") - .extracting(XWriteWeaviateObject::references).extracting("hasFriend") - .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) + .extracting(WeaviateObject::references).extracting("hasFriend") + .asInstanceOf(InstanceOfAssertFactories.list(WeaviateObject.class)) .isEmpty(); } @@ -253,7 +253,7 @@ public void testReplace() throws IOException { Assertions.assertThat(replacedIvanhoe).get() .as("has ONLY year property") - .extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .extracting(WeaviateObject::properties, InstanceOfAssertFactories.MAP) .doesNotContain(Map.entry("title", "ivanhoe")) .contains(Map.entry("year", 1819L)); } @@ -303,20 +303,20 @@ public void testUpdate() throws IOException { .satisfies(book -> { Assertions.assertThat(book) .as("has both year and title property") - .extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .extracting(WeaviateObject::properties, InstanceOfAssertFactories.MAP) .contains(Map.entry("title", "ivanhoe"), Map.entry("year", 1819L)); Assertions.assertThat(book) .as("has reference to Authors") - .extracting(XWriteWeaviateObject::references, InstanceOfAssertFactories.MAP) - .extractingByKey("writtenBy", InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) + .extracting(WeaviateObject::references, InstanceOfAssertFactories.MAP) + .extractingByKey("writtenBy", InstanceOfAssertFactories.list(WeaviateObject.class)) .first() - .extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .extracting(WeaviateObject::properties, InstanceOfAssertFactories.MAP) .contains(Map.entry("name", "walter scott")); Assertions.assertThat(book) .as("has a vector") - .extracting(XWriteWeaviateObject::vectors) + .extracting(WeaviateObject::vectors) .returns(vector, Vectors::getDefaultSingle); }); } @@ -427,10 +427,10 @@ public void testReferenceAddMany() throws IOException { Assertions.assertThat(goodburgAirports).get() .as("Goodburg has 3 airports") - .extracting(XWriteWeaviateObject::references) + .extracting(WeaviateObject::references) .extracting(references -> references.get("hasAirports"), - InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) - .extracting(XWriteWeaviateObject::uuid) + InstanceOfAssertFactories.list(WeaviateObject.class)) + .extracting(WeaviateObject::uuid) .contains(alpha, bravo, charlie); } @@ -508,7 +508,7 @@ public void testDataTypes() throws IOException { // Assert Assertions.assertThat(got).get() - .extracting(XWriteWeaviateObject::properties) + .extracting(WeaviateObject::properties) .asInstanceOf(InstanceOfAssertFactories.map(String.class, Object.class)) // Most of PhoneNumber fields are only present on read and are null on write. .usingRecursiveComparison() @@ -580,6 +580,6 @@ public void test_multiTenant() throws IOException { var inserted = emails.data.insert(Map.of("subject", "McDonald's Xmas Bonanza")); // Assert - Assertions.assertThat(inserted).returns(johndoe, XWriteWeaviateObject::tenant); + Assertions.assertThat(inserted).returns(johndoe, WeaviateObject::tenant); } } diff --git a/src/it/java/io/weaviate/integration/ORMITest.java b/src/it/java/io/weaviate/integration/ORMITest.java index e957ff8c1..6095d91b4 100644 --- a/src/it/java/io/weaviate/integration/ORMITest.java +++ b/src/it/java/io/weaviate/integration/ORMITest.java @@ -17,7 +17,7 @@ import io.weaviate.client6.v1.api.collections.CollectionConfig; import io.weaviate.client6.v1.api.collections.GeoCoordinates; import io.weaviate.client6.v1.api.collections.PhoneNumber; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.annotations.Collection; import io.weaviate.client6.v1.api.collections.annotations.Property; import io.weaviate.client6.v1.api.collections.data.InsertManyResponse.InsertObject; @@ -358,7 +358,7 @@ public void test_partialScan() throws IOException { // Assert Assertions.assertThat(got).get() - .extracting(XWriteWeaviateObject::properties) + .extracting(WeaviateObject::properties) .returns("Dystopia", Song::title) .returns(null, Song::album) .returns(0, Song::year) diff --git a/src/it/java/io/weaviate/integration/PaginationITest.java b/src/it/java/io/weaviate/integration/PaginationITest.java index abde63ca6..be79cd1b2 100644 --- a/src/it/java/io/weaviate/integration/PaginationITest.java +++ b/src/it/java/io/weaviate/integration/PaginationITest.java @@ -18,7 +18,7 @@ import io.weaviate.client6.v1.api.WeaviateClient; import io.weaviate.client6.v1.api.WeaviateException; import io.weaviate.client6.v1.api.collections.Property; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.pagination.PaginationException; import io.weaviate.client6.v1.api.collections.query.Metadata; import io.weaviate.containers.Container; @@ -45,7 +45,7 @@ public void testIterateAll() throws IOException { var allThings = things.paginate(); // Act: stream - var gotStream = allThings.stream().map(XWriteWeaviateObject::uuid).toList(); + var gotStream = allThings.stream().map(WeaviateObject::uuid).toList(); // Assert Assertions.assertThat(gotStream) diff --git a/src/it/java/io/weaviate/integration/ReferencesITest.java b/src/it/java/io/weaviate/integration/ReferencesITest.java index 418dbeb35..36c5b1d8f 100644 --- a/src/it/java/io/weaviate/integration/ReferencesITest.java +++ b/src/it/java/io/weaviate/integration/ReferencesITest.java @@ -13,7 +13,7 @@ import io.weaviate.client6.v1.api.WeaviateClient; import io.weaviate.client6.v1.api.collections.Property; import io.weaviate.client6.v1.api.collections.ReferenceProperty; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.data.Reference; import io.weaviate.client6.v1.api.collections.query.QueryReference; import io.weaviate.containers.Container; @@ -99,9 +99,9 @@ public void testReferences() throws IOException { .as("Artists: fetch by id including hasAwards references") // Cast references to Map> - .extracting(XWriteWeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) + .extracting(WeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) .as("hasAwards object reference").extractingByKey("hasAwards") - .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) + .asInstanceOf(InstanceOfAssertFactories.list(WeaviateObject.class)) .extracting(object -> object.uuid()) .containsOnly( @@ -166,19 +166,19 @@ public void testNestedReferences() throws IOException { .as("Artists: fetch by id including nested references") // Cast references to Map> - .extracting(XWriteWeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) + .extracting(WeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) .as("hasAwards object reference").extractingByKey("hasAwards") - .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) + .asInstanceOf(InstanceOfAssertFactories.list(WeaviateObject.class)) .hasSize(1).allSatisfy(award -> Assertions.assertThat(award) .returns(grammy_1.uuid(), grammy -> grammy.uuid()) // Cast references to Map> - .extracting(XWriteWeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) + .extracting(WeaviateObject::references, InstanceOfAssertFactories.map(String.class, List.class)) .as("presentedBy object reference").extractingByKey("presentedBy") - .asInstanceOf(InstanceOfAssertFactories.list(XWriteWeaviateObject.class)) + .asInstanceOf(InstanceOfAssertFactories.list(WeaviateObject.class)) - .hasSize(1).extracting(XWriteWeaviateObject::properties) + .hasSize(1).extracting(WeaviateObject::properties) .allSatisfy(properties -> Assertions.assertThat(properties) .asInstanceOf(InstanceOfAssertFactories.map(String.class, Object.class)) .containsEntry("ceo", "Harvy Mason"))); diff --git a/src/it/java/io/weaviate/integration/SearchITest.java b/src/it/java/io/weaviate/integration/SearchITest.java index bb0647d2b..08f1d1565 100644 --- a/src/it/java/io/weaviate/integration/SearchITest.java +++ b/src/it/java/io/weaviate/integration/SearchITest.java @@ -27,7 +27,7 @@ import io.weaviate.client6.v1.api.collections.Reranker; import io.weaviate.client6.v1.api.collections.VectorConfig; import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.data.Reference; import io.weaviate.client6.v1.api.collections.generate.GenerativeObject; import io.weaviate.client6.v1.api.collections.generate.TaskOutput; @@ -169,7 +169,7 @@ public void testNearText() throws IOException { .returnProperties("title")); Assertions.assertThat(result.objects()).hasSize(2) - .extracting(XWriteWeaviateObject::properties).allSatisfy( + .extracting(WeaviateObject::properties).allSatisfy( properties -> Assertions.assertThat(properties) .allSatisfy((_k, v) -> Assertions.assertThat((String) v).contains("Jungle"))); } @@ -232,7 +232,7 @@ public void testNearImage() throws IOException { opt -> opt.returnProperties("breed")); Assertions.assertThat(got.objects()).hasSize(1).first() - .extracting(XWriteWeaviateObject::properties, InstanceOfAssertFactories.MAP) + .extracting(WeaviateObject::properties, InstanceOfAssertFactories.MAP) .extractingByKey("breed").isEqualTo("ragdoll"); } @@ -262,7 +262,7 @@ public void testFetchObjectsWithFilters() throws IOException { Filter.property("size").lt(6))))); Assertions.assertThat(got.objects()) - .extracting(XWriteWeaviateObject::uuid) + .extracting(WeaviateObject::uuid) .containsOnly( redHat.uuid(), greenHat.uuid(), @@ -291,7 +291,7 @@ public void testFetchObjectsWithSort() throws Exception { Assertions.assertThat(asc.objects()) .as("value asc") .hasSize(3) - .extracting(XWriteWeaviateObject::properties) + .extracting(WeaviateObject::properties) .extracting(object -> object.get("value")) .containsExactly(1L, 2L, 3L); @@ -302,7 +302,7 @@ public void testFetchObjectsWithSort() throws Exception { Assertions.assertThat(desc.objects()) .as("value desc") .hasSize(3) - .extracting(XWriteWeaviateObject::properties) + .extracting(WeaviateObject::properties) .extracting(object -> object.get("value")) .containsExactly(3L, 2L, 1L); } @@ -328,7 +328,7 @@ public void testBm25() throws IOException, InterruptedException, ExecutionExcept Assertions.assertThat(dollarWorlds.objects()) .hasSize(1) - .extracting(XWriteWeaviateObject::uuid) + .extracting(WeaviateObject::uuid) .containsOnly(want.uuid()); } @@ -360,7 +360,7 @@ public void testBm25_async() throws Exception, InterruptedException, ExecutionEx Assertions.assertThat(dollarWorlds.objects()) .hasSize(1) - .extracting(XWriteWeaviateObject::uuid) + .extracting(WeaviateObject::uuid) .containsOnly(want.uuid()); } } @@ -390,7 +390,7 @@ public void testNearObject() throws IOException { // Assert Assertions.assertThat(terrestrial.objects()) .hasSize(1) - .extracting(XWriteWeaviateObject::uuid) + .extracting(WeaviateObject::uuid) .containsOnly(lion.uuid()); } @@ -417,7 +417,7 @@ public void testHybrid() throws IOException { // Assert Assertions.assertThat(winterSport.objects()) .hasSize(1) - .extracting(XWriteWeaviateObject::uuid) + .extracting(WeaviateObject::uuid) .containsOnly(skiing.uuid()); var first = winterSport.objects().get(0); @@ -487,7 +487,7 @@ public void test_includeVectors() throws IOException { // Assert Assertions.assertThat(got).get() - .extracting(XWriteWeaviateObject::vectors) + .extracting(WeaviateObject::vectors) .returns(true, v -> v.contains("v1")) .returns(true, v -> v.contains("v2")) .returns(false, v -> v.contains("v3")); @@ -553,7 +553,7 @@ public void testNearVector_targetVectors() throws IOException { Vectors.of("v2d", new float[][] { { 1, 2, 3 }, { 1, 2, 3 } }))); var thing456 = things.data.insertMany(List.of( - XWriteWeaviateObject.of(thing -> thing + WeaviateObject.of(thing -> thing .vectors( Vectors.of("v1d", new float[] { 4, 5, 6 }), Vectors.of("v2d", new float[][] { { 4, 5, 6 }, { 4, 5, 6 } }))))); @@ -565,7 +565,7 @@ public void testNearVector_targetVectors() throws IOException { q -> q.limit(1)); Assertions.assertThat(got123.objects()) .as("search v1d") - .hasSize(1).extracting(XWriteWeaviateObject::uuid) + .hasSize(1).extracting(WeaviateObject::uuid) .containsExactly(thing123.uuid()); var got456 = things.query.nearVector( @@ -573,7 +573,7 @@ public void testNearVector_targetVectors() throws IOException { q -> q.limit(1)); Assertions.assertThat(got456.objects()) .as("search v2d") - .hasSize(1).extracting(XWriteWeaviateObject::uuid) + .hasSize(1).extracting(WeaviateObject::uuid) .containsExactly(thing456.uuids().get(0)); } @@ -755,7 +755,7 @@ public void test_maxGrpcMessageSize() throws Exception { .vectorConfig(VectorConfig.selfProvided())); final var vector = randomVector(5000, -.01f, .01f); - final XWriteWeaviateObject> hugeObject = XWriteWeaviateObject.of( + final WeaviateObject> hugeObject = WeaviateObject.of( obj -> obj.vectors(Vectors.of(vector))); Assertions.assertThatThrownBy(() -> { diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java index e0aa0911f..138843cf6 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java @@ -7,5 +7,5 @@ public interface IReference { String collection(); - XWriteWeaviateObject> asWeaviateObject(); + WeaviateObject> asWeaviateObject(); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/IWeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/IWeaviateObject.java new file mode 100644 index 000000000..d7266736d --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/api/collections/IWeaviateObject.java @@ -0,0 +1,26 @@ +package io.weaviate.client6.v1.api.collections; + +import java.util.List; +import java.util.Map; + +import io.weaviate.client6.v1.api.collections.query.QueryMetadata; + +public interface IWeaviateObject { + String uuid(); + + String collection(); + + Vectors vectors(); + + String tenant(); + + PropertiesT properties(); + + Map> references(); + + Long createdAt(); + + Long lastUpdatedAt(); + + QueryMetadata queryMetadata(); +} diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/XWriteWeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java similarity index 89% rename from src/main/java/io/weaviate/client6/v1/api/collections/XWriteWeaviateObject.java rename to src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java index e3e079d09..5cd184a8a 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/XWriteWeaviateObject.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java @@ -25,7 +25,7 @@ import io.weaviate.client6.v1.api.collections.query.QueryMetadata; import io.weaviate.client6.v1.internal.ObjectBuilder; -public record XWriteWeaviateObject( +public record WeaviateObject( @SerializedName("id") String uuid, @SerializedName("class") String collection, @SerializedName("tenant") String tenant, @@ -64,16 +64,16 @@ public record XWriteWeaviateObject( */ @SuppressWarnings("unchecked") @Override - public XWriteWeaviateObject> asWeaviateObject() { - return (XWriteWeaviateObject>) this; + public WeaviateObject> asWeaviateObject() { + return (WeaviateObject>) this; } - public static XWriteWeaviateObject of( - Function, ObjectBuilder>> fn) { + public static WeaviateObject of( + Function, ObjectBuilder>> fn) { return fn.apply(new Builder<>()).build(); } - public XWriteWeaviateObject(Builder builder) { + public WeaviateObject(Builder builder) { this( builder.uuid, null, // collection name is derived from CollectionHandle @@ -86,7 +86,7 @@ public XWriteWeaviateObject(Builder builder) { builder.references); } - public static class Builder implements ObjectBuilder> { + public static class Builder implements ObjectBuilder> { /** * The server should be providing default UUIDs, but it does not do that * during batch inserts and we have to provide our own. @@ -147,8 +147,8 @@ public Builder vectors(Vectors... vectors) { } @Override - public XWriteWeaviateObject build() { - return new XWriteWeaviateObject<>(this); + public WeaviateObject build() { + return new WeaviateObject<>(this); } } @@ -160,7 +160,7 @@ public static enum CustomTypeAdapterFactory implements TypeAdapterFactory { public TypeAdapter create(Gson gson, TypeToken typeToken) { var type = typeToken.getType(); var rawType = typeToken.getRawType(); - if (rawType != XWriteWeaviateObject.class || + if (rawType != WeaviateObject.class || !(type instanceof ParameterizedType parameterized) || parameterized.getActualTypeArguments().length != 1) { return null; @@ -169,15 +169,15 @@ public TypeAdapter create(Gson gson, TypeToken typeToken) { var typeParams = parameterized.getActualTypeArguments(); final var propertiesType = typeParams[0]; - final var delegate = (TypeAdapter>) gson + final var delegate = (TypeAdapter>) gson .getDelegateAdapter(this, typeToken); final var propertiesAdapter = (TypeAdapter) gson.getAdapter(TypeToken.get(propertiesType)); final var referencesAdapter = gson.getAdapter(Reference.class); - return (TypeAdapter) new TypeAdapter>() { + return (TypeAdapter) new TypeAdapter>() { @Override - public void write(JsonWriter out, XWriteWeaviateObject value) throws IOException { + public void write(JsonWriter out, WeaviateObject value) throws IOException { var json = delegate.toJsonTree(value).getAsJsonObject(); var properties = value.properties() != null ? propertiesAdapter.toJsonTree(value.properties()).getAsJsonObject() @@ -200,7 +200,7 @@ public void write(JsonWriter out, XWriteWeaviateObject value) throws IOExcept } @Override - public XWriteWeaviateObject read(JsonReader in) throws IOException { + public WeaviateObject read(JsonReader in) throws IOException { var json = JsonParser.parseReader(in).getAsJsonObject(); var jsonProperties = json.get("properties").getAsJsonObject(); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java index 616d564eb..e8feb243c 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java @@ -7,12 +7,12 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; public record BatchReference(String fromCollection, String fromProperty, String fromUuid, Reference reference) { - public static BatchReference[] objects(XWriteWeaviateObject fromObject, String fromProperty, - XWriteWeaviateObject... toObjects) { + public static BatchReference[] objects(WeaviateObject fromObject, String fromProperty, + WeaviateObject... toObjects) { return Arrays.stream(toObjects) .map(to -> new BatchReference( fromObject.collection(), fromProperty, fromObject.uuid(), @@ -20,7 +20,7 @@ public static BatchReference[] objects(XWriteWeaviateObject fromObject, Strin .toArray(BatchReference[]::new); } - public static BatchReference[] uuids(XWriteWeaviateObject fromObject, String fromProperty, + public static BatchReference[] uuids(WeaviateObject fromObject, String fromProperty, String... toUuids) { return Arrays.stream(toUuids) .map(to -> new BatchReference( diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java index 4c31d1aff..34f0c9175 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java @@ -10,7 +10,7 @@ import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; import io.weaviate.client6.v1.api.collections.GeoCoordinates; import io.weaviate.client6.v1.api.collections.PhoneNumber; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.MapUtil; import io.weaviate.client6.v1.internal.grpc.ByteStringUtil; import io.weaviate.client6.v1.internal.grpc.Rpc; @@ -21,10 +21,10 @@ import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoBatch; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; -public record InsertManyRequest(List> objects) { +public record InsertManyRequest(List> objects) { @SafeVarargs - public InsertManyRequest(XWriteWeaviateObject... objects) { + public InsertManyRequest(WeaviateObject... objects) { this(Arrays.asList(objects)); } @@ -32,13 +32,13 @@ public InsertManyRequest(XWriteWeaviateObject... objects) { @SafeVarargs public static final InsertManyRequest of(PropertiesT... properties) { var objects = Arrays.stream(properties) - .map(p -> (XWriteWeaviateObject) XWriteWeaviateObject.of(obj -> obj.properties(p))) + .map(p -> (WeaviateObject) WeaviateObject.of(obj -> obj.properties(p))) .toList(); return new InsertManyRequest<>(objects); } public static Rpc, WeaviateProtoBatch.BatchObjectsRequest, InsertManyResponse, WeaviateProtoBatch.BatchObjectsReply> rpc( - List> insertObjects, + List> insertObjects, CollectionDescriptor collection, CollectionHandleDefaults defaults) { return Rpc.insert( @@ -93,7 +93,7 @@ public static Rpc, WeaviateProtoBat } public static void buildObject(WeaviateProtoBatch.BatchObject.Builder object, - XWriteWeaviateObject insert, + WeaviateObject insert, CollectionDescriptor collection, CollectionHandleDefaults defaults) { object.setCollection(collection.collectionName()); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java index 95aeb600c..8588eb760 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertObjectRequest.java @@ -7,22 +7,22 @@ import com.google.gson.reflect.TypeToken; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.json.JSON; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; import io.weaviate.client6.v1.internal.rest.Endpoint; import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; -public record InsertObjectRequest(XWriteWeaviateObject object) { +public record InsertObjectRequest(WeaviateObject object) { @SuppressWarnings("unchecked") - public static final Endpoint, XWriteWeaviateObject> endpoint( + public static final Endpoint, WeaviateObject> endpoint( CollectionDescriptor collection, CollectionHandleDefaults defaults) { - final var typeToken = (TypeToken>) TypeToken - .getParameterized(XWriteWeaviateObject.class, collection.typeToken().getType()); + final var typeToken = (TypeToken>) TypeToken + .getParameterized(WeaviateObject.class, collection.typeToken().getType()); return new SimpleEndpoint<>( request -> "POST", @@ -31,7 +31,7 @@ public static final Endpoint, XWr ? Map.of("consistency_level", defaults.consistencyLevel()) : Collections.emptyMap(), request -> JSON.serialize( - new XWriteWeaviateObject<>( + new WeaviateObject<>( request.object.uuid(), collection.collectionName(), defaults.tenant(), @@ -51,7 +51,7 @@ static InsertObjectRequest of(PropertiesT properties) static InsertObjectRequest of( PropertiesT properties, - Function, ObjectBuilder>> fn) { - return new InsertObjectRequest<>(XWriteWeaviateObject.of(ObjectBuilder.partial(fn, b -> b.properties(properties)))); + Function, ObjectBuilder>> fn) { + return new InsertObjectRequest<>(WeaviateObject.of(ObjectBuilder.partial(fn, b -> b.properties(properties)))); } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java index bd3808652..63f7338ad 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java @@ -11,7 +11,7 @@ import com.google.gson.stream.JsonWriter; import io.weaviate.client6.v1.api.collections.IReference; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; public record Reference(String collection, List uuids) implements IReference { @@ -21,7 +21,7 @@ public String uuid() { } @Override - public XWriteWeaviateObject> asWeaviateObject() { + public WeaviateObject> asWeaviateObject() { throw new IllegalStateException("cannot convert to WeaviateObject"); } @@ -40,13 +40,13 @@ public static Reference uuids(String... uuids) { return new Reference(null, Arrays.asList(uuids)); } - /** Create references to single {@link XWriteWeaviateObject}. */ - public static Reference object(XWriteWeaviateObject object) { + /** Create references to single {@link WeaviateObject}. */ + public static Reference object(WeaviateObject object) { return new Reference(object.collection(), object.uuid()); } - /** Create references to multiple {@link XWriteWeaviateObject}. */ - public static Reference[] objects(XWriteWeaviateObject... objects) { + /** Create references to multiple {@link WeaviateObject}. */ + public static Reference[] objects(WeaviateObject... objects) { return Arrays.stream(objects) .map(o -> new Reference(o.collection(), o.uuid())) .toArray(Reference[]::new); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java index 6fb47d8eb..ad6ed9175 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java @@ -8,20 +8,20 @@ import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.json.JSON; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; import io.weaviate.client6.v1.internal.rest.Endpoint; import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; -public record ReplaceObjectRequest(XWriteWeaviateObject object) { +public record ReplaceObjectRequest(WeaviateObject object) { static final Endpoint, Void> endpoint( CollectionDescriptor collection, CollectionHandleDefaults defaults) { - final var typeToken = TypeToken.getParameterized(XWriteWeaviateObject.class, collection.typeToken().getType()); + final var typeToken = TypeToken.getParameterized(WeaviateObject.class, collection.typeToken().getType()); return SimpleEndpoint.sideEffect( request -> "PUT", @@ -30,7 +30,7 @@ static final Endpoint, Void> end ? Map.of("consistency_level", defaults.consistencyLevel()) : Collections.emptyMap(), request -> JSON.serialize( - new XWriteWeaviateObject<>( + new WeaviateObject<>( request.object.uuid(), collection.collectionName(), defaults.tenant(), @@ -54,7 +54,7 @@ public ReplaceObjectRequest(Builder builder) { } public static class Builder implements ObjectBuilder> { - private final XWriteWeaviateObject.Builder object = new XWriteWeaviateObject.Builder<>(); + private final WeaviateObject.Builder object = new WeaviateObject.Builder<>(); public Builder(String uuid) { this.object.uuid(uuid); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java index 4ca108c6d..ebe51d1fe 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java @@ -8,20 +8,20 @@ import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.json.JSON; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; import io.weaviate.client6.v1.internal.rest.Endpoint; import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; -public record UpdateObjectRequest(XWriteWeaviateObject object) { +public record UpdateObjectRequest(WeaviateObject object) { static final Endpoint, Void> endpoint( CollectionDescriptor collection, CollectionHandleDefaults defaults) { - final var typeToken = TypeToken.getParameterized(XWriteWeaviateObject.class, collection.typeToken().getType()); + final var typeToken = TypeToken.getParameterized(WeaviateObject.class, collection.typeToken().getType()); return SimpleEndpoint.sideEffect( request -> "PATCH", @@ -30,7 +30,7 @@ static final Endpoint, Void> endp ? Map.of("consistency_level", defaults.consistencyLevel()) : Collections.emptyMap(), request -> JSON.serialize( - new XWriteWeaviateObject<>( + new WeaviateObject<>( request.object.uuid(), collection.collectionName(), defaults.tenant(), @@ -53,7 +53,7 @@ public UpdateObjectRequest(Builder builder) { } public static class Builder implements ObjectBuilder> { - private final XWriteWeaviateObject.Builder object = new XWriteWeaviateObject.Builder<>(); + private final WeaviateObject.Builder object = new WeaviateObject.Builder<>(); public Builder(String uuid) { this.object.uuid(uuid); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java index 3f8c0aac5..c8b764c21 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java @@ -6,7 +6,7 @@ import java.util.function.Function; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.FilterOperand; import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClient; @@ -44,18 +44,18 @@ public WeaviateDataClient(WeaviateDataClient c, CollectionHandleDef this.defaults = defaults; } - public XWriteWeaviateObject insert(PropertiesT properties) throws IOException { + public WeaviateObject insert(PropertiesT properties) throws IOException { return insert(InsertObjectRequest.of(properties)); } - public XWriteWeaviateObject insert( + public WeaviateObject insert( PropertiesT properties, - Function, ObjectBuilder>> fn) + Function, ObjectBuilder>> fn) throws IOException { return insert(InsertObjectRequest.of(properties, fn)); } - public XWriteWeaviateObject insert(InsertObjectRequest request) + public WeaviateObject insert(InsertObjectRequest request) throws IOException { return this.restTransport.performRequest(request, InsertObjectRequest.endpoint(collection, defaults)); } @@ -65,12 +65,12 @@ public final InsertManyResponse insertMany(PropertiesT... objects) { return insertMany(InsertManyRequest.of(objects)); } - public InsertManyResponse insertMany(List> objects) { + public InsertManyResponse insertMany(List> objects) { return insertMany(new InsertManyRequest<>(objects)); } @SafeVarargs - public final InsertManyResponse insertMany(XWriteWeaviateObject... objects) { + public final InsertManyResponse insertMany(WeaviateObject... objects) { return insertMany(Arrays.asList(objects)); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java index 864e72a7f..568253a49 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java @@ -8,7 +8,7 @@ import java.util.function.Function; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.FilterOperand; import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClientAsync; @@ -46,17 +46,17 @@ public WeaviateDataClientAsync(WeaviateDataClientAsync c, Collectio this.defaults = defaults; } - public CompletableFuture> insert(PropertiesT properties) { + public CompletableFuture> insert(PropertiesT properties) { return insert(InsertObjectRequest.of(properties)); } - public CompletableFuture> insert( + public CompletableFuture> insert( PropertiesT properties, - Function, ObjectBuilder>> fn) { + Function, ObjectBuilder>> fn) { return insert(InsertObjectRequest.of(properties, fn)); } - public CompletableFuture> insert( + public CompletableFuture> insert( InsertObjectRequest request) { return this.restTransport.performRequestAsync(request, InsertObjectRequest.endpoint(collection, defaults)); } @@ -67,11 +67,11 @@ public final CompletableFuture insertMany(PropertiesT... obj } @SafeVarargs - public final CompletableFuture insertMany(XWriteWeaviateObject... objects) { + public final CompletableFuture insertMany(WeaviateObject... objects) { return insertMany(Arrays.asList(objects)); } - public CompletableFuture insertMany(List> objects) { + public CompletableFuture insertMany(List> objects) { return insertMany(new InsertManyRequest<>(objects)); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPage.java b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPage.java index e23a6ad0e..6a4f1bdc0 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPage.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPage.java @@ -7,31 +7,31 @@ import java.util.concurrent.CompletableFuture; import java.util.function.BiFunction; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; -public final class AsyncPage implements Iterable> { +public final class AsyncPage implements Iterable> { private final int pageSize; - private final BiFunction>>> fetch; + private final BiFunction>>> fetch; private final String cursor; - private List> currentPage = new ArrayList<>(); + private List> currentPage = new ArrayList<>(); AsyncPage(String cursor, int pageSize, - BiFunction>>> fetch) { + BiFunction>>> fetch) { this.cursor = cursor; this.pageSize = pageSize; this.fetch = fetch; } AsyncPage(String cursor, int pageSize, - BiFunction>>> fetch, - List> currentPage) { + BiFunction>>> fetch, + List> currentPage) { this(cursor, pageSize, fetch); this.currentPage = Collections.unmodifiableList(currentPage); } - List> items() { + List> items() { return currentPage; } @@ -68,7 +68,7 @@ public CompletableFuture> fetchNextPage() { } @Override - public Iterator> iterator() { + public Iterator> iterator() { return currentPage.iterator(); } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPaginator.java b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPaginator.java index a1b40eab7..caa321837 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPaginator.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/AsyncPaginator.java @@ -5,7 +5,7 @@ import java.util.function.Consumer; import java.util.function.Function; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.query.FetchObjects; import io.weaviate.client6.v1.api.collections.query.Metadata; import io.weaviate.client6.v1.api.collections.query.QueryReference; @@ -45,25 +45,25 @@ public AsyncPaginator(Builder builder) { this.resultSet = builder.prefetch ? rs.fetchNextPage() : CompletableFuture.completedFuture(rs); } - public CompletableFuture forEach(Consumer> action) { + public CompletableFuture forEach(Consumer> action) { return resultSet .thenCompose(rs -> rs.isEmpty() ? rs.fetchNextPage() : CompletableFuture.completedFuture(rs)) .thenCompose(processEachAndAdvance(action)); } - public CompletableFuture forPage(Consumer>> action) { + public CompletableFuture forPage(Consumer>> action) { return resultSet .thenCompose(rs -> rs.isEmpty() ? rs.fetchNextPage() : CompletableFuture.completedFuture(rs)) .thenCompose(processPageAndAdvance(action)); } private static Function, CompletableFuture> processEachAndAdvance( - Consumer> action) { + Consumer> action) { return processAndAdvanceFunc(rs -> rs.forEach(action)); } private static Function, CompletableFuture> processPageAndAdvance( - Consumer>> action) { + Consumer>> action) { return processAndAdvanceFunc(rs -> action.accept(rs.items())); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/CursorSpliterator.java b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/CursorSpliterator.java index c2fc829af..815b01714 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/CursorSpliterator.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/CursorSpliterator.java @@ -7,26 +7,26 @@ import java.util.function.BiFunction; import java.util.function.Consumer; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; -public class CursorSpliterator implements Spliterator> { +public class CursorSpliterator implements Spliterator> { private final int pageSize; - private final BiFunction>> fetch; + private final BiFunction>> fetch; // Spliterators do not promise thread-safety, so there's no mechanism // to protect access to its internal state. private String cursor; - private Iterator> currentPage = Collections.emptyIterator(); + private Iterator> currentPage = Collections.emptyIterator(); public CursorSpliterator(String cursor, int pageSize, - BiFunction>> fetch) { + BiFunction>> fetch) { this.cursor = cursor; this.pageSize = pageSize; this.fetch = fetch; } @Override - public boolean tryAdvance(Consumer> action) { + public boolean tryAdvance(Consumer> action) { // Happy path: there are remaining objects in the current page. if (currentPage.hasNext()) { action.accept(currentPage.next()); @@ -53,7 +53,7 @@ public boolean tryAdvance(Consumer> ac } @Override - public Spliterator> trySplit() { + public Spliterator> trySplit() { // Do not support splitting just now; return null; } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java index a2c3dce7d..8ad18fd67 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/pagination/Paginator.java @@ -8,7 +8,7 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.query.FetchObjects; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.Metadata; @@ -16,7 +16,7 @@ import io.weaviate.client6.v1.api.collections.query.WeaviateQueryClient; import io.weaviate.client6.v1.internal.ObjectBuilder; -public class Paginator implements Iterable> { +public class Paginator implements Iterable> { static final int DEFAULT_PAGE_SIZE = 100; private final WeaviateQueryClient query; @@ -25,15 +25,15 @@ public class Paginator implements Iterable> iterator() { + public Iterator> iterator() { return Spliterators.iterator(spliterator()); } - public Stream> stream() { + public Stream> stream() { return StreamSupport.stream(spliterator(), false); } - public Spliterator> spliterator() { + public Spliterator> spliterator() { return new CursorSpliterator(cursor, pageSize, (after, limit) -> { var fn = ObjectBuilder.partial(queryOptions, q -> q.after(after).limit(limit)); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java index 2083948d2..468643ece 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/AbstractQueryClient.java @@ -7,7 +7,7 @@ import io.weaviate.client6.v1.api.WeaviateApiException; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.grpc.GrpcTransport; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; @@ -73,7 +73,7 @@ public SingleT fetchObjectById(String uuid, Function Optional> optionalFirst(QueryResponse

response) { + protected final

Optional> optionalFirst(QueryResponse

response) { return response == null || response.objects().isEmpty() ? Optional.empty() : Optional.ofNullable(response.objects().get(0)); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java index 04b8aa476..aec77443a 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java @@ -1,6 +1,6 @@ package io.weaviate.client6.v1.api.collections.query; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; public record QueryObjectGrouped( /** Object properties. */ @@ -10,7 +10,7 @@ public record QueryObjectGrouped( /** Name of the group that the object belongs to. */ String belongsToGroup) { - QueryObjectGrouped(XWriteWeaviateObject object, + QueryObjectGrouped(WeaviateObject object, String belongsToGroup) { this(object.properties(), object.queryMetadata(), belongsToGroup); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java index 63d87c865..ebfea445d 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java @@ -11,7 +11,7 @@ import io.weaviate.client6.v1.api.collections.IReference; import io.weaviate.client6.v1.api.collections.PhoneNumber; import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.DateUtil; import io.weaviate.client6.v1.internal.grpc.ByteStringUtil; import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoProperties; @@ -20,7 +20,7 @@ import io.weaviate.client6.v1.internal.orm.PropertiesBuilder; public record QueryResponse( - List> objects) { + List> objects) { static QueryResponse unmarshal(WeaviateProtoSearchGet.SearchReply reply, CollectionDescriptor collection) { @@ -33,7 +33,7 @@ static QueryResponse unmarshal(WeaviateProtoSearchGet return new QueryResponse<>(objects); } - public static XWriteWeaviateObject unmarshalResultObject( + public static WeaviateObject unmarshalResultObject( WeaviateProtoSearchGet.PropertiesResult propertiesResult, WeaviateProtoSearchGet.MetadataResult metadataResult, CollectionDescriptor collection) { @@ -61,7 +61,7 @@ public static XWriteWeaviateObject unmarshalResultObj if (metadataResult.getExplainScorePresent()) { metadata.explainScore(metadataResult.getExplainScore()); } - return new XWriteWeaviateObject<>( + return new WeaviateObject<>( object.uuid(), collection.collectionName(), null, // tenant is not reeturned in the query @@ -73,7 +73,7 @@ public static XWriteWeaviateObject unmarshalResultObj object.references()); } - static XWriteWeaviateObject unmarshalWithReferences( + static WeaviateObject unmarshalWithReferences( WeaviateProtoSearchGet.PropertiesResult propertiesResult, WeaviateProtoSearchGet.MetadataResult metadataResult, CollectionDescriptor descriptor) { @@ -95,7 +95,7 @@ static XWriteWeaviateObject unmarshalWithReferences( var reference = unmarshalWithReferences( property, property.getMetadata(), CollectionDescriptor.ofMap(property.getTargetCollection())); - return (IReference) new XWriteWeaviateObject<>( + return (IReference) new WeaviateObject<>( reference.uuid(), reference.collection(), null, // tenant is not returned in the query @@ -160,7 +160,7 @@ static XWriteWeaviateObject unmarshalWithReferences( metadata = metadataBuilder.build(); } - return new XWriteWeaviateObject<>( + return new WeaviateObject<>( uuid, descriptor.collectionName(), null, // tenant is not returned in the query diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java index 680ba5298..25e899b56 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClient.java @@ -3,13 +3,13 @@ import java.util.Optional; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.grpc.GrpcTransport; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; public class WeaviateQueryClient extends - AbstractQueryClient>, QueryResponse, QueryResponseGrouped> { + AbstractQueryClient>, QueryResponse, QueryResponseGrouped> { public WeaviateQueryClient( CollectionDescriptor collection, @@ -24,7 +24,7 @@ public WeaviateQueryClient(WeaviateQueryClient c, CollectionHandleD } @Override - protected Optional> fetchObjectById(FetchObjectById byId) { + protected Optional> fetchObjectById(FetchObjectById byId) { var request = new QueryRequest(byId, null); var result = this.grpcTransport.performRequest(request, QueryRequest.rpc(collection, defaults)); return optionalFirst(result); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java index 19aae5a16..41a7d902b 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/WeaviateQueryClientAsync.java @@ -4,13 +4,13 @@ import java.util.concurrent.CompletableFuture; import io.weaviate.client6.v1.api.collections.CollectionHandleDefaults; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.grpc.GrpcTransport; import io.weaviate.client6.v1.internal.orm.CollectionDescriptor; public class WeaviateQueryClientAsync extends - AbstractQueryClient>>, CompletableFuture>, CompletableFuture>> { + AbstractQueryClient>>, CompletableFuture>, CompletableFuture>> { public WeaviateQueryClientAsync( CollectionDescriptor collection, @@ -25,7 +25,7 @@ public WeaviateQueryClientAsync(WeaviateQueryClientAsync qc, Collec } @Override - protected CompletableFuture>> fetchObjectById( + protected CompletableFuture>> fetchObjectById( FetchObjectById byId) { var request = new QueryRequest(byId, null); var result = this.grpcTransport.performRequestAsync(request, QueryRequest.rpc(collection, defaults)); diff --git a/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java b/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java index bfebae199..bbcf99bf2 100644 --- a/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java +++ b/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java @@ -23,7 +23,7 @@ public final class JSON { gsonBuilder.registerTypeAdapterFactory( io.weaviate.client6.v1.api.rbac.Role.CustomTypeAdapterFactory.INSTANCE); gsonBuilder.registerTypeAdapterFactory( - io.weaviate.client6.v1.api.collections.XWriteWeaviateObject.CustomTypeAdapterFactory.INSTANCE); + io.weaviate.client6.v1.api.collections.WeaviateObject.CustomTypeAdapterFactory.INSTANCE); gsonBuilder.registerTypeAdapterFactory( io.weaviate.client6.v1.api.collections.CollectionConfig.CustomTypeAdapterFactory.INSTANCE); gsonBuilder.registerTypeAdapterFactory( diff --git a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java index 460590d53..f985d5a6f 100644 --- a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java +++ b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java @@ -25,7 +25,7 @@ import io.weaviate.client6.v1.api.collections.Tokenization; import io.weaviate.client6.v1.api.collections.VectorConfig; import io.weaviate.client6.v1.api.collections.Vectors; -import io.weaviate.client6.v1.api.collections.XWriteWeaviateObject; +import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.data.BatchReference; import io.weaviate.client6.v1.api.collections.data.Reference; import io.weaviate.client6.v1.api.collections.data.ReferenceAddManyResponse; @@ -415,9 +415,9 @@ public static Object[][] testCases() { // XWriteWeaviateObject.CustomTypeAdapterFactory.INSTANCE { - new TypeToken>>() { + new TypeToken>>() { }, - new XWriteWeaviateObject<>( + new WeaviateObject<>( "thing-1", "Things", /* tenant */ null, From b744139e41147508d2540a18c5d4a2809da6c449 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 25 Nov 2025 16:51:22 +0100 Subject: [PATCH 05/11] chore: rename Reference -> ObjectReference and IReference -> Reference --- .../io/weaviate/integration/DataITest.java | 12 +++--- .../weaviate/integration/ReferencesITest.java | 10 ++--- .../io/weaviate/integration/SearchITest.java | 6 +-- .../v1/api/collections/IReference.java | 11 ----- .../v1/api/collections/IWeaviateObject.java | 26 ----------- .../client6/v1/api/collections/Reference.java | 41 ++++++++++++++++++ .../v1/api/collections/WeaviateObject.java | 43 ++++--------------- .../api/collections/data/BatchReference.java | 14 +++--- .../collections/data/InsertManyRequest.java | 4 +- .../{Reference.java => ObjectReference.java} | 32 +++++++------- .../collections/data/ReferenceAddRequest.java | 2 +- .../data/ReferenceDeleteRequest.java | 2 +- .../data/ReferenceReplaceRequest.java | 2 +- .../data/ReplaceObjectRequest.java | 2 +- .../collections/data/UpdateObjectRequest.java | 2 +- .../collections/data/WeaviateDataClient.java | 12 +++--- .../data/WeaviateDataClientAsync.java | 12 +++--- .../api/collections/query/QueryResponse.java | 6 +-- .../client6/v1/internal/json/JSON.java | 8 ++-- .../api/collections/CollectionHandleTest.java | 8 ++-- .../client6/v1/internal/json/JSONTest.java | 14 +++--- 21 files changed, 124 insertions(+), 145 deletions(-) delete mode 100644 src/main/java/io/weaviate/client6/v1/api/collections/IReference.java delete mode 100644 src/main/java/io/weaviate/client6/v1/api/collections/IWeaviateObject.java create mode 100644 src/main/java/io/weaviate/client6/v1/api/collections/Reference.java rename src/main/java/io/weaviate/client6/v1/api/collections/data/{Reference.java => ObjectReference.java} (68%) diff --git a/src/it/java/io/weaviate/integration/DataITest.java b/src/it/java/io/weaviate/integration/DataITest.java index 1ccd4203b..2678744f0 100644 --- a/src/it/java/io/weaviate/integration/DataITest.java +++ b/src/it/java/io/weaviate/integration/DataITest.java @@ -24,7 +24,7 @@ import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.data.BatchReference; import io.weaviate.client6.v1.api.collections.data.DeleteManyResponse; -import io.weaviate.client6.v1.api.collections.data.Reference; +import io.weaviate.client6.v1.api.collections.data.ObjectReference; import io.weaviate.client6.v1.api.collections.query.Filter; import io.weaviate.client6.v1.api.collections.query.Metadata; import io.weaviate.client6.v1.api.collections.query.Metadata.MetadataField; @@ -177,7 +177,7 @@ public void testReferences_AddReplaceDelete() throws IOException { persons.data.referenceAdd( john.uuid(), "hasFriend", - Reference.object(albie)); + ObjectReference.object(albie)); // Assert var johnWithFriends = persons.query.fetchObjectById(john.uuid(), @@ -198,7 +198,7 @@ public void testReferences_AddReplaceDelete() throws IOException { persons.data.referenceReplace( john.uuid(), "hasFriend", - Reference.object(barbara)); + ObjectReference.object(barbara)); johnWithFriends = persons.query.fetchObjectById(john.uuid(), query -> query.returnReferences( @@ -217,7 +217,7 @@ public void testReferences_AddReplaceDelete() throws IOException { persons.data.referenceDelete( john.uuid(), "hasFriend", - Reference.object(barbara)); + ObjectReference.object(barbara)); // Assert johnWithFriends = persons.query.fetchObjectById(john.uuid(), @@ -289,7 +289,7 @@ public void testUpdate() throws IOException { books.data.update(ivanhoe.uuid(), update -> update .properties(Map.of("year", 1819)) - .reference("writtenBy", Reference.objects(walter)) + .reference("writtenBy", ObjectReference.objects(walter)) .vectors(Vectors.of(vector))); // Assert @@ -409,7 +409,7 @@ public void testReferenceAddMany() throws IOException { var alpha = airports.data.insert(Map.of()).uuid(); var goodburg = cities.data.insert(Map.of(), city -> city - .reference("hasAirports", Reference.uuids(alpha))); + .reference("hasAirports", ObjectReference.uuids(alpha))); // Act var newAirports = airports.data.insertMany(Map.of(), Map.of()); diff --git a/src/it/java/io/weaviate/integration/ReferencesITest.java b/src/it/java/io/weaviate/integration/ReferencesITest.java index 36c5b1d8f..e5310ac28 100644 --- a/src/it/java/io/weaviate/integration/ReferencesITest.java +++ b/src/it/java/io/weaviate/integration/ReferencesITest.java @@ -14,7 +14,7 @@ import io.weaviate.client6.v1.api.collections.Property; import io.weaviate.client6.v1.api.collections.ReferenceProperty; import io.weaviate.client6.v1.api.collections.WeaviateObject; -import io.weaviate.client6.v1.api.collections.data.Reference; +import io.weaviate.client6.v1.api.collections.data.ObjectReference; import io.weaviate.client6.v1.api.collections.query.QueryReference; import io.weaviate.containers.Container; @@ -72,9 +72,9 @@ public void testReferences() throws IOException { var alex = artists.data.insert( Map.of("name", "Alex"), opt -> opt - .reference("hasAwards", Reference.uuids( + .reference("hasAwards", ObjectReference.uuids( grammy_1.uuid(), oscar_1.uuid())) - .reference("hasAwards", Reference.objects(grammy_2, oscar_2))); + .reference("hasAwards", ObjectReference.objects(grammy_2, oscar_2))); // Act: add one more reference var nsMovies = ns("Movies"); @@ -146,12 +146,12 @@ public void testNestedReferences() throws IOException { var musicAcademy = academies.data.insert(Map.of("ceo", "Harvy Mason")); var grammy_1 = grammies.data.insert(Map.of(), - opt -> opt.reference("presentedBy", Reference.objects(musicAcademy))); + opt -> opt.reference("presentedBy", ObjectReference.objects(musicAcademy))); var alex = artists.data.insert( Map.of("name", "Alex"), opt -> opt - .reference("hasAwards", Reference.objects(grammy_1))); + .reference("hasAwards", ObjectReference.objects(grammy_1))); // Assert: fetch nested references var gotAlex = artists.query.fetchObjectById(alex.uuid(), diff --git a/src/it/java/io/weaviate/integration/SearchITest.java b/src/it/java/io/weaviate/integration/SearchITest.java index 08f1d1565..35f0aa30d 100644 --- a/src/it/java/io/weaviate/integration/SearchITest.java +++ b/src/it/java/io/weaviate/integration/SearchITest.java @@ -28,7 +28,7 @@ import io.weaviate.client6.v1.api.collections.VectorConfig; import io.weaviate.client6.v1.api.collections.Vectors; import io.weaviate.client6.v1.api.collections.WeaviateObject; -import io.weaviate.client6.v1.api.collections.data.Reference; +import io.weaviate.client6.v1.api.collections.data.ObjectReference; import io.weaviate.client6.v1.api.collections.generate.GenerativeObject; import io.weaviate.client6.v1.api.collections.generate.TaskOutput; import io.weaviate.client6.v1.api.collections.generative.DummyGenerative; @@ -197,9 +197,9 @@ public void testNearText_groupBy() throws IOException { var songs = client.collections.use(nsSongs); songs.data.insert(Map.of("title", "Yellow Submarine"), - s -> s.reference("performedBy", Reference.objects(beatles))); + s -> s.reference("performedBy", ObjectReference.objects(beatles))); songs.data.insert(Map.of("title", "Run Through The Jungle"), - s -> s.reference("performedBy", Reference.objects(ccr))); + s -> s.reference("performedBy", ObjectReference.objects(ccr))); var result = songs.query.nearText("nature", opt -> opt.returnProperties("title"), diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java deleted file mode 100644 index 138843cf6..000000000 --- a/src/main/java/io/weaviate/client6/v1/api/collections/IReference.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.weaviate.client6.v1.api.collections; - -import java.util.Map; - -public interface IReference { - String uuid(); - - String collection(); - - WeaviateObject> asWeaviateObject(); -} diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/IWeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/IWeaviateObject.java deleted file mode 100644 index d7266736d..000000000 --- a/src/main/java/io/weaviate/client6/v1/api/collections/IWeaviateObject.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.weaviate.client6.v1.api.collections; - -import java.util.List; -import java.util.Map; - -import io.weaviate.client6.v1.api.collections.query.QueryMetadata; - -public interface IWeaviateObject { - String uuid(); - - String collection(); - - Vectors vectors(); - - String tenant(); - - PropertiesT properties(); - - Map> references(); - - Long createdAt(); - - Long lastUpdatedAt(); - - QueryMetadata queryMetadata(); -} diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/Reference.java b/src/main/java/io/weaviate/client6/v1/api/collections/Reference.java new file mode 100644 index 000000000..09576f08a --- /dev/null +++ b/src/main/java/io/weaviate/client6/v1/api/collections/Reference.java @@ -0,0 +1,41 @@ +package io.weaviate.client6.v1.api.collections; + +import java.util.Map; + +import io.weaviate.client6.v1.api.collections.data.ObjectReference; + +public interface Reference { + /** UUID of the reference object. */ + String uuid(); + + /** Name of the collection the reference belongs to. */ + String collection(); + + /** + * Cast {@code this} into an instance of {@link WeaviateObject>}. Useful when working with references retrieved in a query. + * + *

{@code
+   *  var metalSongs = songs.query.fetchObjects(q -> q
+   *    .filters(Filter.property("genres").containsAll("metal")
+   *    .returnReferences(QueryReference.multi("performedBy"));
+   *
+   *  metalSongs.objects().forEach(song -> {
+   *    var songName = song.properties().get("name");
+   *    song.references().forEach(ref -> {
+   *      var artistName = ref.asWeaviateObject().properties().get("artistName");
+   *      System.out.printf("%s is performed by %s", songName, artistName);
+   *    });
+   *  });
+   * }
+ * + *

+ * Only call this method on objects returned from methods under {@code .query} + * namespace, as insert-references do not implement this interface. + * + * @throws IllegalStateException if reference object is an instance of + * {@link ObjectReference}. See usage guidelines + * above. + */ + WeaviateObject> asWeaviateObject(); +} diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java index 5cd184a8a..7faf0e20b 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/WeaviateObject.java @@ -21,7 +21,7 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; -import io.weaviate.client6.v1.api.collections.data.Reference; +import io.weaviate.client6.v1.api.collections.data.ObjectReference; import io.weaviate.client6.v1.api.collections.query.QueryMetadata; import io.weaviate.client6.v1.internal.ObjectBuilder; @@ -35,33 +35,8 @@ public record WeaviateObject( @SerializedName("lastUpdateTimeUnix") Long lastUpdatedAt, QueryMetadata queryMetadata, - Map> references) implements IReference { - - /** - * Cast {@code this} into an instance of {@link IWeaviateObject>}. Useful when working with references retrieved in a query. - * - *

{@code
-   *  var metalSongs = songs.query.fetchObjects(q -> q
-   *    .filters(Filter.property("genres").containsAll("metal")
-   *    .returnReferences(QueryReference.multi("performedBy"));
-   *
-   *  metalSongs.objects().forEach(song -> {
-   *    var songName = song.properties().get("name");
-   *    song.references().forEach(ref -> {
-   *      var artistName = ref.asWeaviateObject().properties().get("artistName");
-   *      System.out.printf("%s is performed by %s", songName, artistName);
-   *    });
-   *  });
-   * }
- * - *

- * Only call this method on objects returned from methods under {@code .query} - * namespace, as insert-references do not implement this interface. - * - * @throws IllegalStateException if reference object is an instance of - * {@link Reference}. See usage guidelines above. - */ + Map> references) implements Reference { + @SuppressWarnings("unchecked") @Override public WeaviateObject> asWeaviateObject() { @@ -97,7 +72,7 @@ public static class Builder implements ObjectBuilder> references = new HashMap<>(); + private Map> references = new HashMap<>(); public Builder uuid(String uuid) { this.uuid = uuid; @@ -118,19 +93,19 @@ public Builder properties(PropertiesT properties) { * Add a reference. Calls to {@link #reference} can be chained * to add multiple references. */ - public Builder reference(String property, IReference... references) { + public Builder reference(String property, Reference... references) { for (var ref : references) { addReference(property, ref); } return this; } - public Builder references(Map> references) { + public Builder references(Map> references) { this.references = references; return this; } - private void addReference(String property, IReference reference) { + private void addReference(String property, Reference reference) { if (!references.containsKey(property)) { references.put(property, new ArrayList<>()); } @@ -172,7 +147,7 @@ public TypeAdapter create(Gson gson, TypeToken typeToken) { final var delegate = (TypeAdapter>) gson .getDelegateAdapter(this, typeToken); final var propertiesAdapter = (TypeAdapter) gson.getAdapter(TypeToken.get(propertiesType)); - final var referencesAdapter = gson.getAdapter(Reference.class); + final var referencesAdapter = gson.getAdapter(ObjectReference.class); return (TypeAdapter) new TypeAdapter>() { @@ -187,7 +162,7 @@ public void write(JsonWriter out, WeaviateObject value) throws IOException { for (var refEntry : value.references().entrySet()) { var beacons = new JsonArray(); for (var reference : refEntry.getValue()) { - var beacon = referencesAdapter.toJsonTree((Reference) reference); + var beacon = referencesAdapter.toJsonTree((ObjectReference) reference); beacons.add(beacon); } properties.add(refEntry.getKey(), beacons); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java index e8feb243c..ff7ac4283 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java @@ -9,14 +9,14 @@ import io.weaviate.client6.v1.api.collections.WeaviateObject; -public record BatchReference(String fromCollection, String fromProperty, String fromUuid, Reference reference) { +public record BatchReference(String fromCollection, String fromProperty, String fromUuid, ObjectReference reference) { public static BatchReference[] objects(WeaviateObject fromObject, String fromProperty, WeaviateObject... toObjects) { return Arrays.stream(toObjects) .map(to -> new BatchReference( fromObject.collection(), fromProperty, fromObject.uuid(), - Reference.object(to))) + ObjectReference.object(to))) .toArray(BatchReference[]::new); } @@ -25,7 +25,7 @@ public static BatchReference[] uuids(WeaviateObject fromObject, String fromPr return Arrays.stream(toUuids) .map(to -> new BatchReference( fromObject.collection(), fromProperty, fromObject.uuid(), - Reference.uuids(to))) + ObjectReference.uuids(to))) .toArray(BatchReference[]::new); } @@ -36,10 +36,10 @@ public void write(JsonWriter out, BatchReference value) throws IOException { out.beginObject(); out.name("from"); - out.value(Reference.toBeacon(value.fromCollection, value.fromProperty, value.fromUuid)); + out.value(ObjectReference.toBeacon(value.fromCollection, value.fromProperty, value.fromUuid)); out.name("to"); - out.value(Reference.toBeacon(value.reference.collection(), value.reference.uuids().get(0))); + out.value(ObjectReference.toBeacon(value.reference.collection(), value.reference.uuids().get(0))); // TODO: add tenant @@ -51,7 +51,7 @@ public BatchReference read(JsonReader in) throws IOException { String fromCollection = null; String fromProperty = null; String fromUuid = null; - Reference toReference = null; + ObjectReference toReference = null; in.beginObject(); while (in.hasNext()) { @@ -81,7 +81,7 @@ public BatchReference read(JsonReader in) throws IOException { } else { id = beacon; } - toReference = new Reference(collection, id); + toReference = new ObjectReference(collection, id); break; } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java index 34f0c9175..248f60f75 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java @@ -137,11 +137,11 @@ public static void buildObject(WeaviateProtoBatch.BatchObject.Builder object for (var ref : references) { if (ref.collection() == null) { singleRef.add(WeaviateProtoBatch.BatchObject.SingleTargetRefProps.newBuilder() - .addAllUuids(((Reference) ref).uuids()) + .addAllUuids(((ObjectReference) ref).uuids()) .setPropName(entry.getKey()).build()); } else { multiRef.add(WeaviateProtoBatch.BatchObject.MultiTargetRefProps.newBuilder() - .setTargetCollection(ref.collection()).addAllUuids(((Reference) ref).uuids()) + .setTargetCollection(ref.collection()).addAllUuids(((ObjectReference) ref).uuids()) .setPropName(entry.getKey()).build()); } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/ObjectReference.java similarity index 68% rename from src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java rename to src/main/java/io/weaviate/client6/v1/api/collections/data/ObjectReference.java index 63f7338ad..3d1000b1f 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/Reference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/ObjectReference.java @@ -10,10 +10,10 @@ import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; -import io.weaviate.client6.v1.api.collections.IReference; +import io.weaviate.client6.v1.api.collections.Reference; import io.weaviate.client6.v1.api.collections.WeaviateObject; -public record Reference(String collection, List uuids) implements IReference { +public record ObjectReference(String collection, List uuids) implements Reference { @Override public String uuid() { @@ -25,7 +25,7 @@ public WeaviateObject> asWeaviateObject() { throw new IllegalStateException("cannot convert to WeaviateObject"); } - public Reference(String collection, String uuid) { + public ObjectReference(String collection, String uuid) { this(collection, List.of(uuid)); } @@ -36,25 +36,25 @@ public Reference(String collection, String uuid) { * the objects before inserting the references, so this may include * some performance overhead. */ - public static Reference uuids(String... uuids) { - return new Reference(null, Arrays.asList(uuids)); + public static ObjectReference uuids(String... uuids) { + return new ObjectReference(null, Arrays.asList(uuids)); } /** Create references to single {@link WeaviateObject}. */ - public static Reference object(WeaviateObject object) { - return new Reference(object.collection(), object.uuid()); + public static ObjectReference object(WeaviateObject object) { + return new ObjectReference(object.collection(), object.uuid()); } /** Create references to multiple {@link WeaviateObject}. */ - public static Reference[] objects(WeaviateObject... objects) { + public static ObjectReference[] objects(WeaviateObject... objects) { return Arrays.stream(objects) - .map(o -> new Reference(o.collection(), o.uuid())) - .toArray(Reference[]::new); + .map(o -> new ObjectReference(o.collection(), o.uuid())) + .toArray(ObjectReference[]::new); } /** Create references to objects in a collection by their UUIDs. */ - public static Reference collection(String collection, String... uuids) { - return new Reference(collection, Arrays.asList(uuids)); + public static ObjectReference collection(String collection, String... uuids) { + return new ObjectReference(collection, Arrays.asList(uuids)); } public static String toBeacon(String collection, String uuid) { @@ -73,10 +73,10 @@ public static String toBeacon(String collection, String property, String uuid) { return beacon; } - public static final TypeAdapter TYPE_ADAPTER = new TypeAdapter() { + public static final TypeAdapter TYPE_ADAPTER = new TypeAdapter() { @Override - public void write(JsonWriter out, Reference value) throws IOException { + public void write(JsonWriter out, ObjectReference value) throws IOException { for (var uuid : value.uuids()) { out.beginObject(); out.name("beacon"); @@ -86,7 +86,7 @@ public void write(JsonWriter out, Reference value) throws IOException { } @Override - public Reference read(JsonReader in) throws IOException { + public ObjectReference read(JsonReader in) throws IOException { String collection = null; String id = null; @@ -110,7 +110,7 @@ public Reference read(JsonReader in) throws IOException { id = beacon; } - return new Reference(collection, id); + return new ObjectReference(collection, id); } }.nullSafe(); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceAddRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceAddRequest.java index 00a04c654..174e868c2 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceAddRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceAddRequest.java @@ -6,7 +6,7 @@ import io.weaviate.client6.v1.internal.rest.Endpoint; import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; -public record ReferenceAddRequest(String fromUuid, String fromProperty, Reference reference) { +public record ReferenceAddRequest(String fromUuid, String fromProperty, ObjectReference reference) { public static final Endpoint endpoint( CollectionDescriptor descriptor, diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceDeleteRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceDeleteRequest.java index 9144f2b2f..d17336bb7 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceDeleteRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceDeleteRequest.java @@ -6,7 +6,7 @@ import io.weaviate.client6.v1.internal.rest.Endpoint; import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; -public record ReferenceDeleteRequest(String fromUuid, String fromProperty, Reference reference) { +public record ReferenceDeleteRequest(String fromUuid, String fromProperty, ObjectReference reference) { public static final Endpoint endpoint( CollectionDescriptor descriptor, diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceReplaceRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceReplaceRequest.java index 3bf7b1e30..f68876ee7 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceReplaceRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReferenceReplaceRequest.java @@ -8,7 +8,7 @@ import io.weaviate.client6.v1.internal.rest.Endpoint; import io.weaviate.client6.v1.internal.rest.SimpleEndpoint; -public record ReferenceReplaceRequest(String fromUuid, String fromProperty, Reference reference) { +public record ReferenceReplaceRequest(String fromUuid, String fromProperty, ObjectReference reference) { public static final Endpoint endpoint( CollectionDescriptor descriptor, diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java index ad6ed9175..13a1afacb 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/ReplaceObjectRequest.java @@ -70,7 +70,7 @@ public Builder vectors(Vectors... vectors) { return this; } - public Builder reference(String property, Reference... references) { + public Builder reference(String property, ObjectReference... references) { this.object.reference(property, references); return this; } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java index ebe51d1fe..6157a1cc8 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/UpdateObjectRequest.java @@ -69,7 +69,7 @@ public Builder vectors(Vectors... vectors) { return this; } - public Builder reference(String property, Reference... references) { + public Builder reference(String property, ObjectReference... references) { this.object.reference(property, references); return this; } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java index c8b764c21..6bf0417b8 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java @@ -132,9 +132,9 @@ public DeleteManyResponse deleteMany(DeleteManyRequest request) { return this.grpcTransport.performRequest(request, DeleteManyRequest.rpc(collection, defaults)); } - public void referenceAdd(String fromUuid, String fromProperty, Reference reference) throws IOException { + public void referenceAdd(String fromUuid, String fromProperty, ObjectReference reference) throws IOException { for (var uuid : reference.uuids()) { - var singleRef = new Reference(reference.collection(), uuid); + var singleRef = new ObjectReference(reference.collection(), uuid); this.restTransport.performRequest(new ReferenceAddRequest(fromUuid, fromProperty, singleRef), ReferenceAddRequest.endpoint(collection, defaults)); } @@ -149,17 +149,17 @@ public ReferenceAddManyResponse referenceAddMany(List references ReferenceAddManyRequest.endpoint(references, defaults)); } - public void referenceDelete(String fromUuid, String fromProperty, Reference reference) throws IOException { + public void referenceDelete(String fromUuid, String fromProperty, ObjectReference reference) throws IOException { for (var uuid : reference.uuids()) { - var singleRef = new Reference(reference.collection(), uuid); + var singleRef = new ObjectReference(reference.collection(), uuid); this.restTransport.performRequest(new ReferenceDeleteRequest(fromUuid, fromProperty, singleRef), ReferenceDeleteRequest.endpoint(collection, defaults)); } } - public void referenceReplace(String fromUuid, String fromProperty, Reference reference) throws IOException { + public void referenceReplace(String fromUuid, String fromProperty, ObjectReference reference) throws IOException { for (var uuid : reference.uuids()) { - var singleRef = new Reference(reference.collection(), uuid); + var singleRef = new ObjectReference(reference.collection(), uuid); this.restTransport.performRequest(new ReferenceReplaceRequest(fromUuid, fromProperty, singleRef), ReferenceReplaceRequest.endpoint(collection, defaults)); } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java index 568253a49..59cc852ea 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java @@ -123,9 +123,9 @@ public CompletableFuture deleteMany(DeleteManyRequest reques return this.grpcTransport.performRequestAsync(request, DeleteManyRequest.rpc(collection, defaults)); } - public CompletableFuture referenceAdd(String fromUuid, String fromProperty, Reference reference) { + public CompletableFuture referenceAdd(String fromUuid, String fromProperty, ObjectReference reference) { return forEachAsync(reference.uuids(), uuid -> { - var singleRef = new Reference(reference.collection(), (String) uuid); + var singleRef = new ObjectReference(reference.collection(), (String) uuid); return this.restTransport.performRequestAsync(new ReferenceAddRequest(fromUuid, fromProperty, singleRef), ReferenceAddRequest.endpoint(collection, defaults)); }); @@ -140,17 +140,17 @@ public CompletableFuture referenceAddMany(List referenceDelete(String fromUuid, String fromProperty, Reference reference) { + public CompletableFuture referenceDelete(String fromUuid, String fromProperty, ObjectReference reference) { return forEachAsync(reference.uuids(), uuid -> { - var singleRef = new Reference(reference.collection(), (String) uuid); + var singleRef = new ObjectReference(reference.collection(), (String) uuid); return this.restTransport.performRequestAsync(new ReferenceDeleteRequest(fromUuid, fromProperty, singleRef), ReferenceDeleteRequest.endpoint(collection, defaults)); }); } - public CompletableFuture referenceReplace(String fromUuid, String fromProperty, Reference reference) { + public CompletableFuture referenceReplace(String fromUuid, String fromProperty, ObjectReference reference) { return forEachAsync(reference.uuids(), uuid -> { - var singleRef = new Reference(reference.collection(), (String) uuid); + var singleRef = new ObjectReference(reference.collection(), (String) uuid); return this.restTransport.performRequestAsync(new ReferenceReplaceRequest(fromUuid, fromProperty, singleRef), ReferenceReplaceRequest.endpoint(collection, defaults)); }); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java index ebfea445d..b40dce505 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java @@ -8,7 +8,7 @@ import java.util.stream.Stream; import io.weaviate.client6.v1.api.collections.GeoCoordinates; -import io.weaviate.client6.v1.api.collections.IReference; +import io.weaviate.client6.v1.api.collections.Reference; import io.weaviate.client6.v1.api.collections.PhoneNumber; import io.weaviate.client6.v1.api.collections.Vectors; import io.weaviate.client6.v1.api.collections.WeaviateObject; @@ -88,14 +88,14 @@ static WeaviateObject unmarshalWithReferences( // I.e. { "ref": A-1 } , { "ref": B-1 } => { "ref": [A-1, B-1] } var referenceProperties = propertiesResult.getRefPropsList() .stream().reduce( - new HashMap>(), + new HashMap>(), (map, ref) -> { var refObjects = ref.getPropertiesList().stream() .map(property -> { var reference = unmarshalWithReferences( property, property.getMetadata(), CollectionDescriptor.ofMap(property.getTargetCollection())); - return (IReference) new WeaviateObject<>( + return (Reference) new WeaviateObject<>( reference.uuid(), reference.collection(), null, // tenant is not returned in the query diff --git a/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java b/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java index bbcf99bf2..85bf428bc 100644 --- a/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java +++ b/src/main/java/io/weaviate/client6/v1/internal/json/JSON.java @@ -56,11 +56,11 @@ public final class JSON { // TypeAdapters ----------------------------------------------------------- gsonBuilder.registerTypeAdapter( - io.weaviate.client6.v1.api.collections.data.Reference.class, - io.weaviate.client6.v1.api.collections.data.Reference.TYPE_ADAPTER); + io.weaviate.client6.v1.api.collections.data.ObjectReference.class, + io.weaviate.client6.v1.api.collections.data.ObjectReference.TYPE_ADAPTER); gsonBuilder.registerTypeAdapter( - io.weaviate.client6.v1.api.collections.IReference.class, - io.weaviate.client6.v1.api.collections.data.Reference.TYPE_ADAPTER); + io.weaviate.client6.v1.api.collections.Reference.class, + io.weaviate.client6.v1.api.collections.data.ObjectReference.TYPE_ADAPTER); gsonBuilder.registerTypeAdapter( io.weaviate.client6.v1.api.collections.data.BatchReference.class, io.weaviate.client6.v1.api.collections.data.BatchReference.TYPE_ADAPTER); diff --git a/src/test/java/io/weaviate/client6/v1/api/collections/CollectionHandleTest.java b/src/test/java/io/weaviate/client6/v1/api/collections/CollectionHandleTest.java index e775e92cf..73d13f5c9 100644 --- a/src/test/java/io/weaviate/client6/v1/api/collections/CollectionHandleTest.java +++ b/src/test/java/io/weaviate/client6/v1/api/collections/CollectionHandleTest.java @@ -14,7 +14,7 @@ import com.jparams.junit4.data.DataMethod; import com.jparams.junit4.description.Name; -import io.weaviate.client6.v1.api.collections.data.Reference; +import io.weaviate.client6.v1.api.collections.data.ObjectReference; import io.weaviate.client6.v1.api.collections.query.ConsistencyLevel; import io.weaviate.client6.v1.internal.ObjectBuilder; import io.weaviate.client6.v1.internal.grpc.protocol.WeaviateProtoBase; @@ -86,7 +86,7 @@ public static Object[][] restTestCases() { "data::add reference", ConsistencyLevel.ONE, Location.QUERY, "john_doe", Location.QUERY, - (Act) c -> c.data.referenceAdd("from-uuid", "from_property", Reference.uuids("to-uuid")), + (Act) c -> c.data.referenceAdd("from-uuid", "from_property", ObjectReference.uuids("to-uuid")), }, { "data::add reference many", @@ -98,13 +98,13 @@ public static Object[][] restTestCases() { "data::replace reference", ConsistencyLevel.ONE, Location.QUERY, "john_doe", Location.QUERY, - (Act) c -> c.data.referenceReplace("from-uuid", "from_property", Reference.uuids("to-uuid")), + (Act) c -> c.data.referenceReplace("from-uuid", "from_property", ObjectReference.uuids("to-uuid")), }, { "data::delete reference", ConsistencyLevel.ONE, Location.QUERY, "john_doe", Location.QUERY, - (Act) c -> c.data.referenceDelete("from-uuid", "from_property", Reference.uuids("to-uuid")), + (Act) c -> c.data.referenceDelete("from-uuid", "from_property", ObjectReference.uuids("to-uuid")), }, }; } diff --git a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java index f985d5a6f..0fbb616ea 100644 --- a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java +++ b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java @@ -27,7 +27,7 @@ import io.weaviate.client6.v1.api.collections.Vectors; import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.api.collections.data.BatchReference; -import io.weaviate.client6.v1.api.collections.data.Reference; +import io.weaviate.client6.v1.api.collections.data.ObjectReference; import io.weaviate.client6.v1.api.collections.data.ReferenceAddManyResponse; import io.weaviate.client6.v1.api.collections.quantizers.PQ; import io.weaviate.client6.v1.api.collections.rerankers.CohereReranker; @@ -403,13 +403,13 @@ public static Object[][] testCases() { // Reference.TYPE_ADAPTER { - Reference.class, - Reference.uuids("id-1"), + ObjectReference.class, + ObjectReference.uuids("id-1"), "{\"beacon\": \"weaviate://localhost/id-1\"}", }, { - Reference.class, - Reference.collection("Doodlebops", "id-1"), + ObjectReference.class, + ObjectReference.collection("Doodlebops", "id-1"), "{\"beacon\": \"weaviate://localhost/Doodlebops/id-1\"}", }, @@ -426,7 +426,7 @@ public static Object[][] testCases() { /* creationTimeUnix */ null, /* lastUpdateTimeUnix */ null, /* queryMetadata */ null, - Map.of("hasRef", List.of(Reference.uuids("ref-1")))), + Map.of("hasRef", List.of(ObjectReference.uuids("ref-1")))), """ { @@ -458,7 +458,7 @@ public static Object[][] testCases() { { BatchReference.class, new BatchReference("FromCollection", "fromProperty", "from-uuid", - Reference.collection("ToCollection", "to-uuid")), + ObjectReference.collection("ToCollection", "to-uuid")), """ { "from": "weaviate://localhost/FromCollection/from-uuid/fromProperty", From d0fd489ac76643fc60f0a30c9f273a71168509c2 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 25 Nov 2025 16:52:24 +0100 Subject: [PATCH 06/11] chore: add TODO --- .../client6/v1/api/collections/query/QueryResponse.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java index b40dce505..b1bc7369e 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryResponse.java @@ -8,8 +8,8 @@ import java.util.stream.Stream; import io.weaviate.client6.v1.api.collections.GeoCoordinates; -import io.weaviate.client6.v1.api.collections.Reference; import io.weaviate.client6.v1.api.collections.PhoneNumber; +import io.weaviate.client6.v1.api.collections.Reference; import io.weaviate.client6.v1.api.collections.Vectors; import io.weaviate.client6.v1.api.collections.WeaviateObject; import io.weaviate.client6.v1.internal.DateUtil; @@ -98,6 +98,7 @@ static WeaviateObject unmarshalWithReferences( return (Reference) new WeaviateObject<>( reference.uuid(), reference.collection(), + // TODO(dyma): we can get tenant from CollectionHandle null, // tenant is not returned in the query (Map) reference.properties(), reference.vectors(), From 096b3f26b3d276b39a9ed395786b7721129e6e0a Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 25 Nov 2025 17:41:20 +0100 Subject: [PATCH 07/11] refactor: store 1 UUID per ObjectReference --- .../io/weaviate/integration/DataITest.java | 2 +- .../api/collections/data/BatchReference.java | 4 +- .../collections/data/InsertManyRequest.java | 4 +- .../api/collections/data/ObjectReference.java | 46 +++++++++++-------- .../collections/data/WeaviateDataClient.java | 21 +++------ .../data/WeaviateDataClientAsync.java | 44 +++--------------- .../api/collections/CollectionHandleTest.java | 6 +-- .../client6/v1/internal/json/JSONTest.java | 6 +-- 8 files changed, 50 insertions(+), 83 deletions(-) diff --git a/src/it/java/io/weaviate/integration/DataITest.java b/src/it/java/io/weaviate/integration/DataITest.java index 2678744f0..e2e0ab6be 100644 --- a/src/it/java/io/weaviate/integration/DataITest.java +++ b/src/it/java/io/weaviate/integration/DataITest.java @@ -409,7 +409,7 @@ public void testReferenceAddMany() throws IOException { var alpha = airports.data.insert(Map.of()).uuid(); var goodburg = cities.data.insert(Map.of(), city -> city - .reference("hasAirports", ObjectReference.uuids(alpha))); + .reference("hasAirports", ObjectReference.uuid(alpha))); // Act var newAirports = airports.data.insertMany(Map.of(), Map.of()); diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java index ff7ac4283..34f5f95b2 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java @@ -25,7 +25,7 @@ public static BatchReference[] uuids(WeaviateObject fromObject, String fromPr return Arrays.stream(toUuids) .map(to -> new BatchReference( fromObject.collection(), fromProperty, fromObject.uuid(), - ObjectReference.uuids(to))) + ObjectReference.uuid(to))) .toArray(BatchReference[]::new); } @@ -39,7 +39,7 @@ public void write(JsonWriter out, BatchReference value) throws IOException { out.value(ObjectReference.toBeacon(value.fromCollection, value.fromProperty, value.fromUuid)); out.name("to"); - out.value(ObjectReference.toBeacon(value.reference.collection(), value.reference.uuids().get(0))); + out.value(ObjectReference.toBeacon(value.reference.collection(), value.reference.uuid())); // TODO: add tenant diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java index 248f60f75..11df4e8b9 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/InsertManyRequest.java @@ -137,11 +137,11 @@ public static void buildObject(WeaviateProtoBatch.BatchObject.Builder object for (var ref : references) { if (ref.collection() == null) { singleRef.add(WeaviateProtoBatch.BatchObject.SingleTargetRefProps.newBuilder() - .addAllUuids(((ObjectReference) ref).uuids()) + .addUuids(ref.uuid()) .setPropName(entry.getKey()).build()); } else { multiRef.add(WeaviateProtoBatch.BatchObject.MultiTargetRefProps.newBuilder() - .setTargetCollection(ref.collection()).addAllUuids(((ObjectReference) ref).uuids()) + .setTargetCollection(ref.collection()).addUuids(ref.uuid()) .setPropName(entry.getKey()).build()); } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/ObjectReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/ObjectReference.java index 3d1000b1f..bb6a0f27e 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/ObjectReference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/ObjectReference.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.util.Arrays; -import java.util.List; import java.util.Map; import com.google.gson.TypeAdapter; @@ -13,20 +12,22 @@ import io.weaviate.client6.v1.api.collections.Reference; import io.weaviate.client6.v1.api.collections.WeaviateObject; -public record ObjectReference(String collection, List uuids) implements Reference { - - @Override - public String uuid() { - return uuids.get(0); - } +public record ObjectReference(String collection, String uuid) implements Reference { @Override public WeaviateObject> asWeaviateObject() { throw new IllegalStateException("cannot convert to WeaviateObject"); } - public ObjectReference(String collection, String uuid) { - this(collection, List.of(uuid)); + /** + * Create reference to a single object by UUID. + *

+ * Weaviate will search each of the existing collections to identify + * the objects before inserting the references, so this may include + * some performance overhead. + */ + public static ObjectReference uuid(String uuid) { + return new ObjectReference(null, uuid); } /** @@ -36,8 +37,10 @@ public ObjectReference(String collection, String uuid) { * the objects before inserting the references, so this may include * some performance overhead. */ - public static ObjectReference uuids(String... uuids) { - return new ObjectReference(null, Arrays.asList(uuids)); + public static ObjectReference[] uuids(String... uuids) { + return Arrays.stream(uuids) + .map(ObjectReference::uuid) + .toArray(ObjectReference[]::new); } /** Create references to single {@link WeaviateObject}. */ @@ -52,9 +55,16 @@ public static ObjectReference[] objects(WeaviateObject... objects) { .toArray(ObjectReference[]::new); } + /** Create a reference to an single object in a collection by its UUID. */ + public static ObjectReference collection(String collection, String uuid) { + return new ObjectReference(collection, uuid); + } + /** Create references to objects in a collection by their UUIDs. */ - public static ObjectReference collection(String collection, String... uuids) { - return new ObjectReference(collection, Arrays.asList(uuids)); + public static ObjectReference[] collection(String collection, String... uuids) { + return Arrays.stream(uuids) + .map(uuid -> new ObjectReference(collection, uuid)) + .toArray(ObjectReference[]::new); } public static String toBeacon(String collection, String uuid) { @@ -77,12 +87,10 @@ public static String toBeacon(String collection, String property, String uuid) { @Override public void write(JsonWriter out, ObjectReference value) throws IOException { - for (var uuid : value.uuids()) { - out.beginObject(); - out.name("beacon"); - out.value(toBeacon(value.collection(), uuid)); - out.endObject(); - } + out.beginObject(); + out.name("beacon"); + out.value(toBeacon(value.collection(), value.uuid())); + out.endObject(); } @Override diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java index 6bf0417b8..c7497ec64 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClient.java @@ -133,11 +133,8 @@ public DeleteManyResponse deleteMany(DeleteManyRequest request) { } public void referenceAdd(String fromUuid, String fromProperty, ObjectReference reference) throws IOException { - for (var uuid : reference.uuids()) { - var singleRef = new ObjectReference(reference.collection(), uuid); - this.restTransport.performRequest(new ReferenceAddRequest(fromUuid, fromProperty, singleRef), - ReferenceAddRequest.endpoint(collection, defaults)); - } + this.restTransport.performRequest(new ReferenceAddRequest(fromUuid, fromProperty, reference), + ReferenceAddRequest.endpoint(collection, defaults)); } public ReferenceAddManyResponse referenceAddMany(BatchReference... references) throws IOException { @@ -150,18 +147,12 @@ public ReferenceAddManyResponse referenceAddMany(List references } public void referenceDelete(String fromUuid, String fromProperty, ObjectReference reference) throws IOException { - for (var uuid : reference.uuids()) { - var singleRef = new ObjectReference(reference.collection(), uuid); - this.restTransport.performRequest(new ReferenceDeleteRequest(fromUuid, fromProperty, singleRef), - ReferenceDeleteRequest.endpoint(collection, defaults)); - } + this.restTransport.performRequest(new ReferenceDeleteRequest(fromUuid, fromProperty, reference), + ReferenceDeleteRequest.endpoint(collection, defaults)); } public void referenceReplace(String fromUuid, String fromProperty, ObjectReference reference) throws IOException { - for (var uuid : reference.uuids()) { - var singleRef = new ObjectReference(reference.collection(), uuid); - this.restTransport.performRequest(new ReferenceReplaceRequest(fromUuid, fromProperty, singleRef), - ReferenceReplaceRequest.endpoint(collection, defaults)); - } + this.restTransport.performRequest(new ReferenceReplaceRequest(fromUuid, fromProperty, reference), + ReferenceReplaceRequest.endpoint(collection, defaults)); } } diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java index 59cc852ea..cdbb2b08b 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/WeaviateDataClientAsync.java @@ -1,7 +1,6 @@ package io.weaviate.client6.v1.api.collections.data; import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -124,11 +123,8 @@ public CompletableFuture deleteMany(DeleteManyRequest reques } public CompletableFuture referenceAdd(String fromUuid, String fromProperty, ObjectReference reference) { - return forEachAsync(reference.uuids(), uuid -> { - var singleRef = new ObjectReference(reference.collection(), (String) uuid); - return this.restTransport.performRequestAsync(new ReferenceAddRequest(fromUuid, fromProperty, singleRef), - ReferenceAddRequest.endpoint(collection, defaults)); - }); + return this.restTransport.performRequestAsync(new ReferenceAddRequest(fromUuid, fromProperty, reference), + ReferenceAddRequest.endpoint(collection, defaults)); } public CompletableFuture referenceAddMany(BatchReference... references) { @@ -141,40 +137,12 @@ public CompletableFuture referenceAddMany(List referenceDelete(String fromUuid, String fromProperty, ObjectReference reference) { - return forEachAsync(reference.uuids(), uuid -> { - var singleRef = new ObjectReference(reference.collection(), (String) uuid); - return this.restTransport.performRequestAsync(new ReferenceDeleteRequest(fromUuid, fromProperty, singleRef), - ReferenceDeleteRequest.endpoint(collection, defaults)); - }); + return this.restTransport.performRequestAsync(new ReferenceDeleteRequest(fromUuid, fromProperty, reference), + ReferenceDeleteRequest.endpoint(collection, defaults)); } public CompletableFuture referenceReplace(String fromUuid, String fromProperty, ObjectReference reference) { - return forEachAsync(reference.uuids(), uuid -> { - var singleRef = new ObjectReference(reference.collection(), (String) uuid); - return this.restTransport.performRequestAsync(new ReferenceReplaceRequest(fromUuid, fromProperty, singleRef), - ReferenceReplaceRequest.endpoint(collection, defaults)); - }); - } - - /** - * Spawn execution {@code fn} for each of the {@code elements} and return a - * flattened {@link CompletableFuture#allOf}. - * - *

- * Usage: - * - *

{@code
-   *  // With elements immediately available
-   *  forEachAsync(myElements, element -> doNetworkIo(element));
-   *
-   *  // Chain to another CompletableFuture
-   *  fetch(request).thenCompose(elements -> forEachAsync(...));
-   * }
- */ - private static CompletableFuture forEachAsync(Collection elements, - Function> fn) { - var futures = elements.stream().map(el -> fn.apply(el)) - .toArray(CompletableFuture[]::new); - return CompletableFuture.allOf(futures); + return this.restTransport.performRequestAsync(new ReferenceReplaceRequest(fromUuid, fromProperty, reference), + ReferenceReplaceRequest.endpoint(collection, defaults)); } } diff --git a/src/test/java/io/weaviate/client6/v1/api/collections/CollectionHandleTest.java b/src/test/java/io/weaviate/client6/v1/api/collections/CollectionHandleTest.java index 73d13f5c9..9cf1e99d9 100644 --- a/src/test/java/io/weaviate/client6/v1/api/collections/CollectionHandleTest.java +++ b/src/test/java/io/weaviate/client6/v1/api/collections/CollectionHandleTest.java @@ -86,7 +86,7 @@ public static Object[][] restTestCases() { "data::add reference", ConsistencyLevel.ONE, Location.QUERY, "john_doe", Location.QUERY, - (Act) c -> c.data.referenceAdd("from-uuid", "from_property", ObjectReference.uuids("to-uuid")), + (Act) c -> c.data.referenceAdd("from-uuid", "from_property", ObjectReference.uuid("to-uuid")), }, { "data::add reference many", @@ -98,13 +98,13 @@ public static Object[][] restTestCases() { "data::replace reference", ConsistencyLevel.ONE, Location.QUERY, "john_doe", Location.QUERY, - (Act) c -> c.data.referenceReplace("from-uuid", "from_property", ObjectReference.uuids("to-uuid")), + (Act) c -> c.data.referenceReplace("from-uuid", "from_property", ObjectReference.uuid("to-uuid")), }, { "data::delete reference", ConsistencyLevel.ONE, Location.QUERY, "john_doe", Location.QUERY, - (Act) c -> c.data.referenceDelete("from-uuid", "from_property", ObjectReference.uuids("to-uuid")), + (Act) c -> c.data.referenceDelete("from-uuid", "from_property", ObjectReference.uuid("to-uuid")), }, }; } diff --git a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java index 0fbb616ea..958e1e1d7 100644 --- a/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java +++ b/src/test/java/io/weaviate/client6/v1/internal/json/JSONTest.java @@ -404,7 +404,7 @@ public static Object[][] testCases() { // Reference.TYPE_ADAPTER { ObjectReference.class, - ObjectReference.uuids("id-1"), + ObjectReference.uuid("id-1"), "{\"beacon\": \"weaviate://localhost/id-1\"}", }, { @@ -413,7 +413,7 @@ public static Object[][] testCases() { "{\"beacon\": \"weaviate://localhost/Doodlebops/id-1\"}", }, - // XWriteWeaviateObject.CustomTypeAdapterFactory.INSTANCE + // WriteWeaviateObject.CustomTypeAdapterFactory.INSTANCE { new TypeToken>>() { }, @@ -426,7 +426,7 @@ public static Object[][] testCases() { /* creationTimeUnix */ null, /* lastUpdateTimeUnix */ null, /* queryMetadata */ null, - Map.of("hasRef", List.of(ObjectReference.uuids("ref-1")))), + Map.of("hasRef", List.of(ObjectReference.uuid("ref-1")))), """ { From f6dc56b23630735f66cd9811e084e0c2a3c14413 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 25 Nov 2025 17:45:19 +0100 Subject: [PATCH 08/11] chore: remove sketches --- .../io/weaviate/integration/DataITest.java | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/src/it/java/io/weaviate/integration/DataITest.java b/src/it/java/io/weaviate/integration/DataITest.java index e2e0ab6be..a0969655f 100644 --- a/src/it/java/io/weaviate/integration/DataITest.java +++ b/src/it/java/io/weaviate/integration/DataITest.java @@ -80,32 +80,6 @@ public void testCreateGetDelete() throws IOException { .as("lastUpdatedAt").isNotNull(); }); - // var write = WriteWeaviateObject.of(null); - // write.tenant(); // can be null, but that's perfectly fine - // - // write.references().get("").getFirst().asWeaviateObject(); - // - // // Three key changes: - // var wv = WeaviateObject.write(null); // 1: you can use WeaviateObject, and - // not WriteWeaviateObject - // write.queryMetadata(); // 2: This should be called "queryMetadata" to avoid - // confusion - // wv.references().forEach((key, references) -> { - // references.forEach(ref -> { - // ref.collection(); - // ref.uuid(); - // - // // get "title" property from a referenced object - // var title = ref.asWeaviateObject().properties().get("title"); - // - // ref.asWeaviateObject().references().forEach((__, nestedRefs) -> { - // nestedRefs.forEach(nref -> { - // var n_title = ref.asWeaviateObject().properties().get("title"); - // }); - // }); - // }); - // }); - var deleted = artists.data.deleteById(id); Assertions.assertThat(deleted) .as("object was deleted").isTrue(); From e3293934154742761240f61bab51642cd31e72f5 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 25 Nov 2025 17:47:28 +0100 Subject: [PATCH 09/11] chore: remove TODO cross-tenant references are not supported on the server --- .../v1/api/collections/data/BatchReference.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java index 34f5f95b2..a83652be5 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/BatchReference.java @@ -41,8 +41,6 @@ public void write(JsonWriter out, BatchReference value) throws IOException { out.name("to"); out.value(ObjectReference.toBeacon(value.reference.collection(), value.reference.uuid())); - // TODO: add tenant - out.endObject(); } @@ -84,20 +82,6 @@ public BatchReference read(JsonReader in) throws IOException { toReference = new ObjectReference(collection, id); break; } - - // case "tenant": - // switch (in.peek()) { - // case STRING: - // in.nextString(); - // case NULL: - // in.nextNull(); - // default: - // // We don't expect anything else - // } - // System.out.println("processed tenant"); - // break; - // default: - // in.skipValue(); } } in.endObject(); From ec2de67363d7e403bec29ca94de8395ff50d9773 Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 25 Nov 2025 18:17:27 +0100 Subject: [PATCH 10/11] chore: add UUID and Vectors to grouped query object returns --- .../generate/GenerativeResponseGrouped.java | 2 ++ .../v1/api/collections/query/QueryObjectGrouped.java | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGrouped.java b/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGrouped.java index b73825bac..95710580c 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGrouped.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/generate/GenerativeResponseGrouped.java @@ -36,6 +36,8 @@ static GenerativeResponseGrouped unmarshal( object.getMetadata(), collection)) .map(object -> new QueryObjectGrouped<>( + object.uuid(), + object.vectors(), object.properties(), object.queryMetadata(), groupName)) diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java index aec77443a..9f8ca1133 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/query/QueryObjectGrouped.java @@ -1,8 +1,11 @@ package io.weaviate.client6.v1.api.collections.query; +import io.weaviate.client6.v1.api.collections.Vectors; import io.weaviate.client6.v1.api.collections.WeaviateObject; public record QueryObjectGrouped( + String uuid, + Vectors vectors, /** Object properties. */ PropertiesT properties, /** Object metadata. */ @@ -12,6 +15,11 @@ public record QueryObjectGrouped( QueryObjectGrouped(WeaviateObject object, String belongsToGroup) { - this(object.properties(), object.queryMetadata(), belongsToGroup); + this( + object.uuid(), + object.vectors(), + object.properties(), + object.queryMetadata(), + belongsToGroup); } } From 7ac150149142ea4f9c73933ec827f5168836319b Mon Sep 17 00:00:00 2001 From: dyma solovei Date: Tue, 25 Nov 2025 18:38:07 +0100 Subject: [PATCH 11/11] chore: guard against invalid UUIDs Some integration tests failed w/ a BufferUnderflow exception when run against v1.32.16, which we can handle more gracefully by returning null from decodeUuid(). An invalid UUID is a server-side issue and we should not try to decode it in the client. --- .../v1/api/collections/data/DeleteManyRequest.java | 2 +- .../client6/v1/internal/grpc/ByteStringUtil.java | 7 +++++-- .../client6/v1/internal/grpc/ByteStringUtilTest.java | 9 ++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/weaviate/client6/v1/api/collections/data/DeleteManyRequest.java b/src/main/java/io/weaviate/client6/v1/api/collections/data/DeleteManyRequest.java index 1e71855d0..2fff8681a 100644 --- a/src/main/java/io/weaviate/client6/v1/api/collections/data/DeleteManyRequest.java +++ b/src/main/java/io/weaviate/client6/v1/api/collections/data/DeleteManyRequest.java @@ -46,7 +46,7 @@ public static Rpc new DeleteManyResponse.DeletedObject( - ByteStringUtil.decodeUuid(obj.getUuid()).toString(), + ByteStringUtil.decodeUuid(obj.getUuid()), obj.getSuccessful(), obj.getError())) .toList(); diff --git a/src/main/java/io/weaviate/client6/v1/internal/grpc/ByteStringUtil.java b/src/main/java/io/weaviate/client6/v1/internal/grpc/ByteStringUtil.java index 6bee6de0a..335c428d7 100644 --- a/src/main/java/io/weaviate/client6/v1/internal/grpc/ByteStringUtil.java +++ b/src/main/java/io/weaviate/client6/v1/internal/grpc/ByteStringUtil.java @@ -16,11 +16,14 @@ private ByteStringUtil() { private static final ByteOrder BYTE_ORDER = ByteOrder.LITTLE_ENDIAN; /** Decode ByteString to UUID. */ - public static UUID decodeUuid(ByteString bs) { + public static String decodeUuid(ByteString bs) { + if (bs.size() != Long.BYTES * 2) { + return null; + } var buf = ByteBuffer.wrap(bs.toByteArray()); var most = buf.getLong(); var least = buf.getLong(); - return new UUID(most, least); + return new UUID(most, least).toString(); } /** Encode float[] to ByteString. */ diff --git a/src/test/java/io/weaviate/client6/v1/internal/grpc/ByteStringUtilTest.java b/src/test/java/io/weaviate/client6/v1/internal/grpc/ByteStringUtilTest.java index 147549b2c..6d7b3abe8 100644 --- a/src/test/java/io/weaviate/client6/v1/internal/grpc/ByteStringUtilTest.java +++ b/src/test/java/io/weaviate/client6/v1/internal/grpc/ByteStringUtilTest.java @@ -49,10 +49,17 @@ public void test_decodeVector_2d() { public void test_decodeUuid() { byte[] bytes = { 38, 19, -74, 24, -114, -19, 73, 43, -112, -60, 47, 96, 83, -89, -35, -23 }; String want = "2613b618-8eed-492b-90c4-2f6053a7dde9"; - String got = ByteStringUtil.decodeUuid(ByteString.copyFrom(bytes)).toString(); + String got = ByteStringUtil.decodeUuid(ByteString.copyFrom(bytes)); Assertions.assertThat(got).isEqualTo(want); } + @Test + public void test_decodeUuid_bufferUnderflow() { + byte[] bytes = { 38, 19 }; // A valid UUID is exactly 16 bytes + String got = ByteStringUtil.decodeUuid(ByteString.copyFrom(bytes)); + Assertions.assertThat(got).isNull(); + } + @Test public void test_decodeVector_1d_empty() { byte[] bytes = new byte[0];