-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweave_query.py
137 lines (113 loc) · 2.98 KB
/
weave_query.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import weaviate
import config
import pprint
import sys
from lib.database import weaviate_query
from lib.ai import ai
client = weaviate.Client(
url=config.weaviate_url,
additional_headers={
"X-OpenAI-Api-Key": config.openai_token
}
)
query = input("enter query: ")
near_text_filter = {
"concepts": [query],
"moveTo": {
"concepts": [""],
"force": 0.5
}
}
additional_clause = {
"featureProjection": [
"vector"
]
}
additional_setting = {
"dimensions": 3
}
query_result = (
client.query
.get("Quantum", ["fragment", "gpt_fragment"])
.with_near_text(near_text_filter)
.with_additional(
(additional_clause, additional_setting)
)
.do()
)
datas = query_result.get('data').get('Get').get('Quantum')
content = ""
for i, data in enumerate(datas):
content = content + " " + data.get('gpt_fragment')
if i > 10:
document = {"plain": query, "content": content}
print(ai("quantum", document).get('answer', "None"))
break
print("ending interaction")
sys.exit()
xs = []
ys = []
texts = []
for data in datas:
print(data.get('sentence')[:100], data.get("_additional").get('featureProjection').get('vector'))
# xs.append(data.get("_additional").get('featureProjection').get('vector')[0])
# ys.append(data.get("_additional").get('featureProjection').get('vector')[1])
# texts.append(data.get('title')[:20])
sys.exit()
import plotly.express as px
fig = px.scatter(x=xs, y=ys, text=texts)
fig.show()
"""
all_objects = client.data_object.get(class_name="Support")
print(all_objects)
import sys
sys.exit()
schema = client.schema.get()
for classe in schema.get('classes'):
print(classe.get('class'))
"""
document = {"plain": query}
collection = "Docs"
fields = ["url", "title", "sentence"]
records = weaviate_query([query], collection, fields)
for i, record in enumerate(records):
if i > 10:
break
print(record)
"""
for doc in documents:
nearText = {
"concepts": [doc.get('plain')],
"distance": 0.7,
}
print("=========================================")
print("========", doc.get('plain'))
result = (
client.query
.get("Slothbot", ["table","plain","sql"])
.with_additional(["certainty", "distance"])
.with_near_text(nearText)
.do()
)
for record in result.get('data').get('Get').get('Slothbot'):
print(record.get('_additional').get('certainty'), "|", record.get('_additional').get('distance'), "|", record.get('table'), "|", record.get('sql'))
documents = [
{"plain": "select from planets"}
]
for doc in documents:
nearText = {
"concepts": [doc.get('plain')],
"distance": 0.2,
}
print("=========================================")
print("========", doc.get('plain'))
result = (
client.query
.get("Slothbot", ["plain"])
.with_additional(["certainty", "distance", "id"])
.with_near_text(nearText)
.do()
)
for record in result.get('data').get('Get').get('Slothbot'):
print(record.get('_additional').get('certainty'), "|", record.get('_additional').get('distance'), "|", record.get('table'), "|", record.get('sql'))
"""