weaviate-ruby 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad58e91ebbe32128a41045dd5f04b82dcf7b97030af3609d21b8384fdd755cd9
4
- data.tar.gz: e4da33cbb7a6a09b06ff65b19ee3addf83f7b4d2fe98311158586d1bd3147983
3
+ metadata.gz: fb982e0efa4f7af24b5e5ddc344da70ada13abaf498c2b2cc23eabb0659a78f6
4
+ data.tar.gz: cb1caf49e8e3585f95f7a43d5b6c02acbfe52c4095c3594bd98ba3becc489c09
5
5
  SHA512:
6
- metadata.gz: 5d860ad3d6f33ab341181c6807d7c99b33bed83740ddeca9f297d856791498cfb6028f4bec710667d3d4d80a3d630ec0b95f90018ce23c9d530bd7bafb817d47
7
- data.tar.gz: f54b9d91b2ecb8fdfc8db95d4c654d43fdd5ae28f3561545e19dc39e652bb9dbd838fe77479c909445eb40a905c747924aca715a9e45cef03467e7c358b60a53
6
+ metadata.gz: 9ee15a3b1c4b1a8df15e836e82073310911f7ccb298c49f44cc290533ce407ae5e7410b50424455ac228348ccd2c36b7adc693ffac668876e2af6306b6d7d28e
7
+ data.tar.gz: f9cae1a701db54b908409f1e631d7d1103e6ebef16949d273e565f994bb7eb5cae863372b1141a9646d2509c7b5570a88031855bfa8c4f88a39e71c8c0f70610
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weaviate-ruby (0.6.0)
4
+ weaviate-ruby (0.7.1)
5
5
  faraday (~> 2.7)
6
6
  graphlient (~> 0.7.0)
