Queries
This guide goes through how to query a Vespa instance using the Query API and https://cord19.vespa.ai/ app as an example. You can run this tutorial in Google Colab:
Set the query endpoint:
[ ]:
from vespa.application import Vespa
app = Vespa(url="https://api.cord19.vespa.ai")
See the Vespa query language for the query parameters.
The userQuery() operator uses the query test from query
.
The query uses the weakAnd query operator and bm25 rank profile:
[ ]:
body = {
'yql': 'select cord_uid, title, abstract from sources * where userQuery()',
'hits': 5,
'query': 'Is remdesivir an effective treatment for COVID-19?',
'type': 'weakAnd',
'ranking': 'bm25'
}
results = app.query(body=body)
results.number_documents_retrieved
10977
The query specified 5 hits:
[ ]:
len(results.hits)
5
Iterate over results.hits
:
[ ]:
[hit["fields"]["cord_uid"] for hit in results.hits]
['ysml5abq', 'zpcuwvn4', '8art2tyj', 'xej338lo', 'npoje09j']
Get a specific hit:
[ ]:
results.hits[0]
{'id': 'index:content/1/848ca5db53648911e0a58c78',
'relevance': 30.531354743471304,
'source': 'content',
'fields': {'title': 'Cost utility analysis of <hi>Remdesivir</hi> and Dexamethasone <hi>treatment</hi> for hospitalised <hi>COVID</hi>-<hi>19</hi> patients - a hypothetical study',
'abstract': '<sep />: Sars-Cov-2 is a novel corona virus associated with significant morbidity and mortality. <hi>Remdesivir</hi> and Dexamethasone are two <hi>treatments</hi> that have shown to be <hi>effective</hi> against the Sars-Cov-2 associated disease. However, a cost-effectiveness analysis of the two <hi>treatments</hi> is still lacking. OBJECTIVE: The cost-utility of <hi>Remdesivir</hi>, Dexamethasone and a simultaneous use of the two drugs with respect to standard of care for <hi>treatment</hi> <hi>Covid</hi>-<hi>19</hi> hospitalized patients is evaluated, together with the effect<sep />',
'cord_uid': 'ysml5abq'}}
Access the full response in the default result format:
[ ]:
results.json
{'timing': {'querytime': 0.019,
'summaryfetchtime': 0.001,
'searchtime': 0.021},
'root': {'id': 'toplevel',
'relevance': 1.0,
'fields': {'totalCount': 10977},
'coverage': {'coverage': 100,
'documents': 976355,
'full': True,
'nodes': 2,
'results': 1,
'resultsFull': 1},
'children': [{'id': 'index:content/1/848ca5db53648911e0a58c78',
'relevance': 30.531354743471304,
'source': 'content',
'fields': {'title': 'Cost utility analysis of <hi>Remdesivir</hi> and Dexamethasone <hi>treatment</hi> for hospitalised <hi>COVID</hi>-<hi>19</hi> patients - a hypothetical study',
'abstract': '<sep />: Sars-Cov-2 is a novel corona virus associated with significant morbidity and mortality. <hi>Remdesivir</hi> and Dexamethasone are two <hi>treatments</hi> that have shown to be <hi>effective</hi> against the Sars-Cov-2 associated disease. However, a cost-effectiveness analysis of the two <hi>treatments</hi> is still lacking. OBJECTIVE: The cost-utility of <hi>Remdesivir</hi>, Dexamethasone and a simultaneous use of the two drugs with respect to standard of care for <hi>treatment</hi> <hi>Covid</hi>-<hi>19</hi> hospitalized patients is evaluated, together with the effect<sep />',
'cord_uid': 'ysml5abq'}},
{'id': 'index:content/1/afade29b15d5f83d8dd4d16a',
'relevance': 30.124913401931195,
'source': 'content',
'fields': {'title': '<hi>Remdesivir</hi> is <hi>effective</hi> for moderately severe patients: A re-analysis of the first double-blind, placebo-controlled, randomized trial on <hi>remdesivir</hi> for <hi>treatment</hi> of severe <hi>covid</hi>-<hi>19</hi> patients conducted in wuhan city',
'abstract': '<sep /> with baseline score, day of assessment, <hi>treatment</hi> group, baseline by <hi>treatment</hi> interaction, and day by <hi>treatment</hi> interaction as covariates. The binary endpoint was supported by the recent FDA<sep />oxygen (but not NIV/HFNC)) – the moderately severe category. The response rate was 85% for <hi>remdesivir</hi>-treated patients with baseline disease point=3 versus 70% response rate for likewise placebo-treated<sep />opinions. This result supports the preliminary findings of ACTT that <hi>remdesivir</hi> is <hi>effective</hi> for patients who were not critically severe. This result also suggests that<sep />',
'cord_uid': 'zpcuwvn4'}},
{'id': 'index:content/1/4678cba4fd31160fd163d063',
'relevance': 29.876569304341285,
'source': 'content',
'fields': {'title': 'A Review on <hi>Remdesivir</hi>: A Possible Promising Agent for the <hi>Treatment</hi> of <hi>COVID</hi>-<hi>19</hi>',
'abstract': '<sep />manufacturing of specific therapeutics and vaccines to treat <hi>COVID</hi>-<hi>19</hi> are time-consuming processes. At this time, using available conventional therapeutics along with other <hi>treatment</hi> options may be useful to fight <hi>COVID</hi>-<hi>19</hi>. In different clinical trials, efficacy of <hi>remdesivir</hi> (GS-5734) against Ebola virus has been demonstrated. Moreover, <hi>remdesivir</hi> may be an <hi>effective</hi> therapy in vitro and in animal models infected by SARS and MERS coronaviruses. Hence, the drug may be theoretically <hi>effective</hi> against SARS-CoV-2. <hi>Remdesivir</hi><sep />',
'cord_uid': '8art2tyj'}},
{'id': 'index:content/0/eec37c88ff9aa825c5c79d81',
'relevance': 29.874123437446798,
'source': 'content',
'fields': {'title': 'A Review on <hi>Remdesivir</hi>: A Possible Promising Agent for the <hi>Treatment</hi> of <hi>COVID</hi>-<hi>19</hi>',
'abstract': '<sep />manufacturing of specific therapeutics and vaccines to treat <hi>COVID</hi>-<hi>19</hi> are time-consuming processes. At this time, using available conventional therapeutics along with other <hi>treatment</hi> options may be useful to fight <hi>COVID</hi>-<hi>19</hi>. In different clinical trials, efficacy of <hi>remdesivir</hi> (GS-5734) against Ebola virus has been demonstrated. Moreover, <hi>remdesivir</hi> may be an <hi>effective</hi> therapy in vitro and in animal models infected by SARS and MERS coronaviruses. Hence, the drug may be theoretically <hi>effective</hi> against SARS-CoV-2. <hi>Remdesivir</hi><sep />',
'cord_uid': 'xej338lo'}},
{'id': 'index:content/0/a41b357fc6aa38c6b55a4685',
'relevance': 29.481438680496694,
'source': 'content',
'fields': {'title': '<hi>Remdesivir</hi> for the <hi>Treatment</hi> of <hi>COVID</hi>-<hi>19</hi>: A Systematic Review of the Literature',
'abstract': '<sep />CoV-2 a global pandemic. To date, coronavirus disease-2019 (<hi>COVID</hi>-<hi>19</hi>) has spread to over 200 countries, leading to over 1.6 million cases and over 99,000 deaths. Given that there is neither a vaccine nor proven <hi>treatment</hi> for <hi>COVID</hi>-<hi>19</hi>, there is currently an urgent need for <hi>effective</hi> pharmacotherapy. To address the need for an <hi>effective</hi> <hi>treatment</hi> of SARS-CoV-2 during the worldwide pandemic, this systematic review of intravenous (IV) <hi>remdesivir</hi> was performed. <hi>Remdesivir</hi>, an anti-viral prodrug originally developed to treat Ebola virus disease, has shown broad spectrum activity against the Coronavirus family. A recent case report reported improvement of clinical symptoms with <hi>remdesivir</hi> in a patient with <hi>COVID</hi>-<hi>19</hi>. After<sep />',
'cord_uid': 'npoje09j'}}]}}
Next steps
In the learntorank repository you will find the Query Model API. This is targeted for Data Science experiements.