66
77import java .time .Instant ;
88import java .util .ArrayList ;
9+ import java .util .Arrays ;
910import java .util .Date ;
1011import java .util .HashMap ;
1112import java .util .List ;
@@ -58,11 +59,14 @@ public class GRPCBenchTest {
5859 private static final Date NOW = Date .from (Instant .now ());
5960
6061 private static final int K = 10 ;
61- private static final Map <String , Object > filters = new HashMap <String , Object >() {
62+ private static final String [] notIngredients = { "ketchup" , "mayo" };
63+ private static final Map <String , Object > notEqualFilters = new HashMap <String , Object >() {
6264 {
63- this .put ("title" , "SomeThing" );
64- this .put ("price" , 8 );
65- this .put ("bestBefore" , DateUtils .addDays (NOW , 5 ));
65+ // this.put("title", "SomeThing");
66+ // this.put("price", 8);
67+ // this.put("bestBefore", DateUtils.addDays(NOW, 5));
68+ this .put ("ingredientsList" , Arrays .asList (notIngredients ));
69+ this .put ("ingredientsArray" , notIngredients );
6670 }
6771 };
6872
@@ -102,10 +106,10 @@ public void before() {
102106 assertTrue (writeORM (testData ), "loaded test data successfully" );
103107 }
104108
105- @ Test
109+ // @Test
106110 public void testGraphQL () {
107111 bench ("GraphQL" , () -> {
108- int count = searchKNN (queryVector , K , filters , builder -> {
112+ int count = searchKNN (queryVector , K , notEqualFilters , builder -> {
109113 Result <GraphQLResponse > result = client
110114 .graphQL ().raw ()
111115 .withQuery (builder .build ().buildQuery ())
@@ -121,10 +125,10 @@ public void testGraphQL() {
121125 }, WARMUP_ROUNDS , BENCHMARK_ROUNDS );
122126 }
123127
124- @ Test
128+ // @Test
125129 public void testGRPC () {
126130 bench ("GRPC" , () -> {
127- int count = searchKNN (queryVector , K , filters , builder -> {
131+ int count = searchKNN (queryVector , K , notEqualFilters , builder -> {
128132 SearchResult <Map <String , Object >> result = client
129133 .gRPC ().raw ()
130134 .withSearch (builder .build ().buildSearchRequest ())
@@ -137,7 +141,7 @@ public void testGRPC() {
137141 }, WARMUP_ROUNDS , BENCHMARK_ROUNDS );
138142 }
139143
140- @ Test
144+ // @Test
141145 public void testNewClient () {
142146 final float [] vector = ArrayUtils .toPrimitive (queryVector );
143147 final Collection <Map > things = client .collections .use (className , Map .class );
@@ -160,9 +164,14 @@ public static class Thing {
160164 public String title ;
161165 public Double price ;
162166 public Date bestBefore ;
167+
168+ public String [] ingredientsArray = {};
169+ // WARN: this is to test filtering with List<?> values. Creating List<?>
170+ // properties is not supported in this version.
171+ public String [] ingredientsList = {};
163172 }
164173
165- @ Test
174+ // @Test
166175 public void testORMClient () {
167176 final float [] vector = ArrayUtils .toPrimitive (queryVector );
168177 bench ("GRPC.orm" , () -> {
@@ -190,19 +199,19 @@ public void testORMClientMapFilter() {
190199 vector ,
191200 opt -> opt
192201 .limit (K )
193- .where (Where .and (filters , Where .Operator .NOT_EQUAL )) // Constructed from a Map<String, Object>!
202+ .where (Where .and (notEqualFilters , Where .Operator .NOT_EQUAL )) // Constructed from a Map<String, Object>!
194203 .returnProperties (returnProperties )
195204 .returnMetadata (MetadataField .ID , MetadataField .VECTOR , MetadataField .DISTANCE ));
196205
197206 int count = countGRPC (result );
198207 assertEquals (K , count , String .format ("must return K=%d results" , K ));
199208
200209 // Check that filtering works
201- assertFalse (result .objects .stream ().anyMatch (obj -> obj .properties .title .equals (filters .get ("title" ))),
202- "expected title to not be in result set: " + filters .get ("title" ));
210+ assertFalse (result .objects .stream ().anyMatch (obj -> obj .properties .title .equals (notEqualFilters .get ("title" ))),
211+ "expected title to not be in result set: " + notEqualFilters .get ("title" ));
203212
204- assertFalse (result .objects .stream ().anyMatch (obj -> obj .properties .price .equals (filters .get ("price" ))),
205- "expected price to not be in result set: " + filters .get ("price" ));
213+ assertFalse (result .objects .stream ().anyMatch (obj -> obj .properties .price .equals (notEqualFilters .get ("price" ))),
214+ "expected price to not be in result set: " + notEqualFilters .get ("price" ));
206215 }, WARMUP_ROUNDS , BENCHMARK_ROUNDS );
207216 }
208217
@@ -336,6 +345,7 @@ private boolean write(List<Float[]> embeddings) {
336345 int count = 0 ;
337346 for (Float [] e : embeddings ) {
338347 int i = count ++;
348+ String [] ingr = mixIngredients ();
339349 batcher .withObject (WeaviateObject .builder ()
340350 .className (className )
341351 .vector (e )
@@ -344,6 +354,8 @@ private boolean write(List<Float[]> embeddings) {
344354 this .put ("title" , "Thing-" + String .valueOf (i ));
345355 this .put ("price" , i );
346356 this .put ("bestBefore" , DateFormatUtils .format (DateUtils .addDays (NOW , i ), "yyyy-MM-dd'T'HH:mm:ssZZZZZ" ));
357+ this .put ("ingredientsArray" , ingr );
358+ this .put ("ingredientsList" , ingr );
347359 }
348360 })
349361 // .id(getUuid(e)) -> use generated UUID
@@ -358,6 +370,7 @@ private boolean write(List<Float[]> embeddings) {
358370 /** writeORM creates {@link Thing} objects and inserts them in a batch. */
359371 private boolean writeORM (List <Float []> embeddings ) {
360372 try (Batcher <Thing > batch = client .datax .batch (Thing .class )) {
373+ String [] ingr = mixIngredients ();
361374 return batch .insert (b -> {
362375 int i = 0 ;
363376 for (Float [] e : embeddings ) {
@@ -367,14 +380,22 @@ private boolean writeORM(List<Float[]> embeddings) {
367380
368381 // Notice how the ORM is able to handle a raw Date object
369382 // and convert it to the correct format behind the scenes.
370- /* bestBefore */ DateUtils .addDays (NOW , i ));
383+ /* bestBefore */ DateUtils .addDays (NOW , i ),
384+ /* ingredientsArray */ ingr ,
385+ /* ingredientsList */ ingr );
371386 b .add (thing , e );
372387 i ++;
373388 }
374389 });
375390 }
376391 }
377392
393+ /** Utility for creating random combinations of ingredients for test data. */
394+ private String [] mixIngredients () {
395+ return Arrays .stream (new String [] { "milk" , "honey" , "butter" })
396+ .filter (x -> rand .nextBoolean ()).toArray (String []::new );
397+ }
398+
378399 private static Float [] genVector (int length , float origin , float bound ) {
379400 Float [] vec = new Float [length ];
380401 for (int i = 0 ; i < length ; i ++) {
0 commit comments