|
32 | 32 | import io.weaviate.client6.v1.api.collections.generate.GenerativeObject; |
33 | 33 | import io.weaviate.client6.v1.api.collections.generate.TaskOutput; |
34 | 34 | import io.weaviate.client6.v1.api.collections.generative.DummyGenerative; |
| 35 | +import io.weaviate.client6.v1.api.collections.query.FetchObjectById; |
35 | 36 | import io.weaviate.client6.v1.api.collections.query.Filter; |
36 | 37 | import io.weaviate.client6.v1.api.collections.query.GroupBy; |
37 | 38 | import io.weaviate.client6.v1.api.collections.query.Metadata; |
@@ -790,4 +791,52 @@ public void test_rerankQueries() throws IOException { |
790 | 791 | // Assert: ranking not important really, just that the request was valid. |
791 | 792 | Assertions.assertThat(got.objects()).hasSize(2); |
792 | 793 | } |
| 794 | + |
| 795 | + @Test |
| 796 | + public void testVectorizerModel2VecPropeties() throws IOException { |
| 797 | + var collectionName = ns("Books"); |
| 798 | + client.collections.create(collectionName, |
| 799 | + col -> col |
| 800 | + .properties(Property.text("title"), Property.text("author")) |
| 801 | + .vectorConfig( |
| 802 | + VectorConfig.text2vecModel2Vec("title_vec", v -> v.sourceProperties("title")), |
| 803 | + VectorConfig.text2vecModel2Vec("author_vec", v -> v.sourceProperties("author")))); |
| 804 | + |
| 805 | + var books = client.collections.use(collectionName); |
| 806 | + Assertions.assertThat(books).isNotNull(); |
| 807 | + |
| 808 | + WeaviateObject<Map<String, Object>> dune = WeaviateObject.of( |
| 809 | + o -> o.properties(Map.of( |
| 810 | + "title", "Dune", |
| 811 | + "author", "Frank Herbert"))); |
| 812 | + WeaviateObject<Map<String, Object>> abc = WeaviateObject.of( |
| 813 | + o -> o.properties(Map.of( |
| 814 | + "title", "ABC", |
| 815 | + "author", "ABC"))); |
| 816 | + |
| 817 | + var resp = books.data.insertMany(dune, abc); |
| 818 | + Assertions.assertThat(resp).isNotNull().satisfies(s -> { |
| 819 | + Assertions.assertThat(s.errors()).isEmpty(); |
| 820 | + }); |
| 821 | + |
| 822 | + // Assert that for Dune we have generated 2 different vectors |
| 823 | + var gotDune = books.query.fetchObjectById(dune.uuid(), FetchObjectById.Builder::includeVector); |
| 824 | + Assertions.assertThat(gotDune).get() |
| 825 | + .extracting(WeaviateObject::vectors) |
| 826 | + .satisfies(v -> { |
| 827 | + Assertions.assertThat(v.getSingle("title_vec")).isNotEmpty(); |
| 828 | + Assertions.assertThat(v.getSingle("author_vec")).isNotEmpty(); |
| 829 | + Assertions.assertThat(v.getSingle("title_vec")).isNotEqualTo(v.getSingle("author_vec")); |
| 830 | + }); |
| 831 | + |
| 832 | + // Assert that for ABC we have generated same vectors |
| 833 | + var gotAbc = books.query.fetchObjectById(abc.uuid(), FetchObjectById.Builder::includeVector); |
| 834 | + Assertions.assertThat(gotAbc).get() |
| 835 | + .extracting(WeaviateObject::vectors) |
| 836 | + .satisfies(v -> { |
| 837 | + Assertions.assertThat(v.getSingle("title_vec")).isNotEmpty(); |
| 838 | + Assertions.assertThat(v.getSingle("author_vec")).isNotEmpty(); |
| 839 | + Assertions.assertThat(v.getSingle("title_vec")).isEqualTo(v.getSingle("author_vec")); |
| 840 | + }); |
| 841 | + } |
793 | 842 | } |
0 commit comments