Skip to content
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

The big notebook simplification #904

Merged
merged 20 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 14 additions & 212 deletions docs/sphinx/source/examples/Matryoshka_embeddings_in_Vespa-cloud.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"\n",
"We'll use a standard information retrieval benchmark to evaluate result quality with different embedding sizes and retrieval/ranking strategies.\n",
"\n",
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/vespa-engine/pyvespa/blob/master/docs/sphinx/source/examples/Matryoshka_embeddings_in_Vespa-cloud.ipynb)\n",
"\n",
"Let's get started! First, install a few dependencies:\n"
]
},
Expand All @@ -35,7 +37,7 @@
},
"outputs": [],
"source": [
"!pip3 install -U pyvespa ir_datasets openai pytrec_eval"
"!pip3 install -U pyvespa ir_datasets openai pytrec_eval vespacli"
]
},
{
Expand Down Expand Up @@ -535,210 +537,13 @@
"## Deploy the application to Vespa Cloud\n",
"\n",
"With the configured application, we can deploy it to [Vespa Cloud](https://cloud.vespa.ai/en/).\n",
"It is also possible to deploy the app using docker; see the [Hybrid Search - Quickstart](https://pyvespa.readthedocs.io/en/latest/getting-started-pyvespa.html) guide for\n",
"an example of deploying it to a local docker container.\n"
]
},
{
"cell_type": "markdown",
"id": "59bbdb311c014d738909a11f9e486628",
"metadata": {
"id": "16179d9b"
},
"source": [
"Install the Vespa CLI.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b43b363d81ae4b689946ece5c682cd59",
"metadata": {
"id": "343981ce"
},
"outputs": [],
"source": [
"!pip3 install vespacli"
]
},
{
"cell_type": "markdown",
"id": "4dd4641cc4064e0191573fe9c69df29b",
"metadata": {
"id": "0ff00727"
},
"source": [
"\n",
"To deploy the application to Vespa Cloud we need to create a tenant in the Vespa Cloud:\n",
"\n",
"Create a tenant at [console.vespa-cloud.com](https://console.vespa-cloud.com/) (unless you already have one).\n",
"This step requires a Google or GitHub account, and will start your [free trial](https://cloud.vespa.ai/en/free-trial).\n",
"Make note of the tenant name, it is used in the next steps.\n"
]
},
{
"cell_type": "markdown",
"id": "8309879909854d7188b41380fd92a7c3",
"metadata": {
"id": "df9f9a1c"
},
"source": [
"### Configure Vespa Cloud date-plane security\n",
"\n",
"Create Vespa Cloud data-plane mTLS cert/key-pair. The mutual certificate pair is used to talk to your Vespa cloud endpoints. See [Vespa Cloud Security Guide](https://cloud.vespa.ai/en/security/guide) for details.\n",
"\n",
"We save the paths to the credentials for later data-plane access without using pyvespa APIs.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3ed186c9a28b402fb0bc4494df01f08d",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"executionInfo": {
"elapsed": 611,
"status": "ok",
"timestamp": 1706648115118,
"user": {
"displayName": "Andreas Eriksen",
"userId": "00161553861396505040"
},
"user_tz": -60
},
"id": "b6a766d6",
"outputId": "47075852-89e2-41a8-cb96-af10dbe534d7"
},
"outputs": [],
"source": [
"import os\n",
"\n",
"os.environ[\"TENANT_NAME\"] = \"vespa-team\" # Replace with your tenant name\n",
"\n",
"vespa_cli_command = (\n",
" f'vespa config set application {os.environ[\"TENANT_NAME\"]}.{vespa_app_name}'\n",
")\n",
"\n",
"!vespa config set target cloud\n",
"!{vespa_cli_command}\n",
"!vespa auth cert -N"
]
},
{
"cell_type": "markdown",
"id": "cb1e1581032b452c9409d6c6813c49d1",
"metadata": {
"id": "b228381b"
},
"source": [
"Validate that we have the expected data-plane credential files:\n"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "379cbbc1e968416e875cc15c1202d7eb",
"metadata": {
"executionInfo": {
"elapsed": 241,
"status": "ok",
"timestamp": 1706648119995,
"user": {
"displayName": "Andreas Eriksen",
"userId": "00161553861396505040"
},
"user_tz": -60
},
"id": "1f0b97c8"
},
"outputs": [],
"source": [
"from os.path import exists\n",
"from pathlib import Path\n",
"\n",
"cert_path = (\n",
" Path.home()\n",
" / \".vespa\"\n",
" / f\"{os.environ['TENANT_NAME']}.{vespa_app_name}.default/data-plane-public-cert.pem\"\n",
")\n",
"key_path = (\n",
" Path.home()\n",
" / \".vespa\"\n",
" / f\"{os.environ['TENANT_NAME']}.{vespa_app_name}.default/data-plane-private-key.pem\"\n",
")\n",
"\n",
"if not exists(cert_path) or not exists(key_path):\n",
" print(\n",
" \"ERROR: set the correct paths to security credentials. Correct paths above and rerun until you do not see this error\"\n",
" )"
]
},
{
"cell_type": "markdown",
"id": "277c27b1587741f2af2001be3712ef0d",
"metadata": {
"id": "85ce80e0"
},
"source": [
"Note that the subsequent Vespa Cloud deploy call below will add `data-plane-public-cert.pem` to the application before deploying it to Vespa Cloud, so that\n",
"you have access to both the private key and the public certificate. At the same time, Vespa Cloud only knows the public certificate.\n",
"\n",
"### Configure Vespa Cloud control-plane security\n",
"\n",
"Authenticate to generate a tenant level control plane API key for deploying the applications to Vespa Cloud, and save the path to it.\n",
"\n",
"The generated tenant api key must be added in the Vespa Console before attempting to deploy the application.\n",
"\n",
"```\n",
"To use this key in Vespa Cloud click 'Add custom key' at\n",
"https://console.vespa-cloud.com/tenant/TENANT_NAME/account/keys\n",
"and paste the entire public key including the BEGIN and END lines.\n",
"```\n"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "db7b79bc585a40fcaf58bf750017e135",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"executionInfo": {
"elapsed": 244,
"status": "ok",
"timestamp": 1706648129288,
"user": {
"displayName": "Andreas Eriksen",
"userId": "00161553861396505040"
},
"user_tz": -60
},
"id": "5bf8731c",
"outputId": "5f615d4c-9469-4be8-c8fe-9d0fc9dab4f6"
},
"outputs": [],
"source": [
"!vespa auth api-key\n",
"\n",
"from pathlib import Path\n",
"\n",
"api_key_path = Path.home() / \".vespa\" / f\"{os.environ['TENANT_NAME']}.api-key.pem\""
]
},
{
"cell_type": "markdown",
"id": "916684f9a58a4a2aa5f864670399430d",
"metadata": {
"id": "21db1010"
},
"source": [
"### Deploy to Vespa Cloud\n",
"\n",
"Now that we have data-plane and control-plane credentials ready, we can deploy our application to Vespa Cloud!\n",
"\n",
"`PyVespa` supports deploying apps to the [development zone](https://cloud.vespa.ai/en/reference/environments#dev-and-perf).\n",
"Make note of the tenant name, it is used in the next steps.\n",
"\n",
"> Note: Deployments to dev and perf expire after 7 days of inactivity, i.e., 7 days after running deploy. This applies to all plans, not only the Free Trial. Use the Vespa Console to extend the expiry period, or redeploy the application to add 7 more days.\n"
]
Expand All @@ -763,23 +568,20 @@
"outputs": [],
"source": [
"from vespa.deployment import VespaCloud\n",
"import os\n",
"\n",
"# Replace with your tenant name from the Vespa Cloud Console\n",
"tenant_name = \"vespa-team\"\n",
"\n",
"def read_secret():\n",
" \"\"\"Read the API key from the environment variable. This is\n",
" only used for CI/CD purposes.\"\"\"\n",
" t = os.getenv(\"VESPA_TEAM_API_KEY\")\n",
" if t:\n",
" return t.replace(r\"\\n\", \"\\n\")\n",
" else:\n",
" return t\n",
"\n",
"# Key is only used for CI/CD. Can be removed if logging in interactively\n",
"key = os.getenv(\"VESPA_TEAM_API_KEY\", None)\n",
"if key is not None:\n",
" key = key.replace(r\"\\n\", \"\\n\") # To parse key correctly\n",
"\n",
"vespa_cloud = VespaCloud(\n",
" tenant=os.environ[\"TENANT_NAME\"],\n",
" tenant=tenant_name,\n",
" application=vespa_app_name,\n",
" key_content=read_secret() if read_secret() else None,\n",
" key_location=api_key_path,\n",
" key_content=key, # Key is only used for CI/CD. Can be removed if logging in interactively\n",
" application_package=vespa_application_package,\n",
")"
]
Expand Down
Loading
Loading