weaviate-ruby 0.5.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/Gemfile.lock +1 -1
- data/README.md +60 -21
- data/lib/weaviate/client.rb +6 -1
- 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/Gemfile.lock
CHANGED
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'
|
@@ -22,6 +30,7 @@ require 'weaviate'
|
|
22
30
|
client = Weaviate::Client.new(
|
23
31
|
scheme: 'https',
|
24
32
|
host: 'some-endpoint.weaviate.network', # Replace with your endpoint
|
33
|
+
api_key: '', # Weaviate API key
|
25
34
|
model_service: :openai, # Service that will be used to generate vectors. Possible values: :openai, :cohere, :huggingface
|
26
35
|
model_service_api_key: 'xxxxxxx' # Either OpenAI, Cohere or Hugging Face API key
|
27
36
|
)
|
@@ -39,7 +48,7 @@ client.schema.create(
|
|
39
48
|
"dataType": ["text"],
|
40
49
|
"description": "The question",
|
41
50
|
"name": "question"
|
42
|
-
}
|
51
|
+
}, {
|
43
52
|
"dataType": ["text"],
|
44
53
|
"description": "The answer",
|
45
54
|
"name": "answer"
|
@@ -56,15 +65,27 @@ client.schema.create(
|
|
56
65
|
# Get a single class from the schema
|
57
66
|
client.schema.get(class_name: 'Question')
|
58
67
|
|
59
|
-
#
|
60
|
-
|
61
|
-
response.data
|
68
|
+
# Get the schema
|
69
|
+
client.schema.list()
|
62
70
|
|
63
71
|
# Remove a class (and all data in the instances) from the schema.
|
64
72
|
client.schema.delete(class_name: 'Question')
|
65
73
|
|
66
74
|
# Update settings of an existing schema class.
|
67
|
-
|
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
|
+
)
|
68
89
|
|
69
90
|
# Inspect the shards of a class
|
70
91
|
client.schema.shards(class_name: 'Question')
|
@@ -83,31 +104,30 @@ client.objects.create(
|
|
83
104
|
)
|
84
105
|
|
85
106
|
# Lists all data objects in reverse order of creation.
|
86
|
-
|
87
|
-
response.data
|
107
|
+
client.objects.list()
|
88
108
|
|
89
109
|
# Get a single data object.
|
90
110
|
client.objects.get(
|
91
111
|
class_name: "Question",
|
92
|
-
id:
|
112
|
+
id: "uuid"
|
93
113
|
)
|
94
114
|
|
95
|
-
# Check if a data object exists
|
115
|
+
# Check if a data object exists.
|
96
116
|
client.objects.exists?(
|
97
117
|
class_name: "Question",
|
98
|
-
id:
|
118
|
+
id: "uuid"
|
99
119
|
)
|
100
120
|
|
101
|
-
# Delete
|
121
|
+
# Delete a single data object from Weaviate.
|
102
122
|
client.objects.delete(
|
103
123
|
class_name: "Question",
|
104
|
-
id: ""
|
124
|
+
id: "uuid"
|
105
125
|
)
|
106
126
|
|
107
|
-
# Update
|
127
|
+
# Update a single data object based on its uuid.
|
108
128
|
client.objects.update(
|
109
129
|
class_name: "Question",
|
110
|
-
id:
|
130
|
+
id: "uuid",
|
111
131
|
properties: {
|
112
132
|
question: "What does 6 times 7 equal to?",
|
113
133
|
category: "math",
|
@@ -116,7 +136,7 @@ client.objects.update(
|
|
116
136
|
)
|
117
137
|
|
118
138
|
# Batch create objects
|
119
|
-
|
139
|
+
client.objects.batch_create(objects: [
|
120
140
|
{
|
121
141
|
class: "Question",
|
122
142
|
properties: {
|
@@ -133,13 +153,12 @@ response = client.objects.batch_create(objects: [
|
|
133
153
|
}
|
134
154
|
}
|
135
155
|
])
|
136
|
-
response.data
|
137
156
|
|
138
157
|
# Batch delete objects
|
139
158
|
client.objects.batch_delete(
|
140
159
|
class_name: "Question",
|
141
160
|
where: {
|
142
|
-
valueString: "
|
161
|
+
valueString: "uuid",
|
143
162
|
operator: "Equal",
|
144
163
|
path: ["id"]
|
145
164
|
}
|
@@ -148,7 +167,7 @@ client.objects.batch_delete(
|
|
148
167
|
|
149
168
|
### Querying
|
150
169
|
|
151
|
-
#### Get
|
170
|
+
#### Get{}
|
152
171
|
```ruby
|
153
172
|
near_text = '{ concepts: ["biology"] }'
|
154
173
|
sort_obj = '{ path: ["category"], order: desc }'
|
@@ -186,19 +205,29 @@ client.query.get class_name: 'Question', fields: 'answer question category _addi
|
|
186
205
|
|
187
206
|
```
|
188
207
|
|
189
|
-
#### Aggs
|
208
|
+
#### Aggs{}
|
190
209
|
```ruby
|
191
210
|
client.query.aggs(
|
192
211
|
class_name: "Question",
|
193
|
-
fields: 'meta { count }'
|
212
|
+
fields: 'meta { count }',
|
194
213
|
group_by: ["category"],
|
195
214
|
object_limit: "10",
|
196
215
|
near_text: "{ concepts: [\"knowledge\"] }"
|
197
216
|
)
|
198
217
|
```
|
199
218
|
|
219
|
+
#### Explore{}
|
220
|
+
```ruby
|
221
|
+
client.query.explore(
|
222
|
+
fields: 'className',
|
223
|
+
near_text: "{ concepts: [\"science\"] }",
|
224
|
+
limit: "1"
|
225
|
+
)
|
226
|
+
```
|
227
|
+
|
200
228
|
### Classification
|
201
229
|
```ruby
|
230
|
+
# Start a classification
|
202
231
|
client.classifications.create(
|
203
232
|
type: "zeroshot",
|
204
233
|
class_name: "Posts",
|
@@ -206,6 +235,7 @@ client.classifications.create(
|
|
206
235
|
based_on_properties: ["text"]
|
207
236
|
)
|
208
237
|
|
238
|
+
# Get the status, results and metadata of a previously created classification
|
209
239
|
client.classifications.get(
|
210
240
|
id: ""
|
211
241
|
)
|
@@ -213,22 +243,26 @@ client.classifications.get(
|
|
213
243
|
|
214
244
|
### Backups
|
215
245
|
```ruby
|
246
|
+
# Create backup
|
216
247
|
client.backups.create(
|
217
248
|
backend: "filesystem",
|
218
249
|
id: "my-first-backup",
|
219
250
|
include: ["Question"]
|
220
251
|
)
|
221
252
|
|
253
|
+
# Get the backup
|
222
254
|
client.backups.get(
|
223
255
|
backend: "filesystem",
|
224
256
|
id: "my-first-backup"
|
225
257
|
)
|
226
258
|
|
259
|
+
# Restore backup
|
227
260
|
client.backups.restore(
|
228
261
|
backend: "filesystem",
|
229
262
|
id: "my-first-backup"
|
230
263
|
)
|
231
264
|
|
265
|
+
# Check the backup restore status
|
232
266
|
client.backups.restore_status(
|
233
267
|
backend: "filesystem",
|
234
268
|
id: "my-first-backup"
|
@@ -242,7 +276,12 @@ client.nodes
|
|
242
276
|
|
243
277
|
### Health
|
244
278
|
```ruby
|
279
|
+
# Live determines whether the application is alive. It can be used for Kubernetes liveness probe.
|
245
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.
|
246
285
|
client.ready?
|
247
286
|
```
|
248
287
|
|
data/lib/weaviate/client.rb
CHANGED
@@ -5,7 +5,7 @@ require "graphlient"
|
|
5
5
|
|
6
6
|
module Weaviate
|
7
7
|
class Client
|
8
|
-
attr_reader :scheme, :host, :model_service, :model_service_api_key, :adapter
|
8
|
+
attr_reader :scheme, :host, :api_key, :model_service, :model_service_api_key, :adapter
|
9
9
|
|
10
10
|
API_VERSION = "v1"
|
11
11
|
|
@@ -18,6 +18,7 @@ module Weaviate
|
|
18
18
|
def initialize(
|
19
19
|
scheme:,
|
20
20
|
host:,
|
21
|
+
api_key: nil,
|
21
22
|
model_service: nil,
|
22
23
|
model_service_api_key: nil,
|
23
24
|
adapter: Faraday.default_adapter
|
@@ -26,6 +27,7 @@ module Weaviate
|
|
26
27
|
|
27
28
|
@scheme = scheme
|
28
29
|
@host = host
|
30
|
+
@api_key = api_key
|
29
31
|
@model_service = model_service
|
30
32
|
@model_service_api_key = model_service_api_key
|
31
33
|
@adapter = adapter
|
@@ -93,6 +95,9 @@ module Weaviate
|
|
93
95
|
|
94
96
|
def connection
|
95
97
|
@connection ||= Faraday.new(url: "#{scheme}://#{host}/#{API_VERSION}/") do |faraday|
|
98
|
+
if api_key
|
99
|
+
faraday.request :authorization, :Bearer, api_key
|
100
|
+
end
|
96
101
|
faraday.request :json
|
97
102
|
faraday.response :json, content_type: /\bjson$/
|
98
103
|
faraday.adapter adapter
|
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
|