Class: Weaviate::Objects

Inherits:
Base
  • Object
show all
Defined in:
lib/weaviate/objects.rb

Constant Summary collapse

PATH =
"objects"

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Weaviate::Base

Instance Method Details

#batch_create(objects:, consistency_level: nil, tenant: nil) ⇒ Object

Batch create objects



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/weaviate/objects.rb', line 62

def batch_create(
  objects:,
  consistency_level: nil,
  tenant: nil
)
  validate_consistency_level!(consistency_level) unless consistency_level.nil?

  response = client.connection.post("batch/#{PATH}") do |req|
    req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
    req.body = {objects: objects}
    req.body["tenant"] = tenant unless tenant.nil?
  end

  response.body
end

#batch_delete(class_name:, where:, consistency_level: nil, output: nil, dry_run: nil, tenant: nil) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/weaviate/objects.rb', line 185

def batch_delete(
  class_name:,
  where:,
  consistency_level: nil,
  output: nil,
  dry_run: nil,
  tenant: nil
)
  path = "batch/#{PATH}"

  unless consistency_level.nil?
    validate_consistency_level!(consistency_level)
  end

  response = client.connection.delete(path) do |req|
    req.body = {
      match: {
        class: class_name,
        where: where
      }
    }
    req.body["output"] = output unless output.nil?
    req.body["dryRun"] = dry_run unless dry_run.nil?
    req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
    req.params["tenant"] = tenant unless tenant.nil?
  end

  response.body
end

#create(class_name:, properties:, tenant: nil, consistency_level: nil, id: nil, vector: nil) ⇒ Object

Create a new data object. The provided meta-data and schema values are validated.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/weaviate/objects.rb', line 33

def create(
  class_name:,
  properties:,
  tenant: nil,
  consistency_level: nil,
  id: nil,
  vector: nil
)
  validate_consistency_level!(consistency_level) unless consistency_level.nil?

  response = client.connection.post(PATH) do |req|
    unless consistency_level.nil?
      req.params = {
        consistency_level: consistency_level.to_s.upcase
      }
    end

    req.body = {}
    req.body["class"] = class_name
    req.body["properties"] = properties
    req.body["tenant"] = tenant unless tenant.nil?
    req.body["id"] = id unless id.nil?
    req.body["vector"] = vector unless vector.nil?
  end

  response.body
end

#delete(class_name:, id:, consistency_level: nil, tenant: nil) ⇒ Object

Delete an individual data object from Weaviate.



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/weaviate/objects.rb', line 165

def delete(
  class_name:,
  id:,
  consistency_level: nil,
  tenant: nil
)
  validate_consistency_level!(consistency_level) unless consistency_level.nil?

  response = client.connection.delete("#{PATH}/#{class_name}/#{id}") do |req|
    req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
    req.params["tenant"] = tenant unless tenant.nil?
  end

  if response.success?
    response.body.empty?
  else
    response.body
  end
end

#exists?(class_name:, id:, consistency_level: nil, tenant: nil) ⇒ Boolean

Check if a data object exists

Returns:

  • (Boolean)


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/weaviate/objects.rb', line 98

def exists?(
  class_name:,
  id:,
  consistency_level: nil,
  tenant: nil
)
  validate_consistency_level!(consistency_level) unless consistency_level.nil?

  response = client.connection.head("#{PATH}/#{class_name}/#{id}") do |req|
    req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
    req.params["tenant"] = tenant unless tenant.nil?
  end

  response.status == 204
end

#get(class_name:, id:, include: nil, consistency_level: nil, tenant: nil) ⇒ Object

Get a single data object.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/weaviate/objects.rb', line 79

def get(
  class_name:,
  id:,
  include: nil,
  consistency_level: nil,
  tenant: nil
)
  validate_consistency_level!(consistency_level) unless consistency_level.nil?

  response = client.connection.get("#{PATH}/#{class_name}/#{id}") do |req|
    req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?
    req.params["tenant"] = tenant unless tenant.nil?
    req.params["include"] = include unless include.nil?
  end

  response.body
end

#list(class_name: nil, limit: nil, tenant: nil, offset: nil, after: nil, include: nil, sort: nil, order: nil) ⇒ Object

Lists all data objects in reverse order of creation. The data will be returned as an array of objects.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/weaviate/objects.rb', line 8

def list(
  class_name: nil,
  limit: nil,
  tenant: nil,
  offset: nil,
  after: nil,
  include: nil,
  sort: nil,
  order: nil
)
  response = client.connection.get(PATH) do |req|
    req.params["class"] = class_name unless class_name.nil?
    req.params["tenant"] = tenant unless tenant.nil?
    req.params["limit"] = limit unless limit.nil?
    req.params["offset"] = offset unless offset.nil?
    req.params["after"] = after unless after.nil?
    req.params["include"] = include unless include.nil?
    req.params["sort"] = sort unless sort.nil?
    req.params["order"] = order unless order.nil?
  end

  response.body
end

#replace(class_name:, id:, properties:, vector: nil, tenant: nil, consistency_level: nil) ⇒ Object

Replace an individual data object based on its uuid.



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/weaviate/objects.rb', line 140

def replace(
  class_name:,
  id:,
  properties:,
  vector: nil,
  tenant: nil,
  consistency_level: nil
)
  validate_consistency_level!(consistency_level) unless consistency_level.nil?

  response = client.connection.put("#{PATH}/#{class_name}/#{id}") do |req|
    req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?

    req.body = {}
    req.body["id"] = id
    req.body["class"] = class_name
    req.body["properties"] = properties
    req.body["vector"] = vector unless vector.nil?
    req.body["tenant"] = tenant unless tenant.nil?
  end

  response.body
end

#update(class_name:, id:, properties:, vector: nil, tenant: nil, consistency_level: nil) ⇒ Object

Update an individual data object based on its uuid.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/weaviate/objects.rb', line 115

def update(
  class_name:,
  id:,
  properties:,
  vector: nil,
  tenant: nil,
  consistency_level: nil
)
  validate_consistency_level!(consistency_level) unless consistency_level.nil?

  response = client.connection.patch("#{PATH}/#{class_name}/#{id}") do |req|
    req.params["consistency_level"] = consistency_level.to_s.upcase unless consistency_level.nil?

    req.body = {}
    req.body["id"] = id
    req.body["class"] = class_name
    req.body["properties"] = properties
    req.body["vector"] = vector unless vector.nil?
    req.body["tenant"] = tenant unless tenant.nil?
  end

  response.body
end

#validate(class_name:, properties:, id: nil) ⇒ Object

Validate a data object



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/weaviate/objects.rb', line 216

def validate(
  class_name:,
  properties:,
  id: nil
)
  response = client.connection.post("#{PATH}/validate") do |req|
    req.body = {}
    req.body["class"] = class_name
    req.body["properties"] = properties
    req.body["id"] = id unless id.nil?
  end

  if response.success?
    response.body.empty?
  else
    response.body
  end
end