Skip to content

Instantly share code, notes, and snippets.

@jobergum
Created January 31, 2020 18:46
Show Gist options
  • Save jobergum/d2e8b48bddf15f3210a075eafc6ee71b to your computer and use it in GitHub Desktop.
Save jobergum/d2e8b48bddf15f3210a075eafc6ee71b to your computer and use it in GitHub Desktop.
def get_features_from_vespa(row):
id = row['product_uid']
query = row['search_term']
query_tensor = row['query_embedding']
query_body = {
'hits': 1,
'ranking.profile': 'dump',
'rankfeatures': 'true',
'type': 'any',
'recall': '+id:%i' % id,
'ranking.features.query(tensor)': query_tensor.tolist(),
'query': query + " id:>0"
}
url = 'http://localhost:8080/search/'
r = requests.post(url, json=query_body, headers={'Content-Type':'application/json'})
json_response = r.json()
if json_response["root"]["fields"]["totalCount"] != 1:
return {}
hit = json_response["root"]["children"][0]
rankfeatures = hit['fields']['rankfeatures']
rankfeatures.update(hit['fields']['summaryfeatures'])
return rankfeatures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment