weaviate-ruby 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26b105dbf4536df10fd278d0aac2c437483440c87caf37ec9f6c06e34eeb690b
4
- data.tar.gz: 24b3933c80ebd659f292c0785cdd311733337d1adf21e9ea9d04da602f274d43
3
+ metadata.gz: e9f87a5670b340fe00f3634f0cf7d22b3c699b0737d3cb326d4ec7d55085cea2
4
+ data.tar.gz: 0b7fbe6084e04d5d1a006871deab4972aa965a65bd5bf8080a58f045787841fd
5
5
  SHA512:
6
- metadata.gz: d1961b6e0123e21b60414b53055807ce83305a241c01b74747240cb0022e42483e2a2c2bb9305d2e35630ea2ab28517c311fa094de927c19246f199f91598ce4
7
- data.tar.gz: 68ceaf84cded37b443cd7cf8879d5b947352b7be718f2b5a041571eacc584cfddfffd04f94f3b3daa6d1b712f842ac27a4ae105edb2711ebaef28a7cfe73541a
6
+ metadata.gz: dee8739ad9cd3bb53ae226bd4be6b041fc9af449d47ff6347088514b2db2bfc2adef35e9fc2ff2c6c431ee5f2d311e49c5f78569ff473e36b8da366a01dd9d48
7
+ data.tar.gz: 5dd898fd6c88899b119721369d0f606114cf1be480be31218adbe506954cba1b110f9eead1f135b5619e067d7328aeefd405762159912f93996f9f098b2ff62e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weaviate-ruby (0.2.0)
4
+ weaviate-ruby (0.4.0)
5
5
  faraday (~> 2.7)
6
6
  graphlient (~> 0.7.0)
7
7
 
data/README.md CHANGED
@@ -137,13 +137,21 @@ response.data
137
137
  ```
138
138
 
139
139
  ### Querying
140
+
141
+ #### Get
140
142
  ```ruby
141
- near_text = { "concepts": ["biology"] }
143
+ near_text = '{ concepts: ["biology"] }'
144
+ sort_obj = '{ path: ["category"], order: desc }'
145
+ where_obj = '{ path: ["id"], operator: Equal, valueString: "..." }'
142
146
 
