From 9065008c7383a1ba6c5ff1274369fed70ea71b5d Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Wed, 8 Apr 2026 21:44:44 -0700 Subject: [PATCH 1/5] JAVA-6099 Add new fields for Auto embedding --- ...edEmbeddingVectorSearchFunctionalTest.java | 219 +++++++++++++++++- 1 file changed, 218 insertions(+), 1 deletion(-) diff --git a/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java b/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java index 0331ed563c..349a7d12c2 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java @@ -34,6 +34,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import java.util.ArrayList; import java.util.Collections; @@ -44,6 +46,7 @@ import static com.mongodb.client.model.Aggregates.vectorSearch; import static com.mongodb.client.model.search.SearchPath.fieldPath; import static com.mongodb.client.model.search.VectorSearchOptions.approximateVectorSearchOptions; +import static com.mongodb.client.model.search.VectorSearchOptions.exactVectorSearchOptions; import static com.mongodb.client.model.search.VectorSearchQuery.textQuery; import static java.util.Arrays.asList; import static org.bson.codecs.configuration.CodecRegistries.fromProviders; @@ -74,7 +77,7 @@ public void setUp() { //TODO-JAVA-6059 remove this line when Atlas Vector Search with automated embedding is generally available // right now atlas search with automated embedding is in private preview and // only available via a custom docker image - Assumptions.assumeTrue(false); + Assumptions.assumeTrue(true); super.beforeEach(); mongoClient = getMongoClient(getMongoClientSettingsBuilder() @@ -210,6 +213,220 @@ private void insertDocumentsForEmbedding() { )); } + @Test + @DisplayName("should create auto embedding index with all optional fields") + void shouldCreateAutoEmbeddingIndexWithAllOptionalFields() { + mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); + SearchIndexModel indexModel = new SearchIndexModel( + INDEX_NAME, + new Document( + "fields", + Collections.singletonList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", FIELD_SEARCH_PATH) + .append("model", "voyage-4-large") + .append("quantization", "binary") + .append("similarity", "euclidean") + )), + SearchIndexType.vectorSearch() + ); + List result = documentCollection.createSearchIndexes(Collections.singletonList(indexModel)); + Assertions.assertFalse(result.isEmpty()); + } + + @ParameterizedTest(name = "should create auto embedding index with {0} quantization") + @ValueSource(strings = {"float", "scalar", "binary", "binaryNoRescore"}) + void shouldCreateAutoEmbeddingIndexWithQuantization(final String quantization) { + final String indexName = INDEX_NAME + "_" + quantization; + mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); + SearchIndexModel indexModel = new SearchIndexModel( + indexName, + new Document( + "fields", + Collections.singletonList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", FIELD_SEARCH_PATH) + .append("model", "voyage-4-large") + .append("quantization", quantization) + )), + SearchIndexType.vectorSearch() + ); + List result = documentCollection.createSearchIndexes(Collections.singletonList(indexModel)); + Assertions.assertFalse(result.isEmpty()); + } + + @Test + @DisplayName("should create auto embedding index with custom numDimensions") + void shouldCreateAutoEmbeddingIndexWithCustomNumDimensions() { + mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); + SearchIndexModel indexModel = new SearchIndexModel( + INDEX_NAME, + new Document( + "fields", + Collections.singletonList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", FIELD_SEARCH_PATH) + .append("model", "voyage-4-large") + .append("numDimensions", 512) + )), + SearchIndexType.vectorSearch() + ); + List result = documentCollection.createSearchIndexes(Collections.singletonList(indexModel)); + Assertions.assertFalse(result.isEmpty()); + } + + @Test + @DisplayName("should create auto embedding index with filter field") + void shouldCreateAutoEmbeddingIndexWithFilterField() { + mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); + SearchIndexModel indexModel = new SearchIndexModel( + INDEX_NAME, + new Document( + "fields", + asList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", FIELD_SEARCH_PATH) + .append("model", "voyage-4-large"), + new Document("type", "filter") + .append("path", "director") + )), + SearchIndexType.vectorSearch() + ); + List result = documentCollection.createSearchIndexes(Collections.singletonList(indexModel)); + Assertions.assertFalse(result.isEmpty()); + } + + @Test + @DisplayName("should fail when mixing vector and autoEmbed types in the same index") + void shouldFailWhenMixingVectorAndAutoEmbedTypes() { + mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); + SearchIndexModel indexModel = new SearchIndexModel( + INDEX_NAME, + new Document( + "fields", + asList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", FIELD_SEARCH_PATH) + .append("model", "voyage-4-large"), + new Document("type", "vector") + .append("path", "plot_embedding") + .append("numDimensions", 1024) + .append("similarity", "cosine") + )), + SearchIndexType.vectorSearch() + ); + Assertions.assertThrows( + MongoCommandException.class, + () -> documentCollection.createSearchIndexes(Collections.singletonList(indexModel)), + "Expected index creation to fail because vector and autoEmbed types cannot be mixed" + ); + } + + @Test + @DisplayName("should fail when duplicate paths are used") + void shouldFailWhenDuplicatePathsAreUsed() { + mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); + SearchIndexModel indexModel = new SearchIndexModel( + INDEX_NAME, + new Document( + "fields", + asList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", FIELD_SEARCH_PATH) + .append("model", "voyage-4-large"), + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", FIELD_SEARCH_PATH) + .append("model", "voyage-4-large") + )), + SearchIndexType.vectorSearch() + ); + Assertions.assertThrows( + MongoCommandException.class, + () -> documentCollection.createSearchIndexes(Collections.singletonList(indexModel)), + "Expected index creation to fail because of duplicate paths" + ); + } + + @Test + @DisplayName("should fail when autoEmbed field is used as filter field") + void shouldFailWhenAutoEmbedFieldUsedAsFilterField() { + mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); + SearchIndexModel indexModel = new SearchIndexModel( + INDEX_NAME, + new Document( + "fields", + asList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", FIELD_SEARCH_PATH) + .append("model", "voyage-4-large"), + new Document("type", "filter") + .append("path", FIELD_SEARCH_PATH) + )), + SearchIndexType.vectorSearch() + ); + Assertions.assertThrows( + MongoCommandException.class, + () -> documentCollection.createSearchIndexes(Collections.singletonList(indexModel)), + "Expected index creation to fail because autoEmbed field cannot be used as a filter field" + ); + } + + @Test + @DisplayName("should create auto embedding index and run query with model override") + void shouldCreateAutoEmbeddingIndexAndRunQueryWithModelOverride() throws InterruptedException { + mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); + createAutoEmbeddingIndex("voyage-4-large"); + TimeUnit.SECONDS.sleep(2L); + insertDocumentsForEmbedding(); + TimeUnit.SECONDS.sleep(2L); + + List pipeline = asList( + vectorSearch( + fieldPath(FIELD_SEARCH_PATH), + textQuery("movies about love").model("voyage-4-large"), + INDEX_NAME, + 5L, + approximateVectorSearchOptions(5L) + ) + ); + List documents = documentCollection.aggregate(pipeline).into(new ArrayList<>()); + + Assertions.assertFalse(documents.isEmpty(), "Expected to get some results from vector search query"); + Assertions.assertEquals(MOVIE_NAME, documents.get(0).getString("title")); + } + + @Test + @DisplayName("should create auto embedding index and run exact vector search query") + void shouldCreateAutoEmbeddingIndexAndRunExactVectorSearchQuery() throws InterruptedException { + mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); + createAutoEmbeddingIndex("voyage-4-large"); + TimeUnit.SECONDS.sleep(2L); + insertDocumentsForEmbedding(); + TimeUnit.SECONDS.sleep(2L); + + List pipeline = asList( + vectorSearch( + fieldPath(FIELD_SEARCH_PATH), + textQuery("movies about love"), + INDEX_NAME, + 5L, + exactVectorSearchOptions() + ) + ); + List documents = documentCollection.aggregate(pipeline).into(new ArrayList<>()); + + Assertions.assertFalse(documents.isEmpty(), "Expected to get some results from exact vector search query"); + Assertions.assertEquals(MOVIE_NAME, documents.get(0).getString("title")); + } + private void createAutoEmbeddingIndex(final String modelName) { SearchIndexModel indexModel = new SearchIndexModel( INDEX_NAME, From c140c5830f9c6a5e90d58253bcefb61a5284cccd Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Wed, 8 Apr 2026 21:55:39 -0700 Subject: [PATCH 2/5] disable test case --- .../AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java b/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java index 349a7d12c2..32206af255 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java @@ -77,7 +77,7 @@ public void setUp() { //TODO-JAVA-6059 remove this line when Atlas Vector Search with automated embedding is generally available // right now atlas search with automated embedding is in private preview and // only available via a custom docker image - Assumptions.assumeTrue(true); + Assumptions.assumeTrue(false); super.beforeEach(); mongoClient = getMongoClient(getMongoClientSettingsBuilder() From b674eb90e5eebd3f3d21d9e7a30a1fbbad1d45fb Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Wed, 8 Apr 2026 22:04:13 -0700 Subject: [PATCH 3/5] upgrade embedding test cases --- ...edEmbeddingVectorSearchFunctionalTest.java | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java b/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java index 32206af255..756c899e4f 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java @@ -28,6 +28,7 @@ import org.bson.codecs.configuration.CodecRegistry; import org.bson.codecs.pojo.PojoCodecProvider; import org.bson.conversions.Bson; +import org.junit.Ignore; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; @@ -213,27 +214,6 @@ private void insertDocumentsForEmbedding() { )); } - @Test - @DisplayName("should create auto embedding index with all optional fields") - void shouldCreateAutoEmbeddingIndexWithAllOptionalFields() { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - SearchIndexModel indexModel = new SearchIndexModel( - INDEX_NAME, - new Document( - "fields", - Collections.singletonList( - new Document("type", "autoEmbed") - .append("modality", "text") - .append("path", FIELD_SEARCH_PATH) - .append("model", "voyage-4-large") - .append("quantization", "binary") - .append("similarity", "euclidean") - )), - SearchIndexType.vectorSearch() - ); - List result = documentCollection.createSearchIndexes(Collections.singletonList(indexModel)); - Assertions.assertFalse(result.isEmpty()); - } @ParameterizedTest(name = "should create auto embedding index with {0} quantization") @ValueSource(strings = {"float", "scalar", "binary", "binaryNoRescore"}) @@ -259,6 +239,7 @@ void shouldCreateAutoEmbeddingIndexWithQuantization(final String quantization) { @Test @DisplayName("should create auto embedding index with custom numDimensions") + @Ignore("Currently numDimensions can't be used, it fails with server error: 'Invalid numDimensions value for autoEmbed field in index: test_auto_embed. Expected an integer.'") void shouldCreateAutoEmbeddingIndexWithCustomNumDimensions() { mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); SearchIndexModel indexModel = new SearchIndexModel( From a01a336651735e8f182020bd2ccdf63b892f5362 Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Wed, 15 Apr 2026 21:46:20 -0700 Subject: [PATCH 4/5] JAVA-6099 address PR comments --- ...ctAtlasSearchIndexManagementProseTest.java | 217 +++++++++ ...toEmbeddingVectorSearchFunctionalTest.java | 221 +++++++++ ...oEmbeddingVectorSearchFunctionalTest.java} | 4 +- ...edEmbeddingVectorSearchFunctionalTest.java | 428 ------------------ 4 files changed, 440 insertions(+), 430 deletions(-) create mode 100644 driver-sync/src/test/functional/com/mongodb/client/model/search/AbstractAutoEmbeddingVectorSearchFunctionalTest.java rename driver-sync/src/test/functional/com/mongodb/client/{vector/AutomatedEmbeddingVectorFunctionalTest.java => model/search/AutoEmbeddingVectorSearchFunctionalTest.java} (85%) delete mode 100644 driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java diff --git a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java index 17c007e14b..1685a79fce 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/AbstractAtlasSearchIndexManagementProseTest.java @@ -31,8 +31,11 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import java.util.List; import java.util.Map; @@ -79,6 +82,8 @@ public abstract class AbstractAtlasSearchIndexManagementProseTest { "{" + " mappings: { dynamic: true }" + "}"); + private static final String AUTO_EMBED_FIELD_PATH = "plot"; + private static final String AUTO_EMBED_INDEX_NAME = "voyage_4"; private static final Document VECTOR_SEARCH_DEFINITION = Document.parse( "{" + " fields: [" @@ -281,6 +286,218 @@ public void shouldRequireExplicitTypeToCreateVectorSearchIndex() { VECTOR_SEARCH_DEFINITION)); } + @Test + @DisplayName("should fail when invalid model name was used for auto embedding index") + void shouldFailWhenInvalidModelNameWasUsed() { + //TODO-JAVA-6059 remove this assumption when auto embedding is generally available + Assumptions.assumeTrue(false); + + assertThrows( + MongoCommandException.class, + () -> createAutoEmbeddingIndex("test"), + "Valid voyage model name was not used" + ); + } + + @Test + @DisplayName("should fail to create auto embedding index without model") + void shouldFailToCreateAutoEmbeddingIndexWithoutModel() { + //TODO-JAVA-6059 remove this assumption when auto embedding is generally available + Assumptions.assumeTrue(false); + + SearchIndexModel indexModel = new SearchIndexModel( + AUTO_EMBED_INDEX_NAME, + new Document( + "fields", + singletonList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", AUTO_EMBED_FIELD_PATH) + )), + SearchIndexType.vectorSearch() + ); + assertThrows( + MongoCommandException.class, + () -> collection.createSearchIndexes(singletonList(indexModel)), + "Expected index creation to fail because model is not specified" + ); + } + + @ParameterizedTest(name = "should create auto embedding index with {0} quantization") + @ValueSource(strings = {"float", "scalar", "binary", "binaryNoRescore"}) + void shouldCreateAutoEmbeddingIndexWithQuantization(final String quantization) { + //TODO-JAVA-6059 remove this assumption when auto embedding is generally available + Assumptions.assumeTrue(false); + + final String indexName = AUTO_EMBED_INDEX_NAME + "_" + quantization; + SearchIndexModel indexModel = new SearchIndexModel( + indexName, + new Document( + "fields", + singletonList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", AUTO_EMBED_FIELD_PATH) + .append("model", "voyage-4-large") + .append("quantization", quantization) + )), + SearchIndexType.vectorSearch() + ); + List result = collection.createSearchIndexes(singletonList(indexModel)); + Assertions.assertFalse(result.isEmpty()); + } + + @Test + @DisplayName("should create auto embedding index with custom numDimensions") + @Disabled("Currently numDimensions can't be used, it fails with server error:" + + " 'Invalid numDimensions value for autoEmbed field. Expected an integer.'") + void shouldCreateAutoEmbeddingIndexWithCustomNumDimensions() { + //TODO-JAVA-6059 remove this assumption when auto embedding is generally available + Assumptions.assumeTrue(false); + + SearchIndexModel indexModel = new SearchIndexModel( + AUTO_EMBED_INDEX_NAME, + new Document( + "fields", + singletonList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", AUTO_EMBED_FIELD_PATH) + .append("model", "voyage-4-large") + .append("numDimensions", 512) + )), + SearchIndexType.vectorSearch() + ); + List result = collection.createSearchIndexes(singletonList(indexModel)); + Assertions.assertFalse(result.isEmpty()); + } + + @Test + @DisplayName("should create auto embedding index with filter field") + void shouldCreateAutoEmbeddingIndexWithFilterField() { + //TODO-JAVA-6059 remove this assumption when auto embedding is generally available + Assumptions.assumeTrue(false); + + SearchIndexModel indexModel = new SearchIndexModel( + AUTO_EMBED_INDEX_NAME, + new Document( + "fields", + asList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", AUTO_EMBED_FIELD_PATH) + .append("model", "voyage-4-large"), + new Document("type", "filter") + .append("path", "director") + )), + SearchIndexType.vectorSearch() + ); + List result = collection.createSearchIndexes(singletonList(indexModel)); + Assertions.assertFalse(result.isEmpty()); + } + + @Test + @DisplayName("should fail when mixing vector and autoEmbed types in the same index") + void shouldFailWhenMixingVectorAndAutoEmbedTypes() { + //TODO-JAVA-6059 remove this assumption when auto embedding is generally available + Assumptions.assumeTrue(false); + + SearchIndexModel indexModel = new SearchIndexModel( + AUTO_EMBED_INDEX_NAME, + new Document( + "fields", + asList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", AUTO_EMBED_FIELD_PATH) + .append("model", "voyage-4-large"), + new Document("type", "vector") + .append("path", "plot_embedding") + .append("numDimensions", 1024) + .append("similarity", "cosine") + )), + SearchIndexType.vectorSearch() + ); + assertThrows( + MongoCommandException.class, + () -> collection.createSearchIndexes(singletonList(indexModel)), + "Expected index creation to fail because vector and autoEmbed types cannot be mixed" + ); + } + + @Test + @DisplayName("should fail when duplicate paths are used in auto embedding index") + void shouldFailWhenDuplicatePathsAreUsed() { + //TODO-JAVA-6059 remove this assumption when auto embedding is generally available + Assumptions.assumeTrue(false); + + SearchIndexModel indexModel = new SearchIndexModel( + AUTO_EMBED_INDEX_NAME, + new Document( + "fields", + asList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", AUTO_EMBED_FIELD_PATH) + .append("model", "voyage-4-large"), + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", AUTO_EMBED_FIELD_PATH) + .append("model", "voyage-4-large") + )), + SearchIndexType.vectorSearch() + ); + assertThrows( + MongoCommandException.class, + () -> collection.createSearchIndexes(singletonList(indexModel)), + "Expected index creation to fail because of duplicate paths" + ); + } + + @Test + @DisplayName("should fail when autoEmbed field is used as filter field") + void shouldFailWhenAutoEmbedFieldUsedAsFilterField() { + //TODO-JAVA-6059 remove this assumption when auto embedding is generally available + Assumptions.assumeTrue(false); + + SearchIndexModel indexModel = new SearchIndexModel( + AUTO_EMBED_INDEX_NAME, + new Document( + "fields", + asList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("path", AUTO_EMBED_FIELD_PATH) + .append("model", "voyage-4-large"), + new Document("type", "filter") + .append("path", AUTO_EMBED_FIELD_PATH) + )), + SearchIndexType.vectorSearch() + ); + assertThrows( + MongoCommandException.class, + () -> collection.createSearchIndexes(singletonList(indexModel)), + "Expected index creation to fail because autoEmbed field cannot be used as a filter field" + ); + } + + private void createAutoEmbeddingIndex(final String modelName) { + SearchIndexModel indexModel = new SearchIndexModel( + AUTO_EMBED_INDEX_NAME, + new Document( + "fields", + singletonList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("model", modelName) + .append("path", AUTO_EMBED_FIELD_PATH) + )), + SearchIndexType.vectorSearch() + ); + List result = collection.createSearchIndexes(singletonList(indexModel)); + Assertions.assertFalse(result.isEmpty()); + } + private void assertIndexDeleted() throws InterruptedException { int attempts = MAX_WAIT_ATTEMPTS; while (collection.listSearchIndexes().first() != null && checkAttempt(attempts--)) { diff --git a/driver-sync/src/test/functional/com/mongodb/client/model/search/AbstractAutoEmbeddingVectorSearchFunctionalTest.java b/driver-sync/src/test/functional/com/mongodb/client/model/search/AbstractAutoEmbeddingVectorSearchFunctionalTest.java new file mode 100644 index 0000000000..b7d1c0e696 --- /dev/null +++ b/driver-sync/src/test/functional/com/mongodb/client/model/search/AbstractAutoEmbeddingVectorSearchFunctionalTest.java @@ -0,0 +1,221 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mongodb.client.model.search; + +import com.mongodb.MongoClientSettings; +import com.mongodb.client.Fixture; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.model.OperationTest; +import com.mongodb.client.model.SearchIndexModel; +import com.mongodb.client.model.SearchIndexType; +import org.bson.Document; +import org.bson.codecs.configuration.CodecRegistry; +import org.bson.codecs.pojo.PojoCodecProvider; +import org.bson.conversions.Bson; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static com.mongodb.MongoClientSettings.getDefaultCodecRegistry; +import static com.mongodb.client.model.Aggregates.vectorSearch; +import static com.mongodb.client.model.search.SearchPath.fieldPath; +import static com.mongodb.client.model.search.VectorSearchOptions.approximateVectorSearchOptions; +import static com.mongodb.client.model.search.VectorSearchOptions.exactVectorSearchOptions; +import static com.mongodb.client.model.search.VectorSearchQuery.textQuery; +import static java.util.Arrays.asList; +import static org.bson.codecs.configuration.CodecRegistries.fromProviders; +import static org.bson.codecs.configuration.CodecRegistries.fromRegistries; + +/** + * Tests for auto-embedding vector search queries. + * Index creation and validation tests are in {@link com.mongodb.client.AbstractAtlasSearchIndexManagementProseTest}. + */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public abstract class AbstractAutoEmbeddingVectorSearchFunctionalTest extends OperationTest { + + private static final String FIELD_SEARCH_PATH = "plot"; + private static final String INDEX_NAME = "voyage_4"; + private static final String MOVIE_NAME = "Breathe"; + private static final CodecRegistry CODEC_REGISTRY = fromRegistries(getDefaultCodecRegistry(), + fromProviders(PojoCodecProvider + .builder() + .automatic(true).build())); + + private MongoClient mongoClient; + private MongoCollection documentCollection; + + @BeforeAll + void setUpOnce() throws InterruptedException { + //TODO-JAVA-6059 remove this assumption when Atlas Vector Search with automated embedding is generally available + Assumptions.assumeTrue(false); + + super.beforeEach(); + mongoClient = getMongoClient(getMongoClientSettingsBuilder() + .codecRegistry(CODEC_REGISTRY) + .build()); + documentCollection = mongoClient + .getDatabase(getDatabaseName()) + .getCollection(getCollectionName()); + + mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); + createAutoEmbeddingIndex("voyage-4-large"); + // TODO-JAVA-6063 + // community search with automated embedding doesn't support queryable field yet + // once supported remove the sleep and uncomment waitForIndex + TimeUnit.SECONDS.sleep(2L); + //waitForIndex(documentCollection, INDEX_NAME); + insertDocumentsForEmbedding(); + // TODO-JAVA-6063 wait for embeddings to be generated + TimeUnit.SECONDS.sleep(2L); + } + + @AfterAll + @SuppressWarnings("try") + void tearDownOnce() { + try (MongoClient ignore = mongoClient) { + super.afterEach(); + } + } + + @Override + public void beforeEach() { + // Intentionally empty -- setup is done once in @BeforeAll + } + + @Override + public void afterEach() { + // Intentionally empty -- teardown is done once in @AfterAll + } + + private static MongoClientSettings.Builder getMongoClientSettingsBuilder() { + return Fixture.getMongoClientSettingsBuilder(); + } + + protected abstract MongoClient getMongoClient(MongoClientSettings settings); + + @Test + @DisplayName("should execute vector search query using query text") + void shouldExecuteVectorSearchQuery() { + List pipeline = asList( + vectorSearch( + fieldPath(FIELD_SEARCH_PATH), + textQuery("movies about love"), + INDEX_NAME, + 5L, + approximateVectorSearchOptions(5L) + ) + ); + List documents = documentCollection.aggregate(pipeline).into(new ArrayList<>()); + + Assertions.assertFalse(documents.isEmpty(), "Expected to get some results from vector search query"); + Assertions.assertEquals(MOVIE_NAME, documents.get(0).getString("title")); + } + + @Test + @DisplayName("should execute vector search query with model override") + void shouldExecuteVectorSearchWithModelOverride() { + List pipeline = asList( + vectorSearch( + fieldPath(FIELD_SEARCH_PATH), + textQuery("movies about love").model("voyage-4"), + INDEX_NAME, + 5L, + approximateVectorSearchOptions(5L) + ) + ); + List documents = documentCollection.aggregate(pipeline).into(new ArrayList<>()); + + Assertions.assertFalse(documents.isEmpty(), "Expected to get some results from vector search query"); + Assertions.assertEquals(MOVIE_NAME, documents.get(0).getString("title")); + } + + @Test + @DisplayName("should execute exact vector search query") + void shouldExecuteExactVectorSearchQuery() { + List pipeline = asList( + vectorSearch( + fieldPath(FIELD_SEARCH_PATH), + textQuery("movies about love"), + INDEX_NAME, + 5L, + exactVectorSearchOptions() + ) + ); + List documents = documentCollection.aggregate(pipeline).into(new ArrayList<>()); + + Assertions.assertFalse(documents.isEmpty(), "Expected to get some results from exact vector search query"); + Assertions.assertEquals(MOVIE_NAME, documents.get(0).getString("title")); + } + + private void createAutoEmbeddingIndex(final String modelName) { + SearchIndexModel indexModel = new SearchIndexModel( + INDEX_NAME, + new Document( + "fields", + Collections.singletonList( + new Document("type", "autoEmbed") + .append("modality", "text") + .append("model", modelName) + .append("path", FIELD_SEARCH_PATH) + )), + SearchIndexType.vectorSearch() + ); + List result = documentCollection.createSearchIndexes(Collections.singletonList(indexModel)); + Assertions.assertFalse(result.isEmpty()); + } + + /** + * Documents borrowed from + * here + */ + private void insertDocumentsForEmbedding() { + documentCollection.insertMany(asList( + new Document() + .append("cast", asList("Cillian Murphy", "Emily Blunt", "Matt Damon")) + .append("director", "Christopher Nolan") + .append("genres", asList("Biography", "Drama", "History")) + .append("imdb", new Document() + .append("rating", 8.3) + .append("votes", 680000)) + .append("plot", "The story of American scientist J. Robert Oppenheimer and his role in the development of the atomic bomb during World War II.") + .append("runtime", 180) + .append("title", "Oppenheimer") + .append("year", 2023), + new Document() + .append("cast", asList("Andrew Garfield", "Claire Foy", "Hugh Bonneville")) + .append("director", "Andy Serkis") + .append("genres", asList("Biography", "Drama", "Romance")) + .append("imdb", new Document() + .append("rating", 7.2) + .append("votes", 42000)) + .append("plot", "The inspiring true love story of Robin and Diana Cavendish, an adventurous couple who refuse to give up in the face of a devastating disease.") + .append("runtime", 118) + .append("title", MOVIE_NAME) + .append("year", 2017) + )); + } +} diff --git a/driver-sync/src/test/functional/com/mongodb/client/vector/AutomatedEmbeddingVectorFunctionalTest.java b/driver-sync/src/test/functional/com/mongodb/client/model/search/AutoEmbeddingVectorSearchFunctionalTest.java similarity index 85% rename from driver-sync/src/test/functional/com/mongodb/client/vector/AutomatedEmbeddingVectorFunctionalTest.java rename to driver-sync/src/test/functional/com/mongodb/client/model/search/AutoEmbeddingVectorSearchFunctionalTest.java index 8f7db55744..1798162f17 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/vector/AutomatedEmbeddingVectorFunctionalTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/model/search/AutoEmbeddingVectorSearchFunctionalTest.java @@ -14,13 +14,13 @@ * limitations under the License. */ -package com.mongodb.client.vector; +package com.mongodb.client.model.search; import com.mongodb.MongoClientSettings; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; -public class AutomatedEmbeddingVectorFunctionalTest extends AbstractAutomatedEmbeddingVectorSearchFunctionalTest { +public class AutoEmbeddingVectorSearchFunctionalTest extends AbstractAutoEmbeddingVectorSearchFunctionalTest { @Override protected MongoClient getMongoClient(final MongoClientSettings settings) { return MongoClients.create(settings); diff --git a/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java b/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java deleted file mode 100644 index 756c899e4f..0000000000 --- a/driver-sync/src/test/functional/com/mongodb/client/vector/AbstractAutomatedEmbeddingVectorSearchFunctionalTest.java +++ /dev/null @@ -1,428 +0,0 @@ -/* - * Copyright 2008-present MongoDB, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mongodb.client.vector; - -import com.mongodb.MongoClientSettings; -import com.mongodb.MongoCommandException; -import com.mongodb.client.Fixture; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.model.OperationTest; -import com.mongodb.client.model.SearchIndexModel; -import com.mongodb.client.model.SearchIndexType; -import org.bson.Document; -import org.bson.codecs.configuration.CodecRegistry; -import org.bson.codecs.pojo.PojoCodecProvider; -import org.bson.conversions.Bson; -import org.junit.Ignore; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static com.mongodb.MongoClientSettings.getDefaultCodecRegistry; -import static com.mongodb.client.model.Aggregates.vectorSearch; -import static com.mongodb.client.model.search.SearchPath.fieldPath; -import static com.mongodb.client.model.search.VectorSearchOptions.approximateVectorSearchOptions; -import static com.mongodb.client.model.search.VectorSearchOptions.exactVectorSearchOptions; -import static com.mongodb.client.model.search.VectorSearchQuery.textQuery; -import static java.util.Arrays.asList; -import static org.bson.codecs.configuration.CodecRegistries.fromProviders; -import static org.bson.codecs.configuration.CodecRegistries.fromRegistries; - -/** - * The test cases were borrowed from - * this repository. - */ -public abstract class AbstractAutomatedEmbeddingVectorSearchFunctionalTest extends OperationTest { - - private static final String FIELD_SEARCH_PATH = "plot"; - // as of 2025-01-13 only voyage 4 is supported for automated embedding - // it might change in the future so for now we are only testing with voyage-4-large model - private static final String INDEX_NAME = "voyage_4"; - - private static final String MOVIE_NAME = "Breathe"; - private static final CodecRegistry CODEC_REGISTRY = fromRegistries(getDefaultCodecRegistry(), - fromProviders(PojoCodecProvider - .builder() - .automatic(true).build())); - private MongoCollection documentCollection; - - private MongoClient mongoClient; - - @BeforeEach - public void setUp() { - //TODO-JAVA-6059 remove this line when Atlas Vector Search with automated embedding is generally available - // right now atlas search with automated embedding is in private preview and - // only available via a custom docker image - Assumptions.assumeTrue(false); - - super.beforeEach(); - mongoClient = getMongoClient(getMongoClientSettingsBuilder() - .codecRegistry(CODEC_REGISTRY) - .build()); - documentCollection = mongoClient - .getDatabase(getDatabaseName()) - .getCollection(getCollectionName()); - } - - @AfterEach - @SuppressWarnings("try") - public void afterEach() { - try (MongoClient ignore = mongoClient) { - super.afterEach(); - } - } - - private static MongoClientSettings.Builder getMongoClientSettingsBuilder() { - return Fixture.getMongoClientSettingsBuilder(); - } - - protected abstract MongoClient getMongoClient(MongoClientSettings settings); - - /** - * Happy path for automated embedding with Voyage-4 model. - * - *

Steps: - *

    - *
  1. Create empty collection
  2. - *
  3. Create auto-embedding search index with voyage-4-large model
  4. - *
  5. Insert movie documents
  6. - *
  7. Run vector search query using query text
  8. - *
- * - *

Expected: Query returns "Breathe" as the top match for "movies about love" - */ - @Test - @DisplayName("should create auto embedding index and run vector search query using query text") - void shouldCreateAutoEmbeddingIndexAndRunVectorSearchQuery() throws InterruptedException { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - createAutoEmbeddingIndex("voyage-4-large"); - // TODO-JAVA-6063 - // community search with automated embedding doesn't support queryable field yet - // once supported remove the sleep and uncomment waitForIndex - TimeUnit.SECONDS.sleep(2L); - //waitForIndex(documentCollection, INDEX_NAME); - insertDocumentsForEmbedding(); - // TODO-JAVA-6063 wait for embeddings to be generated - // once there is an official way to check the index status, we should use it instead of sleep - // there is a workaround to pass a feature flag `internalListAllIndexesForTesting` but it's not official yet - TimeUnit.SECONDS.sleep(2L); - runEmbeddingQuery(); - } - - @Test - @DisplayName("should fail when invalid model name was used") - void shouldFailWhenInvalidModelNameWasUsed() { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - Assertions.assertThrows( - MongoCommandException.class, - () -> createAutoEmbeddingIndex("test"), - "Valid voyage model name was not used" - ); - } - - @Test - @DisplayName("should fail to create auto embedding index without model") - void shouldFailToCreateAutoEmbeddingIndexWithoutModel() { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - SearchIndexModel indexModel = new SearchIndexModel( - INDEX_NAME, - new Document( - "fields", - Collections.singletonList( - new Document("type", "autoEmbed") - .append("modality", "text") - .append("path", FIELD_SEARCH_PATH) - )), - SearchIndexType.vectorSearch() - ); - Assertions.assertThrows( - MongoCommandException.class, - () -> documentCollection.createSearchIndexes(Collections.singletonList(indexModel)), - "Expected index creation to fail because model is not specified" - ); - } - - private void runEmbeddingQuery() { - List pipeline = asList( - vectorSearch( - fieldPath(FIELD_SEARCH_PATH), - textQuery("movies about love"), - INDEX_NAME, - 5L, // limit - approximateVectorSearchOptions(5L) // numCandidates - ) - ); - final List documents = documentCollection.aggregate(pipeline).into(new ArrayList<>()); - - Assertions.assertFalse(documents.isEmpty(), "Expected to get some results from vector search query"); - Assertions.assertEquals(MOVIE_NAME, documents.get(0).getString("title")); - } - - /** - * All the documents were borrowed from - * here - */ - private void insertDocumentsForEmbedding() { - documentCollection.insertMany(asList( - new Document() - .append("cast", asList("Cillian Murphy", "Emily Blunt", "Matt Damon")) - .append("director", "Christopher Nolan") - .append("genres", asList("Biography", "Drama", "History")) - .append("imdb", new Document() - .append("rating", 8.3) - .append("votes", 680000)) - .append("plot", "The story of American scientist J. Robert Oppenheimer and his role in the development of the atomic bomb during World War II.") - .append("runtime", 180) - .append("title", "Oppenheimer") - .append("year", 2023), - new Document() - .append("cast", asList("Andrew Garfield", "Claire Foy", "Hugh Bonneville")) - .append("director", "Andy Serkis") - .append("genres", asList("Biography", "Drama", "Romance")) - .append("imdb", new Document() - .append("rating", 7.2) - .append("votes", 42000)) - .append("plot", "The inspiring true love story of Robin and Diana Cavendish, an adventurous couple who refuse to give up in the face of a devastating disease.") - .append("runtime", 118) - .append("title", MOVIE_NAME) - .append("year", 2017) - )); - } - - - @ParameterizedTest(name = "should create auto embedding index with {0} quantization") - @ValueSource(strings = {"float", "scalar", "binary", "binaryNoRescore"}) - void shouldCreateAutoEmbeddingIndexWithQuantization(final String quantization) { - final String indexName = INDEX_NAME + "_" + quantization; - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - SearchIndexModel indexModel = new SearchIndexModel( - indexName, - new Document( - "fields", - Collections.singletonList( - new Document("type", "autoEmbed") - .append("modality", "text") - .append("path", FIELD_SEARCH_PATH) - .append("model", "voyage-4-large") - .append("quantization", quantization) - )), - SearchIndexType.vectorSearch() - ); - List result = documentCollection.createSearchIndexes(Collections.singletonList(indexModel)); - Assertions.assertFalse(result.isEmpty()); - } - - @Test - @DisplayName("should create auto embedding index with custom numDimensions") - @Ignore("Currently numDimensions can't be used, it fails with server error: 'Invalid numDimensions value for autoEmbed field in index: test_auto_embed. Expected an integer.'") - void shouldCreateAutoEmbeddingIndexWithCustomNumDimensions() { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - SearchIndexModel indexModel = new SearchIndexModel( - INDEX_NAME, - new Document( - "fields", - Collections.singletonList( - new Document("type", "autoEmbed") - .append("modality", "text") - .append("path", FIELD_SEARCH_PATH) - .append("model", "voyage-4-large") - .append("numDimensions", 512) - )), - SearchIndexType.vectorSearch() - ); - List result = documentCollection.createSearchIndexes(Collections.singletonList(indexModel)); - Assertions.assertFalse(result.isEmpty()); - } - - @Test - @DisplayName("should create auto embedding index with filter field") - void shouldCreateAutoEmbeddingIndexWithFilterField() { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - SearchIndexModel indexModel = new SearchIndexModel( - INDEX_NAME, - new Document( - "fields", - asList( - new Document("type", "autoEmbed") - .append("modality", "text") - .append("path", FIELD_SEARCH_PATH) - .append("model", "voyage-4-large"), - new Document("type", "filter") - .append("path", "director") - )), - SearchIndexType.vectorSearch() - ); - List result = documentCollection.createSearchIndexes(Collections.singletonList(indexModel)); - Assertions.assertFalse(result.isEmpty()); - } - - @Test - @DisplayName("should fail when mixing vector and autoEmbed types in the same index") - void shouldFailWhenMixingVectorAndAutoEmbedTypes() { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - SearchIndexModel indexModel = new SearchIndexModel( - INDEX_NAME, - new Document( - "fields", - asList( - new Document("type", "autoEmbed") - .append("modality", "text") - .append("path", FIELD_SEARCH_PATH) - .append("model", "voyage-4-large"), - new Document("type", "vector") - .append("path", "plot_embedding") - .append("numDimensions", 1024) - .append("similarity", "cosine") - )), - SearchIndexType.vectorSearch() - ); - Assertions.assertThrows( - MongoCommandException.class, - () -> documentCollection.createSearchIndexes(Collections.singletonList(indexModel)), - "Expected index creation to fail because vector and autoEmbed types cannot be mixed" - ); - } - - @Test - @DisplayName("should fail when duplicate paths are used") - void shouldFailWhenDuplicatePathsAreUsed() { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - SearchIndexModel indexModel = new SearchIndexModel( - INDEX_NAME, - new Document( - "fields", - asList( - new Document("type", "autoEmbed") - .append("modality", "text") - .append("path", FIELD_SEARCH_PATH) - .append("model", "voyage-4-large"), - new Document("type", "autoEmbed") - .append("modality", "text") - .append("path", FIELD_SEARCH_PATH) - .append("model", "voyage-4-large") - )), - SearchIndexType.vectorSearch() - ); - Assertions.assertThrows( - MongoCommandException.class, - () -> documentCollection.createSearchIndexes(Collections.singletonList(indexModel)), - "Expected index creation to fail because of duplicate paths" - ); - } - - @Test - @DisplayName("should fail when autoEmbed field is used as filter field") - void shouldFailWhenAutoEmbedFieldUsedAsFilterField() { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - SearchIndexModel indexModel = new SearchIndexModel( - INDEX_NAME, - new Document( - "fields", - asList( - new Document("type", "autoEmbed") - .append("modality", "text") - .append("path", FIELD_SEARCH_PATH) - .append("model", "voyage-4-large"), - new Document("type", "filter") - .append("path", FIELD_SEARCH_PATH) - )), - SearchIndexType.vectorSearch() - ); - Assertions.assertThrows( - MongoCommandException.class, - () -> documentCollection.createSearchIndexes(Collections.singletonList(indexModel)), - "Expected index creation to fail because autoEmbed field cannot be used as a filter field" - ); - } - - @Test - @DisplayName("should create auto embedding index and run query with model override") - void shouldCreateAutoEmbeddingIndexAndRunQueryWithModelOverride() throws InterruptedException { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - createAutoEmbeddingIndex("voyage-4-large"); - TimeUnit.SECONDS.sleep(2L); - insertDocumentsForEmbedding(); - TimeUnit.SECONDS.sleep(2L); - - List pipeline = asList( - vectorSearch( - fieldPath(FIELD_SEARCH_PATH), - textQuery("movies about love").model("voyage-4-large"), - INDEX_NAME, - 5L, - approximateVectorSearchOptions(5L) - ) - ); - List documents = documentCollection.aggregate(pipeline).into(new ArrayList<>()); - - Assertions.assertFalse(documents.isEmpty(), "Expected to get some results from vector search query"); - Assertions.assertEquals(MOVIE_NAME, documents.get(0).getString("title")); - } - - @Test - @DisplayName("should create auto embedding index and run exact vector search query") - void shouldCreateAutoEmbeddingIndexAndRunExactVectorSearchQuery() throws InterruptedException { - mongoClient.getDatabase(getDatabaseName()).createCollection(getCollectionName()); - createAutoEmbeddingIndex("voyage-4-large"); - TimeUnit.SECONDS.sleep(2L); - insertDocumentsForEmbedding(); - TimeUnit.SECONDS.sleep(2L); - - List pipeline = asList( - vectorSearch( - fieldPath(FIELD_SEARCH_PATH), - textQuery("movies about love"), - INDEX_NAME, - 5L, - exactVectorSearchOptions() - ) - ); - List documents = documentCollection.aggregate(pipeline).into(new ArrayList<>()); - - Assertions.assertFalse(documents.isEmpty(), "Expected to get some results from exact vector search query"); - Assertions.assertEquals(MOVIE_NAME, documents.get(0).getString("title")); - } - - private void createAutoEmbeddingIndex(final String modelName) { - SearchIndexModel indexModel = new SearchIndexModel( - INDEX_NAME, - new Document( - "fields", - Collections.singletonList( - new Document("type", "autoEmbed") // type autoEmbed accepts a text - .append("modality", "text") - .append("model", modelName) - .append("path", FIELD_SEARCH_PATH) - )), - SearchIndexType.vectorSearch() - ); - List result = documentCollection.createSearchIndexes(Collections.singletonList(indexModel)); - - Assertions.assertFalse(result.isEmpty()); - } -} From 615a4d0d953dd2edf7dace66a7868a159fa25557 Mon Sep 17 00:00:00 2001 From: Almas Abdrazak Date: Wed, 15 Apr 2026 22:03:15 -0700 Subject: [PATCH 5/5] JAVA-6099 remove unused methods from tests --- ...bstractAutoEmbeddingVectorSearchFunctionalTest.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/driver-sync/src/test/functional/com/mongodb/client/model/search/AbstractAutoEmbeddingVectorSearchFunctionalTest.java b/driver-sync/src/test/functional/com/mongodb/client/model/search/AbstractAutoEmbeddingVectorSearchFunctionalTest.java index b7d1c0e696..2d1e1feec1 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/model/search/AbstractAutoEmbeddingVectorSearchFunctionalTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/model/search/AbstractAutoEmbeddingVectorSearchFunctionalTest.java @@ -101,16 +101,6 @@ void tearDownOnce() { } } - @Override - public void beforeEach() { - // Intentionally empty -- setup is done once in @BeforeAll - } - - @Override - public void afterEach() { - // Intentionally empty -- teardown is done once in @AfterAll - } - private static MongoClientSettings.Builder getMongoClientSettingsBuilder() { return Fixture.getMongoClientSettingsBuilder(); }