Skip to content

Commit

Permalink
Jobergum/streaming example (#630)
Browse files Browse the repository at this point in the history
* save app when deploying to cloud as well.

* create the dir if it doesn't exist

* new example

* Minor tweaks

* rename

* Minor tweaks

* Apply suggestions from code review

Co-authored-by: Kristian Aune <kkraune@users.noreply.github.com>

* wording and logo

* merge and avoid misspelled api +logo

* Add support for schema inheritance

* Update with multi schema and better language

---------

Co-authored-by: Kristian Aune <kkraune@users.noreply.github.com>
  • Loading branch information
jobergum and kkraune committed Nov 22, 2023
1 parent 557c2af commit b9f6207
Show file tree
Hide file tree
Showing 6 changed files with 1,347 additions and 7 deletions.

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions docs/sphinx/source/getting-started-pyvespa-cloud.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"source": [
"## Install\n",
"\n",
"Install [pyvespa](https://pyvespa.readthedocs.io/) >= 0.35\n",
"Install [pyvespa](https://pyvespa.readthedocs.io/) >= 0.38\n",
"and the [Vespa CLI](https://docs.vespa.ai/en/vespa-cli.html).\n",
"The Vespa CLI is used for data and control plane key management ([Vespa Cloud Security Guide](https://cloud.vespa.ai/en/security/guide))."
]
Expand Down Expand Up @@ -107,7 +107,7 @@
"source": [
"## Configure data-plane security\n",
"\n",
"Create Vespa Cloud data-plane mTLS cert/key-pair. This mututal certificate pair is used to talk to your Vespa cloud endpoints. \n",
"Create Vespa Cloud data-plane mTLS cert/key-pair. This mutual certificate pair is used to talk to your Vespa cloud endpoints. \n",
"See [Vespa Cloud Security Guide](https://cloud.vespa.ai/en/security/guide).\n",
"\n",
"\n",
Expand Down Expand Up @@ -161,7 +161,7 @@
"\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",
"<div style=\"background-color: #ffcc00; padding: 10px; border: 1px solid #ff9900; font-weight: bold;\">\n",
" <strong>Warning:</strong>The generated tenant api key must be added in the Vespa Console before attempting to deploy the application.",
" <strong>Warning:</strong>The generated tenant api key must be added in the Vespa Console before attempting to deploy the application.\n",
"</div>\n",
"\n",
"The following step will print the following message: \n",
Expand Down Expand Up @@ -324,7 +324,10 @@
"metadata": {},
"source": [
"The following will upload the application package to Vespa Cloud Dev Zone (`aws-us-east-1c`), read more about [Vespa Zones](https://cloud.vespa.ai/en/reference/zones.html). PyVespa\n",
"currently only supports deploying to the Vespa Cloud Dev Zone, which is considered as a sandbox environment without high availability guarantees. "
"currently only supports deploying to the Vespa Cloud Dev Zone, which is considered as a sandbox environment where resources are down-scaled and\n",
"idle deployments are expired automatically. \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."
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion vespa/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ def deploy(self, instance: Optional[str]="default", disk_folder: Optional[str] =
"""
if not disk_folder:
disk_folder = os.path.join(os.getcwd(), self.application_package.name)

self.application_package.to_files(disk_folder)

region = self.get_dev_region()
job = "dev-" + region
run = self._start_deployment(instance, job, disk_folder, None)
Expand Down
6 changes: 5 additions & 1 deletion vespa/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ def __init__(
imported_fields: Optional[List[ImportedField]] = None,
document_summaries: Optional[List[DocumentSummary]] = None,
mode: Optional[str] = "index",
inherits: Optional[str] = None,
**kwargs: Unpack[SchemaConfiguration],
) -> None:
"""
Expand All @@ -1249,6 +1250,7 @@ def __init__(
:param imported_fields: A list of :class:`ImportedField` defining fields from global documents to be imported.
:param document_summaries: A list of :class:`DocumentSummary` associated with the schema.
:param mode: Schema mode. Defaults to 'index'. Other options are 'store-only' and 'streaming'.
:param inherits: Schema to inherit from.
:key stemming: The default stemming setting. Defaults to 'best'.
To create a Schema:
Expand All @@ -1259,6 +1261,7 @@ def __init__(
self.name = name
self.document = document
self.global_document = global_document
self.inherits = inherits

if mode not in ["index", "store-only", "streaming"]:
raise ValueError(
Expand Down Expand Up @@ -1359,6 +1362,7 @@ def schema_to_text(self) -> str:
return schema_template.render(
schema_name=self.name,
document_name=self.name,
schema=self,
document=self.document,
fieldsets=self.fieldsets,
rank_profiles=self.rank_profiles,
Expand Down Expand Up @@ -2071,7 +2075,7 @@ def to_files(self, root: Path) -> None:
:return:
"""
if not os.path.exists(root):
raise ValueError("Invalid path for export: {}".format(root))
Path(root).mkdir(parents=True, exist_ok=True)

Path(os.path.join(root, "schemas")).mkdir(parents=True, exist_ok=True)
Path(os.path.join(root, "files")).mkdir(parents=True, exist_ok=True)
Expand Down
3 changes: 2 additions & 1 deletion vespa/templates/schema.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% import 'macros.txt' as macros %}
schema {{ schema_name }} {
schema {{ schema_name }}{% if schema.inherits %} inherits {{ schema.inherits }}{% endif %} {
{% if stemming %}
stemming: {{ stemming }}
{% endif %}
Expand Down Expand Up @@ -114,6 +114,7 @@ schema {{ schema_name }} {
inputs {
{% for input in value.inputs %}
{{ input.0 }} {{ input.1 }} {% if input.2 %}: {{ input.2 }}{% endif %}

{% endfor %}

}
Expand Down
42 changes: 42 additions & 0 deletions vespa/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,47 @@ def test_generated_services_uses_mode_streaming(self):
)
self.assertEqual(self.app_package.services_to_text, expected_result)

class TestSchemaInheritance(unittest.TestCase):
def setUp(self) -> None:
self.news_schema = Schema(
name="news",
document=Document(
fields=[
Field(
name="news_id", type="string", indexing=["attribute", "summary"]
)
]
)
)
self.mail = Schema(
name="mail",
inherits="news",
document=Document(
inherits="news",
fields=[
Field(
name="mail_id", type="string", indexing=["attribute", "summary"]
),
]
),
)

self.app_package = ApplicationPackage(
name="testapp",
schema=[self.news_schema, self.mail],
)
def test_schema_to_text(self):
expected_mail_result = (
"schema mail inherits news {\n"
" document mail inherits news {\n"
" field mail_id type string {\n"
" indexing: attribute | summary\n"
" }\n"
" }\n"
"}"
)
self.assertEqual(self.app_package.get_schema(name="mail").schema_to_text, expected_mail_result)


class TestApplicationPackageMultipleSchema(unittest.TestCase):
def setUp(self) -> None:
Expand Down Expand Up @@ -836,6 +877,7 @@ def setUp(self) -> None:
name="testapp",
schema=[self.news_schema, self.user_schema, self.category_ctr_schema],
)


def test_get_schema(self):
self.assertEqual(self.app_package.get_schema(name="news"), self.news_schema)
Expand Down

0 comments on commit b9f6207

Please sign in to comment.