<jupyter_start><jupyter_text>Faster document operations with pyvespa> Document operations such as feed, get, update and delete now use async implementation by default- toc: true - badges: false- comments: true- categories: [vespa, pyvespa, speed, async] We will demonstrate that the new default implementation for document operations in pyvespa are now much faster due to async mode.  Define Question Answering app<jupyter_code>from vespa.gallery import QuestionAnswering

app_package = QuestionAnswering()<jupyter_output><empty_output><jupyter_text>Deploy to Vespa Cloud<jupyter_code>import os
from vespa.package import VespaCloud

# define your own WORK_DIR and VESPA_CLOUD_USER_KEY env variables

disk_folder = os.path.join(os.getenv("WORK_DIR"), "sample_application")
vespa_cloud = VespaCloud(
    tenant="vespa-team",
    application="pyvespa-integration",
    key_content=os.getenv("VESPA_CLOUD_USER_KEY").replace(r"\n", "\n"),
    application_package=app_package,
)
app = vespa_cloud.deploy(
    instance="msmarco", 
    disk_folder=os.path.join(os.getenv("WORK_DIR"), "sample_application")
)<jupyter_output>Deployment started in run 243 of dev-aws-us-east-1c for vespa-team.pyvespa-integration.msmarco. This may take about 15 minutes the first time.
INFO    [20:02:15]  Deploying platform version 7.452.11 and application version unknown ...
INFO    [20:02:17]  Deployment successful.
INFO    [20:02:17]  Session 43999 for tenant 'vespa-team' prepared and activated.
INFO    [20:02:17]  ######## Details for all nodes ########
INFO    [20:02:17]  h5591e.dev.aws-us-east-1c.vespa-external.aws.oath.cloud: expected to be UP
INFO    [20:02:17]  --- platform vespa/cloud-tenant-rhel8:7.452.11
INFO    [20:02:17]  --- container-clustercontroller on port 19050 has config generation 43999, wanted is 43999
INFO    [20:02:17]  h5580f.dev.aws-us-east-1c.vespa-external.aws.oath.cloud: expected to be UP
INFO    [20:02:17]  --- platform vespa/cloud-tenant-rhel8:7.452.11
INFO    [20:02:17]  --- distributor on port 19111 has config generation 43997, wanted is 43999
INFO    [20:02:17]  --- searchnode on port 19107 h[...]<jupyter_text>Load sample data<jupyter_code>import json, requests

sentence_data = json.loads(
    requests.get("https://data.vespa.oath.cloud/blog/qa/sample_sentence_data_100.json").text
)

batch_feed = [
    {
        "id": idx, 
        "fields": sentence
    }
    for idx, sentence in enumerate(sentence_data)
]<jupyter_output><empty_output><jupyter_text>Feed data  Asynchronous feeding - new default<jupyter_code>import time

start = time.time()
response = app.feed_batch(schema="sentence", batch=batch_feed)
print("{} seconds".format(time.time() - start))<jupyter_output>1.146148920059204 seconds<jupyter_text>Syncronous feeding - old default<jupyter_code>start = time.time()
response = app.feed_batch(schema="sentence", batch=batch_feed, asynchronous=False)
print("{} seconds".format(time.time() - start))<jupyter_output>68.66188383102417 seconds
{'fraction_non_alphanumeric': 0.11970410221923336, 'fraction_numerical': 0.05951580363147276, 'mean_word_length': 5.046747967479675, 'pattern_counts': {'":': 2, '<': 18, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '590897', 'license': 'Apache-2.0', 'n_tokens_mistral': 1122, 'n_tokens_neox': 994, 'n_words': 240, 'path': '_notebooks/2021-08-22-demonstrate-asynchronous-operations.ipynb', 'repo_name': 'thigm85/blog', 'size': '2974'}