-
Notifications
You must be signed in to change notification settings - Fork 47
[CLOUDP-372679] Update code snippets for auto embedding for vector search #701
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
8 commits
Select commit
Hold shift + click to select a range
44999e3
Update code snippets for auto embedding for vector search
viveksinghggits 0147d68
Use voyage provider endpoint for now because of creds
viveksinghggits 08a2630
Change embedding model to voyage-4
viveksinghggits 41636bc
Change model to voyage-4 and have it in env vars
viveksinghggits a87a49f
Run autoEmbed index and search only non community deployments
viveksinghggits 4a52de4
Fix lint issue, handle env var properly
viveksinghggits 8e7bcb9
Use provider endpoint `https://ai.mongodb.com/v1/embeddings`
viveksinghggits 2a0d030
Improvements, remove duplicagte file
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
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
28 changes: 28 additions & 0 deletions
28
...earch-community-deploy/code_snippets/01_0322_create_auto_embed_mongodb_search_resource.sh
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,28 @@ | ||
| # create a Kubernetes secret that would have embedding model's API Keys | ||
| kubectl create secret generic "${AUTO_EMBEDDING_API_KEY_SECRET_NAME}" \ | ||
| --from-literal=query-key="${AUTO_EMBEDDING_API_QUERY_KEY}" \ | ||
| --from-literal=indexing-key="${AUTO_EMBEDDING_API_INDEXING_KEY}" --context "${K8S_CTX}" -n "${MDB_NS}" | ||
|
|
||
| # create MongoDBSearch resource, enabling the auto embedding using the API Keys provided above | ||
| kubectl apply --context "${K8S_CTX}" -n "${MDB_NS}" -f - <<EOF | ||
| apiVersion: mongodb.com/v1 | ||
| kind: MongoDBSearch | ||
| metadata: | ||
| name: ${MDB_RESOURCE_NAME} | ||
| spec: | ||
| security: | ||
| tls: | ||
| certificateKeySecretRef: | ||
| name: ${MDB_SEARCH_TLS_SECRET_NAME} | ||
| resourceRequirements: | ||
| limits: | ||
| cpu: "3" | ||
| memory: 5Gi | ||
| requests: | ||
| cpu: "2" | ||
| memory: 3Gi | ||
| autoEmbedding: | ||
| providerEndpoint: ${PROVIDER_ENDPOINT} | ||
| embeddingModelAPIKeySecret: | ||
| name: ${AUTO_EMBEDDING_API_KEY_SECRET_NAME} | ||
| EOF |
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
3 changes: 3 additions & 0 deletions
3
docs/search/01-search-community-deploy/env_variables_e2e_public.sh
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 |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| export K8S_CTX="${CLUSTER_NAME}" | ||
|
|
||
| export AUTO_EMBEDDING_API_INDEXING_KEY="${AI_MONGODB_EMBEDDING_INDEXING_KEY}" | ||
| export AUTO_EMBEDDING_API_QUERY_KEY="${AI_MONGODB_EMBEDDING_QUERY_KEY}" |
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
10 changes: 10 additions & 0 deletions
10
...arch/03-search-query-usage/code_snippets/03_0437_create_auto_embed_vector_search_index.sh
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,10 @@ | ||
| kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" mongodb-tools-pod -- \ | ||
| mongosh --quiet "${MDB_CONNECTION_STRING}" \ | ||
| --eval "use sample_mflix" \ | ||
| --eval 'db.movies.createSearchIndex("vector_auto_embed_index", "vectorSearch", | ||
| { "fields": [ { | ||
| "type": "autoEmbed", | ||
| "modality": "text", | ||
| "path": "plot", | ||
| "model": "'"${EMBEDDING_MODEL}"'" | ||
| } ] });' | ||
4 changes: 4 additions & 0 deletions
4
...arch/03-search-query-usage/code_snippets/03_0447_list_auto_embed_vector_search_indexes.sh
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,4 @@ | ||
| kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" mongodb-tools-pod -- \ | ||
| mongosh --quiet "${MDB_CONNECTION_STRING}" \ | ||
| --eval "use sample_mflix" \ | ||
| --eval 'db.runCommand({"listSearchIndexes": "movies"});' |
30 changes: 30 additions & 0 deletions
30
...rch/03-search-query-usage/code_snippets/03_0456_execute_auto_embed_vector_search_query.sh
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,30 @@ | ||
| mdb_script=$(cat <<'EOF' | ||
| use sample_mflix; | ||
| db.movies.aggregate([ | ||
| { | ||
| "$vectorSearch": { | ||
| "index": "vector_auto_embed_index", | ||
| "path": "plot", | ||
| "query": "spy thriller", | ||
| "numCandidates": 150, | ||
| "limit": 10 | ||
| } | ||
| }, | ||
| { | ||
| "$project": { | ||
| "_id": 0, | ||
| "plot": 1, | ||
| "title": 1, | ||
| "score": { "$meta": "vectorSearchScore" } | ||
| } | ||
| } | ||
| ]); | ||
| EOF | ||
| ) | ||
|
|
||
| kubectl exec --context "${K8S_CTX}" -n "${MDB_NS}" \ | ||
| mongodb-tools-pod -- /bin/bash -eu -c "$(cat <<EOF | ||
| echo '${mdb_script}' > /tmp/mdb_script.js | ||
| mongosh --quiet "${MDB_CONNECTION_STRING}" < /tmp/mdb_script.js | ||
| EOF | ||
| )" |
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.
Uh oh!
There was an error while loading. Please reload this page.