weaviate-ruby 0.9.1 → 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1132fea78a812b9835eef5a94fffc191551e9f327955e1ba89f4509888fa8146
4
- data.tar.gz: 68eb70bc73f8641c2915028c6d64c48c959bb8bc785a042f0ddee95b0ef07c50
3
+ metadata.gz: ab94f12f2812644897584413ce374e327993f3c4d83201fc466bab50e6272e8a
4
+ data.tar.gz: 8107182f584e4f479f51fb3a24948132c9a19709c8913a0a429fb171747f64a4
5
5
  SHA512:
6
- metadata.gz: 1ac5684f8542587c703b2b694552bb256390af95171e25bce26157fb19c09d4e409a3adaee6b6b9372b8092b4d43e93b03784cbdfe761beb46fc2037d69d14f5
7
- data.tar.gz: 5a1de134f24d453e4fdb2876d4d58ba0564f485aa093f727d37830a9f970c2dce60c648741dcf01dce2f33ccd458ebbb1a514ad546ea399be5c1feec0ec02b20
6
+ metadata.gz: d296219c8e89256d4c899c14a597b4296ed2b9e00efe36d4b1b7a4df0aa22838fc471f9c78981b9d767ced0036d34ec22f92a291ed846cc45de9bd72dadc159b
7
+ data.tar.gz: 9e98c00563e21c746d53a891124333f1afa340144e907516fe9d1cc488678eb390b02bc54c24a37c6f87481bb57e0ace00ae756053dda53b857e9765049c4b9f
data/.standard.yml ADDED
@@ -0,0 +1 @@
1
+ ruby_version: 2.7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.10.0] - 2026-10-21
4
+ - Drop the `faraday` and `graphlient` dependencies in favor of Ruby's built-in `Net::HTTP` (#56)
5
+ - Fix `query.get` failing with "interface conversion: interface {} is nil, not int" on Weaviate >= 1.26.4. Only the arguments that are passed are sent in GraphQL queries (#63)
6
+ - Add `proxy:` option to `Weaviate::Client.new`. The `http_proxy`/`https_proxy` env vars are respected by default (#55)
7
+ - Add `client.collections` (`Weaviate::Collections`) to match Weaviate's terminology. `client.schema` and `Weaviate::Schema` remain as aliases (#69)
8
+ - API keys are filtered out of request logs
9
+ - Fix `collections.update` failing with 422 on immutable settings: the changes are now merged into the current collection definition, since Weaviate replaces the whole definition on update
10
+ - Fix `objects.exists?` raising on missing objects instead of returning `false`
11
+ - Fix `objects.batch_create(tenant:)` being ignored by Weaviate: the tenant is now set on each object
12
+ - Fix `query.aggs` failing with "groupBy must be a list, instead got: <nil>" when `group_by`/`object_limit` are not passed
13
+ - `live?`/`ready?` return `false` when Weaviate responds with an error (e.g. 503 while starting) or cannot be reached, instead of raising
14
+ - `collections.add_tenants` sends a JSON array and accepts hashes with `activityStatus`
15
+ - Query arguments (`where:`, `near_text:`, `sort:`, ...) can be Ruby hashes/arrays, serialized to GraphQL with strings escaped. Raw GraphQL strings still work
16
+ - Add API key headers for all model providers supported by Weaviate 1.38 (e.g. `:anthropic`, `:google_studio`, `:google_vertex`, `:mistral`, `:voyageai`, `:jinaai`, `:nvidia`)
17
+ - Add `headers:`, `open_timeout:`, `read_timeout:` and `write_timeout:` options to `Weaviate::Client.new`
18
+ - Add cross-references: `objects.add_reference`, `replace_references`, `delete_reference` and `batch_create_references`
19
+ - Add `group_by:` to `query.get`, and `limit:`/`with_hybrid:` to `query.aggs`
20
+ - Add `collections.update_tenants`, `get_tenant`, `tenant_exists?`, and `tenant:` to `collections.shards`
21
+ - Add `backups.list`, `cancel`, `cancel_restore`, `config:` on create/restore and `bucket:`/`path:` on status reads
22
+ - Add `client.nodes(output:, class_name:, shard_name:)`
23
+ - Add `client.aliases`, `client.users`, `client.roles` and `client.groups`
24
+ - Deprecate `query.explore`: Weaviate disables Explore when more than one vectorizer module is enabled
25
+ - Add RBS signatures for the public API
26
+ - Minimum Ruby version is now 2.7
27
+
28
+ ### Breaking
29
+ - HTTP errors are raised as `Weaviate::HTTPError` subclasses (e.g. `Weaviate::ResourceNotFound`, `Weaviate::ServerError`) instead of `Faraday::Error` subclasses. Network failures raise `Weaviate::ConnectionFailed`/`Weaviate::TimeoutError`
30
+ - GraphQL errors are raised as `Weaviate::GraphQLError` (a `Weaviate::Error` subclass) whose message is the joined error messages
31
+ - `client.connection` returns a `Weaviate::Connection` and `client.graphql` returns a `Weaviate::GraphQL` instead of Faraday/Graphlient clients
32
+ - The `adapter:` option is deprecated and ignored
33
+
34
+ ## [0.9.2] - 2024-10-01
35
+ - Weaviate::Client constructor accepts customer logger: to be passed in
36
+
3
37
  ## [0.9.1] - 2024-09-19
4
38
 
5
39
  ## [0.9.0] - 2024-07-08
data/Gemfile CHANGED
@@ -8,5 +8,11 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
- gem "standard", "~> 1.25.0"
12
- gem "graphql-client", "~> 0.19.0"
11
+
12
+ gem "ostruct" # used in specs, no longer a default gem on Ruby >= 3.5
13
+
14
+ # Linting runs on the latest Ruby only (standard requires Ruby >= 3.0). Skip with BUNDLE_WITHOUT=lint.
15
+ group :lint do
16
+ gem "standard", "~> 1.57"
17
+ gem "rbs", "~> 3.8"
18
+ end
data/Gemfile.lock CHANGED
@@ -1,67 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weaviate-ruby (0.9.1)
5
- faraday (>= 2.0.1, < 3.0)
6
- graphlient (>= 0.7.0, < 0.9.0)
4
+ weaviate-ruby (0.10.0)
5
+ logger
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
- activesupport (7.1.3)
12
- base64
13
- bigdecimal
14
- concurrent-ruby (~> 1.0, >= 1.0.2)
15
- connection_pool (>= 2.2.5)
16
- drb
17
- i18n (>= 1.6, < 2)
18
- minitest (>= 5.1)
19
- mutex_m
20
- tzinfo (~> 2.0)
21
- ast (2.4.2)
22
- base64 (0.2.0)
23
- bigdecimal (3.1.6)
10
+ ast (2.4.3)
24
11
  byebug (11.1.3)
25
12
  coderay (1.1.3)
26
- concurrent-ruby (1.2.3)
27
- connection_pool (2.4.1)
28
13
  diff-lcs (1.5.0)
29
- drb (2.2.0)
30
- ruby2_keywords
31
- faraday (2.7.10)
32
- faraday-net_http (>= 2.0, < 3.1)
33
- ruby2_keywords (>= 0.0.4)
34
- faraday-net_http (3.0.2)
35
- graphlient (0.7.0)
36
- faraday (~> 2.0)
37
- graphql-client
38
- graphql (2.2.6)
39
- racc (~> 1.4)
40
- graphql-client (0.19.0)
41
- activesupport (>= 3.0)
42
- graphql
43
- i18n (1.14.1)
44
- concurrent-ruby (~> 1.0)
45
- json (2.6.3)
46
- language_server-protocol (3.17.0.3)
14
+ json (3.1.0)
15
+ language_server-protocol (3.17.0.6)
16
+ lint_roller (1.1.0)
17
+ logger (1.7.0)
47
18
  method_source (1.0.0)
48
- minitest (5.21.2)
49
- mutex_m (0.2.0)
50
- parallel (1.22.1)
51
- parser (3.2.1.1)
19
+ ostruct (0.6.3)
20
+ parallel (2.3.0)
21
+ parser (3.3.12.0)
52
22
  ast (~> 2.4.1)
23
+ racc
24
+ prism (1.9.0)
53
25
  pry (0.14.2)
54
26
  coderay (~> 1.1)
55
27
  method_source (~> 1.0)
56
28
  pry-byebug (3.10.1)
57
29
  byebug (~> 11.0)
58
30
  pry (>= 0.13, < 0.15)
59
- racc (1.7.3)
31
+ racc (1.8.1)
60
32
  rainbow (3.1.1)
61
33
  rake (13.0.6)
62
- rdiscount (2.2.7.1)
63
- regexp_parser (2.7.0)
64
- rexml (3.2.5)
34
+ rbs (3.10.4)
35
+ logger
36
+ tsort
37
+ rdiscount (2.2.7.4)
38
+ regexp_parser (2.13.1)
65
39
  rspec (3.11.0)
66
40
  rspec-core (~> 3.11.0)
67
41
  rspec-expectations (~> 3.11.0)
@@ -75,48 +49,62 @@ GEM
75
49
  diff-lcs (>= 1.2.0, < 2.0)
76
50
  rspec-support (~> 3.11.0)
77
51
  rspec-support (3.11.0)
78
- rubocop (1.48.1)
79
- json (~> 2.3)
80
- parallel (~> 1.10)
81
- parser (>= 3.2.0.0)
52
+ rubocop (1.91.0)
53
+ json (>= 2.3)
54
+ language_server-protocol (~> 3.17.0.2)
55
+ lint_roller (~> 1.1.0)
56
+ parallel (>= 1.10)
57
+ parser (>= 3.3.0.2)
82
58
  rainbow (>= 2.2.2, < 4.0)
83
- regexp_parser (>= 1.8, < 3.0)
84
- rexml (>= 3.2.5, < 4.0)
85
- rubocop-ast (>= 1.26.0, < 2.0)
59
+ regexp_parser (>= 2.9.3, < 3.0)
60
+ rubocop-ast (>= 1.49.0, < 2.0)
86
61
  ruby-progressbar (~> 1.7)
87
- unicode-display_width (>= 2.4.0, < 3.0)
88
- rubocop-ast (1.28.0)
89
- parser (>= 3.2.1.0)
90
- rubocop-performance (1.16.0)
91
- rubocop (>= 1.7.0, < 2.0)
92
- rubocop-ast (>= 0.4.0)
62
+ unicode-display_width (>= 2.4.0, < 4.0)
63
+ rubocop-ast (1.50.0)
64
+ parser (>= 3.3.7.2)
65
+ prism (~> 1.7)
66
+ rubocop-performance (1.26.1)
67
+ lint_roller (~> 1.1)
68
+ rubocop (>= 1.75.0, < 2.0)
69
+ rubocop-ast (>= 1.47.1, < 2.0)
93
70
  ruby-progressbar (1.13.0)
94
- ruby2_keywords (0.0.5)
95
- standard (1.25.3)
71
+ standard (1.57.0)
96
72
  language_server-protocol (~> 3.17.0.2)
97
- rubocop (~> 1.48.1)
98
- rubocop-performance (~> 1.16.0)
99
- tzinfo (2.0.6)
100
- concurrent-ruby (~> 1.0)
101
- unicode-display_width (2.4.2)
102
- yard (0.9.34)
73
+ lint_roller (~> 1.0)
74
+ rubocop (~> 1.91.0)
75
+ standard-custom (~> 1.0.0)
76
+ standard-performance (~> 1.8)
77
+ standard-custom (1.0.2)
78
+ lint_roller (~> 1.0)
79
+ rubocop (~> 1.50)
80
+ standard-performance (1.9.0)
81
+ lint_roller (~> 1.1)
82
+ rubocop-performance (~> 1.26.0)
83
+ tsort (0.2.0)
84
+ unicode-display_width (3.3.0)
85
+ unicode-emoji (~> 4.3)
86
+ unicode-emoji (4.3.0)
87
+ yard (0.9.45)
103
88
 
104
89
  PLATFORMS
105
90
  arm64-darwin-21
106
91
  arm64-darwin-23
92
+ arm64-darwin-24
93
+ ruby
107
94
  x86_64-darwin-19
108
95
  x86_64-darwin-21
109
96
  x86_64-linux
110
97
 
111
98
  DEPENDENCIES
112
- graphql-client (~> 0.19.0)
99
+ ostruct
113
100
  pry-byebug (~> 3.9)
114
101
  rake (~> 13.0)
102
+ rbs (~> 3.8)
115
103
  rdiscount
116
104
  rspec (~> 3.0)
117
- standard (~> 1.25.0)
105
+ standard (~> 1.57)
118
106
  weaviate-ruby!
119
107
  yard
120
108
 
121
109
  BUNDLED WITH
122
- 2.4.0
110
+ 2.6.9
data/README.md CHANGED
@@ -8,14 +8,14 @@
8
8
 
9
9
  Ruby wrapper for the Weaviate.io API.
10
10
 
11
- Part of the [Langchain.rb](https://github.com/andreibondarev/langchainrb) stack.
11
+ Part of the [Langchain.rb](https://github.com/patterns-ai-core/langchainrb) stack.
12
12
 
13
13
  Available for paid consulting engagements! [Email me](mailto:andrei@sourcelabs.io).
14
14
 
15
- ![Tests status](https://github.com/andreibondarev/weaviate-ruby/actions/workflows/ci.yml/badge.svg)
15
+ ![Tests status](https://github.com/patterns-ai-core/weaviate-ruby/actions/workflows/ci.yml/badge.svg)
16
16
  [![Gem Version](https://badge.fury.io/rb/weaviate-ruby.svg)](https://badge.fury.io/rb/weaviate-ruby)
17
17
  [![Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/weaviate-ruby)
18
- [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/andreibondarev/weaviate-ruby/blob/main/LICENSE.txt)
18
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/patterns-ai-core/weaviate-ruby/blob/main/LICENSE.txt)
19
19
  [![](https://dcbadge.vercel.app/api/server/WDARp7J2n8?compact=true&style=flat)](https://discord.gg/WDARp7J2n8)
20
20
  [![X](https://img.shields.io/twitter/url/https/twitter.com/cloudposse.svg?style=social&label=Follow%20%40rushing_andrei)](https://twitter.com/rushing_andrei)
21
21
 
@@ -39,16 +39,30 @@ require 'weaviate'
39
39
  client = Weaviate::Client.new(
40
40
  url: 'https://some-endpoint.weaviate.network', # Replace with your endpoint
41
41
  api_key: '', # Weaviate API key
42
- model_service: :openai, # Service that will be used to generate vectors. Possible values: :openai, :azure_openai, :cohere, :huggingface, :google_palm
43
- model_service_api_key: 'xxxxxxx' # Either OpenAI, Azure OpenAI, Cohere, Hugging Face or Google PaLM api key
42
+ model_service: :openai, # Service used to generate vectors, see Weaviate::Client::API_KEY_HEADERS for all values (e.g. :openai, :cohere, :google_studio, :voyageai, :mistral)
43
+ model_service_api_key: 'xxxxxxx', # API key for the model service
44
+ headers: { 'X-Aws-Access-Key' => '...', 'X-Aws-Secret-Key' => '...' }, # Optional. Extra headers, e.g. for providers that need several keys or a custom base URL
45
+ proxy: 'http://user:pass@localhost:8888', # Optional. Defaults to the http_proxy/https_proxy env vars
46
+ open_timeout: 5, read_timeout: 30, write_timeout: 30, # Optional. In seconds, default to 60
47
+ logger: Logger.new($stdout) # Optional. Requests and responses are logged with API keys filtered out
44
48
  )
45
49
  ```
46
50
 
47
- ### Using the Schema endpoints
51
+ ### Errors
52
+
53
+ All errors inherit from `Weaviate::Error`:
54
+
55
+ - `Weaviate::HTTPError` - Weaviate responded with a 4xx/5xx status (`#status` and `#body` are available). Subclasses: `Weaviate::BadRequestError`, `Weaviate::UnauthorizedError`, `Weaviate::ForbiddenError`, `Weaviate::ResourceNotFound`, `Weaviate::ConflictError`, `Weaviate::UnprocessableEntityError`, `Weaviate::ServerError`
56
+ - `Weaviate::GraphQLError` - a GraphQL query returned errors (`#errors` is available)
57
+ - `Weaviate::ConnectionFailed` / `Weaviate::TimeoutError` - Weaviate could not be reached
58
+
59
+ ### Using the Collections endpoints
60
+
61
+ `client.collections` was previously called `client.schema`, which still works as an alias.
48
62
 
49
63
  ```ruby
50
- # Creating a new data object class in the schema
51
- client.schema.create(
64
+ # Creating a new collection
65
+ client.collections.create(
52
66
  class_name: 'Question',
53
67
  description: 'Information from a Jeopardy! question',
54
68
  properties: [
@@ -70,21 +84,21 @@ client.schema.create(
70
84
  vectorizer: "text2vec-openai"
71
85
  )
72
86
 
73
- # Get a single class from the schema
74
- client.schema.get(class_name: 'Question')
87
+ # Get a single collection
88
+ client.collections.get(class_name: 'Question')
75
89
 
76
- # Get the schema
77
- client.schema.list()
90
+ # List all collections
91
+ client.collections.list()
78
92
 
79
- # Update settings of an existing schema class.
93
+ # Update settings of an existing collection.
80
94
  # Does not support modifying existing properties.
81
- client.schema.update(
95
+ client.collections.update(
82
96
  class_name: 'Question',
83
97
  description: 'Information from a Wheel of Fortune question'
84
98
  )
85
99
 
86
100
  # Adding a new property
87
- client.schema.add_property(
101
+ client.collections.add_property(
88
102
  class_name: 'Question',
89
103
  property: {
90
104
  "dataType": ["boolean"],
@@ -92,14 +106,14 @@ client.schema.add_property(
92
106
  }
93
107
  )
94
108
 
95
- # Inspect the shards of a class
96
- client.schema.shards(class_name: 'Question')
109
+ # Inspect the shards of a collection
110
+ client.collections.shards(class_name: 'Question')
97
111
 
98
- # Remove a class (and all data in the instances) from the schema.
99
- client.schema.delete(class_name: 'Question')
112
+ # Remove a collection (and all data in the instances).
113
+ client.collections.delete(class_name: 'Question')
100
114
 
101
- # Creating a new data object class in the schema while configuring the vectorizer on the schema and on individual properties (Ollama example)
102
- client.schema.create(
115
+ # Creating a new collection while configuring the vectorizer on the collection and on individual properties (Ollama example)
116
+ client.collections.create(
103
117
  class_name: 'Question',
104
118
  description: 'Information from a Jeopardy! question',
105
119
  properties: [
@@ -139,6 +153,44 @@ client.schema.create(
139
153
  },
140
154
  },
141
155
  )
156
+
157
+ # Creating collections with named vectors
158
+
159
+ client.collections.create(
160
+ class_name: 'ArticleNV',
161
+ description: 'Articles with named vectors',
162
+ properties: [
163
+ {
164
+ "dataType": ["text"],
165
+ "name": "title"
166
+ },
167
+ {
168
+ "dataType": ["text"],
169
+ "name": "body"
170
+ }
171
+ ],
172
+ # cannot use vectorizer and vector_config at the same time
173
+ # will need to specify for each property
174
+ vector_config: {
175
+ "title": {
176
+ "vectorizer": {
177
+ "text2vec-openai": {
178
+ "properties": ["title"]
179
+ }
180
+ },
181
+ "vectorIndexType": "hnsw", # This is the default
182
+ },
183
+ "body": {
184
+ "vectorizer": {
185
+ "text2vec-openai": {
186
+ "properties": ["body"]
187
+ }
188
+ },
189
+ "vectorIndexType": "hnsw", # This is the default
190
+
191
+ }
192
+ }
193
+ )
142
194
  ```
143
195
 
144
196
  ### Using the Objects endpoint
@@ -224,12 +276,35 @@ client.objects.batch_delete(
224
276
  path: ["id"]
225
277
  }
226
278
  )
279
+
280
+ # References: add, replace and delete cross-references on a reference property
281
+ client.objects.add_reference(class_name: "Post", id: post_id, property: "ofCategory", to_class_name: "Category", to_id: category_id)
282
+ client.objects.replace_references(class_name: "Post", id: post_id, property: "ofCategory", to: [{ class_name: "Category", id: category_id }])
283
+ client.objects.delete_reference(class_name: "Post", id: post_id, property: "ofCategory", to_class_name: "Category", to_id: category_id)
284
+
285
+ # Batch create references
286
+ client.objects.batch_create_references(references: [
287
+ { from_class_name: "Post", from_id: post_id, property: "ofCategory", to_class_name: "Category", to_id: category_id }
288
+ ])
227
289
  ```
228
290
 
229
291
  ### Querying
230
292
 
231
293
  #### Get{}
294
+
295
+ Arguments such as `where`, `near_text` or `sort` can be passed either as raw GraphQL strings or as Ruby hashes/arrays.
296
+ Hashes are converted to GraphQL: strings are quoted and escaped (safe for user input), and symbols are sent as enums.
297
+ `operator`, `order` and `fusionType` values are always sent as enums.
298
+
232
299
  ```ruby
300
+ client.query.get(
301
+ class_name: 'Question',
302
+ fields: 'question category',
303
+ where: { path: ['category'], operator: :Equal, valueText: params[:category] },
304
+ sort: [{ path: ['category'], order: :asc }],
305
+ limit: 10
306
+ )
307
+
233
308
  near_text = '{ concepts: ["biology"] }'
234
309
  near_vector = '{ vector: [0.1, 0.2, ...] }'
235
310
  sort_obj = '{ path: ["category"], order: desc }'
@@ -268,6 +343,34 @@ client.query.get class_name: 'Question', where: '{ operator: Like, valueText: "S
268
343
 
269
344
  client.query.get class_name: 'Question', fields: 'answer question category _additional { id }', after: "3c5f7039-37f3-4244-b3e2-8f4a083e448d", limit: "1"
270
345
 
346
+ # Limiting results by distance or certainty: pass `distance` or `certainty` along with `near_text`, `near_vector`
347
+ # or `near_object`, and request them back via `_additional`.
348
+ client.query.get(
349
+ class_name: 'Question',
350
+ fields: 'question _additional { distance certainty }',
351
+ near_text: '{ concepts: ["biology"], distance: 0.6 }', # or certainty: 0.7
352
+ limit: 5
353
+ )
354
+
355
+ # Grouping results by a property (requires a near_* or hybrid search)
356
+ client.query.get(
357
+ class_name: 'Question',
358
+ fields: '_additional { group { groupedBy { value } count hits { question _additional { id distance } } } }',
359
+ near_text: { concepts: ['biology'] },
360
+ group_by: { path: ['category'], groups: 3, objectsPerGroup: 2 }
361
+ )
362
+
363
+ # Named vector query - uses targetVectors
364
+ query_title = client.query.get(
365
+ class_name: 'ArticleNV',
366
+ fields: 'title body _additional { id }',
367
+ near_text: '{
368
+ targetVectors: ["title"],
369
+ concepts: ["quantum computers advances"]
370
+ }',
371
+ limit: "2"
372
+ )
373
+
271
374
 
272
375
 
273
376
  ```
@@ -281,9 +384,22 @@ client.query.aggs(
281
384
  object_limit: "10",
282
385
  near_text: "{ concepts: [\"knowledge\"] }"
283
386
  )
387
+
388
+ # Aggregating over hybrid search results, limiting the number of groups returned
389
+ client.query.aggs(
390
+ class_name: "Question",
391
+ fields: 'groupedBy { value } meta { count }',
392
+ group_by: ["category"],
393
+ with_hybrid: { query: "knowledge", alpha: 0.5 },
394
+ object_limit: 100,
395
+ limit: 5
396
+ )
284
397
  ```
285
398
 
286
399
  #### Explore{}
400
+
401
+ **Deprecated.** Weaviate disables `Explore` when more than one vectorizer module is enabled, which is the case on a default install of recent versions and on Weaviate Cloud. Use `query.get` on each collection instead.
402
+
287
403
  ```ruby
288
404
  client.query.explore(
289
405
  fields: 'className',
@@ -334,30 +450,94 @@ client.backups.restore_status(
334
450
  backend: "filesystem",
335
451
  id: "my-first-backup"
336
452
  )
453
+
454
+ # List backups, newest first by default
455
+ client.backups.list(backend: "filesystem", order: "desc")
456
+
457
+ # Cancel a backup or restore that is in progress
458
+ client.backups.cancel(backend: "filesystem", id: "my-first-backup")
459
+ client.backups.cancel_restore(backend: "filesystem", id: "my-first-backup")
460
+
461
+ # Cloud storage backends accept a config, plus bucket/path when reading the status
462
+ client.backups.create(backend: "s3", id: "my-backup", config: { Bucket: "my-bucket", Path: "backups" })
463
+ client.backups.get(backend: "s3", id: "my-backup", bucket: "my-bucket", path: "backups")
337
464
  ```
338
465
 
339
466
  ### Nodes
340
467
  ```ruby
341
468
  client.nodes
469
+
470
+ # Include shard details, optionally for one collection or shard
471
+ client.nodes(output: "verbose", class_name: "Question")
342
472
  ```
343
473
 
344
- ### Health
474
+ ### Aliases
345
475
  ```ruby
346
- # Live determines whether the application is alive. It can be used for Kubernetes liveness probe.
347
- client.live?
476
+ # Point an alias at a collection, then query or write through the alias
477
+ client.aliases.create(alias_name: "Questions", class_name: "QuestionV1")
478
+ client.query.get(class_name: "Questions", fields: "question")
479
+
480
+ # Switch the alias to a new collection, e.g. after a re-index
481
+ client.aliases.update(alias_name: "Questions", class_name: "QuestionV2")
482
+
483
+ client.aliases.list
484
+ client.aliases.get(alias_name: "Questions")
485
+ client.aliases.delete(alias_name: "Questions")
348
486
  ```
349
487
 
488
+ ### Users and roles
489
+
490
+ These require [RBAC](https://docs.weaviate.io/deploy/configuration/authorization) to be enabled.
491
+
350
492
  ```ruby
351
- # Live determines whether the application is ready to receive traffic. It can be used for Kubernetes readiness probe.
493
+ client.users.own_info
494
+
495
+ # Database users
496
+ response = client.users.create(user_id: "reporting")
497
+ response["apikey"] # The new user's API key
498
+ client.users.list
499
+ client.users.get(user_id: "reporting")
500
+ client.users.rotate_key(user_id: "reporting")
501
+ client.users.deactivate(user_id: "reporting", revoke_key: true)
502
+ client.users.activate(user_id: "reporting")
503
+ client.users.delete(user_id: "reporting")
504
+
505
+ # Roles and permissions
506
+ client.roles.create(
507
+ name: "question-reader",
508
+ permissions: [
509
+ { action: "read_data", data: { collection: "Question" } },
510
+ { action: "read_collections", collections: { collection: "*" } } # Required for GraphQL queries
511
+ ]
512
+ )
513
+ client.roles.add_permissions(name: "question-reader", permissions: [{ action: "read_tenants", tenants: { collection: "Question" } }])
514
+ client.roles.has_permission?(name: "question-reader", permission: { action: "read_data", data: { collection: "Question" } })
515
+ client.roles.list
516
+
517
+ # Assigning roles to users (user_type: "db" or "oidc") and OIDC groups
518
+ client.users.assign_roles(user_id: "reporting", roles: ["question-reader"])
519
+ client.users.roles(user_id: "reporting")
520
+ client.roles.user_assignments(name: "question-reader")
521
+ client.users.revoke_roles(user_id: "reporting", roles: ["question-reader"])
522
+ client.groups.assign_roles(group_id: "analysts", roles: ["question-reader"])
523
+ ```
524
+
525
+ ### Health
526
+ ```ruby
527
+ # Whether the application is alive. It can be used for Kubernetes liveness probe.
528
+ client.live?
529
+
530
+ # Whether the application is ready to receive traffic. It can be used for Kubernetes readiness probe.
531
+ # Both return false when Weaviate responds with an error or cannot be reached.
352
532
  client.ready?
353
533
  ```
354
534
 
355
535
  ### Tenants
356
536
 
357
- Any schema can be multi-tenant by passing in these options for to `schema.create()`.
537
+ Any collection can be multi-tenant by passing in these options to `collections.create()`.
358
538
 
359
539
  ```ruby
360
- client.schema.create(
540
+ client.collections.create(
361
541
  # Other keys...
362
542
  multi_tenant: true,
363
543
  auto_tenant_creation: true,
@@ -367,7 +547,18 @@ client.schema.create(
367
547
 
368
548
  See [Weaviate Multi-tenancy operations](https://weaviate.io/developers/weaviate/manage-data/multi-tenancy). Note that the mix of snake case(used by Ruby) and lower camel case(used by Weaviate) is intentional as that hash is passed directly to Weaviate.
369
549
 
370
- All data methods in this library support an optional `tenant` argument which must be passed if multi-tenancy is enabled on the related collection
550
+ All data methods in this library support an optional `tenant` argument which must be passed if multi-tenancy is enabled on the related collection.
551
+
552
+ ```ruby
553
+ # Tenants can be added by name, or with an activity status
554
+ client.collections.add_tenants(class_name: "Question", tenants: ["tenant-a", { name: "tenant-b", activityStatus: "COLD" }])
555
+ client.collections.update_tenants(class_name: "Question", tenants: [{ name: "tenant-b", activityStatus: "HOT" }])
556
+ client.collections.get_tenant(class_name: "Question", tenant: "tenant-b")
557
+ client.collections.tenant_exists?(class_name: "Question", tenant: "tenant-b")
558
+ client.collections.list_tenants(class_name: "Question")
559
+ client.collections.remove_tenants(class_name: "Question", tenants: ["tenant-a"])
560
+ client.collections.shards(class_name: "Question", tenant: "tenant-b")
561
+ ```
371
562
 
372
563
  ## Development
373
564
 
@@ -377,7 +568,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
377
568
 
378
569
  ## Contributing
379
570
 
380
- Bug reports and pull requests are welcome on GitHub at https://github.com/andreibondarev/weaviate.
571
+ Bug reports and pull requests are welcome on GitHub at https://github.com/patterns-ai-core/weaviate-ruby.
381
572
 
382
573
  ## License
383
574
 
data/Rakefile CHANGED
@@ -9,5 +9,7 @@ RSpec::Core::RakeTask.new(:spec)
9
9
  task default: :spec
10
10
 
11
11
  YARD::Rake::YardocTask.new do |t|
12
+ # Document from the Ruby sources only. YARD's RBS parser doesn't handle multi-line signatures in sig/
13
+ t.files = ["lib/**/*.rb"]
12
14
  t.options = ["--fail-on-warning"]
13
15
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Weaviate
4
+ # Aliases are alternative names for a collection, e.g. to switch a "Products" alias to a newly built collection.
5
+ class Aliases < Base
6
+ PATH = "aliases"
7
+
8
+ def list(class_name: nil)
9
+ response = client.connection.get(PATH) do |req|
10
+ req.params["class"] = class_name unless class_name.nil?
11
+ end
12
+ response.body
13
+ end
14
+
15
+ def create(alias_name:, class_name:)
16
+ response = client.connection.post(PATH) do |req|
17
+ req.body = {alias: alias_name, class: class_name}
18
+ end
19
+ response.body
20
+ end
21
+
22
+ def get(alias_name:)
23
+ response = client.connection.get("#{PATH}/#{alias_name}")
24
+ response.body
25
+ end
26
+
27
+ # Point an alias to a different collection.
28
+ def update(alias_name:, class_name:)
29
+ response = client.connection.put("#{PATH}/#{alias_name}") do |req|
30
+ req.body = {class: class_name}
31
+ end
32
+ response.body
33
+ end
34
+
35
+ def delete(alias_name:)
36
+ response = client.connection.delete("#{PATH}/#{alias_name}")
37
+ response.success?
38
+ end
39
+ end
40
+ end