weaviate-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +149 -0
- data/Rakefile +8 -0
- data/lib/weaviate/base.rb +11 -0
- data/lib/weaviate/client.rb +68 -0
- data/lib/weaviate/error.rb +6 -0
- data/lib/weaviate/meta.rb +12 -0
- data/lib/weaviate/objects.rb +112 -0
- data/lib/weaviate/oidc.rb +12 -0
- data/lib/weaviate/response/base.rb +23 -0
- data/lib/weaviate/response/class.rb +8 -0
- data/lib/weaviate/response/collection.rb +23 -0
- data/lib/weaviate/response/object.rb +8 -0
- data/lib/weaviate/schema.rb +117 -0
- data/lib/weaviate/version.rb +5 -0
- data/lib/weaviate.rb +20 -0
- data/sig/weaviate.rbs +4 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4eb276e9b3dd49bfbdfbbe59abfba8f63c3e4d9f93f1942aede595c991300626
|
4
|
+
data.tar.gz: 7ed2ed88ae192a6b7cd52bdf01fd683cae274b78f61f1a19bf2703c63adc6dad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cac32112b0c05d70ff0862c70b63567bd1688c8518617d263a3262711f5919a73e6a94eb5e0161e18a791249b89607a69a110f78caa7532088ab5329bede4d01
|
7
|
+
data.tar.gz: eb14f8b055ed26adb286d54232922d0bb883c11654b15261fc694391bc8ea36d21627d09416f6d81db8030cf956fd7c440db69bd6b33037e4a499f2f39654685
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
weaviate-ruby (0.1.0)
|
5
|
+
faraday (~> 2.7)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
byebug (11.1.3)
|
12
|
+
coderay (1.1.3)
|
13
|
+
diff-lcs (1.5.0)
|
14
|
+
faraday (2.7.4)
|
15
|
+
faraday-net_http (>= 2.0, < 3.1)
|
16
|
+
ruby2_keywords (>= 0.0.4)
|
17
|
+
faraday-net_http (3.0.2)
|
18
|
+
json (2.6.3)
|
19
|
+
language_server-protocol (3.17.0.3)
|
20
|
+
method_source (1.0.0)
|
21
|
+
parallel (1.22.1)
|
22
|
+
parser (3.2.1.1)
|
23
|
+
ast (~> 2.4.1)
|
24
|
+
pry (0.14.2)
|
25
|
+
coderay (~> 1.1)
|
26
|
+
method_source (~> 1.0)
|
27
|
+
pry-byebug (3.10.1)
|
28
|
+
byebug (~> 11.0)
|
29
|
+
pry (>= 0.13, < 0.15)
|
30
|
+
rainbow (3.1.1)
|
31
|
+
rake (13.0.6)
|
32
|
+
regexp_parser (2.7.0)
|
33
|
+
rexml (3.2.5)
|
34
|
+
rspec (3.11.0)
|
35
|
+
rspec-core (~> 3.11.0)
|
36
|
+
rspec-expectations (~> 3.11.0)
|
37
|
+
rspec-mocks (~> 3.11.0)
|
38
|
+
rspec-core (3.11.0)
|
39
|
+
rspec-support (~> 3.11.0)
|
40
|
+
rspec-expectations (3.11.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.11.0)
|
43
|
+
rspec-mocks (3.11.1)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.11.0)
|
46
|
+
rspec-support (3.11.0)
|
47
|
+
rubocop (1.48.1)
|
48
|
+
json (~> 2.3)
|
49
|
+
parallel (~> 1.10)
|
50
|
+
parser (>= 3.2.0.0)
|
51
|
+
rainbow (>= 2.2.2, < 4.0)
|
52
|
+
regexp_parser (>= 1.8, < 3.0)
|
53
|
+
rexml (>= 3.2.5, < 4.0)
|
54
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
55
|
+
ruby-progressbar (~> 1.7)
|
56
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
57
|
+
rubocop-ast (1.28.0)
|
58
|
+
parser (>= 3.2.1.0)
|
59
|
+
rubocop-performance (1.16.0)
|
60
|
+
rubocop (>= 1.7.0, < 2.0)
|
61
|
+
rubocop-ast (>= 0.4.0)
|
62
|
+
ruby-progressbar (1.13.0)
|
63
|
+
ruby2_keywords (0.0.5)
|
64
|
+
standard (1.25.3)
|
65
|
+
language_server-protocol (~> 3.17.0.2)
|
66
|
+
rubocop (~> 1.48.1)
|
67
|
+
rubocop-performance (~> 1.16.0)
|
68
|
+
unicode-display_width (2.4.2)
|
69
|
+
|
70
|
+
PLATFORMS
|
71
|
+
x86_64-darwin-19
|
72
|
+
x86_64-linux
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
pry-byebug (~> 3.9)
|
76
|
+
rake (~> 13.0)
|
77
|
+
rspec (~> 3.0)
|
78
|
+
standard (~> 1.25.0)
|
79
|
+
weaviate-ruby!
|
80
|
+
|
81
|
+
BUNDLED WITH
|
82
|
+
2.4.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Andrei Bondarev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
# Weaviate
|
2
|
+
|
3
|
+
Ruby wrapper for the Weaviate.io API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add weaviate-ruby
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install weaviate-ruby
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Instantiating the API client
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'weaviate'
|
21
|
+
|
22
|
+
client = Weaviate::Client.new(
|
23
|
+
scheme: 'https',
|
24
|
+
host: 'some-endpoint.weaviate.network', # Replace with your endpoint
|
25
|
+
model_service: :openai, # Service that will be used to generate vectors. Possible values: :openai, :cohere, :huggingface
|
26
|
+
model_service_api_key: 'xxxxxxx' # Either OpenAI, Cohere or Hugging Face API key
|
27
|
+
)
|
28
|
+
```
|
29
|
+
|
30
|
+
### Using the Schema endpoints
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# Creating a new data object class in the schema
|
34
|
+
client.schema.create(
|
35
|
+
class_name: 'Question',
|
36
|
+
description: 'Information from a Jeopardy! question',
|
37
|
+
properties: [
|
38
|
+
{
|
39
|
+
"dataType": ["text"],
|
40
|
+
"description": "The question",
|
41
|
+
"name": "question"
|
42
|
+
} ,{
|
43
|
+
"dataType": ["text"],
|
44
|
+
"description": "The answer",
|
45
|
+
"name": "answer"
|
46
|
+
}, {
|
47
|
+
"dataType": ["text"],
|
48
|
+
"description": "The category",
|
49
|
+
"name": "category"
|
50
|
+
}
|
51
|
+
]
|
52
|
+
)
|
53
|
+
|
54
|
+
# Get a single class from the schema
|
55
|
+
client.schema.get(class_name: 'Question')
|
56
|
+
|
57
|
+
# Dumps the current Weaviate schema.
|
58
|
+
response = client.schema.list()
|
59
|
+
response.data
|
60
|
+
|
61
|
+
# Remove a class (and all data in the instances) from the schema.
|
62
|
+
client.schema.delete(class_name: 'Question')
|
63
|
+
|
64
|
+
# Update settings of an existing schema class.
|
65
|
+
client.schema.update(class_name: 'Question')
|
66
|
+
|
67
|
+
# Inspect the shards of a class
|
68
|
+
client.schema.shards(class_name: 'Question')
|
69
|
+
```
|
70
|
+
|
71
|
+
### Using the Objects endpoint
|
72
|
+
```ruby
|
73
|
+
# Create a new data object.
|
74
|
+
client.objects.create(
|
75
|
+
class_name: 'Question',
|
76
|
+
properties: {
|
77
|
+
answer: '42',
|
78
|
+
question: 'What is the meaning of life?',
|
79
|
+
category: 'philosophy'
|
80
|
+
}
|
81
|
+
)
|
82
|
+
|
83
|
+
# Lists all data objects in reverse order of creation.
|
84
|
+
response = client.objects.list()
|
85
|
+
response.data
|
86
|
+
|
87
|
+
# Get a single data object.
|
88
|
+
client.objects.get(
|
89
|
+
class_name: "Question",
|
90
|
+
id: ''
|
91
|
+
)
|
92
|
+
|
93
|
+
# Check if a data object exists
|
94
|
+
client.objects.exists?(
|
95
|
+
class_name: "Question",
|
96
|
+
id: ''
|
97
|
+
)
|
98
|
+
|
99
|
+
# Delete an individual data object from Weaviate.
|
100
|
+
client.objects.delete(
|
101
|
+
class_name: "Question",
|
102
|
+
id: ""
|
103
|
+
)
|
104
|
+
|
105
|
+
# Update an individual data object based on its uuid.
|
106
|
+
client.objects.update(
|
107
|
+
class_name: "Question",
|
108
|
+
id: '',
|
109
|
+
properties: {
|
110
|
+
question: "What does 6 times 7 equal to?",
|
111
|
+
category: "math",
|
112
|
+
answer: "42"
|
113
|
+
}
|
114
|
+
)
|
115
|
+
|
116
|
+
# Batch create objects
|
117
|
+
response = client.objects.batch_create(objects: [
|
118
|
+
{
|
119
|
+
class: "Question",
|
120
|
+
properties: {
|
121
|
+
answer: "42",
|
122
|
+
question: "What is the meaning of life?",
|
123
|
+
category: "philosophy"
|
124
|
+
}
|
125
|
+
}, {
|
126
|
+
class: "Question",
|
127
|
+
properties: {
|
128
|
+
answer: "42",
|
129
|
+
question: "What does 6 times 7 equal to?",
|
130
|
+
category: "math"
|
131
|
+
}
|
132
|
+
}
|
133
|
+
])
|
134
|
+
response.data
|
135
|
+
```
|
136
|
+
|
137
|
+
## Development
|
138
|
+
|
139
|
+
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.
|
140
|
+
|
141
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
142
|
+
|
143
|
+
## Contributing
|
144
|
+
|
145
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/andreibondarev/weaviate.
|
146
|
+
|
147
|
+
## License
|
148
|
+
|
149
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
|
5
|
+
module Weaviate
|
6
|
+
class Client
|
7
|
+
attr_reader :scheme, :host, :model_service, :model_service_api_key, :adapter
|
8
|
+
|
9
|
+
API_VERSION = "v1"
|
10
|
+
|
11
|
+
API_KEY_HEADERS = {
|
12
|
+
openai: "X-OpenAI-Api-Key",
|
13
|
+
cohere: "X-Cohere-Api-Key",
|
14
|
+
huggingface: "X-HuggingFace-Api-Key"
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(
|
18
|
+
scheme:,
|
19
|
+
host:,
|
20
|
+
model_service: nil,
|
21
|
+
model_service_api_key: nil,
|
22
|
+
adapter: Faraday.default_adapter
|
23
|
+
)
|
24
|
+
validate_model_service!(model_service) unless model_service.nil?
|
25
|
+
|
26
|
+
@scheme = scheme
|
27
|
+
@host = host
|
28
|
+
@model_service = model_service
|
29
|
+
@model_service_api_key = model_service_api_key
|
30
|
+
@adapter = adapter
|
31
|
+
end
|
32
|
+
|
33
|
+
def oidc
|
34
|
+
Weaviate::OIDC.new(client: self).get
|
35
|
+
end
|
36
|
+
|
37
|
+
def schema
|
38
|
+
@schema ||= Weaviate::Schema.new(client: self)
|
39
|
+
end
|
40
|
+
|
41
|
+
def meta
|
42
|
+
@meta ||= Weaviate::Meta.new(client: self)
|
43
|
+
@meta.get
|
44
|
+
end
|
45
|
+
|
46
|
+
def objects
|
47
|
+
@objects ||= Weaviate::Objects.new(client: self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def connection
|
51
|
+
@connection ||= Faraday.new(url: "#{scheme}://#{host}/#{API_VERSION}/") do |faraday|
|
52
|
+
faraday.request :json
|
53
|
+
faraday.response :json, content_type: /\bjson$/
|
54
|
+
faraday.adapter adapter
|
55
|
+
|
56
|
+
faraday.headers[API_KEY_HEADERS[model_service]] = model_service_api_key if model_service && model_service_api_key
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def validate_model_service!(model_service)
|
63
|
+
unless API_KEY_HEADERS.key?(model_service)
|
64
|
+
raise ArgumentError, "Invalid model service: #{model_service}. Acceptable values are: #{API_KEY_HEADERS.keys.join(", ")}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Weaviate
|
4
|
+
class Objects < Base
|
5
|
+
PATH = "objects"
|
6
|
+
|
7
|
+
# Lists all data objects in reverse order of creation. The data will be returned as an array of objects.
|
8
|
+
def list(
|
9
|
+
class_name: nil,
|
10
|
+
limit: nil,
|
11
|
+
offset: nil,
|
12
|
+
after: nil,
|
13
|
+
include: nil,
|
14
|
+
sort: nil,
|
15
|
+
order: nil
|
16
|
+
)
|
17
|
+
response = client.connection.get(PATH) do |req|
|
18
|
+
req.params["class"] = class_name unless class_name.nil?
|
19
|
+
req.params["limit"] = limit unless limit.nil?
|
20
|
+
req.params["offset"] = offset unless offset.nil?
|
21
|
+
req.params["after"] = after unless after.nil?
|
22
|
+
req.params["include"] = include unless include.nil?
|
23
|
+
req.params["sort"] = sort unless sort.nil?
|
24
|
+
req.params["order"] = order unless order.nil?
|
25
|
+
end
|
26
|
+
Response::Collection.from_response(response, key: "objects", type: Response::Object)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Create a new data object. The provided meta-data and schema values are validated.
|
30
|
+
def create(
|
31
|
+
class_name:,
|
32
|
+
properties:,
|
33
|
+
id: nil,
|
34
|
+
vector: nil
|
35
|
+
)
|
36
|
+
response = client.connection.post(PATH) do |req|
|
37
|
+
req.body = {}
|
38
|
+
req.body["class"] = class_name
|
39
|
+
req.body["properties"] = properties
|
40
|
+
req.body["id"] = id unless id.nil?
|
41
|
+
req.body["vector"] = vector unless vector.nil?
|
42
|
+
end
|
43
|
+
if response.success?
|
44
|
+
Weaviate::Response::Object.new(response.body)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Batch create objects
|
49
|
+
def batch_create(objects:)
|
50
|
+
response = client.connection.post("batch/#{PATH}") do |req|
|
51
|
+
req.body = {objects: objects}
|
52
|
+
end
|
53
|
+
|
54
|
+
if response.success?
|
55
|
+
Response::Collection.from_response(response, type: Response::Object)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Get a single data object.
|
60
|
+
def get(
|
61
|
+
class_name:,
|
62
|
+
id:,
|
63
|
+
include: nil
|
64
|
+
)
|
65
|
+
# TODO: validate `include` param values
|
66
|
+
# include | query | param | string | Include additional information, such as classification info. Allowed values include: classification, vector.
|
67
|
+
|
68
|
+
response = client.connection.get("#{PATH}/#{class_name}/#{id}") do |req|
|
69
|
+
req.params["include"] = include unless include.nil?
|
70
|
+
end
|
71
|
+
|
72
|
+
if response.success?
|
73
|
+
Weaviate::Response::Object.new(response.body)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Check if a data object exists
|
78
|
+
def exists?(class_name:, id:)
|
79
|
+
response = client.connection.head("#{PATH}/#{class_name}/#{id}")
|
80
|
+
response.status == 204
|
81
|
+
end
|
82
|
+
|
83
|
+
# Update an individual data object based on its uuid.
|
84
|
+
def update(
|
85
|
+
class_name:,
|
86
|
+
id:,
|
87
|
+
properties:,
|
88
|
+
vector: nil
|
89
|
+
)
|
90
|
+
response = client.connection.put("#{PATH}/#{class_name}/#{id}") do |req|
|
91
|
+
req.body = {}
|
92
|
+
req.body["id"] = id
|
93
|
+
req.body["class"] = class_name
|
94
|
+
req.body["properties"] = properties
|
95
|
+
req.body["vector"] = vector unless vector.nil?
|
96
|
+
end
|
97
|
+
if response.success?
|
98
|
+
Weaviate::Response::Object.new(response.body)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Delete an individual data object from Weaviate.
|
103
|
+
def delete(class_name:, id:)
|
104
|
+
response = client.connection.delete("#{PATH}/#{class_name}/#{id}")
|
105
|
+
response.success? && response.body.empty?
|
106
|
+
end
|
107
|
+
|
108
|
+
# Validate a data object
|
109
|
+
# def validate
|
110
|
+
# end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
module Weaviate
|
6
|
+
module Response
|
7
|
+
class Base < OpenStruct
|
8
|
+
def initialize(attributes)
|
9
|
+
super to_ostruct(attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_ostruct(obj)
|
13
|
+
if obj.is_a?(Hash)
|
14
|
+
OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
|
15
|
+
elsif obj.is_a?(Array)
|
16
|
+
obj.map { |o| to_ostruct(o) }
|
17
|
+
else # Assumed to be a primitive value
|
18
|
+
obj
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Weaviate
|
4
|
+
module Response
|
5
|
+
class Collection
|
6
|
+
attr_reader :data, :total_results
|
7
|
+
|
8
|
+
def self.from_response(response, type:, key: nil)
|
9
|
+
body = response.body
|
10
|
+
new(
|
11
|
+
data: (key.nil? ? body : body[key]).map { |attrs| type.new(attrs) }
|
12
|
+
# TODO: Integrate and use the totalResults from the response.
|
13
|
+
# total_results: body["totalResults"]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(data:, total_results: nil)
|
18
|
+
@data = data
|
19
|
+
@total_results = total_results
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Weaviate
|
4
|
+
class Schema < Base
|
5
|
+
PATH = "schema"
|
6
|
+
|
7
|
+
# Dumps the current Weaviate schema. The result contains an array of objects.
|
8
|
+
def list
|
9
|
+
response = client.connection.get(PATH)
|
10
|
+
Response::Collection.from_response(response, key: "classes", type: Response::Class)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Get a single class from the schema
|
14
|
+
def get(class_name:)
|
15
|
+
response = client.connection.get("#{PATH}/#{class_name}")
|
16
|
+
|
17
|
+
if response.success?
|
18
|
+
Response::Class.new(response.body)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Create a new data object class in the schema.
|
23
|
+
def create(
|
24
|
+
class_name:,
|
25
|
+
description:,
|
26
|
+
properties:,
|
27
|
+
vector_index_type: nil,
|
28
|
+
vector_index_config: nil,
|
29
|
+
vectorizer: nil,
|
30
|
+
module_config: nil,
|
31
|
+
inverted_index_config: nil,
|
32
|
+
replication_config: nil
|
33
|
+
)
|
34
|
+
response = client.connection.post(PATH) do |req|
|
35
|
+
req.body = {}
|
36
|
+
req.body["class"] = class_name unless class_name.nil?
|
37
|
+
req.body["description"] = description unless description.nil?
|
38
|
+
req.body["vectorIndexType"] = vector_index_type unless vector_index_type.nil?
|
39
|
+
req.body["vectorIndexConfig"] = vector_index_config unless vector_index_config.nil?
|
40
|
+
req.body["vectorizer"] = vectorizer unless vectorizer.nil?
|
41
|
+
req.body["moduleConfig"] = module_config unless module_config.nil?
|
42
|
+
req.body["properties"] = properties unless properties.nil?
|
43
|
+
req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil?
|
44
|
+
req.body["replicationConfig"] = replication_config unless replication_config.nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
if response.success?
|
48
|
+
Response::Class.new(response.body)
|
49
|
+
else
|
50
|
+
response.body
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Remove a class (and all data in the instances) from the schema.
|
55
|
+
def delete(class_name:)
|
56
|
+
response = client.connection.delete("#{PATH}/#{class_name}")
|
57
|
+
response.success? && response.body.empty?
|
58
|
+
end
|
59
|
+
|
60
|
+
# Update settings of an existing schema class.
|
61
|
+
def update(
|
62
|
+
class_name:,
|
63
|
+
description: nil,
|
64
|
+
vector_index_type: nil,
|
65
|
+
vector_index_config: nil,
|
66
|
+
vectorizer: nil,
|
67
|
+
module_config: nil,
|
68
|
+
properties: nil,
|
69
|
+
inverted_index_config: nil,
|
70
|
+
replication_config: nil
|
71
|
+
)
|
72
|
+
response = client.connection.put("#{PATH}/#{class_name}") do |req|
|
73
|
+
req.body = {}
|
74
|
+
req.body["class"] = class_name unless class_name.nil?
|
75
|
+
req.body["description"] = description unless description.nil?
|
76
|
+
req.body["vectorIndexType"] = vector_index_type unless vector_index_type.nil?
|
77
|
+
req.body["vectorIndexConfig"] = vector_index_config unless vector_index_config.nil?
|
78
|
+
req.body["vectorizer"] = vectorizer unless vectorizer.nil?
|
79
|
+
req.body["moduleConfig"] = module_config unless module_config.nil?
|
80
|
+
req.body["properties"] = properties unless properties.nil?
|
81
|
+
req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil?
|
82
|
+
req.body["replicationConfig"] = replication_config unless replication_config.nil?
|
83
|
+
end
|
84
|
+
|
85
|
+
if response.success?
|
86
|
+
Response::Class.new(response.body)
|
87
|
+
else
|
88
|
+
response.body
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Inspect the shards of a class
|
93
|
+
def shards(class_name:)
|
94
|
+
response = client.connection.get("#{PATH}/#{class_name}/shards")
|
95
|
+
response.body if response.success?
|
96
|
+
end
|
97
|
+
|
98
|
+
# Update shard status
|
99
|
+
def update_shard_status(class_name:, shard_name:, status:)
|
100
|
+
validate_status!(status)
|
101
|
+
|
102
|
+
response = client.connection.put("#{PATH}/#{class_name}/shards/#{shard_name}") do |req|
|
103
|
+
req.body = {}
|
104
|
+
req.body["status"] = status
|
105
|
+
end
|
106
|
+
response.body if response.success?
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def validate_status!(status)
|
112
|
+
unless %w[READONLY READY].include?(status.to_s.upcase)
|
113
|
+
raise ArgumentError, 'status must be either "READONLY" or "READY"'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/lib/weaviate.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "weaviate/version"
|
4
|
+
|
5
|
+
module Weaviate
|
6
|
+
autoload :Base, "weaviate/base"
|
7
|
+
autoload :Client, "weaviate/client"
|
8
|
+
autoload :Error, "weaviate/error"
|
9
|
+
autoload :Schema, "weaviate/schema"
|
10
|
+
autoload :Meta, "weaviate/meta"
|
11
|
+
autoload :Objects, "weaviate/objects"
|
12
|
+
autoload :OIDC, "weaviate/oidc"
|
13
|
+
|
14
|
+
module Response
|
15
|
+
autoload :Base, "weaviate/response/base"
|
16
|
+
autoload :Object, "weaviate/response/object"
|
17
|
+
autoload :Class, "weaviate/response/class"
|
18
|
+
autoload :Collection, "weaviate/response/collection"
|
19
|
+
end
|
20
|
+
end
|
data/sig/weaviate.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: weaviate-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrei Bondarev
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry-byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.9'
|
41
|
+
description: Ruby wrapper for the Weaviate.io API
|
42
|
+
email:
|
43
|
+
- andrei@sourcelabs.io
|
44
|
+
- andrei.bondarev13@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".rspec"
|
50
|
+
- CHANGELOG.md
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/weaviate.rb
|
57
|
+
- lib/weaviate/base.rb
|
58
|
+
- lib/weaviate/client.rb
|
59
|
+
- lib/weaviate/error.rb
|
60
|
+
- lib/weaviate/meta.rb
|
61
|
+
- lib/weaviate/objects.rb
|
62
|
+
- lib/weaviate/oidc.rb
|
63
|
+
- lib/weaviate/response/base.rb
|
64
|
+
- lib/weaviate/response/class.rb
|
65
|
+
- lib/weaviate/response/collection.rb
|
66
|
+
- lib/weaviate/response/object.rb
|
67
|
+
- lib/weaviate/schema.rb
|
68
|
+
- lib/weaviate/version.rb
|
69
|
+
- sig/weaviate.rbs
|
70
|
+
homepage: https://github.com/andreibondarev/weaviate
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata:
|
74
|
+
homepage_uri: https://github.com/andreibondarev/weaviate
|
75
|
+
source_code_uri: https://github.com/andreibondarev/weaviate
|
76
|
+
changelog_uri: https://github.com/andreibondarev/weaviate/CHANGELOG.md
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.6.0
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.2.3
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Ruby wrapper for the Weaviate.io API
|
96
|
+
test_files: []
|