Skip to content

Commit

Permalink
Merge pull request #564 from vespa-engine/kkraune/endpoint-connect
Browse files Browse the repository at this point in the history
Add example for (connecting to) endpoints
  • Loading branch information
jobergum authored Sep 15, 2023
2 parents 0b3eff5 + a5a16ca commit 7d8177f
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 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": "0552322b",
"metadata": {},
"outputs": [],
"source": [
"!vespa status container"
]
},
{
Expand Down Expand Up @@ -539,6 +548,47 @@
"doc = session.get(url).json()\n",
"doc"
]
},
{
"cell_type": "markdown",
"id": "e2480213",
"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": "c87da6cf",
"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": "183bff2b",
"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 7d8177f

Please sign in to comment.