weaviate-ruby 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +59 -21
- data/lib/weaviate/objects.rb +92 -28
- data/lib/weaviate/query.rb +57 -2
- data/lib/weaviate/schema.rb +32 -12
- data/lib/weaviate/version.rb +1 -1
- data/lib/weaviate.rb +0 -7
- metadata +2 -6
- data/lib/weaviate/response/base.rb +0 -23
- data/lib/weaviate/response/class.rb +0 -8
- data/lib/weaviate/response/collection.rb +0 -22
- data/lib/weaviate/response/object.rb +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: eec9c4e909fa4b73ed59023c291cbc0171c72fcc2aeeef2773b6744b2de6144c
|
|
4
|
+
data.tar.gz: b66b81b77feb0b5777a15ef833eea0ebdd7f1660208c5f53893887c95aa56201
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b32d7546e9dc5484b63abe834667e03733e694b1fd6d7c10306cc09cb96ecbb8e63f84aaa682452ae881de79cf3f6f2c49dccf744761e6c95a7539e3feef068
|
|
7
|
+
data.tar.gz: 1a3774e88f29d0de254bd06b912bbcf4b4fa33cfa2b0ac87a60c38e340503c9119fdc6556bc5d7ff77c06097519e9f9122d2ef6cc8ca1541c245091c4bef0115
|
data/README.md
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
# Weaviate
|
|
2
2
|
|
|
3
|
+
<p>
|
|
4
|
+
<img alt='Weaviate logo' src='https://weaviate.io/img/site/weaviate-logo-light.png' height='50' />
|
|
5
|
+
+
|
|
6
|
+
<img alt='Weaviate logo' src='https://user-images.githubusercontent.com/541665/230231593-43861278-4550-421d-a543-fd3553aac4f6.png' height='40' />
|
|
7
|
+
</p>
|
|
8
|
+
|
|
3
9
|
Ruby wrapper for the Weaviate.io API
|
|
4
10
|
|
|
11
|
+

