Getting started with pyvespa

Vespa logo

This notebook starts Vespa, configures the application and tests the document and query APIs.

See pyvespa, jupyter notebooks and Docker requirements to run this notebook.

Create the application package

Create an application package:

[3]:
from typing import List

from vespa.package import (
    Document,
    Field,
    Schema,
    FieldSet,
    RankProfile,
    HNSW,
    ApplicationPackage,
    QueryProfile,
    QueryProfileType,
    QueryTypeField,
)

from vespa.query import QueryModel, AND, RankProfile as Ranking

class QuestionAnswering(ApplicationPackage):
    def __init__(self, name: str = "qa"):
        context_document = Document(
            fields=[
                Field(
                    name="questions",
                    type="array<int>",
                    indexing=["summary", "attribute"],
                ),
                Field(name="dataset", type="string", indexing=["summary", "attribute"]),
                Field(name="context_id", type="int", indexing=["summary", "attribute"]),
                Field(
                    name="text",
                    type="string",
                    indexing=["summary", "index"],
                    index="enable-bm25",
                ),
            ]
        )
        context_schema = Schema(
            name="context",
            document=context_document,
            fieldsets=[FieldSet(name="default", fields=["text"])],
            rank_profiles=[
                RankProfile(name="bm25", inherits="default", first_phase="bm25(text)"),
                RankProfile(
                    name="nativeRank",
                    inherits="default",
                    first_phase="nativeRank(text)",
                ),
            ],
        )
        sentence_document = Document(
            inherits="context",
            fields=[
                Field(
                    name="sentence_embedding",
                    type="tensor<float>(x[512])",
                    indexing=["attribute", "index"],
                    ann=HNSW(
                        distance_metric="euclidean",
                        max_links_per_node=16,
                        neighbors_to_explore_at_insert=500,
                    ),
                )
            ],
        )
        sentence_schema = Schema(
            name="sentence",
            document=sentence_document,
            fieldsets=[FieldSet(name="default", fields=["text"])],
            rank_profiles=[
                RankProfile(
                    name="semantic-similarity",
                    inherits="default",
                    first_phase="closeness(sentence_embedding)",
                ),
                RankProfile(name="bm25", inherits="default", first_phase="bm25(text)"),
                RankProfile(
                    name="bm25-semantic-similarity",
                    inherits="default",
                    first_phase="bm25(text) + closeness(sentence_embedding)",
                ),
            ],
        )
        super().__init__(
            name=name,
            schema=[context_schema, sentence_schema],
            query_profile=QueryProfile(),
            query_profile_type=QueryProfileType(
                fields=[
                    QueryTypeField(
                        name="ranking.features.query(query_embedding)",
                        type="tensor<float>(x[512])",
                    )
                ]
            ),
        )

app_package = QuestionAnswering()

Deploy the application using Docker

Deploy the app_package, wait for Finished deployment:

[4]:
import os
from vespa.deployment import VespaDocker

vespa_docker = VespaDocker()
app = vespa_docker.deploy(application_package=app_package)
Waiting for configuration server, 0/300 seconds...
Waiting for configuration server, 5/300 seconds...
Waiting for application status, 0/300 seconds...
Waiting for application status, 5/300 seconds...
Waiting for application status, 10/300 seconds...
Waiting for application status, 15/300 seconds...
Waiting for application status, 20/300 seconds...
Waiting for application status, 25/300 seconds...
Waiting for application status, 30/300 seconds...
Finished deployment.

The above deploys the application package to a running Vespa instance. Before moving on, inspect the generated configuration that was deployed.

See deploy-docker for how to export the application package to files, and how to deploy after modifying the application package.

Download, prepare and feed sample data

[10]:
import json, requests

sentence_data = json.loads(
    requests.get("https://data.vespa.oath.cloud/blog/qa/sample_sentence_data_100.json").text
)
list(sentence_data[0].keys())
[10]:
['text', 'dataset', 'questions', 'context_id', 'sentence_embedding']

Prepare the data as a list of dicts having the id key holding a unique id of the data point and the fields key holding a dict with the data fields required by the application:

[11]:
batch_feed = [
    {
        "id": idx,
        "fields": sentence
    }
    for idx, sentence in enumerate(sentence_data)
]

Feed the batch using the sentence schema:

[12]:
response = app.feed_batch(schema="sentence", batch=batch_feed)

Run a query

Query the application using the Vespa Query Language:

[13]:
result = app.query(body={
  'yql': 'select text from sources sentence  where userQuery();',
  'query': 'What is in front of the Notre Dame Main Building?',
  'type': 'any',
  'hits': 5,
  'ranking.profile': 'bm25'
})
[14]:
result.hits[0]
[14]:
{'id': 'index:qa_content/0/a87ff679ab8603b42a4ffde2',
 'relevance': 11.19486220083039,
 'source': 'qa_content',
 'fields': {'text': 'Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend "Venite Ad Me Omnes".'}}

Get documents

Get the sentences with ids = 0, 1 and 2. Inspect the response in json:

[15]:
batch = [{"id": 0}, {"id": 1}, {"id": 2}]
response = app.get_batch(schema="sentence", batch=batch)
[16]:
response
[16]:
[<vespa.io.VespaResponse at 0x1046facd0>,
 <vespa.io.VespaResponse at 0x11c3acfd0>,
 <vespa.io.VespaResponse at 0x11c3ac310>]
