Skip to content

Commit

Permalink
Add example for (connecting to) endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristian Aune committed Sep 14, 2023
1 parent 0b3eff5 commit 7f813db
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions docs/sphinx/source/getting-started-pyvespa-cloud.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
},
{
"cell_type": "code",
"execution_count": 71,
"execution_count": null,
"id": "64da11f2",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -326,8 +326,17 @@
"metadata": {},
"source": [
"`app` now holds a reference to a [Vespa](https://pyvespa.readthedocs.io/en/latest/reference-api.html#vespa.application.Vespa) instance.\n",
"\n",
"Store the endpoint for later usage - paste from the deploy-output above:"
"Store the endpoint for later usage - set `endpoint` from this output:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1370dc4c",
"metadata": {},
"outputs": [],
"source": [
"!vespa status container"
]
},
{
Expand All @@ -337,7 +346,7 @@
"metadata": {},
"outputs": [],
"source": [
"endpoint = \"https://textsearch-container.textsearch.mytenant.aws-us-east-1c.dev.z.vespa-app.cloud/\""
"endpoint = \"https://textsearch-container.textsearch.kkraunetenant1.aws-us-east-1c.dev.z.vespa-app.cloud/\""
]
},
{
Expand Down Expand Up @@ -539,6 +548,47 @@
"doc = session.get(url).json()\n",
"doc"
]
},
{
"cell_type": "markdown",
"id": "0a42b504",
"metadata": {},
"source": [
"## Example: Reconnect pyvespa using cert/key pair\n",
"\n",
"Above, we stored the dataplane credentials for later use. Deployment of an application usually happens when the schema changes, whereas accessing the dataplane is for document updates and user queries.\n",
"\n",
"One only needs to know the endpoint and the cert/key pair to enable a connection to a Vespa Cloud application:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "714147ee",
"metadata": {},
"outputs": [],
"source": [
"# cert_path = \"/Users/me/.vespa/mytenant.textsearch.default/data-plane-public-cert.pem\"\n",
"# key_path = \"/Users/me/.vespa/mytenant.textsearch.default/data-plane-private-key.pem\"\n",
"\n",
"from vespa.application import Vespa\n",
"\n",
"the_app = Vespa(endpoint, cert=cert_path, key=key_path)\n",
"\n",
"res = the_app.query(body={\n",
" 'yql': 'select * from sources * where true',\n",
" 'hits': 1\n",
"})\n",
"res.hits[0]"
]
},
{
"cell_type": "markdown",
"id": "708d5dee",
"metadata": {},
"source": [
"A common problem is a cert mismatch - the cert/key pair used when deployed is different than the pair used when making queries. Make sure it is the same pair / re-create with `vespa auth cert -f` and redeploy as needed."
]
}
],
"metadata": {
Expand Down

0 comments on commit 7f813db

Please sign in to comment.