weaviate-ruby 0.4.0 → 0.6.0

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: e9f87a5670b340fe00f3634f0cf7d22b3c699b0737d3cb326d4ec7d55085cea2
4
- data.tar.gz: 0b7fbe6084e04d5d1a006871deab4972aa965a65bd5bf8080a58f045787841fd
3
+ metadata.gz: ad58e91ebbe32128a41045dd5f04b82dcf7b97030af3609d21b8384fdd755cd9
4
+ data.tar.gz: e4da33cbb7a6a09b06ff65b19ee3addf83f7b4d2fe98311158586d1bd3147983
5
5
  SHA512:
6
- metadata.gz: dee8739ad9cd3bb53ae226bd4be6b041fc9af449d47ff6347088514b2db2bfc2adef35e9fc2ff2c6c431ee5f2d311e49c5f78569ff473e36b8da366a01dd9d48
7
- data.tar.gz: 5dd898fd6c88899b119721369d0f606114cf1be480be31218adbe506954cba1b110f9eead1f135b5619e067d7328aeefd405762159912f93996f9f098b2ff62e
6
+ metadata.gz: 5d860ad3d6f33ab341181c6807d7c99b33bed83740ddeca9f297d856791498cfb6028f4bec710667d3d4d80a3d630ec0b95f90018ce23c9d530bd7bafb817d47
7
+ data.tar.gz: f54b9d91b2ecb8fdfc8db95d4c654d43fdd5ae28f3561545e19dc39e652bb9dbd838fe77479c909445eb40a905c747924aca715a9e45cef03467e7c358b60a53
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weaviate-ruby (0.4.0)
4
+ weaviate-ruby (0.6.0)
5
5
  faraday (~> 2.7)
6
6
  graphlient (~> 0.7.0)
7
7
 
data/README.md CHANGED
@@ -22,6 +22,7 @@ require 'weaviate'
22
22
  client = Weaviate::Client.new(
23
23
  scheme: 'https',
24
24
  host: 'some-endpoint.weaviate.network', # Replace with your endpoint
25
+ api_key: '', # Weaviate API key
25
26
  model_service: :openai, # Service that will be used to generate vectors. Possible values: :openai, :cohere, :huggingface
26
27
  model_service_api_key: 'xxxxxxx' # Either OpenAI, Cohere or Hugging Face API key
27
28
  )
@@ -134,6 +135,16 @@ response = client.objects.batch_create(objects: [
134
135
  }
135
136
  ])
136
137
  response.data
138
+
139
+ # Batch delete objects
140
+ client.objects.batch_delete(
141
+ class_name: "Question",
142
+ where: {
143
+ valueString: "1",
144
+ operator: "Equal",
145
+ path: ["id"]
146
+ }
147
+ )
137
148
  ```
138
149
 
139
150
  ### Querying
@@ -187,12 +198,50 @@ client.query.aggs(
187
198
  )
188
199
  ```
189
200
 
190
- #### Nodes
201
+ ### Classification
202
+ ```ruby
203
+ client.classifications.create(
204
+ type: "zeroshot",
205
+ class_name: "Posts",
206
+ classify_properties: ["hasColor"],
207
+ based_on_properties: ["text"]
208
+ )
209
+
210
+ client.classifications.get(
211
+ id: ""
212
+ )
213
+ ```
214
+
215
+ ### Backups
216
+ ```ruby
217
+ client.backups.create(
218
+ backend: "filesystem",
219
+ id: "my-first-backup",
220
+ include: ["Question"]
221
+ )
222
+
223
+ client.backups.get(
224
+ backend: "filesystem",
225
+ id: "my-first-backup"
226
+ )
227
+
228
+ client.backups.restore(
229
+ backend: "filesystem",
230
+ id: "my-first-backup"
231
+ )
232
+
233
+ client.backups.restore_status(
234
+ backend: "filesystem",
235
+ id: "my-first-backup"
236
+ )
237
+ ```
238
+
239
+ ### Nodes
191
240
  ```ruby
192
241
  client.nodes
193
242
  ```
194
243
 
