Skip to content

Commit b9d2add

Browse files
committed
Fix azure store test and redundant code
1 parent faee5fe commit b9d2add

File tree

3 files changed

+42
-52
lines changed

3 files changed

+42
-52
lines changed

vector-stores/spring-ai-azure/src/main/java/org/springframework/ai/vectorstore/azure/AzureAiSearchFilterExpressionConverter.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public class AzureAiSearchFilterExpressionConverter extends AbstractFilterExpres
4242

4343
private static Pattern DATE_FORMAT_PATTERN = Pattern.compile("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z");
4444

45-
private final List<MetadataField> filterMetadataFields;
46-
4745
private final SimpleDateFormat dateFormat;
4846

4947
private List<String> allowedIdentifierNames;
@@ -52,9 +50,7 @@ public AzureAiSearchFilterExpressionConverter(List<MetadataField> filterMetadata
5250
Assert.notNull(filterMetadataFields, "The filterMetadataFields can not null.");
5351

5452
this.allowedIdentifierNames = filterMetadataFields.stream().map(MetadataField::name).toList();
55-
this.filterMetadataFields = filterMetadataFields;
5653
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
57-
// this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");
5854
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
5955
}
6056

vector-stores/spring-ai-azure/src/test/java/org/springframework/ai/vectorstore/azure/AzureAiSearchFilterExpressionConverterTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.junit.jupiter.api.Test;
2323

24-
import org.springframework.ai.vectorstore.azure.AzureAiSearchFilterExpressionConverter;
2524
import org.springframework.ai.vectorstore.azure.AzureVectorStore.MetadataField;
2625
import org.springframework.ai.vectorstore.filter.Filter.Expression;
2726
import org.springframework.ai.vectorstore.filter.Filter.Group;

vector-stores/spring-ai-azure/src/test/java/org/springframework/ai/vectorstore/azure/AzureVectorStoreIT.java

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.springframework.ai.embedding.TransformersEmbeddingClient;
4040
import org.springframework.ai.vectorstore.SearchRequest;
4141
import org.springframework.ai.vectorstore.VectorStore;
42-
import org.springframework.ai.vectorstore.azure.AzureVectorStore;
4342
import org.springframework.ai.vectorstore.azure.AzureVectorStore.MetadataField;
4443
import org.springframework.boot.SpringBootConfiguration;
4544
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -124,67 +123,63 @@ public void searchWithFilters() throws InterruptedException {
124123
return vectorStore.similaritySearch(SearchRequest.query("The World").withTopK(5));
125124
}, hasSize(3));
126125

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());
145132

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'"));
150137

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());
153141

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"));
158146

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());
164149

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']"));
169154

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());
171158

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']"));
176163

177-
// assertThat(results).hasSize(1);
178-
// assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId());
164+
assertThat(results).hasSize(3);
179165

180-
List<Document> results = vectorStore.similaritySearch(SearchRequest.query("The World")
166+
results = vectorStore.similaritySearch(SearchRequest.query("The World")
181167
.withTopK(5)
182168
.withSimilarityThresholdAll()
183-
.withFilterExpression("activationDate > '1970-01-01T00:00:02Z'"));
169+
.withFilterExpression("country nin ['BG']"));
184170

185171
assertThat(results).hasSize(1);
186172
assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId());
187173

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+
188183
vectorStore.delete(List.of(bgDocument.getId(), nlDocument.getId(), bgDocument2.getId()));
189184
});
190185
}

0 commit comments

Comments
 (0)