|
19 | 19 | import io.weaviate.ConcurrentTest; |
20 | 20 | import io.weaviate.client6.v1.api.WeaviateApiException; |
21 | 21 | import io.weaviate.client6.v1.api.WeaviateClient; |
| 22 | +import io.weaviate.client6.v1.api.collections.ObjectMetadata; |
22 | 23 | import io.weaviate.client6.v1.api.collections.Property; |
23 | 24 | import io.weaviate.client6.v1.api.collections.ReferenceProperty; |
24 | 25 | import io.weaviate.client6.v1.api.collections.VectorConfig; |
|
31 | 32 | import io.weaviate.client6.v1.api.collections.query.QueryMetadata; |
32 | 33 | import io.weaviate.client6.v1.api.collections.query.QueryResponseGroup; |
33 | 34 | import io.weaviate.client6.v1.api.collections.query.SortBy; |
| 35 | +import io.weaviate.client6.v1.api.collections.query.Target; |
34 | 36 | import io.weaviate.client6.v1.api.collections.query.Where; |
| 37 | +import io.weaviate.client6.v1.api.collections.vectorindex.Hnsw; |
| 38 | +import io.weaviate.client6.v1.api.collections.vectorindex.MultiVector; |
35 | 39 | import io.weaviate.containers.Container; |
36 | 40 | import io.weaviate.containers.Container.ContainerGroup; |
37 | 41 | import io.weaviate.containers.Contextionary; |
@@ -499,4 +503,50 @@ public void testMetadataAll() throws IOException { |
499 | 503 | Assertions.assertThat(metadataNearText.distance()).as("distance").isNotNull(); |
500 | 504 | Assertions.assertThat(metadataNearText.certainty()).as("certainty").isNotNull(); |
501 | 505 | } |
| 506 | + |
| 507 | + @Test |
| 508 | + public void testNearVector_targetVectors() throws IOException { |
| 509 | + // Arrange |
| 510 | + var nsThings = ns("Things"); |
| 511 | + |
| 512 | + client.collections.create(nsThings, |
| 513 | + c -> c.vectorConfig( |
| 514 | + VectorConfig.selfProvided("v1d"), |
| 515 | + VectorConfig.selfProvided("v2d", |
| 516 | + none -> none |
| 517 | + .vectorIndex(Hnsw.of( |
| 518 | + hnsw -> hnsw.multiVector(MultiVector.of())))))); |
| 519 | + |
| 520 | + var things = client.collections.use(nsThings); |
| 521 | + |
| 522 | + var thing123 = things.data.insert(Map.of(), thing -> thing.vectors( |
| 523 | + Vectors.of("v1d", new float[] { 1, 2, 3 }), |
| 524 | + Vectors.of("v2d", new float[][] { { 1, 2, 3 }, { 1, 2, 3 } }))); |
| 525 | + |
| 526 | + var thing456 = things.data.insertMany(List.of( |
| 527 | + WeaviateObject.of(thing -> thing |
| 528 | + .metadata(ObjectMetadata.of( |
| 529 | + meta -> meta |
| 530 | + .vectors( |
| 531 | + Vectors.of("v1d", new float[] { 4, 5, 6 }), |
| 532 | + Vectors.of("v2d", new float[][] { { 4, 5, 6 }, { 4, 5, 6 } }))))))); |
| 533 | + Assertions.assertThat(thing456.errors()).as("insert many").isEmpty(); |
| 534 | + |
| 535 | + // Act |
| 536 | + var got123 = things.query.nearVector( |
| 537 | + Target.vector("v1d", new float[] { 1, 2, 3 }), |
| 538 | + q -> q.limit(1)); |
| 539 | + Assertions.assertThat(got123.objects()) |
| 540 | + .as("search v1d") |
| 541 | + .hasSize(1).extracting(WeaviateObject::uuid) |
| 542 | + .containsExactly(thing123.uuid()); |
| 543 | + |
| 544 | + var got456 = things.query.nearVector( |
| 545 | + Target.vector("v2d", new float[][] { { 4, 5, 6 }, { 4, 5, 6 } }), |
| 546 | + q -> q.limit(1)); |
| 547 | + Assertions.assertThat(got456.objects()) |
| 548 | + .as("search v2d") |
| 549 | + .hasSize(1).extracting(WeaviateObject::uuid) |
| 550 | + .containsExactly(thing456.uuids().get(0)); |
| 551 | + } |
502 | 552 | } |
0 commit comments