-
Notifications
You must be signed in to change notification settings - Fork 2k
Make the meta field prefix configurable in Weaviate vector store properties
#3585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ | |
| import io.weaviate.client.Config; | ||
| import io.weaviate.client.WeaviateClient; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.testcontainers.containers.wait.strategy.Wait; | ||
| import org.testcontainers.junit.jupiter.Container; | ||
| import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
|
@@ -359,6 +361,77 @@ public void addAndSearchWithCustomContentFieldName() { | |
| }); | ||
| } | ||
|
|
||
| @ParameterizedTest(name = "{0} : {displayName} ") | ||
| @ValueSource(strings = { "custom_", "" }) | ||
| public void addAndSearchWithCustomMetaFieldPrefix(String metaFieldPrefix) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you help me understand where the configurable metadata prefix is used in this test and then assert that it takes effect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this test, the following behavior is expected:
If there’s a better approach, I’m open to suggestions for improvement. 👍 |
||
| WeaviateVectorStoreOptions optionsWithCustomContentFieldName = new WeaviateVectorStoreOptions(); | ||
| optionsWithCustomContentFieldName.setMetaFieldPrefix(metaFieldPrefix); | ||
|
|
||
| this.contextRunner.run(context -> { | ||
| VectorStore vectorStore = context.getBean(VectorStore.class); | ||
| resetCollection(vectorStore); | ||
| }); | ||
|
|
||
| this.contextRunner.run(context -> { | ||
| WeaviateClient weaviateClient = context.getBean(WeaviateClient.class); | ||
| EmbeddingModel embeddingModel = context.getBean(EmbeddingModel.class); | ||
|
|
||
| VectorStore customVectorStore = WeaviateVectorStore.builder(weaviateClient, embeddingModel) | ||
| .filterMetadataFields(List.of(WeaviateVectorStore.MetadataField.text("country"))) | ||
| .options(optionsWithCustomContentFieldName) | ||
| .build(); | ||
|
|
||
| var bgDocument = new Document("The World is Big and Salvation Lurks Around the Corner", | ||
| Map.of("country", "BG", "year", 2020)); | ||
| var nlDocument = new Document("The World is Big and Salvation Lurks Around the Corner", | ||
| Map.of("country", "NL")); | ||
| var bgDocument2 = new Document("The World is Big and Salvation Lurks Around the Corner", | ||
| Map.of("country", "BG", "year", 2023)); | ||
|
|
||
| customVectorStore.add(List.of(bgDocument, nlDocument, bgDocument2)); | ||
|
|
||
| List<Document> results = customVectorStore | ||
| .similaritySearch(SearchRequest.builder().query("The World").topK(5).build()); | ||
| assertThat(results).hasSize(3); | ||
|
|
||
| results = customVectorStore.similaritySearch(SearchRequest.builder() | ||
| .query("The World") | ||
| .topK(5) | ||
| .similarityThresholdAll() | ||
| .filterExpression("country == 'NL'") | ||
| .build()); | ||
| assertThat(results).hasSize(1); | ||
| assertThat(results.get(0).getId()).isEqualTo(nlDocument.getId()); | ||
| }); | ||
|
|
||
| this.contextRunner.run(context -> { | ||
| VectorStore vectorStore = context.getBean(VectorStore.class); | ||
| List<Document> results = vectorStore.similaritySearch(SearchRequest.builder() | ||
| .query("The World") | ||
| .topK(5) | ||
| .similarityThresholdAll() | ||
| .filterExpression("country == 'NL'") | ||
| .build()); | ||
| assertThat(results).hasSize(0); | ||
| }); | ||
|
|
||
| // remove documents for parameterized test | ||
| this.contextRunner.run(context -> { | ||
| WeaviateClient weaviateClient = context.getBean(WeaviateClient.class); | ||
| EmbeddingModel embeddingModel = context.getBean(EmbeddingModel.class); | ||
|
|
||
| VectorStore customVectorStore = WeaviateVectorStore.builder(weaviateClient, embeddingModel) | ||
| .filterMetadataFields(List.of(WeaviateVectorStore.MetadataField.text("country"))) | ||
| .options(optionsWithCustomContentFieldName) | ||
| .build(); | ||
|
|
||
| List<Document> results = customVectorStore | ||
| .similaritySearch(SearchRequest.builder().query("The World").topK(5).build()); | ||
|
|
||
| customVectorStore.delete(results.stream().map(Document::getId).toList()); | ||
| }); | ||
| } | ||
|
|
||
| @SpringBootConfiguration | ||
| @EnableAutoConfiguration | ||
| public static class TestApplication { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods are newly created, but since the class Javadoc already includes the
@since 1.1.0tag, the@sincetag was not added to the methods.