1717import org .junit .Ignore ;
1818import org .junit .Test ;
1919import org .junit .rules .TestRule ;
20+ import org .junit .runner .RunWith ;
21+
22+ import com .jparams .junit4 .JParamsTestRunner ;
23+ import com .jparams .junit4 .data .DataMethod ;
24+ import com .jparams .junit4 .description .Name ;
2025
2126import io .weaviate .ConcurrentTest ;
2227import io .weaviate .client6 .v1 .api .WeaviateApiException ;
3237import io .weaviate .client6 .v1 .api .collections .generate .GenerativeObject ;
3338import io .weaviate .client6 .v1 .api .collections .generate .TaskOutput ;
3439import io .weaviate .client6 .v1 .api .collections .generative .DummyGenerative ;
40+ import io .weaviate .client6 .v1 .api .collections .query .Boost ;
3541import io .weaviate .client6 .v1 .api .collections .query .Diversity ;
3642import io .weaviate .client6 .v1 .api .collections .query .FetchObjectById ;
3743import io .weaviate .client6 .v1 .api .collections .query .Filter ;
5460import io .weaviate .containers .Weaviate ;
5561import io .weaviate .containers .Weaviate .Version ;
5662
63+ @ RunWith (JParamsTestRunner .class )
5764public class SearchITest extends ConcurrentTest {
5865 private static final ContainerGroup compose = Container .compose (
5966 Weaviate .custom ()
@@ -132,7 +139,10 @@ private static Map<String, float[]> populateTest(int n) throws IOException {
132139 for (int i = 0 ; i < n ; i ++) {
133140 var vector = randomVector (10 , -.01f , .001f );
134141 var object = things .data .insert (
135- Map .of ("category" , CATEGORIES .get (i % CATEGORIES .size ())),
142+ Map .of (
143+ "category" , CATEGORIES .get (i % CATEGORIES .size ()),
144+ "created_at" , OffsetDateTime .now (),
145+ "position" , i ),
136146 metadata -> metadata
137147 .uuid (randomUUID ())
138148 .vectors (Vectors .of (VECTOR_INDEX , vector )));
@@ -150,7 +160,10 @@ private static Map<String, float[]> populateTest(int n) throws IOException {
150160 */
151161 private static void createTestCollection () throws IOException {
152162 client .collections .create (COLLECTION , cfg -> cfg
153- .properties (Property .text ("category" ))
163+ .properties (
164+ Property .text ("category" ),
165+ Property .date ("created_at" ),
166+ Property .integer ("position" ))
154167 .vectorConfig (VectorConfig .selfProvided (VECTOR_INDEX )));
155168 }
156169
@@ -886,6 +899,61 @@ public void testQueryProfile_groupBy() throws Exception {
886899 .isNotEmpty ());
887900 }
888901
902+ public static Object [][] boostCases () {
903+ return new Object [][] {
904+ { "filter" , Boost .filter (Filter .property ("category" ).eq ("red" )), },
905+ { "timeDecay" , Boost .timeDecay ("created_at" , "365d" ,
906+ time -> time
907+ .origin ("2024-01-01T00:00:00Z" )
908+ .curve (Boost .Curve .EXPONENTIAL )
909+ .decay (.3f )
910+ .weight (1f )),
911+ },
912+ {
913+ "numericDecay" , Boost .numericDecay ("position" , 1f , 3f ,
914+ num -> num
915+ .curve (Boost .Curve .LINEAR )
916+ .decay (0.2f )
917+ .weight (1f )),
918+ },
919+ {
920+ "numericProperty" , Boost .numericProperty ("position" ,
921+ prop -> prop
922+ .modifier (Boost .Modifier .LOG1P )
923+ .weight (1f )),
924+ },
925+ };
926+ }
927+
928+ @ Test
929+ @ DataMethod (source = SearchITest .class , method = "boostCases" )
930+ @ Name ("{0}" )
931+ public void testBoost (String __ , Object boost ) throws Exception {
932+ Version .V138 .orSkip ();
933+
934+ // Boosting reranks query results. To verify the boost parameter
935+ // made it to request, check that boosted results arrive in the
936+ // different order from those in a plain vector search.
937+ //
938+ // Because boosting is a common parameter for all query types,
939+ // testing one (e.g. nearVector) is sufficient.
940+
941+ // Arrange
942+ var things = client .collections .use (COLLECTION );
943+ var baseline = things .query .nearVector (searchVector ,
944+ opt -> opt .limit (5 ))
945+ .objects ().stream ().map (WeaviateObject ::uuid ).toList ();
946+
947+ // Act
948+ var got = things .query .nearVector (searchVector ,
949+ opt -> opt .limit (5 ).boost ((Boost ) boost ))
950+ .objects ().stream ().map (WeaviateObject ::uuid ).toList ();
951+
952+ // Assert
953+ Assertions .assertThat (got ).hasSameSizeAs (baseline );
954+ Assertions .assertThat (got ).doesNotContainSequence (baseline );
955+ }
956+
889957 @ Test
890958 public void testDiversity () throws Exception {
891959 Version .V137 .orSkip ();
0 commit comments