weaviate-ruby 0.8.9 → 0.8.11

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: 8289cf9c5b37631db1c1d0607f0e2820477e8edb637b34a3efbef8bc80af80bf
4
- data.tar.gz: 7423bff81c02baad908512e0818abc43fbbcc3d0204b4ada1c2f978493349737
3
+ metadata.gz: f1533db1f83e65e849863776ab0312149c0e5dcdcbb2c65ea922294ea9af6ee7
4
+ data.tar.gz: ce9ca1a00db9c4b117a8c19216c9049663f481750b7773bd69a4637f26074282
5
5
  SHA512:
6
- metadata.gz: 4887f5222fbb592df702fbc2a6907f5513285143c4b3bb838486120045de58a2d866554d340ed098a9c3edb6a090e96e941f879e27c3bfa9654aa39ed5afcc78
7
- data.tar.gz: a708d38650a8e83e94bd660b2a34860488e0e123eb3e69c6afc868b832e69a6c352468d30d1b101b0ed757d855420a40651d16bc7da08e8adac151fbd6690f7c
6
+ metadata.gz: 8af749e6537bdef2d2c87fdc0b0724e860368f00f37550c94a7b3e0139555c89d624fda050abda601b7c7d317ad9eccdfb01ee654586e6ce038e7048128d37cb
7
+ data.tar.gz: 4afef756ad24eba7c8fb9314219dda512e49ae2cf0dc07ce9f8cc9ec1269d4b71c7ef738b4f36de780147e9b707f384bf0cb271d7ebf57d3333c2ce9e135ac07
data/Gemfile CHANGED
@@ -9,3 +9,4 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
  gem "standard", "~> 1.25.0"
12
+ gem "graphql-client", "~> 0.19.0"
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weaviate-ruby (0.8.9)
4
+ weaviate-ruby (0.8.11)
5
5
  faraday (>= 2.0.1, < 3.0)