143
147
  client.query.get(
144
148
  class_name: 'Question',
145
- fields: ['question', 'answer', 'category'],
146
- limit: 1,
149
+ fields: 'question answer category',
150
+ limit: "1",
151
+ offset: "1",
152
+ after: "id",
153
+ sort: sort_obj,
154
+ where_obj: where_obj,
147
155
 
148
156
  # To use this parameter you must have created your schema by setting the `vectorizer:` property to
149
157
  # either 'text2vec-transformers', 'text2vec-contextionary', 'text2vec-openai', 'multi2vec-clip', 'text2vec-huggingface' or 'text2vec-cohere'
@@ -158,6 +166,36 @@ client.query.get(
158
166
 
159
167
  # near_object: ...,
160
168
  )
169
+
170
+ # Example queries:
171
+ client.query.get class_name: 'Question', where: '{ operator: Like, valueText: "SCIENCE", path: ["category"] }', fields: 'answer question category', limit: "2"
172
+
173
+ client.query.get class_name: 'Question', fields: 'answer question category _additional { id }', after: "3c5f7039-37f3-4244-b3e2-8f4a083e448d", limit: "1"
174
+
175
+
176
+
177
+ ```
178
+
179
+ #### Aggs
180
+ ```ruby
181
+ client.query.aggs(
182
+ class_name: "Question",
183
+ fields: 'meta { count }'
184
+ group_by: ["category"],
185
+ object_limit: "10",
186
+ near_text: "{ concepts: [\"knowledge\"] }"
187
+ )
188
+ ```
189
+
190
+ #### Nodes
191
+ ```ruby
192
+ client.nodes
193
+ ```
194
+
195
+ #### Health
196
+ ```ruby
197
+ client.live?
198
+ client.ready?
161
199
  ```
162
200
 
163
201
  ## Development
@@ -44,6 +44,21 @@ module Weaviate
44
44
  @meta.get
45
45
  end
46
46
 
47
+ def nodes
48
+ @nodes ||= Weaviate::Nodes.new(client: self)
49
+ @nodes.list
50
+ end
51
+
52
+ def live?
53
+ @health ||= Weaviate::Health.new(client: self)
54
+ @health.live?
55
+ end
56
+
57
+ def ready?
58
+ @health ||= Weaviate::Health.new(client: self)
59
+ @health.ready?
60
+ end
61
+
47
62
  def objects
48
63
  @objects ||= Weaviate::Objects.new(client: self)
49
64
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weaviate
4
- class Error
4
+ class Error < StandardError
5
5
  end
6
6
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Weaviate
4
+ class Health < Base
5
+ PATH = ".well-known"
6
+
7
+ def live?
8
+ response = client.connection.get("#{PATH}/live")
9
+ response.status == 200
10
+ end
11
+
12
+ def ready?
13
+ response = client.connection.get("#{PATH}/ready")
14
+ response.status == 200
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Weaviate
4
+ class Nodes < Base
5
+ PATH = "nodes"
6
+
7
+ def list
8
+ response = client.connection.get(PATH)
9
+ response.body
10
+ end
11
+ end
12
+ end
@@ -40,8 +40,11 @@ module Weaviate
40
40
  req.body["id"] = id unless id.nil?
41
41
  req.body["vector"] = vector unless vector.nil?
42
42
  end
43
+
43
44
  if response.success?
44
45
  Weaviate::Response::Object.new(response.body)
46
+ else
47
+ response.body
45
48
  end
46
49
  end
47
50
 
@@ -5,32 +5,119 @@ module Weaviate
5
5
  def get(
6
6
  class_name:,
7
7
  fields:,
8
+ after: nil,
8
9
  limit: nil,
9
- near_text: nil
10
+ offset: nil,
11
+ sort: nil,
12
+ where: nil,
13
+ near_text: nil,
14
+ near_vector: nil,
15
+ near_object: nil
10
16
  )
11
- params = {}
12
- params["nearText"] = near_text unless near_text.nil?
13
- params["limit"] = limit unless limit.nil?
14
- # TODO implement the rest of the API params
15
-
16
- response = client.graphql.execute(get_query(class_name, params, fields), near_text: near_text)
17
+ response = client.graphql.execute(
18
+ get_query(
19
+ class_name: class_name,
20
+ fields: fields,
21
+ sort: sort,
22
+ where: where,
23
+ near_text: near_text,
24
+ near_vector: near_vector,
25
+ near_object: near_object
26
+ ),
27
+ after: after,
28
+ limit: limit,
29
+ offset: offset
30
+ )
17
31
  response.data.get.send(class_name.downcase)
32
+ rescue Graphlient::Errors::ExecutionError => error
33
+ raise Weaviate::Error.new(error.response.data.get.errors.messages.to_h)
34
+ end
35
+
36
+ def aggs(
37
+ class_name:,
38
+ fields: nil,
39
+ object_limit: nil,
40
+ near_text: nil,
41
+ near_vector: nil,
42
+ near_object: nil,
43
+ group_by: nil
44
+ )
45
+ response = client.graphql.execute(
46
+ aggs_query(
47
+ class_name: class_name,
48
+ fields: fields,
49
+ near_text: near_text,
50
+ near_vector: near_vector,
51
+ near_object: near_object
52
+ ),
53
+ group_by: group_by,
54
+ object_limit: object_limit
55
+ )
56
+ response.data.aggregate.send(class_name.downcase)
57
+ rescue Graphlient::Errors::ExecutionError => error
58
+ raise Weaviate::Error.new(error.response.data.aggregate.errors.messages.to_h)
18
59
  end
19
60
 
20
61
  private
21
62
 
22
- def get_query(class_name, params, fields)
23
- client.graphql.parse do
24
- query do
25
- Get do
26
- public_send(class_name, params) do
27
- fields.map do |field|
28
- public_send(field)
29
- end
30
- end
31
- end
32
- end
33
- end
63
+ def get_query(
64
+ class_name:,
65
+ fields:,
66
+ where: nil,
67
+ near_text: nil,
68
+ near_vector: nil,
69
+ near_object: nil,
70
+ sort: nil
71
+ )
72
+ client.graphql.parse <<~GRAPHQL
73
+ query(
74
+ $after: String,
75
+ $limit: Int,
76
+ $offset: Int,
77
+ ) {
78
+ Get {
79
+ #{class_name}(
80
+ after: $after,
81
+ limit: $limit,
82
+ offset: $offset,
83
+ #{near_text.present? ? "nearText: #{near_text}" : ""},
84
+ #{near_vector.present? ? "nearVector: #{near_vector}" : ""},
85
+ #{near_object.present? ? "nearObject: #{near_object}" : ""},
86
+ #{where.present? ? "where: #{where}" : ""},
87
+ #{sort.present? ? "sort: #{sort}" : ""}
88
+ ) {
89
+ #{fields}
90
+ }
91
+ }
92
+ }
93
+ GRAPHQL
94
+ end
95
+
96
+ def aggs_query(
97
+ class_name:,
98
+ fields:,
99
+ near_text: nil,
100
+ near_vector: nil,
101
+ near_object: nil
102
+ )
103
+ client.graphql.parse <<~GRAPHQL
104
+ query(
105
+ $group_by: [String],
106
+ $object_limit: Int,
107
+ ) {
108
+ Aggregate {
109
+ #{class_name}(
110
+ objectLimit: $object_limit,
111
+ groupBy: $group_by,
112
+ #{near_text.present? ? "nearText: #{near_text}" : ""},
113
+ #{near_vector.present? ? "nearVector: #{near_vector}" : ""},
114
+ #{near_object.present? ? "nearObject: #{near_object}" : ""}
115
+ ) {
116
+ #{fields}
117
+ }
118
+ }
119
+ }
120
+ GRAPHQL
34
121
  end
35
122
  end
36
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weaviate
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/weaviate.rb CHANGED
@@ -11,6 +11,8 @@ module Weaviate
11
11
  autoload :Objects, "weaviate/objects"
12
12
  autoload :OIDC, "weaviate/oidc"
13
13
  autoload :Query, "weaviate/query"
14
+ autoload :Nodes, "weaviate/nodes"
15
+ autoload :Health, "weaviate/health"
14
16
 
15
17
  module Response
16
18
  autoload :Base, "weaviate/response/base"
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.2.0
4
+ version: 0.4.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: 2023-03-27 00:00:00.000000000 Z
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -71,7 +71,9 @@ files:
71
71
  - lib/weaviate/base.rb
72
72
  - lib/weaviate/client.rb
73
73
  - lib/weaviate/error.rb
74
+ - lib/weaviate/health.rb
74
75
  - lib/weaviate/meta.rb
76
+ - lib/weaviate/nodes.rb
75
77
  - lib/weaviate/objects.rb
76
78
  - lib/weaviate/oidc.rb
77
79
  - lib/weaviate/query.rb