Skip to content

Commit 9289e16

Browse files
author
Thiago G. Martins
authored
Merge pull request #199 from vespa-engine/tgm/doc-stateless
Document stateless apps and include more detailed deploy to vespa cloud quick-start
2 parents 3d8280b + 59c717f commit 9289e16

File tree

4 files changed

+198
-4
lines changed

4 files changed

+198
-4
lines changed
+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Deploy to Vespa Cloud\n",
8+
"\n",
9+
"> How to host your Vespa application in the cloud\n",
10+
"\n",
11+
"[![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/deploy-vespa-cloud.ipynb)"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"## Define your application package"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"This tutorial assumes you have defined your Vespa application package and stored it in the variable `app_package`. To illustrate this tutorial, we will use a basic question answering app from our gallery."
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 1,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"from vespa.gallery import QuestionAnswering\n",
35+
"\n",
36+
"app_package = QuestionAnswering()"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"## Setup your Vespa Cloud account"
44+
]
45+
},
46+
{
47+
"cell_type": "markdown",
48+
"metadata": {},
49+
"source": [
50+
"1. Sign-in or sign-up:\n",
51+
" * To deploy `app_package` on Vespa Cloud, you need to [login into your account](https://cloud.vespa.ai/) first. You can create one and give it a try for free.\n",
52+
"2. Choose a tenant:\n",
53+
" * You either create a new tenant or use an existing one. That will be the `TENANT_NAME` env variable in the example below. \n",
54+
"3. Get your user key:\n",
55+
" * Once you are on your chosen tenant dashboard, you can generate and download a user key under the key tab. Set the `USER_KEY` env variable to be the path to the downloaded user key. \n",
56+
"4. Create a new application under your tenant\n",
57+
" * Within the tenant dashboard, you can also create a new application associated with that tenant and set the `APPLICATION_NAME` env variable below to the name of the application. \n",
58+
" \n",
59+
"That is all that needs to be setup on the Vespa Cloud dashboard before deployment."
60+
]
61+
},
62+
{
63+
"cell_type": "markdown",
64+
"metadata": {},
65+
"source": [
66+
"## Create a VespaCloud instance"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": 2,
72+
"metadata": {
73+
"nbsphinx": "hidden"
74+
},
75+
"outputs": [],
76+
"source": [
77+
"import os\n",
78+
"\n",
79+
"os.environ[\"WORK_DIR\"] = \"/Users/tmartins/projects/vespa/pyvespa/\"\n",
80+
"os.environ[\"VESPA_CLOUD_USER_KEY\"] = \"-----BEGIN PRIVATE KEY-----\\nMIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgfuuKjPOWBQIrT9gd\\n1eezkuzqk9IIiwJnSMpFS7jZLAShRANCAAQg5CR0IhuADhVnEVwizXEWmmDcc2ML\\ni3VmInWOHsYrNSzEXNepXuvgo2w/WpCIxQPfntx+J239+Qqw2bc07huF\\n-----END PRIVATE KEY-----\"\n",
81+
"\n",
82+
"os.environ[\"TENANT_NAME\"] = \"vespa-team\"\n",
83+
"os.environ[\"APPLICATION_NAME\"] = \"pyvespa-integration\"\n",
84+
"with open(os.path.join(os.getenv(\"WORK_DIR\"), \"key.pem\"), \"w\") as f:\n",
85+
" f.write(os.getenv(\"VESPA_CLOUD_USER_KEY\").replace(r\"\\n\", \"\\n\"))\n",
86+
"os.environ[\"USER_KEY\"] = os.path.join(os.getenv(\"WORK_DIR\"), \"key.pem\")\n",
87+
"os.environ[\"INSTANCE_NAME\"] = \"test\"\n",
88+
"os.environ[\"DISK_FOLDER\"] = os.path.join(os.getenv(\"WORK_DIR\"), \"sample_application\")"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": 3,
94+
"metadata": {},
95+
"outputs": [],
96+
"source": [
97+
"from vespa.deployment import VespaCloud\n",
98+
"\n",
99+
"vespa_cloud = VespaCloud(\n",
100+
" tenant=os.getenv(\"TENANT_NAME\"),\n",
101+
" application=os.getenv(\"APPLICATION_NAME\"),\n",
102+
" key_location=os.getenv(\"USER_KEY\"),\n",
103+
" application_package=app_package,\n",
104+
")"
105+
]
106+
},
107+
{
108+
"cell_type": "markdown",
109+
"metadata": {},
110+
"source": [
111+
"## Deploy to the Cloud"
112+
]
113+
},
114+
{
115+
"cell_type": "markdown",
116+
"metadata": {},
117+
"source": [
118+
"We can have multiple instances of the same application, we can then chose a valid `INSTANCE_NAME` to identify the instance created here and set the `DISK_FOLDER` to a local path to hold deployment related files such as certifications and Vespa config files."
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": null,
124+
"metadata": {},
125+
"outputs": [],
126+
"source": [
127+
"app = vespa_cloud.deploy(\n",
128+
" instance=os.getenv(\"INSTANCE_NAME\"), disk_folder=os.getenv(\"DISK_FOLDER\")\n",
129+
")"
130+
]
131+
},
132+
{
133+
"cell_type": "markdown",
134+
"metadata": {},
135+
"source": [
136+
"That is it, you can now interact with your deployed application through the `app` instance."
137+
]
138+
}
139+
],
140+
"metadata": {
141+
"kernelspec": {
142+
"display_name": "Python 3",
143+
"language": "python",
144+
"name": "python3"
145+
},
146+
"language_info": {
147+
"codemirror_mode": {
148+
"name": "ipython",
149+
"version": 3
150+
},
151+
"file_extension": ".py",
152+
"mimetype": "text/x-python",
153+
"name": "python",
154+
"nbconvert_exporter": "python",
155+
"pygments_lexer": "ipython3",
156+
"version": "3.9.1"
157+
}
158+
},
159+
"nbformat": 4,
160+
"nbformat_minor": 2
161+
}

docs/sphinx/source/quickstart.rst

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ by clicking on the badge at the top of the tutorial.
99
connect-to-vespa-instance
1010
create-and-deploy-vespa-cloud
1111
create-and-deploy-vespa-docker
12+
deploy-vespa-cloud

docs/sphinx/source/reference-api.rst

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Reference API
22
=============
33

4-
Define application
5-
******************
4+
Define stateful application
5+
***************************
66

77
Create an Application Package
88
-----------------------------
@@ -108,9 +108,34 @@ QueryProfile
108108
:members:
109109
:special-members: __init__
110110

111+
Define stateless application
112+
****************************
113+
114+
Create tasks
115+
------------
116+
117+
SequenceClassification
118+
++++++++++++++++++++++
119+
120+
.. autoclass:: vespa.ml.SequenceClassification
121+
:members:
122+
:special-members: __init__
123+
124+
Create model server
125+
-------------------
126+
127+
ModelServer
128+
+++++++++++
129+
130+
.. autoclass:: vespa.package.ModelServer
131+
:members:
132+
:special-members: __init__
133+
111134
Deploy your application
112135
***********************
113136

137+
Deploy your stateful or stateless applications.
138+
114139
VespaDocker
115140
-----------
116141

vespa/ml.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,16 @@ def __init__(
103103
"""
104104
Sequence Classification task.
105105
106+
It takes a text input and returns an array of floats depending on which
107+
model is used to solve the task.
108+
106109
:param model_id: Id used to identify the model on Vespa applications.
107-
:param model: Id of the model as used by the model hub.
108-
:param tokenizer: Id of the tokenizer as used by the model hub.
110+
:param model: Id of the model as used by the model hub. Alternatively, it can
111+
also be the path to the folder containing the model files, as long as
112+
the model config is also there.
113+
:param tokenizer: Id of the tokenizer as used by the model hub. Alternatively, it can
114+
also be the path to the folder containing the tokenizer files, as long as
115+
the model config is also there.
109116
:param output_file: Output file to write output messages.
110117
"""
111118
super().__init__(

0 commit comments

Comments
 (0)