-
Notifications
You must be signed in to change notification settings - Fork 14
/
make-feed.py
35 lines (32 loc) · 986 Bytes
/
make-feed.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
import h5py
import sys
import concurrent.futures
import requests
file= sys.argv[1]
train = h5py.File(file, 'r')['train']
def feed_to_es_and_vespa(data):
docid,vector = data
vector = vector.tolist()
vespa_body = {
"fields": {
'vector': {
'values': vector
},
'id': docid
}
}
es_body={
'id': docid,
'vector': vector
}
response = requests.post('http://localhost:8080/document/v1/test/doc/docid/%i' % docid, json=vespa_body)
response.raise_for_status()
response = requests.post('http://localhost:9200/doc/_doc/%i' %docid, json=es_body)
response.raise_for_status()
response = requests.post('http://localhost:19200/doc/_doc/%i' %docid, json=es_body)
response.raise_for_status()
nthreads=18
with concurrent.futures.ThreadPoolExecutor(max_workers=nthreads) as executor:
futures = [executor.submit(feed_to_es_and_vespa,data) for data in enumerate(train)]
for result in concurrent.futures.as_completed(futures):
pass