-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmake-queries.py
60 lines (55 loc) · 1.49 KB
/
make-queries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import numpy as np
import json
import h5py
import sys
file= sys.argv[1]
test= h5py.File(file, 'r')['test']
oes_queries = open('data/opendistroforelasticsearch/queries.txt', 'w')
es_queries = open('data/elastic/queries.txt', 'w')
vespa_queries_ann = open('data/vespa/queries_ann.txt', 'w')
for v in test:
query_vector = v.tolist()
vespa_body_ann = {
'yql': 'select * from sources * where [{"targetNumHits":%i}]nearestNeighbor(vector,vector);' % 10,
'hits': 10,
'ranking.features.query(vector)': query_vector,
'ranking.profile': 'euclidean-rank',
'summary': 'id',
'timeout': '15s',
'ranking.softtimeout.enable': 'false'
}
vespa_queries_ann.write('/search/\n')
vespa_queries_ann.write(json.dumps(vespa_body_ann) + '\n')
es_script_query = {
'script_score': {
'query': {'match_all': {}},
'script': {
'source': '1/(1 + l2norm(params.query_vector, doc[\'vector\']))',
'params': {'query_vector': query_vector}
}
}
}
es_body={
'size': 10,
'timeout': '15s',
'query': es_script_query
}
es_queries.write('/doc/_search\n')
es_queries.write(json.dumps(es_body) + '\n')
oes_script_query = {
'knn': {
'vector': {
'vector': query_vector,
'k': '10'
}
}
}
oes_body={
'size': 10,
'timeout': '15s',
'stored_fields': '_none_',
'docvalue_fields': ['_id'],
'query': oes_script_query
}
oes_queries.write('/doc/_search\n')
oes_queries.write(json.dumps(oes_body) + '\n')