weaviate-ruby 0.2.0 → 0.3.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: 52fb7ba7147345178fa220aa2bbed2ce66a7903a4df42b8cf5a016ddd329ff3f
4
+ data.tar.gz: c03e3a537651f2c9e5beb4febdf826f22eadbce6cc1c96ed983b8e0311140604
5
5
  SHA512:
6
- metadata.gz: d1961b6e0123e21b60414b53055807ce83305a241c01b74747240cb0022e42483e2a2c2bb9305d2e35630ea2ab28517c311fa094de927c19246f199f91598ce4
7
- data.tar.gz: 68ceaf84cded37b443cd7cf8879d5b947352b7be718f2b5a041571eacc584cfddfffd04f94f3b3daa6d1b712f842ac27a4ae105edb2711ebaef28a7cfe73541a
6
+ metadata.gz: f53cf142fa41ce9236e865c251c8e183669b0c3fea0b8b3fe0720a8e9b30dedfd0e37fea888a86b75e9e3d8c5a7118592e5d4b14b1dcfc36221c85a996e332c6
7
+ data.tar.gz: a71fa15a01d2d75c51de572b2f87d231862ae442a5841a2022ef25c7b20400cc3469217c1ca6d5af42a4995d5b4393f4f33795e846361cdfb663cdf6431edeed
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.3.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,25 @@ 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
+ )
161
188
  ```
162
189
 
163
190
  ## Development
@@ -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
@@ -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.3.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.2.0
4
+ version: 0.3.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-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday