Skip to content
4 changes: 4 additions & 0 deletions .evergreen-functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ variables:
- VERSION_UPGRADE_HOOK_VERSION
- BUILD_SCENARIO
- MDB_BASH_DEBUG
- AI_MONGODB_EMBEDDING_INDEXING_KEY
- AI_MONGODB_EMBEDDING_QUERY_KEY

functions:

Expand Down Expand Up @@ -743,6 +745,8 @@ functions:
- code_snippets_reset
- task_name
- MDB_BASH_DEBUG
- AI_MONGODB_EMBEDDING_INDEXING_KEY
- AI_MONGODB_EMBEDDING_QUERY_KEY
add_to_path:
- ${workdir}/bin
script: |
Expand Down
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
7 changes: 7 additions & 0 deletions docs/search/01-search-community-deploy/env_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ export OPERATOR_ADDITIONAL_HELM_VALUES=""
export MDB_CONNECTION_STRING="mongodb://mdb-user:${MDB_USER_PASSWORD}@${MDB_RESOURCE_NAME}-0.${MDB_RESOURCE_NAME}-svc.${MDB_NS}.svc.cluster.local:27017/?replicaSet=${MDB_RESOURCE_NAME}&tls=true&tlsCAFile=/tls/ca.crt"

export CERT_MANAGER_NAMESPACE="cert-manager"

# Vector Search auto embedding related configurations
export AUTO_EMBEDDING_API_KEY_SECRET_NAME="voyage-api-keys"
export AUTO_EMBEDDING_API_QUERY_KEY="<embedding-model-query-key>"
export AUTO_EMBEDDING_API_INDEXING_KEY="<embedding-model-indexing-key>"
export PROVIDER_ENDPOINT="https://ai.mongodb.com/v1/embeddings"
export EMBEDDING_MODEL="voyage-4"
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ source "${PROJECT_DIR}/scripts/dev/contexts/e2e_mdb_community"
OPERATOR_ADDITIONAL_HELM_VALUES="$(get_operator_helm_values | tr ' ' ',')"
export OPERATOR_ADDITIONAL_HELM_VALUES
export OPERATOR_HELM_CHART="${PROJECT_DIR}/helm_chart"

export AUTO_EMBEDDING_API_INDEXING_KEY="${AI_MONGODB_EMBEDDING_INDEXING_KEY}"
export AUTO_EMBEDDING_API_QUERY_KEY="${AI_MONGODB_EMBEDDING_QUERY_KEY}"
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}"
2 changes: 2 additions & 0 deletions docs/search/01-search-community-deploy/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ run 01_0310_create_mongodb_community_resource.sh
run_for_output 01_0315_wait_for_community_resource.sh
run 01_0320_create_mongodb_search_resource.sh
run 01_0325_wait_for_search_resource.sh
run 01_0322_create_auto_embed_mongodb_search_resource.sh
run 01_0325_wait_for_search_resource.sh
run_for_output 01_0330_wait_for_community_resource.sh
run_for_output 01_0335_show_running_pods.sh

Expand Down
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}"'"
} ] });'
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"});'
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
)"
13 changes: 13 additions & 0 deletions docs/search/03-search-query-usage/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@ run 03_0410_run_mongodb_tools_pod.sh
run_for_output 03_0420_import_movies_mflix_database.sh
run 03_0430_create_search_index.sh
run 03_0435_create_vector_search_index.sh
# don't create auto embedding vector search if it's not community deployment.
# since we set EMBEDDING_MODEL env var just in community, we can check that env var.
if [ -n "${EMBEDDING_MODEL:-}" ]; then
run 03_0437_create_auto_embed_vector_search_index.sh
else
echo "Skipping creation of autoEmbed vector search index for non community deployments."
fi
run_for_output 03_0440_wait_for_search_index_ready.sh
run_for_output 03_0444_list_search_indexes.sh
run_for_output 03_0445_list_vector_search_indexes.sh
run_for_output 03_0447_list_auto_embed_vector_search_indexes.sh
run_for_output 03_0450_execute_search_query.sh
run_for_output 03_0455_execute_vector_search_query.sh
if [ -n "${EMBEDDING_MODEL:-}" ]; then
run_for_output 03_0456_execute_auto_embed_vector_search_query.sh
else
echo "Skipping running autoEmbed vector search query for non community deployments."
fi

cd -