[17]:
response[0].json
[17]:
{'pathId': '/document/v1/sentence/sentence/docid/0',
 'id': 'id:sentence:sentence::0',
 'fields': {'text': "Atop the Main Building's gold dome is a golden statue of the Virgin Mary.",
  'dataset': 'squad',
  'sentence_embedding': {'cells': [{'address': {'x': '0'},
     'value': -0.005731593817472458},
    {'address': {'x': '1'}, 'value': 0.007575507741421461},
    {'address': {'x': '2'}, 'value': -0.06413306295871735},
    {'address': {'x': '3'}, 'value': -0.007967847399413586},
    {'address': {'x': '4'}, 'value': -0.06464996933937073},
    {'address': {'x': '5'}, 'value': -0.07429644465446472},
    {'address': {'x': '6'}, 'value': 0.005069912411272526},
    {'address': {'x': '7'}, 'value': -0.019518841058015823},
    {'address': {'x': '8'}, 'value': -0.021434271708130836},
    {'address': {'x': '9'}, 'value': -0.06423905491828918},
    {'address': {'x': '10'}, 'value': 0.0652240440249443},
    {'address': {'x': '11'}, 'value': -0.06434165686368942},
    {'address': {'x': '12'}, 'value': -0.06569897383451462},
    {'address': {'x': '13'}, 'value': 0.040481165051460266},
    {'address': {'x': '14'}, 'value': 0.024145686998963356},
    {'address': {'x': '15'}, 'value': 0.007362892851233482},
    {'address': {'x': '16'}, 'value': 0.07771800458431244},
    {'address': {'x': '17'}, 'value': 0.00946187973022461},
    {'address': {'x': '18'}, 'value': -0.028259800747036934},
    {'address': {'x': '19'}, 'value': 0.005866243038326502},
    {'address': {'x': '20'}, 'value': 0.015300747938454151},
    {'address': {'x': '21'}, 'value': 0.021307284012436867},
    {'address': {'x': '22'}, 'value': -0.05775361880660057},
    {'address': {'x': '23'}, 'value': -0.017718791961669922},
    {'address': {'x': '24'}, 'value': 0.02191190794110298},
    {'address': {'x': '25'}, 'value': 0.006564970128238201},
    {'address': {'x': '26'}, 'value': -0.005148318596184254},
    {'address': {'x': '27'}, 'value': 0.048069994896650314},
    {'address': {'x': '28'}, 'value': -0.00011502391862450168},
    {'address': {'x': '29'}, 'value': -0.06791272759437561},
    {'address': {'x': '30'}, 'value': -0.009163320064544678},
    {'address': {'x': '31'}, 'value': -0.07174629718065262},
    {'address': {'x': '32'}, 'value': 0.017720846459269524},
    {'address': {'x': '33'}, 'value': 0.037869423627853394},
    {'address': {'x': '34'}, 'value': 0.07788487523794174},
    {'address': {'x': '35'}, 'value': -0.04319801554083824},
    {'address': {'x': '36'}, 'value': 0.013778245076537132},
    {'address': {'x': '37'}, 'value': -0.05123303085565567},
    {'address': {'x': '38'}, 'value': -0.07474122196435928},
    {'address': {'x': '39'}, 'value': 0.0666406899690628},
    {'address': {'x': '40'}, 'value': -0.0534103699028492},
    {'address': {'x': '41'}, 'value': -0.037872593849897385},
    {'address': {'x': '42'}, 'value': 0.010211014188826084},
    {'address': {'x': '43'}, 'value': 0.008907281793653965},
    {'address': {'x': '44'}, 'value': -0.05693356692790985},
    {'address': {'x': '45'}, 'value': 0.06317473948001862},
    {'address': {'x': '46'}, 'value': 0.0785011276602745},
    {'address': {'x': '47'}, 'value': 0.026305610314011574},
    {'address': {'x': '48'}, 'value': -0.04362558200955391},
    {'address': {'x': '49'}, 'value': 0.05106586217880249},
    {'address': {'x': '50'}, 'value': 0.06952179223299026},
    {'address': {'x': '51'}, 'value': -0.029939323663711548},
    {'address': {'x': '52'}, 'value': 0.008242297917604446},
    {'address': {'x': '53'}, 'value': -0.023817898705601692},
    {'address': {'x': '54'}, 'value': 0.04810205101966858},
    {'address': {'x': '55'}, 'value': -0.023464491590857506},
    {'address': {'x': '56'}, 'value': -0.02842424064874649},
    {'address': {'x': '57'}, 'value': 0.003361016744747758},
    {'address': {'x': '58'}, 'value': 0.0604083277285099},
    {'address': {'x': '59'}, 'value': -0.00028857155120931566},
    {'address': {'x': '60'}, 'value': -0.019782839342951775},
    {'address': {'x': '61'}, 'value': 0.04528861120343208},
    {'address': {'x': '62'}, 'value': -0.052865512669086456},
    {'address': {'x': '63'}, 'value': 0.002612191950902343},
    {'address': {'x': '64'}, 'value': -0.05548971891403198},
    {'address': {'x': '65'}, 'value': 0.07642041146755219},
    {'address': {'x': '66'}, 'value': -0.0598042868077755},
    {'address': {'x': '67'}, 'value': 0.03133942186832428},
    {'address': {'x': '68'}, 'value': -0.007824675180017948},
    {'address': {'x': '69'}, 'value': 0.06480591744184494},
    {'address': {'x': '70'}, 'value': 0.0025388130452483892},
    {'address': {'x': '71'}, 'value': -0.07243897020816803},
    {'address': {'x': '72'}, 'value': -0.04542206600308418},
    {'address': {'x': '73'}, 'value': -0.007309886626899242},
    {'address': {'x': '74'}, 'value': 0.0840393528342247},
    {'address': {'x': '75'}, 'value': 0.052954018115997314},
    {'address': {'x': '76'}, 'value': -0.04401383921504021},
    {'address': {'x': '77'}, 'value': -0.06654049456119537},
    {'address': {'x': '78'}, 'value': 0.001990059856325388},
    {'address': {'x': '79'}, 'value': -0.040212906897068024},
    {'address': {'x': '80'}, 'value': -0.016776256263256073},
    {'address': {'x': '81'}, 'value': 0.013370862230658531},
    {'address': {'x': '82'}, 'value': -0.008448323234915733},
    {'address': {'x': '83'}, 'value': 0.0728844702243805},
    {'address': {'x': '84'}, 'value': 0.024126939475536346},
    {'address': {'x': '85'}, 'value': -0.06769422441720963},
    {'address': {'x': '86'}, 'value': 0.06302408874034882},
    {'address': {'x': '87'}, 'value': 0.07067032158374786},
    {'address': {'x': '88'}, 'value': -0.038075320422649384},
    {'address': {'x': '89'}, 'value': -0.015602963045239449},
    {'address': {'x': '90'}, 'value': -0.027085624635219574},
    {'address': {'x': '91'}, 'value': 0.037075914442539215},
    {'address': {'x': '92'}, 'value': 0.005181755404919386},
    {'address': {'x': '93'}, 'value': 0.06082254648208618},
    {'address': {'x': '94'}, 'value': 0.032451849430799484},
    {'address': {'x': '95'}, 'value': -0.04409795254468918},
    {'address': {'x': '96'}, 'value': 0.03051387146115303},
    {'address': {'x': '97'}, 'value': -0.05744433403015137},
    {'address': {'x': '98'}, 'value': -0.03471038118004799},
    {'address': {'x': '99'}, 'value': 0.03276345506310463},
    {'address': {'x': '100'}, 'value': 0.006043457426130772},
    {'address': {'x': '101'}, 'value': -0.03554929047822952},
    {'address': {'x': '102'}, 'value': -0.07440878450870514},
    {'address': {'x': '103'}, 'value': 0.02351159043610096},
    {'address': {'x': '104'}, 'value': 0.03136656433343887},
    {'address': {'x': '105'}, 'value': 0.07823910564184189},
    {'address': {'x': '106'}, 'value': -0.02737349644303322},
    {'address': {'x': '107'}, 'value': 0.011265130713582039},
    {'address': {'x': '108'}, 'value': 0.03432106599211693},
    {'address': {'x': '109'}, 'value': 0.06546878069639206},
    {'address': {'x': '110'}, 'value': -0.00023396419419441372},
    {'address': {'x': '111'}, 'value': -0.011557986959815025},
    {'address': {'x': '112'}, 'value': 0.025620460510253906},
    {'address': {'x': '113'}, 'value': 0.05357709899544716},
    {'address': {'x': '114'}, 'value': -0.0035238536074757576},
    {'address': {'x': '115'}, 'value': 0.03427300974726677},
    {'address': {'x': '116'}, 'value': -0.04426465556025505},
    {'address': {'x': '117'}, 'value': -0.027798393741250038},
    {'address': {'x': '118'}, 'value': -0.038985710591077805},
    {'address': {'x': '119'}, 'value': 0.0077178506180644035},
    {'address': {'x': '120'}, 'value': 0.046469274908304214},
    {'address': {'x': '121'}, 'value': -0.0731307864189148},
    {'address': {'x': '122'}, 'value': -0.06964877992868423},
    {'address': {'x': '123'}, 'value': 0.01783963479101658},
    {'address': {'x': '124'}, 'value': 0.07705194503068924},
    {'address': {'x': '125'}, 'value': 0.0249634962528944},
    {'address': {'x': '126'}, 'value': -0.043792326003313065},
    {'address': {'x': '127'}, 'value': 0.032148510217666626},
    {'address': {'x': '128'}, 'value': -0.05472841486334801},
    {'address': {'x': '129'}, 'value': -0.006402152124792337},
    {'address': {'x': '130'}, 'value': -0.04752308502793312},
    {'address': {'x': '131'}, 'value': -0.03934653848409653},
    {'address': {'x': '132'}, 'value': -0.003358342917636037},
    {'address': {'x': '133'}, 'value': -0.07451613992452621},
    {'address': {'x': '134'}, 'value': -0.06583846360445023},
    {'address': {'x': '135'}, 'value': 0.014880238100886345},
    {'address': {'x': '136'}, 'value': 0.058178842067718506},
    {'address': {'x': '137'}, 'value': -0.0744597315788269},
    {'address': {'x': '138'}, 'value': -0.04388468712568283},
    {'address': {'x': '139'}, 'value': -0.006177771836519241},
    {'address': {'x': '140'}, 'value': 0.06300053000450134},
    {'address': {'x': '141'}, 'value': 0.015160247683525085},
    {'address': {'x': '142'}, 'value': 0.08213217556476593},
    {'address': {'x': '143'}, 'value': -0.028674177825450897},
    {'address': {'x': '144'}, 'value': 0.018802916631102562},
    {'address': {'x': '145'}, 'value': -0.01958850957453251},
    {'address': {'x': '146'}, 'value': -0.02518400177359581},
    {'address': {'x': '147'}, 'value': -0.06280948221683502},
    {'address': {'x': '148'}, 'value': -0.042627815157175064},
    {'address': {'x': '149'}, 'value': -0.06520876288414001},
    {'address': {'x': '150'}, 'value': -0.002140427241101861},
    {'address': {'x': '151'}, 'value': 0.028858941048383713},
    {'address': {'x': '152'}, 'value': 0.04875727742910385},
    {'address': {'x': '153'}, 'value': -0.04436075687408447},
    {'address': {'x': '154'}, 'value': -0.012736239470541477},
    {'address': {'x': '155'}, 'value': -0.032670967280864716},
    {'address': {'x': '156'}, 'value': 0.048136305063962936},
    {'address': {'x': '157'}, 'value': 0.07212428748607635},
    {'address': {'x': '158'}, 'value': -0.06159426271915436},
    {'address': {'x': '159'}, 'value': 0.026047125458717346},
    {'address': {'x': '160'}, 'value': -0.00029080818057991564},
    {'address': {'x': '161'}, 'value': 0.011187436990439892},
    {'address': {'x': '162'}, 'value': 0.01240565162152052},
    {'address': {'x': '163'}, 'value': 0.048478174954652786},
    {'address': {'x': '164'}, 'value': 0.012715257704257965},
    {'address': {'x': '165'}, 'value': 0.011652180925011635},
    {'address': {'x': '166'}, 'value': -0.0013308337656781077},
    {'address': {'x': '167'}, 'value': 0.032670535147190094},
    {'address': {'x': '168'}, 'value': 0.00945266243070364},
    {'address': {'x': '169'}, 'value': 0.014488788321614265},
    {'address': {'x': '170'}, 'value': -0.029567314311861992},
    {'address': {'x': '171'}, 'value': -0.032574769109487534},
    {'address': {'x': '172'}, 'value': -0.021792365238070488},
    {'address': {'x': '173'}, 'value': -0.020808113738894463},
    {'address': {'x': '174'}, 'value': -0.03401615098118782},
    {'address': {'x': '175'}, 'value': 0.06680087745189667},
    {'address': {'x': '176'}, 'value': -0.06250281631946564},
    {'address': {'x': '177'}, 'value': 0.03272148594260216},
    {'address': {'x': '178'}, 'value': 0.01936480775475502},
    {'address': {'x': '179'}, 'value': -0.026815583929419518},
    {'address': {'x': '180'}, 'value': 0.07208762317895889},
    {'address': {'x': '181'}, 'value': -0.03973960131406784},
    {'address': {'x': '182'}, 'value': 0.006415614392608404},
    {'address': {'x': '183'}, 'value': 0.0011102595599368215},
    {'address': {'x': '184'}, 'value': 0.05931733176112175},
    {'address': {'x': '185'}, 'value': -0.07598836719989777},
    {'address': {'x': '186'}, 'value': -0.026091668754816055},
    {'address': {'x': '187'}, 'value': 0.02341729961335659},
    {'address': {'x': '188'}, 'value': -0.040755417197942734},
    {'address': {'x': '189'}, 'value': 0.001604373101145029},
    {'address': {'x': '190'}, 'value': -0.0760861188173294},
    {'address': {'x': '191'}, 'value': 0.058562636375427246},
    {'address': {'x': '192'}, 'value': -0.002422476653009653},
    {'address': {'x': '193'}, 'value': 0.022913040593266487},
    {'address': {'x': '194'}, 'value': 0.01795356161892414},
    {'address': {'x': '195'}, 'value': -0.06944388151168823},
    {'address': {'x': '196'}, 'value': -0.029202986508607864},
    {'address': {'x': '197'}, 'value': -0.07684884965419769},
    {'address': {'x': '198'}, 'value': 0.06695760041475296},
    {'address': {'x': '199'}, 'value': 0.023546423763036728},
    {'address': {'x': '200'}, 'value': 0.07279899716377258},
    {'address': {'x': '201'}, 'value': -0.043952248990535736},
    {'address': {'x': '202'}, 'value': -0.0794493705034256},
    {'address': {'x': '203'}, 'value': 0.03422931954264641},
    {'address': {'x': '204'}, 'value': 0.06903161853551865},
    {'address': {'x': '205'}, 'value': 0.0034821887966245413},
    {'address': {'x': '206'}, 'value': 0.028148461133241653},
    {'address': {'x': '207'}, 'value': 0.021342268213629723},
    {'address': {'x': '208'}, 'value': 0.01619466207921505},
    {'address': {'x': '209'}, 'value': 0.037691012024879456},
    {'address': {'x': '210'}, 'value': 0.006760886870324612},
    {'address': {'x': '211'}, 'value': 0.013903879560530186},
    {'address': {'x': '212'}, 'value': -0.02044975571334362},
    {'address': {'x': '213'}, 'value': -0.04147280380129814},
    {'address': {'x': '214'}, 'value': 0.0027645062655210495},
    {'address': {'x': '215'}, 'value': -0.015008649788796902},
    {'address': {'x': '216'}, 'value': -0.01891951821744442},
    {'address': {'x': '217'}, 'value': -0.03634532168507576},
    {'address': {'x': '218'}, 'value': -0.05369746685028076},
    {'address': {'x': '219'}, 'value': -0.009175799787044525},
    {'address': {'x': '220'}, 'value': -0.0006909870426170528},
    {'address': {'x': '221'}, 'value': -0.01112089492380619},
    {'address': {'x': '222'}, 'value': 0.01724017970263958},
    {'address': {'x': '223'}, 'value': 0.010581694543361664},
    {'address': {'x': '224'}, 'value': -0.032602451741695404},
    {'address': {'x': '225'}, 'value': -0.025953255593776703},
    {'address': {'x': '226'}, 'value': 0.020451324060559273},
    {'address': {'x': '227'}, 'value': 0.001531854155473411},
    {'address': {'x': '228'}, 'value': -0.025993842631578445},
    {'address': {'x': '229'}, 'value': -0.0008596995030529797},
    {'address': {'x': '230'}, 'value': 0.018400054425001144},
    {'address': {'x': '231'}, 'value': 0.025778459385037422},
    {'address': {'x': '232'}, 'value': 0.0212404727935791},
    {'address': {'x': '233'}, 'value': 0.06938228011131287},
    {'address': {'x': '234'}, 'value': -0.042927153408527374},
    {'address': {'x': '235'}, 'value': 0.03705870732665062},
    {'address': {'x': '236'}, 'value': 0.03841257467865944},
    {'address': {'x': '237'}, 'value': -0.024157313629984856},
    {'address': {'x': '238'}, 'value': 0.0269605815410614},
    {'address': {'x': '239'}, 'value': 0.0248009841889143},
    {'address': {'x': '240'}, 'value': -0.03208054602146149},
    {'address': {'x': '241'}, 'value': 0.021425766870379448},
    {'address': {'x': '242'}, 'value': -0.007572891656309366},
    {'address': {'x': '243'}, 'value': 0.017943117767572403},
    {'address': {'x': '244'}, 'value': -0.03873080760240555},
    {'address': {'x': '245'}, 'value': 0.03102504275739193},
    {'address': {'x': '246'}, 'value': 0.04988511651754379},
    {'address': {'x': '247'}, 'value': -0.0019366168417036533},
    {'address': {'x': '248'}, 'value': 0.04786434397101402},
    {'address': {'x': '249'}, 'value': 0.014679402112960815},
    {'address': {'x': '250'}, 'value': -0.03031056746840477},
    {'address': {'x': '251'}, 'value': -0.019375672563910484},
    {'address': {'x': '252'}, 'value': -0.06264447420835495},
    {'address': {'x': '253'}, 'value': 0.06096327304840088},
    {'address': {'x': '254'}, 'value': -0.04018431156873703},
    {'address': {'x': '255'}, 'value': -0.06047431007027626},
    {'address': {'x': '256'}, 'value': 0.008236786350607872},
    {'address': {'x': '257'}, 'value': -0.053653497248888016},
    {'address': {'x': '258'}, 'value': 0.07289472222328186},
    {'address': {'x': '259'}, 'value': 0.07068130373954773},
    {'address': {'x': '260'}, 'value': -0.032801978290081024},
    {'address': {'x': '261'}, 'value': -0.0745716392993927},
    {'address': {'x': '262'}, 'value': -0.005813592113554478},
    {'address': {'x': '263'}, 'value': 0.05783914402127266},
    {'address': {'x': '264'}, 'value': -0.03435840085148811},
    {'address': {'x': '265'}, 'value': 0.009527141228318214},
    {'address': {'x': '266'}, 'value': 0.018685584887862206},
    {'address': {'x': '267'}, 'value': -0.06751752644777298},
    {'address': {'x': '268'}, 'value': -0.06509213149547577},
    {'address': {'x': '269'}, 'value': -0.08372518420219421},
    {'address': {'x': '270'}, 'value': -0.05446317046880722},
    {'address': {'x': '271'}, 'value': 0.053907327353954315},
    {'address': {'x': '272'}, 'value': -0.05474940314888954},
    {'address': {'x': '273'}, 'value': 0.014350458979606628},
    {'address': {'x': '274'}, 'value': -0.07023079693317413},
    {'address': {'x': '275'}, 'value': -0.011159663088619709},
    {'address': {'x': '276'}, 'value': 0.039929576218128204},
    {'address': {'x': '277'}, 'value': -0.015988843515515327},
    {'address': {'x': '278'}, 'value': 0.004941158927977085},
    {'address': {'x': '279'}, 'value': 0.003037756308913231},
    {'address': {'x': '280'}, 'value': -0.02879311889410019},
    {'address': {'x': '281'}, 'value': 0.01633497327566147},
    {'address': {'x': '282'}, 'value': -0.041140444576740265},
    {'address': {'x': '283'}, 'value': -0.07165240496397018},
    {'address': {'x': '284'}, 'value': 0.011640839278697968},
    {'address': {'x': '285'}, 'value': -0.052849967032670975},
    {'address': {'x': '286'}, 'value': 0.009558329358696938},
    {'address': {'x': '287'}, 'value': -0.04208458587527275},
    {'address': {'x': '288'}, 'value': -0.06771799176931381},
    {'address': {'x': '289'}, 'value': 0.06408269703388214},
    {'address': {'x': '290'}, 'value': -0.03123757801949978},
    {'address': {'x': '291'}, 'value': -0.041630007326602936},
    {'address': {'x': '292'}, 'value': -0.060997989028692245},
    {'address': {'x': '293'}, 'value': -0.03564658388495445},
    {'address': {'x': '294'}, 'value': -0.023803366348147392},
    {'address': {'x': '295'}, 'value': -0.06091669574379921},
    {'address': {'x': '296'}, 'value': -0.02365335449576378},
    {'address': {'x': '297'}, 'value': -0.07259650528430939},
    {'address': {'x': '298'}, 'value': -0.025628216564655304},
    {'address': {'x': '299'}, 'value': 0.04468527063727379},
    {'address': {'x': '300'}, 'value': -0.04823016747832298},
    {'address': {'x': '301'}, 'value': -0.03465230390429497},
    {'address': {'x': '302'}, 'value': 0.07370327413082123},
    {'address': {'x': '303'}, 'value': -0.02722766250371933},
    {'address': {'x': '304'}, 'value': -0.041227713227272034},
    {'address': {'x': '305'}, 'value': -0.06710455566644669},
    {'address': {'x': '306'}, 'value': -0.0018554985290393233},
    {'address': {'x': '307'}, 'value': 0.005912774242460728},
    {'address': {'x': '308'}, 'value': 0.02462003566324711},
    {'address': {'x': '309'}, 'value': 0.00448566023260355},
    {'address': {'x': '310'}, 'value': -0.017967991530895233},
    {'address': {'x': '311'}, 'value': -0.05529441684484482},
    {'address': {'x': '312'}, 'value': -0.0009463604656048119},
    {'address': {'x': '313'}, 'value': -0.006434826646000147},
    {'address': {'x': '314'}, 'value': -0.048404306173324585},
    {'address': {'x': '315'}, 'value': 0.03753988444805145},
    {'address': {'x': '316'}, 'value': 0.06669825315475464},
    {'address': {'x': '317'}, 'value': 0.025847231969237328},
    {'address': {'x': '318'}, 'value': -0.03900757059454918},
    {'address': {'x': '319'}, 'value': 0.06327608972787857},
    {'address': {'x': '320'}, 'value': 0.06903517246246338},
    {'address': {'x': '321'}, 'value': 0.02192314900457859},
    {'address': {'x': '322'}, 'value': -0.008090319111943245},
    {'address': {'x': '323'}, 'value': 0.08822548389434814},
    {'address': {'x': '324'}, 'value': 0.03539515286684036},
    {'address': {'x': '325'}, 'value': 0.07631707191467285},
    {'address': {'x': '326'}, 'value': 0.002548432210460305},
    {'address': {'x': '327'}, 'value': 0.020233100280165672},
    {'address': {'x': '328'}, 'value': -0.02968069165945053},
    {'address': {'x': '329'}, 'value': -0.03596833720803261},
    {'address': {'x': '330'}, 'value': 0.04826529324054718},
    {'address': {'x': '331'}, 'value': 0.05092062056064606},
    {'address': {'x': '332'}, 'value': 0.05145549401640892},
    {'address': {'x': '333'}, 'value': -0.05773278698325157},
    {'address': {'x': '334'}, 'value': -0.05899902805685997},
    {'address': {'x': '335'}, 'value': 0.05344465747475624},
    {'address': {'x': '336'}, 'value': 0.04117647185921669},
    {'address': {'x': '337'}, 'value': 0.08456218242645264},
    {'address': {'x': '338'}, 'value': -0.0005618633585982025},
    {'address': {'x': '339'}, 'value': -0.05918756499886513},
    {'address': {'x': '340'}, 'value': -0.014348267577588558},
    {'address': {'x': '341'}, 'value': 0.047307293862104416},
    {'address': {'x': '342'}, 'value': -0.036367423832416534},
    {'address': {'x': '343'}, 'value': 0.07344646006822586},
    {'address': {'x': '344'}, 'value': 0.03181513398885727},
    {'address': {'x': '345'}, 'value': 0.08482533693313599},
    {'address': {'x': '346'}, 'value': -0.021844688802957535},
    {'address': {'x': '347'}, 'value': 0.02116752788424492},
    {'address': {'x': '348'}, 'value': 0.01678370125591755},
    {'address': {'x': '349'}, 'value': 0.009503713808953762},
    {'address': {'x': '350'}, 'value': 0.05740010365843773},
    {'address': {'x': '351'}, 'value': 0.04721197858452797},
    {'address': {'x': '352'}, 'value': -0.003934822976589203},
    {'address': {'x': '353'}, 'value': -0.00770507100969553},
    {'address': {'x': '354'}, 'value': -0.0020017882343381643},
    {'address': {'x': '355'}, 'value': -0.0712333470582962},
    {'address': {'x': '356'}, 'value': 0.020015541464090347},
    {'address': {'x': '357'}, 'value': 0.07017334550619125},
    {'address': {'x': '358'}, 'value': -0.07388505339622498},
    {'address': {'x': '359'}, 'value': 0.07016339898109436},
    {'address': {'x': '360'}, 'value': -0.003999287728220224},
    {'address': {'x': '361'}, 'value': -0.04195589944720268},
    {'address': {'x': '362'}, 'value': -0.0726010650396347},
    {'address': {'x': '363'}, 'value': -0.041846826672554016},
    {'address': {'x': '364'}, 'value': -0.07102943956851959},
    {'address': {'x': '365'}, 'value': 0.06908860057592392},
    {'address': {'x': '366'}, 'value': 0.0383109450340271},
    {'address': {'x': '367'}, 'value': 0.05483092740178108},
    {'address': {'x': '368'}, 'value': 0.05271876975893974},
    {'address': {'x': '369'}, 'value': 0.02798583172261715},
    {'address': {'x': '370'}, 'value': 0.05721564218401909},
    {'address': {'x': '371'}, 'value': -0.07676921039819717},
    {'address': {'x': '372'}, 'value': -0.02675732411444187},
    {'address': {'x': '373'}, 'value': -0.07017832249403},
    {'address': {'x': '374'}, 'value': 0.05919730290770531},
    {'address': {'x': '375'}, 'value': 0.035828378051519394},
    {'address': {'x': '376'}, 'value': -0.05044249817728996},
    {'address': {'x': '377'}, 'value': 0.051987338811159134},
    {'address': {'x': '378'}, 'value': -0.00882241502404213},
    {'address': {'x': '379'}, 'value': 0.01890091598033905},
    {'address': {'x': '380'}, 'value': 0.03677179664373398},
    {'address': {'x': '381'}, 'value': -0.07210833579301834},
    {'address': {'x': '382'}, 'value': -0.04706022888422012},
    {'address': {'x': '383'}, 'value': 0.006130976136773825},
    {'address': {'x': '384'}, 'value': 0.01891031488776207},
    {'address': {'x': '385'}, 'value': -0.06158973649144173},
    {'address': {'x': '386'}, 'value': 0.05529525876045227},
    {'address': {'x': '387'}, 'value': -0.0246284119784832},
    {'address': {'x': '388'}, 'value': -0.03294168785214424},
    {'address': {'x': '389'}, 'value': 0.06761419028043747},
    {'address': {'x': '390'}, 'value': -0.046971697360277176},
    {'address': {'x': '391'}, 'value': 0.06714886426925659},
    {'address': {'x': '392'}, 'value': 0.050442636013031006},
    {'address': {'x': '393'}, 'value': 0.03374863788485527},
    {'address': {'x': '394'}, 'value': 0.020866308361291885},
    {'address': {'x': '395'}, 'value': -0.03665538132190704},
    {'address': {'x': '396'}, 'value': 0.06490837782621384},
    {'address': {'x': '397'}, 'value': -0.012313500046730042},
    {'address': {'x': '398'}, 'value': -0.05381961539387703},
    {'address': {'x': '399'}, 'value': -0.012739498168230057},
    {'address': {'x': '400'}, 'value': 0.05014671012759209},
    {'address': {'x': '401'}, 'value': -0.07939334213733673},
    {'address': {'x': '402'}, 'value': -0.065677210688591},
    {'address': {'x': '403'}, 'value': -0.02065417543053627},
    {'address': {'x': '404'}, 'value': 0.014188568107783794},
    {'address': {'x': '405'}, 'value': 0.025993280112743378},
    {'address': {'x': '406'}, 'value': -0.015794135630130768},
    {'address': {'x': '407'}, 'value': 0.08905654400587082},
    {'address': {'x': '408'}, 'value': -0.0700952485203743},
    {'address': {'x': '409'}, 'value': 0.006811636500060558},
    {'address': {'x': '410'}, 'value': 0.012133410200476646},
    {'address': {'x': '411'}, 'value': -0.03085549734532833},
    {'address': {'x': '412'}, 'value': -0.009217693470418453},
    {'address': {'x': '413'}, 'value': -0.054441213607788086},
    {'address': {'x': '414'}, 'value': -0.05287398770451546},
    {'address': {'x': '415'}, 'value': -0.038465626537799835},
    {'address': {'x': '416'}, 'value': 0.023438384756445885},
    {'address': {'x': '417'}, 'value': 0.03366180509328842},
    {'address': {'x': '418'}, 'value': 0.013422048650681973},
    {'address': {'x': '419'}, 'value': -0.01985223777592182},
    {'address': {'x': '420'}, 'value': -0.014284738339483738},
    {'address': {'x': '421'}, 'value': 0.059922955930233},
    {'address': {'x': '422'}, 'value': 0.028297947719693184},
    {'address': {'x': '423'}, 'value': -0.02536710724234581},
    {'address': {'x': '424'}, 'value': -0.07693523168563843},
    {'address': {'x': '425'}, 'value': -0.08256203681230545},
    {'address': {'x': '426'}, 'value': 0.024241937324404716},
    {'address': {'x': '427'}, 'value': -0.07366729527711868},
    {'address': {'x': '428'}, 'value': 0.057095978409051895},
    {'address': {'x': '429'}, 'value': 0.05186446011066437},
    {'address': {'x': '430'}, 'value': -0.013500767759978771},
    {'address': {'x': '431'}, 'value': -0.05222296714782715},
    {'address': {'x': '432'}, 'value': 0.05155124515295029},
    {'address': {'x': '433'}, 'value': 0.0519084706902504},
    {'address': {'x': '434'}, 'value': 0.029741182923316956},
    {'address': {'x': '435'}, 'value': 0.014399838633835316},
    {'address': {'x': '436'}, 'value': 0.02402777597308159},
    {'address': {'x': '437'}, 'value': 0.03734354302287102},
    {'address': {'x': '438'}, 'value': -0.0008057677769102156},
    {'address': {'x': '439'}, 'value': -0.06729704886674881},
    {'address': {'x': '440'}, 'value': 0.05468644201755524},
    {'address': {'x': '441'}, 'value': -0.04701060801744461},
    {'address': {'x': '442'}, 'value': 0.02575099840760231},
    {'address': {'x': '443'}, 'value': -0.018379278481006622},
    {'address': {'x': '444'}, 'value': 0.024666225537657738},
    {'address': {'x': '445'}, 'value': -0.06913184374570847},
    {'address': {'x': '446'}, 'value': -0.003778835292905569},
    {'address': {'x': '447'}, 'value': 0.02831369824707508},
    {'address': {'x': '448'}, 'value': 0.0012387082679197192},
    {'address': {'x': '449'}, 'value': 0.012194967828691006},
    {'address': {'x': '450'}, 'value': 0.05198746919631958},
    {'address': {'x': '451'}, 'value': -0.04047307372093201},
    {'address': {'x': '452'}, 'value': 0.06428617984056473},
    {'address': {'x': '453'}, 'value': -0.06766947358846664},
    {'address': {'x': '454'}, 'value': -0.0054612732492387295},
    {'address': {'x': '455'}, 'value': 0.007396876811981201},
    {'address': {'x': '456'}, 'value': -0.05219375714659691},
    {'address': {'x': '457'}, 'value': 0.08037269860506058},
    {'address': {'x': '458'}, 'value': -0.024306727573275566},
    {'address': {'x': '459'}, 'value': -0.03241264447569847},
    {'address': {'x': '460'}, 'value': 0.05088223144412041},
    {'address': {'x': '461'}, 'value': -0.010638539679348469},
    {'address': {'x': '462'}, 'value': -0.027046995237469673},
    {'address': {'x': '463'}, 'value': -0.03496580943465233},
    {'address': {'x': '464'}, 'value': 0.05657656863331795},
    {'address': {'x': '465'}, 'value': 0.03490531072020531},
    {'address': {'x': '466'}, 'value': 0.043829623609781265},
    {'address': {'x': '467'}, 'value': 0.0055516925640404224},
    {'address': {'x': '468'}, 'value': 0.06429943442344666},
    {'address': {'x': '469'}, 'value': 0.01735875941812992},
    {'address': {'x': '470'}, 'value': -0.0634138211607933},
    {'address': {'x': '471'}, 'value': 0.0782628059387207},
    {'address': {'x': '472'}, 'value': 0.04917420819401741},
    {'address': {'x': '473'}, 'value': 0.019163435325026512},
    {'address': {'x': '474'}, 'value': 0.03917761519551277},
    {'address': {'x': '475'}, 'value': -0.04597480595111847},
    {'address': {'x': '476'}, 'value': -0.054439157247543335},
    {'address': {'x': '477'}, 'value': 0.004626117646694183},
    {'address': {'x': '478'}, 'value': -0.02272822894155979},
    {'address': {'x': '479'}, 'value': -0.06397286802530289},
    {'address': {'x': '480'}, 'value': 0.03678639233112335},
    {'address': {'x': '481'}, 'value': 0.004487334750592709},
    {'address': {'x': '482'}, 'value': 0.030818555504083633},
    {'address': {'x': '483'}, 'value': 0.051590774208307266},
    {'address': {'x': '484'}, 'value': -0.05228615179657936},
    {'address': {'x': '485'}, 'value': -0.03993840888142586},
    {'address': {'x': '486'}, 'value': 0.004463767632842064},
    {'address': {'x': '487'}, 'value': 0.04185232147574425},
    {'address': {'x': '488'}, 'value': -0.02518554776906967},
    {'address': {'x': '489'}, 'value': -0.01816924475133419},
    {'address': {'x': '490'}, 'value': 0.03335050866007805},
    {'address': {'x': '491'}, 'value': 0.00811048038303852},
    {'address': {'x': '492'}, 'value': 0.034591205418109894},
    {'address': {'x': '493'}, 'value': -0.08239106088876724},
    {'address': {'x': '494'}, 'value': -0.016733549535274506},
    {'address': {'x': '495'}, 'value': 0.07935647666454315},
    {'address': {'x': '496'}, 'value': 0.03704648092389107},
    {'address': {'x': '497'}, 'value': 0.013241861946880817},
    {'address': {'x': '498'}, 'value': -0.007764177396893501},
    {'address': {'x': '499'}, 'value': 0.04041573405265808},
    {'address': {'x': '500'}, 'value': 0.007542093750089407},
    {'address': {'x': '501'}, 'value': 0.0336596816778183},
    {'address': {'x': '502'}, 'value': -0.03812943026423454},
    {'address': {'x': '503'}, 'value': -0.0482783168554306},
    {'address': {'x': '504'}, 'value': 0.08552124351263046},
    {'address': {'x': '505'}, 'value': 0.05144829675555229},
    {'address': {'x': '506'}, 'value': -0.04466550424695015},
    {'address': {'x': '507'}, 'value': 0.05642062425613403},
    {'address': {'x': '508'}, 'value': 0.06042104959487915},
    {'address': {'x': '509'}, 'value': -0.01285067480057478},
    {'address': {'x': '510'}, 'value': -0.047095801681280136},
    {'address': {'x': '511'}, 'value': -0.019968846812844276}]},
  'context_id': 0,
  'questions': [4]}}

Update a document

Update a data point by id. Optionally, create the data point if it does not exist:

[18]:
batch_update = [
    {
        "id": 0,                               # data_id
        "fields": {"text": "this is a test"},  # fields to be updated
        "create": False                        # Optional. Create data point if not exist, default to False.

    }
]
[19]:
response = app.update_batch(schema="sentence", batch=batch_update)

Delete documents

Delete the sentences with ids = 0, 1 and 2:

[20]:
batch = [{"id": 0}, {"id": 1}, {"id": 2}]
response = app.delete_batch(schema="sentence", batch=batch)

Cleanup

[21]:
vespa_docker.container.stop()
vespa_docker.container.remove()