6
6
  graphlient (~> 0.7.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (7.1.0)
11
+ activesupport (7.1.3)
12
12
  base64
13
13
  bigdecimal
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -19,14 +19,14 @@ GEM
19
19
  mutex_m
20
20
  tzinfo (~> 2.0)
21
21
  ast (2.4.2)
22
- base64 (0.1.1)
23
- bigdecimal (3.1.4)
22
+ base64 (0.2.0)
23
+ bigdecimal (3.1.6)
24
24
  byebug (11.1.3)
25
25
  coderay (1.1.3)
26
- concurrent-ruby (1.2.2)
26
+ concurrent-ruby (1.2.3)
27
27
  connection_pool (2.4.1)
28
28
  diff-lcs (1.5.0)
29
- drb (2.1.1)
29
+ drb (2.2.0)
30
30
  ruby2_keywords
31
31
  faraday (2.7.10)
32
32
  faraday-net_http (>= 2.0, < 3.1)
@@ -35,8 +35,9 @@ GEM
35
35
  graphlient (0.7.0)
36
36
  faraday (~> 2.0)
37
37
  graphql-client
38
- graphql (2.1.1)
39
- graphql-client (0.18.0)
38
+ graphql (2.2.6)
39
+ racc (~> 1.4)
40
+ graphql-client (0.19.0)
40
41
  activesupport (>= 3.0)
41
42
  graphql
42
43
  i18n (1.14.1)
@@ -44,8 +45,8 @@ GEM
44
45
  json (2.6.3)
45
46
  language_server-protocol (3.17.0.3)
46
47
  method_source (1.0.0)
47
- minitest (5.20.0)
48
- mutex_m (0.1.2)
48
+ minitest (5.21.2)
49
+ mutex_m (0.2.0)
49
50
  parallel (1.22.1)
50
51
  parser (3.2.1.1)
51
52
  ast (~> 2.4.1)
@@ -55,6 +56,7 @@ GEM
55
56
  pry-byebug (3.10.1)
56
57
  byebug (~> 11.0)
57
58
  pry (>= 0.13, < 0.15)
59
+ racc (1.7.3)
58
60
  rainbow (3.1.1)
59
61
  rake (13.0.6)
60
62
  rdiscount (2.2.7.1)
@@ -101,11 +103,13 @@ GEM
101
103
 
102
104
  PLATFORMS
103
105
  arm64-darwin-21
106
+ arm64-darwin-23
104
107
  x86_64-darwin-19
105
108
  x86_64-darwin-21
106
109
  x86_64-linux
107
110
 
108
111
  DEPENDENCIES
112
+ graphql-client (~> 0.19.0)
109
113
  pry-byebug (~> 3.9)
110
114
  rake (~> 13.0)
111
115
  rdiscount
data/README.md CHANGED
@@ -10,11 +10,14 @@ Ruby wrapper for the Weaviate.io API.
10
10
 
11
11
  Part of the [Langchain.rb](https://github.com/andreibondarev/langchainrb) stack.
12
12
 
13
+ Available for paid consulting engagements! [Email me](mailto:andrei@sourcelabs.io).
14
+
13
15
  ![Tests status](https://github.com/andreibondarev/weaviate-ruby/actions/workflows/ci.yml/badge.svg)
14
16
  [![Gem Version](https://badge.fury.io/rb/weaviate-ruby.svg)](https://badge.fury.io/rb/weaviate-ruby)
15
17
  [![Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/gems/weaviate-ruby)
16
18
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/andreibondarev/weaviate-ruby/blob/main/LICENSE.txt)
17
19
  [![](https://dcbadge.vercel.app/api/server/WDARp7J2n8?compact=true&style=flat)](https://discord.gg/WDARp7J2n8)
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)
18
21
 
19
22
  ## Installation
20
23
 
@@ -63,7 +66,7 @@ client.schema.create(
63
66
  "name": "category"
64
67
  }
65
68
  ],
66
- # Possible values: 'text2vec-cohere', 'text2vec-openai', 'text2vec-huggingface', 'text2vec-transformers', 'text2vec-contextionary', 'img2vec-neural', 'multi2vec-clip', 'ref2vec-centroid'
69
+ # Possible values: 'text2vec-cohere', 'text2vec-ollama', 'text2vec-openai', 'text2vec-huggingface', 'text2vec-transformers', 'text2vec-contextionary', 'img2vec-neural', 'multi2vec-clip', 'ref2vec-centroid'
67
70
  vectorizer: "text2vec-openai"
68
71
  )
69
72
 
@@ -73,9 +76,6 @@ client.schema.get(class_name: 'Question')
73
76
  # Get the schema
74
77
  client.schema.list()
75
78
 
76
- # Remove a class (and all data in the instances) from the schema.
77
- client.schema.delete(class_name: 'Question')
78
-
79
79
  # Update settings of an existing schema class.
80
80
  # Does not support modifying existing properties.
81
81
  client.schema.update(
@@ -94,6 +94,51 @@ client.schema.add_property(
94
94
 
95
95
  # Inspect the shards of a class
96
96
  client.schema.shards(class_name: 'Question')
97
+
98
+ # Remove a class (and all data in the instances) from the schema.
99
+ client.schema.delete(class_name: 'Question')
100
+
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(
103
+ class_name: 'Question',
104
+ description: 'Information from a Jeopardy! question',
105
+ properties: [
106
+ {
107
+ "dataType": ["text"],
108
+ "description": "The question",
109
+ "name": "question"
110
+ # By default all properties are included in the vector
111
+ }, {
112
+ "dataType": ["text"],
113
+ "description": "The answer",
114
+ "name": "answer",
115
+ "moduleConfig": {
116
+ "text2vec-ollama": {
117
+ "skip": false,
118
+ "vectorizePropertyName": true,
119
+ },
120
+ },
121
+ }, {
122
+ "dataType": ["text"],
123
+ "description": "The category",
124
+ "name": "category",
125
+ "indexFilterable": true,
126
+ "indexSearchable": false,
127
+ "moduleConfig": {
128
+ "text2vec-ollama": {
129
+ "skip": true, # Don't include in the vector
130
+ },
131
+ },
132
+ }
133
+ ],
134
+ vectorizer: "text2vec-ollama",
135
+ module_config: {
136
+ "text2vec-ollama": {
137
+ apiEndpoint: "http://localhost:11434",
138
+ model: "mxbai-embed-large",
139
+ },
140
+ },
141
+ )
97
142
  ```
98
143
 
99
144
  ### Using the Objects endpoint
@@ -296,6 +341,30 @@ client.live?
296
341
  client.ready?
297
342
  ```
298
343
 
344
+ ### Tenants
345
+
346
+ Any schema can be multi-tenant
347
+
348
+ ```ruby
349
+ client.schema.create(
350
+ # Other keys...
351
+ mutli_tenant: true, # passes { enabled: true } to weaviate
352
+ )
353
+ ```
354
+
355
+ You can also manually specify your multi tenancy configuration with a hash
356
+
357
+ ```ruby
358
+ client.schema.create(
359
+ # Other keys...
360
+ mutli_tenant: { enabled: true, autoTenantCreation: true, autoTenantActivation: true },
361
+ )
362
+ ```
363
+
364
+ 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.
365
+
366
+ All data methods in this library support an optional `tenant` argument which must be passed if multi-tenancy is enabled on the related collection
367
+
299
368
  ## Development
300
369
 
301
370
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -10,6 +10,7 @@ module Weaviate
10
10
  API_VERSION = "v1"
11
11
 
12
12
  API_KEY_HEADERS = {
13
+ ollama: "X-Ollama-Not-Used",
13
14
  openai: "X-OpenAI-Api-Key",
14
15
  azure_openai: "X-Azure-Api-Key",
15
16
  cohere: "X-Cohere-Api-Key",
@@ -61,13 +61,15 @@ module Weaviate
61
61
  # Batch create objects
62
62
  def batch_create(
63
63
  objects:,
64
- consistency_level: nil
64
+ consistency_level: nil,
65
+ tenant: nil
65
66
  )
66
67
  validate_consistency_level!(consistency_level) unless consistency_level.nil?
67
68
 
68
69
  response = client.connection.post("batch/#{PATH}") do |req|
69
70
  req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
70
71
  req.body = {objects: objects}
72
+ req.body["tenant"] = tenant unless tenant.nil?
71
73
  end
72
74
 
73
75
  response.body
@@ -78,12 +80,14 @@ module Weaviate
78
80
  class_name:,
79
81
  id:,
80
82
  include: nil,
81
- consistency_level: nil
83
+ consistency_level: nil,
84
+ tenant: nil
82
85
  )
83
86
  validate_consistency_level!(consistency_level) unless consistency_level.nil?
84
87
 
85
88
  response = client.connection.get("#{PATH}/#{class_name}/#{id}") do |req|
86
89
  req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
90
+ req.params["tenant"] = tenant unless tenant.nil?
87
91
  req.params["include"] = include unless include.nil?
88
92
  end
89
93
 
@@ -94,12 +98,14 @@ module Weaviate
94
98
  def exists?(
95
99
  class_name:,
96
100
  id:,
97
- consistency_level: nil
101
+ consistency_level: nil,
102
+ tenant: nil
98
103
  )
99
104
  validate_consistency_level!(consistency_level) unless consistency_level.nil?
100
105
 
101
106
  response = client.connection.head("#{PATH}/#{class_name}/#{id}") do |req|
102
107
  req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
108
+ req.params["tenant"] = tenant unless tenant.nil?
103
109
  end
104
110
 
105
111
  response.status == 204
@@ -111,6 +117,7 @@ module Weaviate
111
117
  id:,
112
118
  properties:,
113
119
  vector: nil,
120
+ tenant: nil,
114
121
  consistency_level: nil
115
122
  )
116
123
  validate_consistency_level!(consistency_level) unless consistency_level.nil?
@@ -123,6 +130,7 @@ module Weaviate
123
130
  req.body["class"] = class_name
124
131
  req.body["properties"] = properties
125
132
  req.body["vector"] = vector unless vector.nil?
133
+ req.body["tenant"] = tenant unless tenant.nil?
126
134
  end
127
135
 
128
136
  response.body
@@ -132,12 +140,14 @@ module Weaviate
132
140
  def delete(
133
141
  class_name:,
134
142
  id:,
135
- consistency_level: nil
143
+ consistency_level: nil,
144
+ tenant: nil
136
145
  )
137
146
  validate_consistency_level!(consistency_level) unless consistency_level.nil?
138
147
 
139
148
  response = client.connection.delete("#{PATH}/#{class_name}/#{id}") do |req|
140
149
  req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
150
+ req.params["tenant"] = tenant unless tenant.nil?
141
151
  end
142
152
 
143
153
  if response.success?
@@ -152,14 +162,13 @@ module Weaviate
152
162
  where:,
153
163
  consistency_level: nil,
154
164
  output: nil,
155
- dry_run: nil
165
+ dry_run: nil,
166
+ tenant: nil
156
167
  )
157
168
  path = "batch/#{PATH}"
158
169
 
159
170
  unless consistency_level.nil?
160
171
  validate_consistency_level!(consistency_level)
161
-
162
- path << "?consistency_level=#{consistency_level.to_s.upcase}"
163
172
  end
164
173
 
165
174
  response = client.connection.delete(path) do |req|
@@ -171,6 +180,8 @@ module Weaviate
171
180
  }
172
181
  req.body["output"] = output unless output.nil?
173
182
  req.body["dryRun"] = dry_run unless dry_run.nil?
183
+ req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
184
+ req.params["tenant"] = tenant unless tenant.nil?
174
185
  end
175
186
 
176
187
  response.body
@@ -48,6 +48,7 @@ module Weaviate
48
48
  def aggs(
49
49
  class_name:,
50
50
  fields: nil,
51
+ tenant: nil,
51
52
  where: nil,
52
53
  object_limit: nil,
53
54
  near_text: nil,
@@ -59,6 +60,7 @@ module Weaviate
59
60
  response = client.graphql.execute(
60
61
  aggs_query(
61
62
  class_name: class_name,
63
+ tenant: tenant,
62
64
  fields: fields,
63
65
  where: where,
64
66
  near_text: near_text,
@@ -164,7 +166,7 @@ module Weaviate
164
166
  limit: $limit,
165
167
  offset: $offset,
166
168
  #{(!autocut.nil?) ? "autocut: #{autocut}" : ""},
167
- #{(!tenant.nil?) ? "tenant: #{tenant}" : ""},
169
+ #{(!tenant.nil?) ? "tenant: \"#{tenant}\"" : ""},
168
170
  #{(!near_text.nil?) ? "nearText: #{near_text}" : ""},
169
171
  #{(!near_vector.nil?) ? "nearVector: #{near_vector}" : ""},
170
172
  #{(!near_image.nil?) ? "nearImage: #{near_image}" : ""},
@@ -185,6 +187,7 @@ module Weaviate
185
187
  def aggs_query(
186
188
  class_name:,
187
189
  fields:,
190
+ tenant: nil,
188
191
  where: nil,
189
192
  near_text: nil,
190
193
  near_vector: nil,
@@ -200,6 +203,7 @@ module Weaviate
200
203
  #{class_name}(
201
204
  objectLimit: $object_limit,
202
205
  groupBy: $group_by,
206
+ #{(!tenant.nil?) ? "tenant: \"#{tenant}\"" : ""},
203
207
  #{(!near_text.nil?) ? "nearText: #{near_text}" : ""},
204
208
  #{(!near_vector.nil?) ? "nearVector: #{near_vector}" : ""},
205
209
  #{(!near_image.nil?) ? "nearImage: #{near_image}" : ""},
@@ -43,7 +43,11 @@ module Weaviate
43
43
  req.body["vectorizer"] = vectorizer unless vectorizer.nil?
44
44
  req.body["moduleConfig"] = module_config unless module_config.nil?
45
45
  req.body["properties"] = properties unless properties.nil?
46
- req.body["multiTenancyConfig"] = {enabled: true} unless multi_tenant.nil?
46
+ if multi_tenant.is_a?(Hash)
47
+ req.body["multiTenancyConfig"] = multi_tenant
48
+ elsif multi_tenant.present?
49
+ req.body["multiTenancyConfig"] = {enabled: true}
50
+ end
47
51
  req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil?
48
52
  req.body["replicationConfig"] = replication_config unless replication_config.nil?
49
53
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weaviate
4
- VERSION = "0.8.9"
4
+ VERSION = "0.8.11"
5
5
  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.8.9
4
+ version: 0.8.11
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-10-10 00:00:00.000000000 Z
11
+ date: 2024-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubygems_version: 3.2.3
141
+ rubygems_version: 3.4.1
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: Ruby wrapper for the Weaviate.io API