7
7
 
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
+ +&nbsp;&nbsp;
6
+ <img alt='Ruby 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
+ ![Tests status](https://github.com/andreibondarev/weaviate-ruby/actions/workflows/ci.yml/badge.svg)
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 the API client
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
- # Dumps the current Weaviate schema.
61
- response = client.schema.list()
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
- client.schema.update(class_name: 'Question')
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
- response = client.objects.list()
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 an individual data object from Weaviate.
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 an individual data object based on its uuid.
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
- response = client.objects.batch_create(objects: [
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: "1",
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 }'
@@ -157,7 +175,7 @@ where_obj = '{ path: ["id"], operator: Equal, valueString: "..." }'
157
175
 
158
176
  client.query.get(
159
177
  class_name: 'Question',
160
- fields: 'question answer category',
178
+ fields: "question answer category _additional { answer { result hasAnswer property startPosition endPosition } }",
161
179
  limit: "1",
162
180
  offset: "1",
163
181
  after: "id",
@@ -176,6 +194,8 @@ client.query.get(
176
194
  # bm25: ...,
177
195
 
178
196
  # near_object: ...,
197
+
198
+ ask: '{ question: "your-question?" }'
179
199
  )
180
200
 
181
201
  # Example queries:
@@ -187,19 +207,29 @@ client.query.get class_name: 'Question', fields: 'answer question category _addi
187
207
 
188
208
  ```
189
209
 
190
- #### Aggs
210
+ #### Aggs{}
191
211
  ```ruby
192
212
  client.query.aggs(
193
213
  class_name: "Question",
194
- fields: 'meta { count }'
214
+ fields: 'meta { count }',
195
215
  group_by: ["category"],
196
216
  object_limit: "10",
197
217
  near_text: "{ concepts: [\"knowledge\"] }"
198
218
  )
199
219
  ```
200
220
 
221
+ #### Explore{}
222
+ ```ruby
223
+ client.query.explore(
224
+ fields: 'className',
225
+ near_text: "{ concepts: [\"science\"] }",
226
+ limit: "1"
227
+ )
228
+ ```
229
+
201
230
  ### Classification
202
231
  ```ruby
232
+ # Start a classification
203
233
  client.classifications.create(
204
234
  type: "zeroshot",
205
235
  class_name: "Posts",
@@ -207,6 +237,7 @@ client.classifications.create(
207
237
  based_on_properties: ["text"]
208
238
  )
209
239
 
240
+ # Get the status, results and metadata of a previously created classification
210
241
  client.classifications.get(
211
242
  id: ""
212
243
  )
@@ -214,22 +245,26 @@ client.classifications.get(
214
245
 
215
246
  ### Backups
216
247
  ```ruby
248
+ # Create backup
217
249
  client.backups.create(
218
250
  backend: "filesystem",
219
251
  id: "my-first-backup",
220
252
  include: ["Question"]
221
253
  )
222
254
 
255
+ # Get the backup
223
256
  client.backups.get(
224
257
  backend: "filesystem",
225
258
  id: "my-first-backup"
226
259
  )
227
260
 
261
+ # Restore backup
228
262
  client.backups.restore(
229
263
  backend: "filesystem",
230
264
  id: "my-first-backup"
231
265
  )
232
266
 
267
+ # Check the backup restore status
233
268
  client.backups.restore_status(
234
269
  backend: "filesystem",
235
270
  id: "my-first-backup"
@@ -243,7 +278,12 @@ client.nodes
243
278
 
244
279
  ### Health
245
280
  ```ruby
281
+ # Live determines whether the application is alive. It can be used for Kubernetes liveness probe.
246
282
  client.live?
283
+ ```
284
+
285
+ ```ruby
286
+ # Live determines whether the application is ready to receive traffic. It can be used for Kubernetes readiness probe.
247
287
  client.ready?
248
288
  ```
249
289
 
@@ -79,10 +79,15 @@ module Weaviate
79
79
 
80
80
  def graphql
81
81
  headers = {}
82
+
82
83
  if model_service && model_service_api_key
83
84
  headers[API_KEY_HEADERS[model_service]] = model_service_api_key
84
85
  end
85
86
 
87
+ if api_key
88
+ headers["Authorization"] = "Bearer #{api_key}"
89
+ end
90
+
86
91
  @graphql ||= Graphlient::Client.new(
87
92
  "#{scheme}://#{host}/#{API_VERSION}/graphql",
88
93
  headers: headers,
@@ -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
- Response::Collection.from_response(response.body, key: "objects", type: Response::Object)
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
- if response.success?
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(objects:)
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
- if response.success?
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
- # TODO: validate `include` param values
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
- if response.success?
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?(class_name:, id:)
82
- response = client.connection.head("#{PATH}/#{class_name}/#{id}")
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
- if response.success?
101
- Weaviate::Response::Object.new(response.body)
102
- end
123
+
124
+ response.body
103
125
  end
104
126
 
105
127
  # Delete an individual data object from Weaviate.
106
- def delete(class_name:, id:)
107
- response = client.connection.delete("#{PATH}/#{class_name}/#{id}")
108
- response.success? && response.body.empty?
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
- path << "?consistency_level=#{consistency_level}" unless consistency_level.nil?
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
- # def validate
137
- # end
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
@@ -12,7 +12,8 @@ module Weaviate
12
12
  where: nil,
13
13
  near_text: nil,
14
14
  near_vector: nil,
15
- near_object: nil
15
+ near_object: nil,
16
+ ask: nil
16
17
  )
17
18
  response = client.graphql.execute(
18
19
  get_query(
@@ -22,13 +23,14 @@ module Weaviate
22
23
  where: where,
23
24
  near_text: near_text,
24
25
  near_vector: near_vector,
25
- near_object: near_object
26
+ near_object: near_object,
27
+ ask: ask
26
28
  ),
27
29
  after: after,
28
30
  limit: limit,
29
31
  offset: offset
30
32
  )
31
- response.data.get.send(class_name.downcase)
33
+ response.original_hash.dig("data", "Get", class_name)
32
34
  rescue Graphlient::Errors::ExecutionError => error
33
35
  raise Weaviate::Error.new(error.response.data.get.errors.messages.to_h)
34
36
  end
@@ -53,13 +55,68 @@ module Weaviate
53
55
  group_by: group_by,
54
56
  object_limit: object_limit
55
57
  )
56
- response.data.aggregate.send(class_name.downcase)
58
+ response.original_hash.dig("data", "Aggregate", class_name)
57
59
  rescue Graphlient::Errors::ExecutionError => error
58
60
  raise Weaviate::Error.new(error.response.data.aggregate.errors.messages.to_h)
59
61
  end
60
62
 
63
+ def explore(
64
+ fields:,
65
+ after: nil,
66
+ limit: nil,
67
+ offset: nil,
68
+ sort: nil,
69
+ where: nil,
70
+ near_text: nil,
71
+ near_vector: nil,
72
+ near_object: nil
73
+ )
74
+ response = client.graphql.execute(
75
+ explore_query(
76
+ fields: fields,
77
+ near_text: near_text,
78
+ near_vector: near_vector,
79
+ near_object: near_object
80
+ ),
81
+ after: after,
82
+ limit: limit,
83
+ offset: offset
84
+ )
85
+ response.original_hash.dig("data", "Explore")
86
+ rescue Graphlient::Errors::ExecutionError => error
87
+ raise Weaviate::Error.new(error.to_s)
88
+ end
89
+
61
90
  private
62
91
 
92
+ def explore_query(
93
+ fields:,
94
+ where: nil,
95
+ near_text: nil,
96
+ near_vector: nil,
97
+ near_object: nil,
98
+ sort: nil
99
+ )
100
+ client.graphql.parse <<~GRAPHQL
101
+ query(
102
+ $limit: Int,
103
+ $offset: Int
104
+ ) {
105
+ Explore (
106
+ limit: $limit,
107
+ offset: $offset,
108
+ #{near_text.present? ? "nearText: #{near_text}" : ""},
109
+ #{near_vector.present? ? "nearVector: #{near_vector}" : ""},
110
+ #{near_object.present? ? "nearObject: #{near_object}" : ""}
111
+ #{where.present? ? "where: #{where}" : ""},
112
+ #{sort.present? ? "sort: #{sort}" : ""}
113
+ ) {
114
+ #{fields}
115
+ }
116
+ }
117
+ GRAPHQL
118
+ end
119
+
63
120
  def get_query(
64
121
  class_name:,
65
122
  fields:,
@@ -67,6 +124,7 @@ module Weaviate
67
124
  near_text: nil,
68
125
  near_vector: nil,
69
126
  near_object: nil,
127
+ ask: nil,
70
128
  sort: nil
71
129
  )
72
130
  client.graphql.parse <<~GRAPHQL
@@ -83,6 +141,7 @@ module Weaviate
83
141
  #{near_text.present? ? "nearText: #{near_text}" : ""},
84
142
  #{near_vector.present? ? "nearVector: #{near_vector}" : ""},
85
143
  #{near_object.present? ? "nearObject: #{near_object}" : ""},
144
+ #{ask.present? ? "ask: #{ask}" : ""},
86
145
  #{where.present? ? "where: #{where}" : ""},
87
146
  #{sort.present? ? "sort: #{sort}" : ""}
88
147
  ) {
@@ -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
- Response::Collection.from_response(response.body, key: "classes", type: Response::Class)
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
- Response::Class.new(response.body)
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 unless class_name.nil?
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?
@@ -44,20 +46,24 @@ module Weaviate
44
46
  req.body["replicationConfig"] = replication_config unless replication_config.nil?
45
47
  end
46
48
 
47
- if response.success?
48
- Response::Class.new(response.body)
49
- else
50
- response.body
51
- end
49
+ response.body
52
50
  end
53
51
 
54
52
  # Remove a class (and all data in the instances) from the schema.
55
53
  def delete(class_name:)
56
54
  response = client.connection.delete("#{PATH}/#{class_name}")
57
- response.success? && response.body.empty?
55
+
56
+ if response.success?
57
+ response.body.empty?
58
+ else
59
+ response.body
60
+ end
58
61
  end
59
62
 
60
63
  # Update settings of an existing schema class.
64
+ # TODO: Fix it.
65
+ # This endpoint keeps returning the following error:
66
+ # => {"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
67
  def update(
62
68
  class_name:,
63
69
  description: nil,
@@ -83,10 +89,22 @@ module Weaviate
83
89
  end
84
90
 
85
91
  if response.success?
86
- Response::Class.new(response.body)
87
- else
88
- response.body
89
92
  end
93
+ response.body
94
+ end
95
+
96
+ # Add a property to an existing schema class.
97
+ def add_property(
98
+ class_name:,
99
+ property:
100
+ )
101
+ response = client.connection.post("#{PATH}/#{class_name}/properties") do |req|
102
+ req.body = property
103
+ end
104
+
105
+ if response.success?
106
+ end
107
+ response.body
90
108
  end
91
109
 
92
110
  # Inspect the shards of a class
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weaviate
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.1"
5
5
  end
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.6.0
4
+ version: 0.7.1
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-04 00:00:00.000000000 Z
11
+ date: 2023-04-09 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,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Weaviate
4
- module Response
5
- class Class < Base
6
- end
7
- end
8
- 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
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Weaviate
4
- module Response
5
- class Object < Base
6
- end
7
- end
8
- end