|
39 | 39 | import org.springframework.ai.embedding.TransformersEmbeddingClient;
|
40 | 40 | import org.springframework.ai.vectorstore.SearchRequest;
|
41 | 41 | import org.springframework.ai.vectorstore.VectorStore;
|
42 |
| -import org.springframework.ai.vectorstore.azure.AzureVectorStore; |
43 | 42 | import org.springframework.ai.vectorstore.azure.AzureVectorStore.MetadataField;
|
44 | 43 | import org.springframework.boot.SpringBootConfiguration;
|
45 | 44 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
@@ -124,67 +123,63 @@ public void searchWithFilters() throws InterruptedException {
|
124 | 123 | return vectorStore.similaritySearch(SearchRequest.query("The World").withTopK(5));
|
125 | 124 | }, hasSize(3));
|
126 | 125 |
|
127 |
| - // List<Document> results = |
128 |
| - // vectorStore.similaritySearch(SearchRequest.query("The World") |
129 |
| - // .withTopK(5) |
130 |
| - // .withSimilarityThresholdAll() |
131 |
| - // .withFilterExpression("country == 'NL'")); |
132 |
| - // assertThat(results).hasSize(1); |
133 |
| - // assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId()); |
134 |
| - |
135 |
| - // results = vectorStore.similaritySearch(SearchRequest.query("The World") |
136 |
| - // .withTopK(5) |
137 |
| - // .withSimilarityThresholdAll() |
138 |
| - // .withFilterExpression("country == 'BG'")); |
139 |
| - |
140 |
| - // assertThat(results).hasSize(2); |
141 |
| - // assertThat(results.get(0).getId()).isIn(bgDocument.getId(), |
142 |
| - // bgDocument2.getId()); |
143 |
| - // assertThat(results.get(1).getId()).isIn(bgDocument.getId(), |
144 |
| - // bgDocument2.getId()); |
| 126 | + List<Document> results = vectorStore.similaritySearch(SearchRequest.query("The World") |
| 127 | + .withTopK(5) |
| 128 | + .withSimilarityThresholdAll() |
| 129 | + .withFilterExpression("country == 'NL'")); |
| 130 | + assertThat(results).hasSize(1); |
| 131 | + assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId()); |
145 | 132 |
|
146 |
| - // results = vectorStore.similaritySearch(SearchRequest.query("The World") |
147 |
| - // .withTopK(5) |
148 |
| - // .withSimilarityThresholdAll() |
149 |
| - // .withFilterExpression("country == 'BG' && year == 2020")); |
| 133 | + results = vectorStore.similaritySearch(SearchRequest.query("The World") |
| 134 | + .withTopK(5) |
| 135 | + .withSimilarityThresholdAll() |
| 136 | + .withFilterExpression("country == 'BG'")); |
150 | 137 |
|
151 |
| - // assertThat(results).hasSize(1); |
152 |
| - // assertThat(results.get(0).getId()).isEqualTo(bgDocument.getId()); |
| 138 | + assertThat(results).hasSize(2); |
| 139 | + assertThat(results.get(0).getId()).isIn(bgDocument.getId(), bgDocument2.getId()); |
| 140 | + assertThat(results.get(1).getId()).isIn(bgDocument.getId(), bgDocument2.getId()); |
153 | 141 |
|
154 |
| - // results = vectorStore.similaritySearch(SearchRequest.query("The World") |
155 |
| - // .withTopK(5) |
156 |
| - // .withSimilarityThresholdAll() |
157 |
| - // .withFilterExpression("country in ['BG']")); |
| 142 | + results = vectorStore.similaritySearch(SearchRequest.query("The World") |
| 143 | + .withTopK(5) |
| 144 | + .withSimilarityThresholdAll() |
| 145 | + .withFilterExpression("country == 'BG' && year == 2020")); |
158 | 146 |
|
159 |
| - // assertThat(results).hasSize(2); |
160 |
| - // assertThat(results.get(0).getId()).isIn(bgDocument.getId(), |
161 |
| - // bgDocument2.getId()); |
162 |
| - // assertThat(results.get(1).getId()).isIn(bgDocument.getId(), |
163 |
| - // bgDocument2.getId()); |
| 147 | + assertThat(results).hasSize(1); |
| 148 | + assertThat(results.get(0).getId()).isEqualTo(bgDocument.getId()); |
164 | 149 |
|
165 |
| - // results = vectorStore.similaritySearch(SearchRequest.query("The World") |
166 |
| - // .withTopK(5) |
167 |
| - // .withSimilarityThresholdAll() |
168 |
| - // .withFilterExpression("country in ['BG','NL']")); |
| 150 | + results = vectorStore.similaritySearch(SearchRequest.query("The World") |
| 151 | + .withTopK(5) |
| 152 | + .withSimilarityThresholdAll() |
| 153 | + .withFilterExpression("country in ['BG']")); |
169 | 154 |
|
170 |
| - // assertThat(results).hasSize(3); |
| 155 | + assertThat(results).hasSize(2); |
| 156 | + assertThat(results.get(0).getId()).isIn(bgDocument.getId(), bgDocument2.getId()); |
| 157 | + assertThat(results.get(1).getId()).isIn(bgDocument.getId(), bgDocument2.getId()); |
171 | 158 |
|
172 |
| - // results = vectorStore.similaritySearch(SearchRequest.query("The World") |
173 |
| - // .withTopK(5) |
174 |
| - // .withSimilarityThresholdAll() |
175 |
| - // .withFilterExpression("country nin ['BG']")); |
| 159 | + results = vectorStore.similaritySearch(SearchRequest.query("The World") |
| 160 | + .withTopK(5) |
| 161 | + .withSimilarityThresholdAll() |
| 162 | + .withFilterExpression("country in ['BG','NL']")); |
176 | 163 |
|
177 |
| - // assertThat(results).hasSize(1); |
178 |
| - // assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId()); |
| 164 | + assertThat(results).hasSize(3); |
179 | 165 |
|
180 |
| - List<Document> results = vectorStore.similaritySearch(SearchRequest.query("The World") |
| 166 | + results = vectorStore.similaritySearch(SearchRequest.query("The World") |
181 | 167 | .withTopK(5)
|
182 | 168 | .withSimilarityThresholdAll()
|
183 |
| - .withFilterExpression("activationDate > '1970-01-01T00:00:02Z'")); |
| 169 | + .withFilterExpression("country nin ['BG']")); |
184 | 170 |
|
185 | 171 | assertThat(results).hasSize(1);
|
186 | 172 | assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId());
|
187 | 173 |
|
| 174 | + // List<Document> results = |
| 175 | + // vectorStore.similaritySearch(SearchRequest.query("The World") |
| 176 | + // .withTopK(5) |
| 177 | + // .withSimilarityThresholdAll() |
| 178 | + // .withFilterExpression("activationDate > '1970-01-01T00:00:02Z'")); |
| 179 | + |
| 180 | + // assertThat(results).hasSize(1); |
| 181 | + // assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId()); |
| 182 | + |
188 | 183 | vectorStore.delete(List.of(bgDocument.getId(), nlDocument.getId(), bgDocument2.getId()));
|
189 | 184 | });
|
190 | 185 | }
|
|
0 commit comments