195
- #### Health
244
+ ### Health
196
245
  ```ruby
197
246
  client.live?
198
247
  client.ready?
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Weaviate
4
+ class Backups < Base
5
+ PATH = "backups"
6
+
7
+ def create(
8
+ backend:,
9
+ id:,
10
+ include: nil,
11
+ exclude: nil
12
+ )
13
+ response = client.connection.post("#{PATH}/#{backend}") do |req|
14
+ req.body = {}
15
+ req.body["id"] = id
16
+ req.body["include"] = include if include
17
+ req.body["exclude"] = exclude if exclude
18
+ end
19
+
20
+ response.body
21
+ end
22
+
23
+ def get(
24
+ backend:,
25
+ id:
26
+ )
27
+ response = client.connection.get("#{PATH}/#{backend}/#{id}")
28
+ response.body
29
+ end
30
+
31
+ def restore(
32
+ backend:,
33
+ id:,
34
+ include: nil,
35
+ exclude: nil
36
+ )
37
+ response = client.connection.post("#{PATH}/#{backend}/#{id}/restore") do |req|
38
+ req.body = {}
39
+ req.body["include"] = include if include
40
+ req.body["exclude"] = exclude if exclude
41
+ end
42
+
43
+ response.body
44
+ end
45
+
46
+ def restore_status(
47
+ backend:,
48
+ id:
49
+ )
50
+ response = client.connection.get("#{PATH}/#{backend}/#{id}/restore")
51
+ response.body
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Weaviate
4
+ class Classifications < Base
5
+ PATH = "classifications"
6
+
7
+ def get(id:)
8
+ response = client.connection.get("#{PATH}/#{id}")
9
+ response.body
10
+ end
11
+
12
+ def create(
13
+ class_name:,
14
+ type:,
15
+ classify_properties: nil,
16
+ based_on_properties: nil,
17
+ settings: nil,
18
+ filters: nil
19
+ )
20
+ response = client.connection.post(PATH) do |req|
21
+ req.body = {}
22
+ req.body["class"] = class_name
23
+ req.body["type"] = type
24
+ req.body["classifyProperties"] = classify_properties if classify_properties
25
+ req.body["basedOnProperties"] = based_on_properties if based_on_properties
26
+ req.body["settings"] = settings if settings
27
+ req.body["filters"] = filters if filters
28
+ end
29
+
30
+ if response.success?
31
+ response.body
32
+ end
33
+ end
34
+ end
35
+ end
@@ -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
@@ -59,6 +61,14 @@ module Weaviate
59
61
  @health.ready?
60
62
  end
61
63
 
64
+ def backups
65
+ @backups ||= Weaviate::Backups.new(client: self)
66
+ end
67
+
68
+ def classifications
69
+ @classifications ||= Weaviate::Classifications.new(client: self)
70
+ end
71
+
62
72
  def objects
63
73
  @objects ||= Weaviate::Objects.new(client: self)
64
74
  end
@@ -85,6 +95,9 @@ module Weaviate
85
95
 
86
96
  def connection
87
97
  @connection ||= Faraday.new(url: "#{scheme}://#{host}/#{API_VERSION}/") do |faraday|
98
+ if api_key
99
+ faraday.request :authorization, :Bearer, api_key
100
+ end
88
101
  faraday.request :json
89
102
  faraday.response :json, content_type: /\bjson$/
90
103
  faraday.adapter adapter
@@ -108,6 +108,30 @@ module Weaviate
108
108
  response.success? && response.body.empty?
109
109
  end
110
110
 
111
+ def batch_delete(
112
+ class_name:,
113
+ where:,
114
+ consistency_level: nil,
115
+ output: nil,
116
+ dry_run: nil
117
+ )
118
+ path = "batch/#{PATH}"
119
+ path << "?consistency_level=#{consistency_level}" unless consistency_level.nil?
120
+
121
+ response = client.connection.delete(path) do |req|
122
+ req.body = {
123
+ match: {
124
+ class: class_name,
125
+ where: where
126
+ }
127
+ }
128
+ req.body["output"] = output unless output.nil?
129
+ req.body["dryRun"] = dry_run unless dry_run.nil?
130
+ end
131
+
132
+ response.body
133
+ end
134
+
111
135
  # Validate a data object
112
136
  # def validate
113
137
  # end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weaviate
4
- VERSION = "0.4.0"
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/weaviate.rb CHANGED
@@ -13,6 +13,8 @@ module Weaviate
13
13
  autoload :Query, "weaviate/query"
14
14
  autoload :Nodes, "weaviate/nodes"
15
15
  autoload :Health, "weaviate/health"
16
+ autoload :Classifications, "weaviate/classifications"
17
+ autoload :Backups, "weaviate/backups"
16
18
 
17
19
  module Response
18
20
  autoload :Base, "weaviate/response/base"
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.0
4
+ version: 0.6.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-03 00:00:00.000000000 Z
11
+ date: 2023-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -68,7 +68,9 @@ files:
68
68
  - README.md
69
69
  - Rakefile
70
70
  - lib/weaviate.rb
71
+ - lib/weaviate/backups.rb
71
72
  - lib/weaviate/base.rb
73
+ - lib/weaviate/classifications.rb
72
74
  - lib/weaviate/client.rb
73
75
  - lib/weaviate/error.rb
74
76
  - lib/weaviate/health.rb
@@ -84,13 +86,13 @@ files:
84
86
  - lib/weaviate/schema.rb
85
87
  - lib/weaviate/version.rb
86
88
  - sig/weaviate.rbs
87
- homepage: https://github.com/andreibondarev/weaviate
89
+ homepage: https://github.com/andreibondarev/weaviate-ruby
88
90
  licenses:
89
91
  - MIT
90
92
  metadata:
91
- homepage_uri: https://github.com/andreibondarev/weaviate
92
- source_code_uri: https://github.com/andreibondarev/weaviate
93
- changelog_uri: https://github.com/andreibondarev/weaviate/CHANGELOG.md
93
+ homepage_uri: https://github.com/andreibondarev/weaviate-ruby
94
+ source_code_uri: https://github.com/andreibondarev/weaviate-ruby
95
+ changelog_uri: https://github.com/andreibondarev/weaviate-ruby/CHANGELOG.md
94
96
  post_install_message:
95
97
  rdoc_options: []
96
98
  require_paths: