weaviate-ruby 0.9.2 → 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 +4 -4
- data/.standard.yml +1 -0
- data/CHANGELOG.md +31 -0
- data/Gemfile +8 -2
- data/Gemfile.lock +56 -68
- data/README.md +220 -29
- data/Rakefile +2 -0
- data/lib/weaviate/aliases.rb +40 -0
- data/lib/weaviate/backups.rb +61 -6
- data/lib/weaviate/classifications.rb +1 -3
- data/lib/weaviate/client.rb +88 -40
- data/lib/weaviate/{schema.rb → collections.rb} +84 -51
- data/lib/weaviate/connection.rb +147 -0
- data/lib/weaviate/error.rb +52 -0
- data/lib/weaviate/graphql.rb +19 -0
- data/lib/weaviate/groups.rb +39 -0
- data/lib/weaviate/health.rb +13 -4
- data/lib/weaviate/nodes.rb +10 -2
- data/lib/weaviate/objects.rb +101 -11
- data/lib/weaviate/query.rb +158 -84
- data/lib/weaviate/roles.rb +65 -0
- data/lib/weaviate/users.rb +94 -0
- data/lib/weaviate/version.rb +1 -1
- data/lib/weaviate.rb +9 -2
- data/sig/weaviate.rbs +419 -1
- metadata +19 -41
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ab94f12f2812644897584413ce374e327993f3c4d83201fc466bab50e6272e8a
|
|
4
|
+
data.tar.gz: 8107182f584e4f479f51fb3a24948132c9a19709c8913a0a429fb171747f64a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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,36 @@
|
|
|
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
|
+
|
|
3
34
|
## [0.9.2] - 2024-10-01
|
|
4
35
|
- Weaviate::Client constructor accepts customer logger: to be passed in
|
|
5
36
|
|
data/Gemfile
CHANGED
|
@@ -8,5 +8,11 @@ gemspec
|
|
|
8
8
|
gem "rake", "~> 13.0"
|
|
9
9
|
|
|
10
10
|
gem "rspec", "~> 3.0"
|
|
11
|
-
|
|
12
|
-
gem "
|
|
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.
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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.
|
|
31
|
+
racc (1.8.1)
|
|
60
32
|
rainbow (3.1.1)
|
|
61
33
|
rake (13.0.6)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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.
|
|
79
|
-
json (
|
|
80
|
-
|
|
81
|
-
|
|
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 (>=
|
|
84
|
-
|
|
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, <
|
|
88
|
-
rubocop-ast (1.
|
|
89
|
-
parser (>= 3.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
standard (1.25.3)
|
|
71
|
+
standard (1.57.0)
|
|
96
72
|
language_server-protocol (~> 3.17.0.2)
|
|
97
|
-
|
|
98
|
-
rubocop
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
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.
|
|
105
|
+
standard (~> 1.57)
|
|
118
106
|
weaviate-ruby!
|
|
119
107
|
yard
|
|
120
108
|
|
|
121
109
|
BUNDLED WITH
|
|
122
|
-
2.
|
|
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/
|
|
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
|
-

|
|
16
16
|
[](https://badge.fury.io/rb/weaviate-ruby)
|
|
17
17
|
[](http://rubydoc.info/gems/weaviate-ruby)
|
|
18
|
-
[](https://github.com/
|
|
18
|
+
[](https://github.com/patterns-ai-core/weaviate-ruby/blob/main/LICENSE.txt)
|
|
19
19
|
[](https://discord.gg/WDARp7J2n8)
|
|
20
20
|
[](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
|
|
43
|
-
model_service_api_key: 'xxxxxxx' #
|
|
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
|
-
###
|
|
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
|
|
51
|
-
client.
|
|
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
|
|
74
|
-
client.
|
|
87
|
+
# Get a single collection
|
|
88
|
+
client.collections.get(class_name: 'Question')
|
|
75
89
|
|
|
76
|
-
#
|
|
77
|
-
client.
|
|
90
|
+
# List all collections
|
|
91
|
+
client.collections.list()
|
|
78
92
|
|
|
79
|
-
# Update settings of an existing
|
|
93
|
+
# Update settings of an existing collection.
|
|
80
94
|
# Does not support modifying existing properties.
|
|
81
|
-
client.
|
|
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.
|
|
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
|
|
96
|
-
client.
|
|
109
|
+
# Inspect the shards of a collection
|
|
110
|
+
client.collections.shards(class_name: 'Question')
|
|
97
111
|
|
|
98
|
-
# Remove a
|
|
99
|
-
client.
|
|
112
|
+
# Remove a collection (and all data in the instances).
|
|
113
|
+
client.collections.delete(class_name: 'Question')
|
|
100
114
|
|
|
101
|
-
# Creating a new
|
|
102
|
-
client.
|
|
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
|
-
###
|
|
474
|
+
### Aliases
|
|
345
475
|
```ruby
|
|
346
|
-
#
|
|
347
|
-
client.
|
|
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
|
-
|
|
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
|
|
537
|
+
Any collection can be multi-tenant by passing in these options to `collections.create()`.
|
|
358
538
|
|
|
359
539
|
```ruby
|
|
360
|
-
client.
|
|
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/
|
|
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
|