|
|
12
|
+
|
|
5
13
|
## Installation
|
|
6
14
|
|
|
7
15
|
Install the gem and add to the application's Gemfile by executing:
|
|
@@ -14,7 +22,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
|
14
22
|
|
|
15
23
|
## Usage
|
|
16
24
|
|
|
17
|
-
### Instantiating
|
|
25
|
+
### Instantiating API client
|
|
18
26
|
|
|
19
27
|
```ruby
|
|
20
28
|
require 'weaviate'
|
|
@@ -40,7 +48,7 @@ client.schema.create(
|
|
|
40
48
|
"dataType": ["text"],
|
|
41
49
|
"description": "The question",
|
|
42
50
|
"name": "question"
|
|
43
|
-
}
|
|
51
|
+
}, {
|
|
44
52
|
"dataType": ["text"],
|
|
45
53
|
"description": "The answer",
|
|
46
54
|
"name": "answer"
|
|
@@ -57,15 +65,27 @@ client.schema.create(
|
|
|
57
65
|
# Get a single class from the schema
|
|
58
66
|
client.schema.get(class_name: 'Question')
|
|
59
67
|
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
response.data
|
|
68
|
+
# Get the schema
|
|
69
|
+
client.schema.list()
|
|
63
70
|
|
|
64
71
|
# Remove a class (and all data in the instances) from the schema.
|
|
65
72
|
client.schema.delete(class_name: 'Question')
|
|
66
73
|
|
|
67
74
|
# Update settings of an existing schema class.
|
|
68
|
-
|
|
75
|
+
# Does not support modifying existing properties.
|
|
76
|
+
client.schema.update(
|
|
77
|
+
class_name: 'Question',
|
|
78
|
+
description: 'Information from a Wheel of Fortune question'
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# Adding a new property
|
|
82
|
+
client.schema.add_property(
|
|
83
|
+
class_name: 'Question',
|
|
84
|
+
property: {
|
|
85
|
+
"dataType": ["boolean"],
|
|
86
|
+
"name": "homepage"
|
|
87
|
+
}
|
|
88
|
+
)
|
|
69
89
|
|
|
70
90
|
# Inspect the shards of a class
|
|
71
91
|
client.schema.shards(class_name: 'Question')
|
|
@@ -84,31 +104,30 @@ client.objects.create(
|
|
|
84
104
|
)
|
|
85
105
|
|
|
86
106
|
# Lists all data objects in reverse order of creation.
|
|
87
|
-
|
|
88
|
-
response.data
|
|
107
|
+
client.objects.list()
|
|
89
108
|
|
|
90
109
|
# Get a single data object.
|
|
91
110
|
client.objects.get(
|
|
92
111
|
class_name: "Question",
|
|
93
|
-
id:
|
|
112
|
+
id: "uuid"
|
|
94
113
|
)
|
|
95
114
|
|
|
96
|
-
# Check if a data object exists
|
|
115
|
+
# Check if a data object exists.
|
|
97
116
|
client.objects.exists?(
|
|
98
117
|
class_name: "Question",
|
|
99
|
-
id:
|
|
118
|
+
id: "uuid"
|
|
100
119
|
)
|
|
101
120
|
|
|
102
|
-
# Delete
|
|
121
|
+
# Delete a single data object from Weaviate.
|
|
103
122
|
client.objects.delete(
|
|
104
123
|
class_name: "Question",
|
|
105
|
-
id: ""
|
|
124
|
+
id: "uuid"
|
|
106
125
|
)
|
|
107
126
|
|
|
108
|
-
# Update
|
|
127
|
+
# Update a single data object based on its uuid.
|
|
109
128
|
client.objects.update(
|
|
110
129
|
class_name: "Question",
|
|
111
|
-
id:
|
|
130
|
+
id: "uuid",
|
|
112
131
|
properties: {
|
|
113
132
|
question: "What does 6 times 7 equal to?",
|
|
114
133
|
category: "math",
|
|
@@ -117,7 +136,7 @@ client.objects.update(
|
|
|
117
136
|
)
|
|
118
137
|
|
|
119
138
|
# Batch create objects
|
|
120
|
-
|
|
139
|
+
client.objects.batch_create(objects: [
|
|
121
140
|
{
|
|
122
141
|
class: "Question",
|
|
123
142
|
properties: {
|
|
@@ -134,13 +153,12 @@ response = client.objects.batch_create(objects: [
|
|
|
134
153
|
}
|
|
135
154
|
}
|
|
136
155
|
])
|
|
137
|
-
response.data
|
|
138
156
|
|
|
139
157
|
# Batch delete objects
|
|
140
158
|
client.objects.batch_delete(
|
|
141
159
|
class_name: "Question",
|
|
142
160
|
where: {
|
|
143
|
-
valueString: "
|
|
161
|
+
valueString: "uuid",
|
|
144
162
|
operator: "Equal",
|
|
145
163
|
path: ["id"]
|
|
146
164
|
}
|
|
@@ -149,7 +167,7 @@ client.objects.batch_delete(
|
|
|
149
167
|
|
|
150
168
|
### Querying
|
|
151
169
|
|
|
152
|
-
#### Get
|
|
170
|
+
#### Get{}
|
|
153
171
|
```ruby
|
|
154
172
|
near_text = '{ concepts: ["biology"] }'
|
|
155
173
|
sort_obj = '{ path: ["category"], order: desc }'
|
|
@@ -187,19 +205,29 @@ client.query.get class_name: 'Question', fields: 'answer question category _addi
|
|
|
187
205
|
|
|
188
206
|
```
|
|
189
207
|
|
|
190
|
-
#### Aggs
|
|
208
|
+
#### Aggs{}
|
|
191
209
|
```ruby
|
|
192
210
|
client.query.aggs(
|
|
193
211
|
class_name: "Question",
|
|
194
|
-
fields: 'meta { count }'
|
|
212
|
+
fields: 'meta { count }',
|
|
195
213
|
group_by: ["category"],
|
|
196
214
|
object_limit: "10",
|
|
197
215
|
near_text: "{ concepts: [\"knowledge\"] }"
|
|
198
216
|
)
|
|
199
217
|
```
|
|
200
218
|
|
|
219
|
+
#### Explore{}
|
|
220
|
+
```ruby
|
|
221
|
+
client.query.explore(
|
|
222
|
+
fields: 'className',
|
|
223
|
+
near_text: "{ concepts: [\"science\"] }",
|
|
224
|
+
limit: "1"
|
|
225
|
+
)
|
|
226
|
+
```
|
|
227
|
+
|
|
201
228
|
### Classification
|
|
202
229
|
```ruby
|
|
230
|
+
# Start a classification
|
|
203
231
|
client.classifications.create(
|
|
204
232
|
type: "zeroshot",
|
|
205
233
|
class_name: "Posts",
|
|
@@ -207,6 +235,7 @@ client.classifications.create(
|
|
|
207
235
|
based_on_properties: ["text"]
|
|
208
236
|
)
|
|
209
237
|
|
|
238
|
+
# Get the status, results and metadata of a previously created classification
|
|
210
239
|
client.classifications.get(
|
|
211
240
|
id: ""
|
|
212
241
|
)
|
|
@@ -214,22 +243,26 @@ client.classifications.get(
|
|
|
214
243
|
|
|
215
244
|
### Backups
|
|
216
245
|
```ruby
|
|
246
|
+
# Create backup
|
|
217
247
|
client.backups.create(
|
|
218
248
|
backend: "filesystem",
|
|
219
249
|
id: "my-first-backup",
|
|
220
250
|
include: ["Question"]
|
|
221
251
|
)
|
|
222
252
|
|
|
253
|
+
# Get the backup
|
|
223
254
|
client.backups.get(
|
|
224
255
|
backend: "filesystem",
|
|
225
256
|
id: "my-first-backup"
|
|
226
257
|
)
|
|
227
258
|
|
|
259
|
+
# Restore backup
|
|
228
260
|
client.backups.restore(
|
|
229
261
|
backend: "filesystem",
|
|
230
262
|
id: "my-first-backup"
|
|
231
263
|
)
|
|
232
264
|
|
|
265
|
+
# Check the backup restore status
|
|
233
266
|
client.backups.restore_status(
|
|
234
267
|
backend: "filesystem",
|
|
235
268
|
id: "my-first-backup"
|
|
@@ -243,7 +276,12 @@ client.nodes
|
|
|
243
276
|
|
|
244
277
|
### Health
|
|
245
278
|
```ruby
|
|
279
|
+
# Live determines whether the application is alive. It can be used for Kubernetes liveness probe.
|
|
246
280
|
client.live?
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
```ruby
|
|
284
|
+
# Live determines whether the application is ready to receive traffic. It can be used for Kubernetes readiness probe.
|
|
247
285
|
client.ready?
|
|
248
286
|
```
|
|
249
287
|
|
data/lib/weaviate/objects.rb
CHANGED
|
@@ -23,17 +23,27 @@ module Weaviate
|
|
|
23
23
|
req.params["sort"] = sort unless sort.nil?
|
|
24
24
|
req.params["order"] = order unless order.nil?
|
|
25
25
|
end
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
response.body
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
# Create a new data object. The provided meta-data and schema values are validated.
|
|
30
31
|
def create(
|
|
31
32
|
class_name:,
|
|
32
33
|
properties:,
|
|
34
|
+
consistency_level: nil,
|
|
33
35
|
id: nil,
|
|
34
36
|
vector: nil
|
|
35
37
|
)
|
|
38
|
+
validate_consistency_level!(consistency_level) unless consistency_level.nil?
|
|
39
|
+
|
|
36
40
|
response = client.connection.post(PATH) do |req|
|
|
41
|
+
unless consistency_level.nil?
|
|
42
|
+
req.params = {
|
|
43
|
+
consistency_level: consistency_level.to_s.upcase
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
|
|
37
47
|
req.body = {}
|
|
38
48
|
req.body["class"] = class_name
|
|
39
49
|
req.body["properties"] = properties
|
|
@@ -41,45 +51,53 @@ module Weaviate
|
|
|
41
51
|
req.body["vector"] = vector unless vector.nil?
|
|
42
52
|
end
|
|
43
53
|
|
|
44
|
-
|
|
45
|
-
Weaviate::Response::Object.new(response.body)
|
|
46
|
-
else
|
|
47
|
-
response.body
|
|
48
|
-
end
|
|
54
|
+
response.body
|
|
49
55
|
end
|
|
50
56
|
|
|
51
57
|
# Batch create objects
|
|
52
|
-
def batch_create(
|
|
58
|
+
def batch_create(
|
|
59
|
+
objects:,
|
|
60
|
+
consistency_level: nil
|
|
61
|
+
)
|
|
62
|
+
validate_consistency_level!(consistency_level) unless consistency_level.nil?
|
|
63
|
+
|
|
53
64
|
response = client.connection.post("batch/#{PATH}") do |req|
|
|
65
|
+
req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
|
|
54
66
|
req.body = {objects: objects}
|
|
55
67
|
end
|
|
56
68
|
|
|
57
|
-
|
|
58
|
-
Response::Collection.from_response(response.body, type: Response::Object)
|
|
59
|
-
end
|
|
69
|
+
response.body
|
|
60
70
|
end
|
|
61
71
|
|
|
62
72
|
# Get a single data object.
|
|
63
73
|
def get(
|
|
64
74
|
class_name:,
|
|
65
75
|
id:,
|
|
66
|
-
include: nil
|
|
76
|
+
include: nil,
|
|
77
|
+
consistency_level: nil
|
|
67
78
|
)
|
|
68
|
-
|
|
69
|
-
# include | query | param | string | Include additional information, such as classification info. Allowed values include: classification, vector.
|
|
79
|
+
validate_consistency_level!(consistency_level) unless consistency_level.nil?
|
|
70
80
|
|
|
71
81
|
response = client.connection.get("#{PATH}/#{class_name}/#{id}") do |req|
|
|
82
|
+
req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
|
|
72
83
|
req.params["include"] = include unless include.nil?
|
|
73
84
|
end
|
|
74
85
|
|
|
75
|
-
|
|
76
|
-
Weaviate::Response::Object.new(response.body)
|
|
77
|
-
end
|
|
86
|
+
response.body
|
|
78
87
|
end
|
|
79
88
|
|
|
80
89
|
# Check if a data object exists
|
|
81
|
-
def exists?(
|
|
82
|
-
|
|
90
|
+
def exists?(
|
|
91
|
+
class_name:,
|
|
92
|
+
id:,
|
|
93
|
+
consistency_level: nil
|
|
94
|
+
)
|
|
95
|
+
validate_consistency_level!(consistency_level) unless consistency_level.nil?
|
|
96
|
+
|
|
97
|
+
response = client.connection.head("#{PATH}/#{class_name}/#{id}") do |req|
|
|
98
|
+
req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
|
|
99
|
+
end
|
|
100
|
+
|
|
83
101
|
response.status == 204
|
|
84
102
|
end
|
|
85
103
|
|
|
@@ -88,24 +106,41 @@ module Weaviate
|
|
|
88
106
|
class_name:,
|
|
89
107
|
id:,
|
|
90
108
|
properties:,
|
|
91
|
-
vector: nil
|
|
109
|
+
vector: nil,
|
|
110
|
+
consistency_level: nil
|
|
92
111
|
)
|
|
112
|
+
validate_consistency_level!(consistency_level) unless consistency_level.nil?
|
|
113
|
+
|
|
93
114
|
response = client.connection.put("#{PATH}/#{class_name}/#{id}") do |req|
|
|
115
|
+
req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
|
|
116
|
+
|
|
94
117
|
req.body = {}
|
|
95
118
|
req.body["id"] = id
|
|
96
119
|
req.body["class"] = class_name
|
|
97
120
|
req.body["properties"] = properties
|
|
98
121
|
req.body["vector"] = vector unless vector.nil?
|
|
99
122
|
end
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
end
|
|
123
|
+
|
|
124
|
+
response.body
|
|
103
125
|
end
|
|
104
126
|
|
|
105
127
|
# Delete an individual data object from Weaviate.
|
|
106
|
-
def delete(
|
|
107
|
-
|
|
108
|
-
|
|
128
|
+
def delete(
|
|
129
|
+
class_name:,
|
|
130
|
+
id:,
|
|
131
|
+
consistency_level: nil
|
|
132
|
+
)
|
|
133
|
+
validate_consistency_level!(consistency_level) unless consistency_level.nil?
|
|
134
|
+
|
|
135
|
+
response = client.connection.delete("#{PATH}/#{class_name}/#{id}") do |req|
|
|
136
|
+
req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
if response.success?
|
|
140
|
+
response.body.empty?
|
|
141
|
+
else
|
|
142
|
+
response.body
|
|
143
|
+
end
|
|
109
144
|
end
|
|
110
145
|
|
|
111
146
|
def batch_delete(
|
|
@@ -116,7 +151,12 @@ module Weaviate
|
|
|
116
151
|
dry_run: nil
|
|
117
152
|
)
|
|
118
153
|
path = "batch/#{PATH}"
|
|
119
|
-
|
|
154
|
+
|
|
155
|
+
unless consistency_level.nil?
|
|
156
|
+
validate_consistency_level!(consistency_level)
|
|
157
|
+
|
|
158
|
+
path << "?consistency_level=#{consistency_level.to_s.upcase}"
|
|
159
|
+
end
|
|
120
160
|
|
|
121
161
|
response = client.connection.delete(path) do |req|
|
|
122
162
|
req.body = {
|
|
@@ -133,7 +173,31 @@ module Weaviate
|
|
|
133
173
|
end
|
|
134
174
|
|
|
135
175
|
# Validate a data object
|
|
136
|
-
|
|
137
|
-
|
|
176
|
+
def validate(
|
|
177
|
+
class_name:,
|
|
178
|
+
properties:,
|
|
179
|
+
id: nil
|
|
180
|
+
)
|
|
181
|
+
response = client.connection.post("#{PATH}/validate") do |req|
|
|
182
|
+
req.body = {}
|
|
183
|
+
req.body["class"] = class_name
|
|
184
|
+
req.body["properties"] = properties
|
|
185
|
+
req.body["id"] = id unless id.nil?
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
if response.success?
|
|
189
|
+
response.body.empty?
|
|
190
|
+
else
|
|
191
|
+
response.body
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
private
|
|
196
|
+
|
|
197
|
+
def validate_consistency_level!(consistency_level)
|
|
198
|
+
unless %w[ONE QUORUM ALL].include?(consistency_level.to_s.upcase)
|
|
199
|
+
raise ArgumentError, 'consistency_level must be either "ONE" or "QUORUM" OR "ALL"'
|
|
200
|
+
end
|
|
201
|
+
end
|
|
138
202
|
end
|
|
139
203
|
end
|
data/lib/weaviate/query.rb
CHANGED
|
@@ -28,7 +28,7 @@ module Weaviate
|
|
|
28
28
|
limit: limit,
|
|
29
29
|
offset: offset
|
|
30
30
|
)
|
|
31
|
-
response.
|
|
31
|
+
response.original_hash.dig("data", "Get", class_name)
|
|
32
32
|
rescue Graphlient::Errors::ExecutionError => error
|
|
33
33
|
raise Weaviate::Error.new(error.response.data.get.errors.messages.to_h)
|
|
34
34
|
end
|
|
@@ -53,13 +53,68 @@ module Weaviate
|
|
|
53
53
|
group_by: group_by,
|
|
54
54
|
object_limit: object_limit
|
|
55
55
|
)
|
|
56
|
-
response.
|
|
56
|
+
response.original_hash.dig("data", "Aggregate", class_name)
|
|
57
57
|
rescue Graphlient::Errors::ExecutionError => error
|
|
58
58
|
raise Weaviate::Error.new(error.response.data.aggregate.errors.messages.to_h)
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
+
def explore(
|
|
62
|
+
fields:,
|
|
63
|
+
after: nil,
|
|
64
|
+
limit: nil,
|
|
65
|
+
offset: nil,
|
|
66
|
+
sort: nil,
|
|
67
|
+
where: nil,
|
|
68
|
+
near_text: nil,
|
|
69
|
+
near_vector: nil,
|
|
70
|
+
near_object: nil
|
|
71
|
+
)
|
|
72
|
+
response = client.graphql.execute(
|
|
73
|
+
explore_query(
|
|
74
|
+
fields: fields,
|
|
75
|
+
near_text: near_text,
|
|
76
|
+
near_vector: near_vector,
|
|
77
|
+
near_object: near_object
|
|
78
|
+
),
|
|
79
|
+
after: after,
|
|
80
|
+
limit: limit,
|
|
81
|
+
offset: offset
|
|
82
|
+
)
|
|
83
|
+
response.original_hash.dig("data", "Explore")
|
|
84
|
+
rescue Graphlient::Errors::ExecutionError => error
|
|
85
|
+
raise Weaviate::Error.new(error.to_s)
|
|
86
|
+
end
|
|
87
|
+
|
|
61
88
|
private
|
|
62
89
|
|
|
90
|
+
def explore_query(
|
|
91
|
+
fields:,
|
|
92
|
+
where: nil,
|
|
93
|
+
near_text: nil,
|
|
94
|
+
near_vector: nil,
|
|
95
|
+
near_object: nil,
|
|
96
|
+
sort: nil
|
|
97
|
+
)
|
|
98
|
+
client.graphql.parse <<~GRAPHQL
|
|
99
|
+
query(
|
|
100
|
+
$limit: Int,
|
|
101
|
+
$offset: Int
|
|
102
|
+
) {
|
|
103
|
+
Explore (
|
|
104
|
+
limit: $limit,
|
|
105
|
+
offset: $offset,
|
|
106
|
+
#{near_text.present? ? "nearText: #{near_text}" : ""},
|
|
107
|
+
#{near_vector.present? ? "nearVector: #{near_vector}" : ""},
|
|
108
|
+
#{near_object.present? ? "nearObject: #{near_object}" : ""}
|
|
109
|
+
#{where.present? ? "where: #{where}" : ""},
|
|
110
|
+
#{sort.present? ? "sort: #{sort}" : ""}
|
|
111
|
+
) {
|
|
112
|
+
#{fields}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
GRAPHQL
|
|
116
|
+
end
|
|
117
|
+
|
|
63
118
|
def get_query(
|
|
64
119
|
class_name:,
|
|
65
120
|
fields:,
|
data/lib/weaviate/schema.rb
CHANGED
|
@@ -7,7 +7,7 @@ module Weaviate
|
|
|
7
7
|
# Dumps the current Weaviate schema. The result contains an array of objects.
|
|
8
8
|
def list
|
|
9
9
|
response = client.connection.get(PATH)
|
|
10
|
-
|
|
10
|
+
response.body
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
# Get a single class from the schema
|
|
@@ -15,15 +15,17 @@ module Weaviate
|
|
|
15
15
|
response = client.connection.get("#{PATH}/#{class_name}")
|
|
16
16
|
|
|
17
17
|
if response.success?
|
|
18
|
-
|
|
18
|
+
response.body
|
|
19
|
+
elsif response.status == 404
|
|
20
|
+
response.reason_phrase
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
# Create a new data object class in the schema.
|
|
23
25
|
def create(
|
|
24
26
|
class_name:,
|
|
25
|
-
description
|
|
26
|
-
properties
|
|
27
|
+
description: nil,
|
|
28
|
+
properties: nil,
|
|
27
29
|
vector_index_type: nil,
|
|
28
30
|
vector_index_config: nil,
|
|
29
31
|
vectorizer: nil,
|
|
@@ -33,7 +35,7 @@ module Weaviate
|
|
|
33
35
|
)
|
|
34
36
|
response = client.connection.post(PATH) do |req|
|
|
35
37
|
req.body = {}
|
|
36
|
-
req.body["class"] = class_name
|
|
38
|
+
req.body["class"] = class_name
|
|
37
39
|
req.body["description"] = description unless description.nil?
|
|
38
40
|
req.body["vectorIndexType"] = vector_index_type unless vector_index_type.nil?
|
|
39
41
|
req.body["vectorIndexConfig"] = vector_index_config unless vector_index_config.nil?
|
|
@@ -45,19 +47,25 @@ module Weaviate
|
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
if response.success?
|
|
48
|
-
Response::Class.new(response.body)
|
|
49
|
-
else
|
|
50
|
-
response.body
|
|
51
50
|
end
|
|
51
|
+
response.body
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# Remove a class (and all data in the instances) from the schema.
|
|
55
55
|
def delete(class_name:)
|
|
56
56
|
response = client.connection.delete("#{PATH}/#{class_name}")
|
|
57
|
-
|
|
57
|
+
|
|
58
|
+
if response.success?
|
|
59
|
+
response.body.empty?
|
|
60
|
+
else
|
|
61
|
+
response.body
|
|
62
|
+
end
|
|
58
63
|
end
|
|
59
64
|
|
|
60
65
|
# Update settings of an existing schema class.
|
|
66
|
+
# TODO: Fix it.
|
|
67
|
+
# This endpoint keeps returning the following error:
|
|
68
|
+
# => {"error"=>[{"message"=>"properties cannot be updated through updating the class. Use the add property feature (e.g. \"POST /v1/schema/{className}/properties\") to add additional properties"}]}
|
|
61
69
|
def update(
|
|
62
70
|
class_name:,
|
|
63
71
|
description: nil,
|
|
@@ -83,10 +91,22 @@ module Weaviate
|
|
|
83
91
|
end
|
|
84
92
|
|
|
85
93
|
if response.success?
|
|
86
|
-
Response::Class.new(response.body)
|
|
87
|
-
else
|
|
88
|
-
response.body
|
|
89
94
|
end
|
|
95
|
+
response.body
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Add a property to an existing schema class.
|
|
99
|
+
def add_property(
|
|
100
|
+
class_name:,
|
|
101
|
+
property:
|
|
102
|
+
)
|
|
103
|
+
response = client.connection.post("#{PATH}/#{class_name}/properties") do |req|
|
|
104
|
+
req.body = property
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
if response.success?
|
|
108
|
+
end
|
|
109
|
+
response.body
|
|
90
110
|
end
|
|
91
111
|
|
|
92
112
|
# Inspect the shards of a class
|
data/lib/weaviate/version.rb
CHANGED
data/lib/weaviate.rb
CHANGED
|
@@ -15,11 +15,4 @@ module Weaviate
|
|
|
15
15
|
autoload :Health, "weaviate/health"
|
|
16
16
|
autoload :Classifications, "weaviate/classifications"
|
|
17
17
|
autoload :Backups, "weaviate/backups"
|
|
18
|
-
|
|
19
|
-
module Response
|
|
20
|
-
autoload :Base, "weaviate/response/base"
|
|
21
|
-
autoload :Object, "weaviate/response/object"
|
|
22
|
-
autoload :Class, "weaviate/response/class"
|
|
23
|
-
autoload :Collection, "weaviate/response/collection"
|
|
24
|
-
end
|
|
25
18
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: weaviate-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Bondarev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-04-
|
|
11
|
+
date: 2023-04-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
@@ -79,10 +79,6 @@ files:
|
|
|
79
79
|
- lib/weaviate/objects.rb
|
|
80
80
|
- lib/weaviate/oidc.rb
|
|
81
81
|
- lib/weaviate/query.rb
|
|
82
|
-
- lib/weaviate/response/base.rb
|
|
83
|
-
- lib/weaviate/response/class.rb
|
|
84
|
-
- lib/weaviate/response/collection.rb
|
|
85
|
-
- lib/weaviate/response/object.rb
|
|
86
82
|
- lib/weaviate/schema.rb
|
|
87
83
|
- lib/weaviate/version.rb
|
|
88
84
|
- sig/weaviate.rbs
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "ostruct"
|
|
4
|
-
|
|
5
|
-
module Weaviate
|
|
6
|
-
module Response
|
|
7
|
-
class Base < OpenStruct
|
|
8
|
-
def initialize(attributes)
|
|
9
|
-
super to_ostruct(attributes)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def to_ostruct(obj)
|
|
13
|
-
if obj.is_a?(Hash)
|
|
14
|
-
OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
|
|
15
|
-
elsif obj.is_a?(Array)
|
|
16
|
-
obj.map { |o| to_ostruct(o) }
|
|
17
|
-
else # Assumed to be a primitive value
|
|
18
|
-
obj
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Weaviate
|
|
4
|
-
module Response
|
|
5
|
-
class Collection
|
|
6
|
-
attr_reader :data, :total_results
|
|
7
|
-
|
|
8
|
-
def self.from_response(body, type:, key: nil)
|
|
9
|
-
new(
|
|
10
|
-
data: (key.nil? ? body : body[key]).map { |attrs| type.new(attrs) }
|
|
11
|
-
# TODO: Integrate and use the totalResults from the response.
|
|
12
|
-
# total_results: body["totalResults"]
|
|
13
|
-
)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def initialize(data:, total_results: nil)
|
|
17
|
-
@data = data
|
|
18
|
-
@total_results = total_results
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|