@@ -189,7 +189,7 @@ public void getBatchAsync(RecordCollectionOptions options) {
189189 List <String > ids = new ArrayList <>();
190190 hotels .forEach (hotel -> ids .add (hotel .getId ()));
191191
192- List <Hotel > retrievedHotels = recordCollection .getBatchAsync (ids , null ).block ();
192+ List <Hotel > retrievedHotels = recordCollection .getBatchAsync (ids , new GetRecordOptions ( true ) ).block ();
193193
194194 assertNotNull (retrievedHotels );
195195 assertEquals (hotels .size (), retrievedHotels .size ());
@@ -341,38 +341,71 @@ private static Stream<Arguments> provideSearchParameters() {
341341 );
342342 }
343343
344- // @ParameterizedTest
345- // @MethodSource("provideSearchParameters")
346- // public void search(RecordCollectionOptions options, String embeddingName) {
347- // String collectionName = "search" + embeddingName;
348- // RedisHashSetVectorStoreRecordCollection<Hotel> recordCollection = buildRecordCollection(optionsMap.get(options), collectionName);
349- //
350- // List<Hotel> hotels = getHotels();
351- // recordCollection.upsertBatchAsync(hotels, null).block();
352- //
353- // VectorSearchOptions searchOptions = VectorSearchOptions.builder()
354- // .withVectorFieldName(embeddingName)
355- // .withLimit(3)
356- // .build();
357- //
358- // // Embeddings similar to the third hotel
359- // List<VectorSearchResult<Hotel>> results = recordCollection.searchAsync(SEARCH_EMBEDDINGS, searchOptions).block();
360- // assertNotNull(results);
361- // assertEquals(3, results.size());
362- // // The third hotel should be the most similar
363- // assertEquals(hotels.get(2).getId(), results.get(0).getRecord().getId());
364- //
365- // searchOptions = VectorSearchOptions.builder()
366- // .withVectorFieldName(embeddingName)
367- // .withOffset(1)
368- // .withLimit(-100)
369- // .build();
370- //
371- // // Skip the first result
372- // results = recordCollection.searchAsync(SEARCH_EMBEDDINGS, searchOptions).block();
373- // assertNotNull(results);
374- // assertEquals(1, results.size());
375- // // The first hotel should be the most similar
376- // assertEquals(hotels.get(0).getId(), results.get(0).getRecord().getId());
377- // }
344+ @ ParameterizedTest
345+ @ MethodSource ("provideSearchParameters" )
346+ public void search (RecordCollectionOptions options , String embeddingName ) {
347+ String collectionName = "search" + embeddingName ;
348+ RedisHashSetVectorStoreRecordCollection <Hotel > recordCollection = buildRecordCollection (optionsMap .get (options ), collectionName );
349+
350+ List <Hotel > hotels = getHotels ();
351+ recordCollection .upsertBatchAsync (hotels , null ).block ();
352+
353+ VectorSearchOptions searchOptions = VectorSearchOptions .builder ()
354+ .withVectorFieldName (embeddingName )
355+ .build ();
356+
357+ // Embeddings similar to the third hotel
358+ List <VectorSearchResult <Hotel >> results = recordCollection .searchAsync (SEARCH_EMBEDDINGS , searchOptions ).block ();
359+ assertNotNull (results );
360+ assertEquals (VectorSearchOptions .DEFAULT_RESULT_LIMIT , results .size ());
361+ // The third hotel should be the most similar
362+ assertEquals (hotels .get (2 ).getId (), results .get (0 ).getRecord ().getId ());
363+ assertNull (results .get (0 ).getRecord ().getEuclidean ());
364+ }
365+
366+ @ ParameterizedTest
367+ @ MethodSource ("provideSearchParameters" )
368+ public void searchWithVectors (RecordCollectionOptions options , String embeddingName ) {
369+ String collectionName = "search" + embeddingName ;
370+ RedisHashSetVectorStoreRecordCollection <Hotel > recordCollection = buildRecordCollection (optionsMap .get (options ), collectionName );
371+
372+ List <Hotel > hotels = getHotels ();
373+ recordCollection .upsertBatchAsync (hotels , null ).block ();
374+
375+ VectorSearchOptions searchOptions = VectorSearchOptions .builder ()
376+ .withVectorFieldName (embeddingName )
377+ .withIncludeVectors (true )
378+ .build ();
379+
380+ // Embeddings similar to the third hotel
381+ List <VectorSearchResult <Hotel >> results = recordCollection .searchAsync (SEARCH_EMBEDDINGS , searchOptions ).block ();
382+ assertNotNull (results );
383+ assertEquals (VectorSearchOptions .DEFAULT_RESULT_LIMIT , results .size ());
384+ // The third hotel should be the most similar
385+ assertEquals (hotels .get (2 ).getId (), results .get (0 ).getRecord ().getId ());
386+ assertNotNull (results .get (0 ).getRecord ().getEuclidean ());
387+ }
388+
389+ @ ParameterizedTest
390+ @ MethodSource ("provideSearchParameters" )
391+ public void searchWithOffSet (RecordCollectionOptions options , String embeddingName ) {
392+ String collectionName = "search" + embeddingName ;
393+ RedisHashSetVectorStoreRecordCollection <Hotel > recordCollection = buildRecordCollection (optionsMap .get (options ), collectionName );
394+
395+ List <Hotel > hotels = getHotels ();
396+ recordCollection .upsertBatchAsync (hotels , null ).block ();
397+
398+ VectorSearchOptions searchOptions = VectorSearchOptions .builder ()
399+ .withVectorFieldName (embeddingName )
400+ .withOffset (1 )
401+ .withLimit (4 )
402+ .build ();
403+
404+ // Embeddings similar to the third hotel
405+ List <VectorSearchResult <Hotel >> results = recordCollection .searchAsync (SEARCH_EMBEDDINGS , searchOptions ).block ();
406+ assertNotNull (results );
407+ assertEquals (4 , results .size ());
408+ // The first hotel should be the most similar
409+ assertEquals (hotels .get (0 ).getId (), results .get (0 ).getRecord ().getId ());
410+ }
378411}
0 commit comments