|
1 | 1 | package com.redis.om.spring.annotations.document.vectorize; |
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.assertj.core.api.Assertions.within; |
4 | 5 | import static org.junit.jupiter.api.Assertions.assertAll; |
5 | 6 |
|
6 | 7 | import java.io.IOException; |
@@ -89,7 +90,9 @@ void testKnnSentenceSimilaritySearch() { |
89 | 90 | .limit(K) // |
90 | 91 | .collect(Collectors.toList()); |
91 | 92 |
|
92 | | - assertThat(results).hasSize(5).map(DocWithOllamaEmbedding::getName).containsExactly( // |
| 93 | + assertThat(results).hasSize(5); |
| 94 | + assertThat(results.get(0).getName()).isEqualTo("cat"); // Exact match should be first |
| 95 | + assertThat(results).map(DocWithOllamaEmbedding::getName).containsExactlyInAnyOrder( // |
93 | 96 | "cat", "dog", "lion", "elephant", "giraffe" // |
94 | 97 | ); |
95 | 98 | } |
@@ -136,10 +139,11 @@ void testKnnSentenceSimilaritySearchWithScores() { |
136 | 139 | .collect(Collectors.toList()); |
137 | 140 |
|
138 | 141 | assertAll( // |
139 | | - () -> assertThat(results).hasSize(5).map(Pair::getFirst).map(DocWithOllamaEmbedding::getName).containsExactly( |
| 142 | + () -> assertThat(results).hasSize(5), // |
| 143 | + () -> assertThat(results.get(0).getFirst().getName()).isEqualTo("cat"), // Exact match should be first |
| 144 | + () -> assertThat(results).map(Pair::getFirst).map(DocWithOllamaEmbedding::getName).containsExactlyInAnyOrder( |
140 | 145 | "cat", "dog", "lion", "elephant", "giraffe"), // |
141 | | - () -> assertThat(results).hasSize(5).map(Pair::getSecond).usingElementComparator(closeToComparator) |
142 | | - .containsExactly(1.78813934326E-7, 0.301205277443, 0.315115869045, 0.338551998138, 0.407371640205) // |
| 146 | + () -> assertThat(results.get(0).getSecond()).isCloseTo(0.0, within(0.001)) // Cat should have ~0 distance to itself |
143 | 147 | ); |
144 | 148 | } |
145 | 149 |
|
|
0 commit comments