|
15 | 15 | import io.weaviate.client6.v1.api.collections.WeaviateObject; |
16 | 16 | import io.weaviate.client6.v1.api.collections.data.Reference; |
17 | 17 | import io.weaviate.client6.v1.api.collections.query.Metadata; |
| 18 | +import io.weaviate.client6.v1.api.collections.query.QueryMetadata; |
18 | 19 | import io.weaviate.client6.v1.api.collections.query.QueryReference; |
19 | 20 | import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw; |
20 | 21 | import io.weaviate.client6.v1.api.collections.vectorizers.NoneVectorizer; |
@@ -180,9 +181,73 @@ public void testReferences_AddReplaceDelete() throws IOException { |
180 | 181 |
|
181 | 182 | @Test |
182 | 183 | public void testReplace() { |
| 184 | + // Replace (PUT): |
| 185 | + // properties, reference, vectors |
183 | 186 | } |
184 | 187 |
|
185 | 188 | @Test |
186 | | - public void testUpdate() { |
| 189 | + public void testUpdate() throws IOException { |
| 190 | + // Arrange |
| 191 | + var nsBooks = ns("Books"); |
| 192 | + var nsAuthors = ns("Authors"); |
| 193 | + |
| 194 | + client.collections.create(nsAuthors, |
| 195 | + collection -> collection |
| 196 | + .properties(Property.text("name"))); |
| 197 | + |
| 198 | + client.collections.create(nsBooks, |
| 199 | + collection -> collection |
| 200 | + .properties(Property.text("title"), Property.integer("year")) |
| 201 | + .references(Property.reference("writtenBy", nsAuthors)) |
| 202 | + .vector(Hnsw.of(new NoneVectorizer()))); |
| 203 | + |
| 204 | + var authors = client.collections.use(nsAuthors); |
| 205 | + var walter = authors.data.insert(Map.of("name", "walter scott")); |
| 206 | + |
| 207 | + var vector = new Float[] { 1f, 2f, 3f }; |
| 208 | + |
| 209 | + var books = client.collections.use(nsBooks); |
| 210 | + |
| 211 | + // Add 1 book without mentioning its author, year published, |
| 212 | + // or supplying a vector. |
| 213 | + var ivanhoe = books.data.insert(Map.of("title", "ivanhoe")); |
| 214 | + |
| 215 | + // Act |
| 216 | + books.data.update(ivanhoe.metadata().uuid(), |
| 217 | + update -> update |
| 218 | + .properties(Map.of("year", 1819)) |
| 219 | + .reference("writtenBy", Reference.objects(walter)) |
| 220 | + .vectors(Vectors.of(vector))); |
| 221 | + |
| 222 | + // Assert |
| 223 | + var updIvanhoe = books.query.byId( |
| 224 | + ivanhoe.metadata().uuid(), |
| 225 | + query -> query |
| 226 | + .returnMetadata(Metadata.VECTOR) |
| 227 | + .returnReferences( |
| 228 | + QueryReference.single("writtenBy", |
| 229 | + writtenBy -> writtenBy.returnMetadata(Metadata.ID)))); |
| 230 | + |
| 231 | + Assertions.assertThat(updIvanhoe).get() |
| 232 | + .satisfies(book -> { |
| 233 | + Assertions.assertThat(book) |
| 234 | + .as("has year property") |
| 235 | + .extracting(WeaviateObject::properties, InstanceOfAssertFactories.MAP) |
| 236 | + .contains(Map.entry("year", 1819L)); |
| 237 | + |
| 238 | + Assertions.assertThat(book) |
| 239 | + .as("has reference to Authors") |
| 240 | + .extracting(WeaviateObject::references, InstanceOfAssertFactories.MAP) |
| 241 | + .extractingByKey("writtenBy", InstanceOfAssertFactories.list(WeaviateObject.class)) |
| 242 | + .first() |
| 243 | + .extracting(WeaviateObject::properties, InstanceOfAssertFactories.MAP) |
| 244 | + .contains(Map.entry("name", "walter scott")); |
| 245 | + |
| 246 | + Assertions.assertThat(book) |
| 247 | + .as("has a vector") |
| 248 | + .extracting(WeaviateObject::metadata) |
| 249 | + .extracting(QueryMetadata::vectors) |
| 250 | + .returns(vector, Vectors::getDefaultSingle); |
| 251 | + }); |
187 | 252 | } |
188 | 253 | } |
0 commit comments