-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvectara_low_level_indexing_api.py
59 lines (48 loc) · 1.17 KB
/
vectara_low_level_indexing_api.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
import json
import requests
_CUSTOMER_ID=123456789
_CORPUS_ID=1
_API_KEY="zwt_..."
document = {}
document["document_id"] = "Book15.txt"
document["metadata_json"] = json.dumps(
{
"collection": "Mathematics",
"author": "Justin"
}
)
parts = []
part = {}
part["text"] = "This was possibly the best purchase I have ever made."
part["metadata_json"] = json.dumps(
{
"reviewer": "Mike",
"stars": 5
}
)
parts.append(part)
part = {}
part["text"] = "It is totally worth the wait!"
part["metadata_json"] = json.dumps(
{
"reviewer": "Susan",
"stars": 4
}
)
parts.append(part)
document["parts"] = parts
request = {}
request['customer_id'] = _CUSTOMER_ID
request['corpus_id'] = _CORPUS_ID
request['document'] = document
post_headers = {
"x-api-key": f"{_API_KEY}",
"customer-id": f"{_CUSTOMER_ID}"
}
response = requests.post(
"https://api.vectara.io/v1/core/index",
timeout=10,
data=json.dumps(request),
verify=True,
headers=post_headers)
print(f"Response code {response.status_code}, reason {response.reason} text {response.text}")