weaviate-ruby 0.8.10 → 0.9.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: 78db75797066d9789e8c9da6e48aeb031f71f8d47709b87b08ce5caac3b3e04b
4
- data.tar.gz: 96f9491d8ea9970cb2b2e0a1b5935b66ff63c18629055b5b08de9a9967167387
3
+ metadata.gz: df0801c83bc409a791c5a2737f0574def072660fdac96b32261b02aaa6665f33
4
+ data.tar.gz: d720fc99beed7b91b844479116caa54f6805e8807c4375e67bdffdb9a52573fe
5
5
  SHA512:
6
- metadata.gz: 621fb1ba1685ac3c934e545732184b10509dc4366089cc8d6e985dbfe49144aa82894e78281c0761857999b920b549a1ccc3da863f3a85d3843e9c2cdeef0128
7
- data.tar.gz: 17b5588cddb8ada1fd1ebe0e8bd877d74ca637a9756f686418c6a751504ef3b54369ed7c0a2ee319802d72b87329108a018ed1b5041af2103f6511438fa03170
6
+ metadata.gz: 807e7b52c259e8559c0b581c1d96a175e95bba8dff16091dd67746a41451b10b3f68c26bbc081c22c862eafeeac2c9d65a7aa12dcbbf69d5521cab8b98cc3275
7
+ data.tar.gz: 203f861b21b501deff8a787168920c3946cd28682112aa73ed3fc238a52feeb4dd6ee0a5d1eef7c28258210e88b3aca232fa63ee027fce976ab2c54ccba1e12c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.0] - 2024-07-08
4
+
5
+ - Add object.replace method which uses PUT which performs a complete object replacement
6
+
7
+ ### Breaking
8
+ - Change the object.update method to use PATCH which only performs a partial update(previously performed a replacement)
9
+
10
+ ## [0.8.11] - 2024-07-02
11
+ - Allow the user to specify any options they want for multi-tenancy when creating a schema using their own hash
12
+ - Allow Ollama vectorizer
13
+
14
+ ## [0.8.10] - 2024-01-25
15
+
16
+ ## [0.8.9] - 2023-10-10
17
+
18
+ ## [0.8.8] - 2023-10-10
19
+
20
+ ## [0.8.7] - 2023-09-11
21
+
22
+ ## [0.8.6] - 2023-08-10
23
+
3
24
  ## [0.8.5] - 2023-07-19
4
25
  - Add multi-tenancy support
5
26
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weaviate-ruby (0.8.10)
4
+ weaviate-ruby (0.9.0)
5
5
  faraday (>= 2.0.1, < 3.0)
6
6
  graphlient (~> 0.7.0)
7
7
 
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
@@ -123,14 +168,17 @@ client.objects.exists?(
123
168
  id: "uuid"
124
169
  )
125
170
 
126
- # Delete a single data object from Weaviate.
127
- client.objects.delete(
171
+ # Perform a partial update on an object based on its uuid.
172
+ client.objects.update(
128
173
  class_name: "Question",
129
- id: "uuid"
174
+ id: "uuid",
175
+ properties: {
176
+ category: "simple-math"
177
+ }
130
178
  )
131
179
 
132
- # Update a single data object based on its uuid.
133
- client.objects.update(
180
+ # Replace an object based on its uuid.
181
+ client.objects.replace(
134
182
  class_name: "Question",
135
183
  id: "uuid",
136
184
  properties: {
@@ -140,6 +188,12 @@ client.objects.update(
140
188
  }
141
189
  )
142
190
 
191
+ # Delete a single data object from Weaviate.
192
+ client.objects.delete(
193
+ class_name: "Question",
194
+ id: "uuid"
195
+ )
196
+
143
197
  # Batch create objects
144
198
  client.objects.batch_create(objects: [
145
199
  {
@@ -296,6 +350,30 @@ client.live?
296
350
  client.ready?
297
351
  ```
298
352
 
353
+ ### Tenants
354
+
355
+ Any schema can be multi-tenant
356
+
357
+ ```ruby
358
+ client.schema.create(
359
+ # Other keys...
360
+ mutli_tenant: true, # passes { enabled: true } to weaviate
361
+ )
362
+ ```
363
+
364
+ You can also manually specify your multi tenancy configuration with a hash
365
+
366
+ ```ruby
367
+ client.schema.create(
368
+ # Other keys...
369
+ mutli_tenant: { enabled: true, autoTenantCreation: true, autoTenantActivation: true },
370
+ )
371
+ ```
372
+
373
+ 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.
374
+
375
+ All data methods in this library support an optional `tenant` argument which must be passed if multi-tenancy is enabled on the related collection
376
+
299
377
  ## Development
300
378
 
301
379
  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",
@@ -122,6 +122,31 @@ module Weaviate
122
122
  )
123
123
  validate_consistency_level!(consistency_level) unless consistency_level.nil?
124
124
 
125
+ response = client.connection.patch("#{PATH}/#{class_name}/#{id}") do |req|
126
+ req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
127
+
128
+ req.body = {}
129
+ req.body["id"] = id
130
+ req.body["class"] = class_name
131
+ req.body["properties"] = properties
132
+ req.body["vector"] = vector unless vector.nil?
133
+ req.body["tenant"] = tenant unless tenant.nil?
134
+ end
135
+
136
+ response.body
137
+ end
138
+
139
+ # Replace an individual data object based on its uuid.
140
+ def replace(
141
+ class_name:,
142
+ id:,
143
+ properties:,
144
+ vector: nil,
145
+ tenant: nil,
146
+ consistency_level: nil
147
+ )
148
+ validate_consistency_level!(consistency_level) unless consistency_level.nil?
149
+
125
150
  response = client.connection.put("#{PATH}/#{class_name}/#{id}") do |req|
126
151
  req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
127
152
 
@@ -162,14 +187,13 @@ module Weaviate
162
187
  where:,
163
188
  consistency_level: nil,
164
189
  output: nil,
165
- dry_run: nil
190
+ dry_run: nil,
191
+ tenant: nil
166
192
  )
167
193
  path = "batch/#{PATH}"
168
194
 
169
195
  unless consistency_level.nil?
170
196
  validate_consistency_level!(consistency_level)
171
-
172
- path << "?consistency_level=#{consistency_level.to_s.upcase}"
173
197
  end
174
198
 
175
199
  response = client.connection.delete(path) do |req|
@@ -181,6 +205,8 @@ module Weaviate
181
205
  }
182
206
  req.body["output"] = output unless output.nil?
183
207
  req.body["dryRun"] = dry_run unless dry_run.nil?
208
+ req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
209
+ req.params["tenant"] = tenant unless tenant.nil?
184
210
  end
185
211
 
186
212
  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,
@@ -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.10"
4
+ VERSION = "0.9.0"
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.10
4
+ version: 0.9.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: 2024-01-25 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday