Connect to Vespa instance

Connect to a running Vespa instance:

app = Vespa(url = "http://localhost", port = 8080)

Assume the Vespa instance has a Schema called msmarco with the following fields:

document = Document(
    fields=[
        Field(name="id", type="string", indexing=["attribute", "summary"]),
        Field(
            name="title",
            type="string",
            indexing=["index", "summary"],
            index="enable-bm25",
        ),
        Field(
            name="body",
            type="string",
            indexing=["index", "summary"],
            index="enable-bm25",
        ),
    ]
)

Data operations

Feed data

response = app.feed_data_point(
    schema="msmarco",
    data_id="1",
    fields={
        "id": "1",
        "title": "this is my first title",
        "body": "this is my first body",
    },
)
assert response.json()["id"] == "id:msmarco:msmarco::1"

Get data

response = app.get_data(schema="msmarco", data_id="1")

expected_data = {
    "fields": {
        "id": "1",
        "title": "this is my first title",
        "body": "this is my first body",
    },
    "id": "id:msmarco:msmarco::1",
    "pathId": "/document/v1/msmarco/msmarco/docid/1"
}

assert response.status_code == 200
assert response.json() == expected_data

Update data

response = app.update_data(
    schema="msmarco", data_id="1", fields={"title": "this is my updated title"}
)

assert response.json()["id"] == "id:msmarco:msmarco::1"

Delete data

response = app.delete_data(schema="msmarco", data_id="1")

assert response.json()["id"] == "id:msmarco:msmarco::1"