2727import io .weaviate .client6 .v1 .api .collections .WeaviateMetadata ;
2828import io .weaviate .client6 .v1 .api .collections .WeaviateObject ;
2929import io .weaviate .client6 .v1 .api .collections .data .Reference ;
30+ import io .weaviate .client6 .v1 .api .collections .generate .GenerativeObject ;
31+ import io .weaviate .client6 .v1 .api .collections .generate .TaskOutput ;
32+ import io .weaviate .client6 .v1 .api .collections .generative .DummyGenerative ;
3033import io .weaviate .client6 .v1 .api .collections .query .GroupBy ;
3134import io .weaviate .client6 .v1 .api .collections .query .Metadata ;
3235import io .weaviate .client6 .v1 .api .collections .query .QueryMetadata ;
@@ -47,6 +50,7 @@ public class SearchITest extends ConcurrentTest {
4750 Weaviate .custom ()
4851 .withContextionaryUrl (Contextionary .URL )
4952 .withImageInference (Img2VecNeural .URL , Img2VecNeural .MODULE )
53+ .addModules ("generative-dummy" )
5054 .build (),
5155 Container .IMG2VEC_NEURAL ,
5256 Container .CONTEXTIONARY );
@@ -549,4 +553,98 @@ public void testNearVector_targetVectors() throws IOException {
549553 .hasSize (1 ).extracting (WeaviateObject ::uuid )
550554 .containsExactly (thing456 .uuids ().get (0 ));
551555 }
556+
557+ @ Test
558+ public void testGenerative_bm25 () throws IOException {
559+ // Arrange
560+ var nsThings = ns ("Things" );
561+
562+ client .collections .create (nsThings ,
563+ c -> c
564+ .properties (Property .text ("title" ))
565+ .generativeModule (new DummyGenerative ())
566+ .vectorConfig (VectorConfig .text2vecContextionary (
567+ t2v -> t2v .sourceProperties ("title" ))));
568+
569+ var things = client .collections .use (nsThings );
570+
571+ things .data .insertMany (
572+ Map .of ("title" , "Salad Fork" ),
573+ Map .of ("title" , "Dessert Fork" ));
574+
575+ // Act
576+ var french = things .generate .bm25 (
577+ "fork" ,
578+ bm25 -> bm25 .queryProperties ("title" ).limit (2 ),
579+ generate -> generate
580+ .singlePrompt ("translate to French" )
581+ .groupedTask ("count letters R" ));
582+
583+ // Assert
584+ Assertions .assertThat (french .objects ())
585+ .as ("individual results" )
586+ .hasSize (2 )
587+ .extracting (GenerativeObject ::generated )
588+ .allSatisfy (generated -> {
589+ Assertions .assertThat (generated .text ()).isNotBlank ();
590+ });
591+
592+ Assertions .assertThat (french .generated ())
593+ .as ("summary" )
594+ .extracting (TaskOutput ::text , InstanceOfAssertFactories .STRING )
595+ .isNotBlank ();
596+ }
597+
598+ @ Test
599+ public void testGenerative_bm25_groupBy () throws IOException {
600+ // Arrange
601+ var nsThings = ns ("Things" );
602+
603+ client .collections .create (nsThings ,
604+ c -> c
605+ .properties (Property .text ("title" ))
606+ .generativeModule (new DummyGenerative ())
607+ .vectorConfig (VectorConfig .text2vecContextionary (
608+ t2v -> t2v .sourceProperties ("title" ))));
609+
610+ var things = client .collections .use (nsThings );
611+
612+ things .data .insertMany (
613+ Map .of ("title" , "Salad Fork" ),
614+ Map .of ("title" , "Dessert Fork" ));
615+
616+ // Act
617+ var french = things .generate .bm25 (
618+ "fork" ,
619+ bm25 -> bm25 .queryProperties ("title" ).limit (2 ),
620+ generate -> generate
621+ .singlePrompt ("translate to French" )
622+ .groupedTask ("count letters R" ),
623+ GroupBy .property ("title" , 5 , 5 ));
624+
625+ // Assert
626+ Assertions .assertThat (french .objects ())
627+ .as ("individual results" )
628+ .hasSize (2 );
629+
630+ Assertions .assertThat (french .groups ())
631+ .as ("grouped results" )
632+ .hasSize (2 )
633+ .allSatisfy ((groupName , group ) -> {
634+ Assertions .assertThat (group .objects ())
635+ .describedAs ("objects in group %s" , groupName )
636+ .hasSize (1 );
637+
638+ Assertions .assertThat (group .generated ())
639+ .describedAs ("summary group %s" , groupName )
640+ .extracting (TaskOutput ::text , InstanceOfAssertFactories .STRING )
641+ .isNotBlank ();
642+
643+ });
644+
645+ Assertions .assertThat (french .generated ())
646+ .as ("summary" )
647+ .extracting (TaskOutput ::text , InstanceOfAssertFactories .STRING )
648+ .isNotBlank ();
649+ }
552650}
0 commit comments