-
Notifications
You must be signed in to change notification settings - Fork 47
Add E2E test for MongoDBSearch autoEmbedding support #704
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
abd0c19
Add E2E test for MongoDBSearch autoEmbedding support
viveksinghggits 63cc423
Test fixx
viveksinghggits 62f1de8
Use ai.mongodb for endpoint and diff keys
viveksinghggits 9713318
Set correct env var to test pod
viveksinghggits c8594dd
Correct index cration query
viveksinghggits e310d87
Address review comments
viveksinghggits 25b613b
Fix lint issue
viveksinghggits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
docker/mongodb-kubernetes-tests/tests/search/search_community_auto_embedding.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import os | ||
|
|
||
| from kubetester import create_or_update_secret, try_load | ||
| from kubetester.kubetester import fixture as yaml_fixture | ||
| from kubetester.mongodb_community import MongoDBCommunity | ||
| from kubetester.mongodb_search import MongoDBSearch | ||
| from kubetester.phase import Phase | ||
| from pytest import fixture, mark | ||
| from tests import test_logger | ||
| from tests.common.search import movies_search_helper | ||
| from tests.common.search.movies_search_helper import SampleMoviesSearchHelper | ||
| from tests.common.search.search_tester import SearchTester | ||
| from tests.conftest import get_default_operator | ||
|
|
||
| logger = test_logger.get_test_logger(__name__) | ||
|
|
||
| ADMIN_USER_NAME = "mdb-admin-user" | ||
| ADMIN_USER_PASSWORD = "mdb-admin-user-pass" | ||
|
|
||
| MONGOT_USER_NAME = "search-sync-source" | ||
| MONGOT_USER_PASSWORD = "search-sync-source-user-password" | ||
|
|
||
| USER_NAME = "mdb-user" | ||
| USER_PASSWORD = "mdb-user-pass" | ||
|
|
||
| MDBC_RESOURCE_NAME = "mdbc-rs" | ||
| EMBEDDING_INDEXING_KEY_ENV_VAR = "AI_MONGODB_EMBEDDING_INDEXING_KEY" | ||
| EMBEDDING_QUERY_KEY_ENV_VAR = "AI_MONGODB_EMBEDDING_QUERY_KEY" | ||
| VOYAGE_API_KEY_SECRET_NAME = "voyage-api-keys" | ||
| PROVIDER_ENDPOINT = "https://ai.mongodb.com/v1/embeddings" | ||
|
|
||
|
|
||
| @fixture(scope="function") | ||
| def mdbc(namespace: str) -> MongoDBCommunity: | ||
| resource = MongoDBCommunity.from_yaml( | ||
| yaml_fixture("community-replicaset-sample-mflix.yaml"), | ||
| name=MDBC_RESOURCE_NAME, | ||
| namespace=namespace, | ||
| ) | ||
|
|
||
| if try_load(resource): | ||
| return resource | ||
|
|
||
| return resource | ||
|
|
||
|
|
||
| @fixture(scope="function") | ||
| def mdbs(namespace: str) -> MongoDBSearch: | ||
| resource = MongoDBSearch.from_yaml( | ||
| yaml_fixture("search-minimal.yaml"), | ||
| namespace=namespace, | ||
| ) | ||
|
|
||
| if try_load(resource): | ||
| return resource | ||
|
|
||
| return resource | ||
|
|
||
|
|
||
| @mark.e2e_search_community_auto_embedding | ||
| def test_install_operator(namespace: str, operator_installation_config: dict[str, str]): | ||
| operator = get_default_operator(namespace, operator_installation_config=operator_installation_config) | ||
| operator.assert_is_running() | ||
|
|
||
|
|
||
| @mark.e2e_search_community_auto_embedding | ||
| def test_install_secrets(namespace: str, mdbs: MongoDBSearch): | ||
| create_or_update_secret(namespace=namespace, name=f"{USER_NAME}-password", data={"password": USER_PASSWORD}) | ||
| create_or_update_secret( | ||
| namespace=namespace, name=f"{ADMIN_USER_NAME}-password", data={"password": ADMIN_USER_PASSWORD} | ||
| ) | ||
| create_or_update_secret( | ||
| namespace=namespace, name=f"{mdbs.name}-{MONGOT_USER_NAME}-password", data={"password": MONGOT_USER_PASSWORD} | ||
| ) | ||
|
|
||
| indexing_key = os.getenv(EMBEDDING_INDEXING_KEY_ENV_VAR) | ||
| query_key = os.getenv(EMBEDDING_QUERY_KEY_ENV_VAR) | ||
| if not indexing_key or not query_key: | ||
| raise ValueError( | ||
| f"Missing required environment variables: {EMBEDDING_INDEXING_KEY_ENV_VAR} and/or {EMBEDDING_QUERY_KEY_ENV_VAR}" | ||
| ) | ||
| create_or_update_secret( | ||
| namespace=namespace, | ||
| name=VOYAGE_API_KEY_SECRET_NAME, | ||
| data={"query-key": query_key, "indexing-key": indexing_key}, | ||
| ) | ||
|
|
||
|
|
||
| @mark.e2e_search_community_auto_embedding | ||
| def test_create_database_resource(mdbc: MongoDBCommunity): | ||
| mdbc.update() | ||
| mdbc.assert_reaches_phase(Phase.Running, timeout=300) | ||
|
|
||
|
|
||
| @mark.e2e_search_community_auto_embedding | ||
| def test_create_search_resource(mdbs: MongoDBSearch): | ||
| mdbs["spec"]["autoEmbedding"] = { | ||
| "embeddingModelAPIKeySecret": {"name": VOYAGE_API_KEY_SECRET_NAME}, | ||
| "providerEndpoint": PROVIDER_ENDPOINT, | ||
| } | ||
| mdbs.update() | ||
| mdbs.assert_reaches_phase(Phase.Running, timeout=300) | ||
|
|
||
|
|
||
| @mark.e2e_search_community_auto_embedding | ||
| def test_wait_for_community_resource_ready(mdbc: MongoDBCommunity): | ||
| mdbc.assert_reaches_phase(Phase.Running, timeout=300) | ||
|
|
||
|
|
||
| @fixture(scope="function") | ||
| def sample_movies_helper(mdbc: MongoDBCommunity) -> SampleMoviesSearchHelper: | ||
| return movies_search_helper.SampleMoviesSearchHelper( | ||
| SearchTester(get_connection_string(mdbc, USER_NAME, USER_PASSWORD)) | ||
| ) | ||
|
|
||
|
|
||
| @mark.e2e_search_community_auto_embedding | ||
| def test_search_restore_sample_database(sample_movies_helper: SampleMoviesSearchHelper): | ||
| sample_movies_helper.restore_sample_database() | ||
|
|
||
|
|
||
| @mark.e2e_search_community_auto_embedding | ||
| def test_search_create_search_index(sample_movies_helper: SampleMoviesSearchHelper): | ||
| sample_movies_helper.create_auto_embedding_vector_search_index() | ||
|
|
||
|
|
||
| @mark.e2e_search_community_auto_embedding | ||
| def test_search_assert_search_query(sample_movies_helper: SampleMoviesSearchHelper): | ||
| sample_movies_helper.assert_auto_emb_vector_search_query(retry_timeout=90) | ||
|
|
||
|
|
||
| def get_connection_string(mdbc: MongoDBCommunity, user_name: str, user_password: str) -> str: | ||
| return f"mongodb://{user_name}:{user_password}@{mdbc.name}-0.{mdbc.name}-svc.{mdbc.namespace}.svc.cluster.local:27017/?replicaSet={mdbc.name}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,3 +51,8 @@ helm: | |
| registry: "" | ||
| repository: "" | ||
| region: "" | ||
|
|
||
| autoEmbedding: | ||
| providerMongoDB: | ||
| indexingKey: "" | ||
| queryKey: "" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
q: shouldn't we make the default timeout a bit higher? I see it is invoked with 60 seconds.
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.
In most of the places when we wait for index to be ready, we just sleep for 60 seconds, but I have increased this to 90 seconds.