Fix azure store test and redundant code

This commit is contained in:
Christian Tzolov
2023-11-22 01:03:40 +01:00
parent faee5fef6f
commit b9d2add707
3 changed files with 49 additions and 59 deletions

View File

@@ -42,8 +42,6 @@ public class AzureAiSearchFilterExpressionConverter extends AbstractFilterExpres
private static Pattern DATE_FORMAT_PATTERN = Pattern.compile("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z");
private final List<MetadataField> filterMetadataFields;
private final SimpleDateFormat dateFormat;
private List<String> allowedIdentifierNames;
@@ -52,9 +50,7 @@ public class AzureAiSearchFilterExpressionConverter extends AbstractFilterExpres
Assert.notNull(filterMetadataFields, "The filterMetadataFields can not null.");
this.allowedIdentifierNames = filterMetadataFields.stream().map(MetadataField::name).toList();
this.filterMetadataFields = filterMetadataFields;
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
// this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}

View File

@@ -21,7 +21,6 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.ai.vectorstore.azure.AzureAiSearchFilterExpressionConverter;
import org.springframework.ai.vectorstore.azure.AzureVectorStore.MetadataField;
import org.springframework.ai.vectorstore.filter.Filter.Expression;
import org.springframework.ai.vectorstore.filter.Filter.Group;

View File

@@ -39,7 +39,6 @@ import org.springframework.ai.embedding.EmbeddingClient;
import org.springframework.ai.embedding.TransformersEmbeddingClient;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.azure.AzureVectorStore;
import org.springframework.ai.vectorstore.azure.AzureVectorStore.MetadataField;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -124,67 +123,63 @@ public class AzureVectorStoreIT {
return vectorStore.similaritySearch(SearchRequest.query("The World").withTopK(5));
}, hasSize(3));
List<Document> results = vectorStore.similaritySearch(SearchRequest.query("The World")
.withTopK(5)
.withSimilarityThresholdAll()
.withFilterExpression("country == 'NL'"));
assertThat(results).hasSize(1);
assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId());
results = vectorStore.similaritySearch(SearchRequest.query("The World")
.withTopK(5)
.withSimilarityThresholdAll()
.withFilterExpression("country == 'BG'"));
assertThat(results).hasSize(2);
assertThat(results.get(0).getId()).isIn(bgDocument.getId(), bgDocument2.getId());
assertThat(results.get(1).getId()).isIn(bgDocument.getId(), bgDocument2.getId());
results = vectorStore.similaritySearch(SearchRequest.query("The World")
.withTopK(5)
.withSimilarityThresholdAll()
.withFilterExpression("country == 'BG' && year == 2020"));
assertThat(results).hasSize(1);
assertThat(results.get(0).getId()).isEqualTo(bgDocument.getId());
results = vectorStore.similaritySearch(SearchRequest.query("The World")
.withTopK(5)
.withSimilarityThresholdAll()
.withFilterExpression("country in ['BG']"));
assertThat(results).hasSize(2);
assertThat(results.get(0).getId()).isIn(bgDocument.getId(), bgDocument2.getId());
assertThat(results.get(1).getId()).isIn(bgDocument.getId(), bgDocument2.getId());
results = vectorStore.similaritySearch(SearchRequest.query("The World")
.withTopK(5)
.withSimilarityThresholdAll()
.withFilterExpression("country in ['BG','NL']"));
assertThat(results).hasSize(3);
results = vectorStore.similaritySearch(SearchRequest.query("The World")
.withTopK(5)
.withSimilarityThresholdAll()
.withFilterExpression("country nin ['BG']"));
assertThat(results).hasSize(1);
assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId());
// List<Document> results =
// vectorStore.similaritySearch(SearchRequest.query("The World")
// .withTopK(5)
// .withSimilarityThresholdAll()
// .withFilterExpression("country == 'NL'"));
// assertThat(results).hasSize(1);
// assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId());
// results = vectorStore.similaritySearch(SearchRequest.query("The World")
// .withTopK(5)
// .withSimilarityThresholdAll()
// .withFilterExpression("country == 'BG'"));
// assertThat(results).hasSize(2);
// assertThat(results.get(0).getId()).isIn(bgDocument.getId(),
// bgDocument2.getId());
// assertThat(results.get(1).getId()).isIn(bgDocument.getId(),
// bgDocument2.getId());
// results = vectorStore.similaritySearch(SearchRequest.query("The World")
// .withTopK(5)
// .withSimilarityThresholdAll()
// .withFilterExpression("country == 'BG' && year == 2020"));
// assertThat(results).hasSize(1);
// assertThat(results.get(0).getId()).isEqualTo(bgDocument.getId());
// results = vectorStore.similaritySearch(SearchRequest.query("The World")
// .withTopK(5)
// .withSimilarityThresholdAll()
// .withFilterExpression("country in ['BG']"));
// assertThat(results).hasSize(2);
// assertThat(results.get(0).getId()).isIn(bgDocument.getId(),
// bgDocument2.getId());
// assertThat(results.get(1).getId()).isIn(bgDocument.getId(),
// bgDocument2.getId());
// results = vectorStore.similaritySearch(SearchRequest.query("The World")
// .withTopK(5)
// .withSimilarityThresholdAll()
// .withFilterExpression("country in ['BG','NL']"));
// assertThat(results).hasSize(3);
// results = vectorStore.similaritySearch(SearchRequest.query("The World")
// .withTopK(5)
// .withSimilarityThresholdAll()
// .withFilterExpression("country nin ['BG']"));
// .withFilterExpression("activationDate > '1970-01-01T00:00:02Z'"));
// assertThat(results).hasSize(1);
// assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId());
List<Document> results = vectorStore.similaritySearch(SearchRequest.query("The World")
.withTopK(5)
.withSimilarityThresholdAll()
.withFilterExpression("activationDate > '1970-01-01T00:00:02Z'"));
assertThat(results).hasSize(1);
assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId());
vectorStore.delete(List.of(bgDocument.getId(), nlDocument.getId(), bgDocument2.getId()));
});
}