-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_schema.py
executable file
·46 lines (40 loc) · 1.16 KB
/
create_schema.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
import weaviate
import os
import requests
import json
import os
import weaviate.classes as wvc
# Connect to a local Weaviate instance
client = weaviate.connect_to_custom(
http_host="192.168.10.165",
http_port=8080,
http_secure=False,
grpc_host="192.168.10.165",
grpc_port=50051,
grpc_secure=False,
auth_credentials=weaviate.auth.AuthApiKey(
os.getenv("WEAVIATE_KEY")
), # Set this environment variable
)
try:
# Wrap in try/finally to ensure client is closed gracefully
# ===== define collection =====
questions = client.collections.create(
name="JeopardyCategory",
)
client.collections.create(
name="JeopardyQuestion",
description="A Jeopardy! question",
properties=[
wvc.config.Property(name="question", data_type=wvc.config.DataType.TEXT),
wvc.config.Property(name="answer", data_type=wvc.config.DataType.TEXT),
],
references=[
wvc.config.ReferenceProperty(
name="hasCategory",
target_collection="JeopardyCategory"
)
]
)
finally:
client.close() # Close client gracefully