weaviate_record 0.0.3 → 0.1.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: af84dff0fba26b232fd8b537749ff5742f5bcc0197656cc647e8b6791a55bd85
4
- data.tar.gz: 9534adbc21943b257d0e8f0a517721dd17bb93a1d1e3c14f284e11f30499f1f9
3
+ metadata.gz: b8e3a3dbf676df52348c83eb5a472516ca992c7ea956127d6a7ba81ee8fdb311
4
+ data.tar.gz: 35cf2a6a0369e9e6370e0bbb245c0ada8aa5e82d3f5dcd4c504d65295eacb9ac
5
5
  SHA512:
6
- metadata.gz: e7d0fda549172607928d6e943426f5091d481d4cbcd4c44bb767a32ef667769091238125f79926c1070358dc1095a191e52af70d20ea915b17acbf4eeac51beb
7
- data.tar.gz: dde3def3b42f332182c8d7f8cc115a1516f177be5abedbd516713e00474f9c1b7b9935da51ef134d9010b773df8acb95d2f867a4be043765edef53308e97b201
6
+ metadata.gz: 1aefd604f54db251167b59e76d2f1542178cbb4e857b7a9b476b89b7d0e503103cd3f4e60777c8b20a9631e0411301d93e052e63d483d536f04faaf3be0a0233
7
+ data.tar.gz: 2c2fae434083f2cef4a96618e929b73f1392912e80e81a4567329b108496b1fbf528869dde504936f994db9da3da1b198f6e9c08af085cf1ad51bb35cbde6f30
@@ -22,32 +22,46 @@ module WeaviateRecord
22
22
  # Returns the present schema of the Weaviate database.
23
23
  def schema_list
24
24
  client.schema.list.deep_symbolize_keys!
25
+ rescue Faraday::ConnectionFailed => e
26
+ raise WeaviateRecord::Errors::DatabaseNotConnected, e.message, cause: nil
25
27
  end
26
28
 
27
29
  # :enddoc:
28
30
 
29
31
  def find_call(id)
30
32
  client.objects.get(class_name: @collection_name, id: id)
33
+ rescue Faraday::ConnectionFailed => e
34
+ raise WeaviateRecord::Errors::DatabaseNotConnected, e.message, cause: nil
31
35
  end
32
36
 
33
37
  def create_call(properties)
34
38
  client.objects.create(class_name: @collection_name, properties: properties)
39
+ rescue Faraday::ConnectionFailed => e
40
+ raise WeaviateRecord::Errors::DatabaseNotConnected, e.message, cause: nil
35
41
  end
36
42
 
37
43
  def update_call(id, properties)
38
44
  client.objects.update(class_name: @collection_name, id: id, properties: properties)
45
+ rescue Faraday::ConnectionFailed => e
46
+ raise WeaviateRecord::Errors::DatabaseNotConnected, e.message, cause: nil
39
47
  end
40
48
 
41
49
  def delete_call(id)
42
50
  client.objects.delete(class_name: @collection_name, id: id)
51
+ rescue Faraday::ConnectionFailed => e
52
+ raise WeaviateRecord::Errors::DatabaseNotConnected, e.message, cause: nil
43
53
  end
44
54
 
45
55
  def check_existence(id)
46
56
  client.objects.exists?(class_name: @collection_name, id: id)
57
+ rescue Faraday::ConnectionFailed => e
58
+ raise WeaviateRecord::Errors::DatabaseNotConnected, e.message, cause: nil
47
59
  end
48
60
 
49
61
  def delete_where(condition)
50
62
  client.objects.batch_delete(class_name: @collection_name, where: condition)
63
+ rescue Faraday::ConnectionFailed => e
64
+ raise WeaviateRecord::Errors::DatabaseNotConnected, e.message, cause: nil
51
65
  end
52
66
  end
53
67
  end
@@ -65,5 +65,9 @@ module WeaviateRecord # :nodoc: all
65
65
  # Raised when required argument is empty
66
66
  class EmptyPrompt < StandardError
67
67
  end
68
+
69
+ # Raised when the weaviate database is not connected
70
+ class DatabaseNotConnected < StandardError
71
+ end
68
72
  end
69
73
  end
@@ -6,7 +6,7 @@ module WeaviateRecord
6
6
  module Order
7
7
  # Sort the records based on the given attributes.
8
8
  # You can pass multiple attributes to sort the records.
9
- # This sorting specification will be ignored if you are performing keyword (bm25) search.
9
+ # This sorting specification will be ignored if you are performing +bm25+ search.
10
10
  #
11
11
  # ==== Example:
12
12
  # Article.order(:title)
@@ -88,12 +88,21 @@ module WeaviateRecord
88
88
  def create_query_condition(equation)
89
89
  return null_condition(equation[0]) if equation[2].nil?
90
90
 
91
+ validate_attribute!(equation[0])
91
92
  handle_timestamps_condition(equation)
92
93
  "{ path: [\"#{equation[0]}\"], " \
93
94
  "operator: #{map_operator(equation[1])}, " \
94
95
  "#{map_value_type(equation[2])}: #{equation[2].inspect} }"
95
96
  end
96
97
 
98
+ def validate_attribute!(attribute)
99
+ unless ['id', 'created_at', 'updated_at',
100
+ *WeaviateRecord::Schema.find_collection(@klass).attributes_list].include?(attribute)
101
+ raise WeaviateRecord::Errors::InvalidAttributeError,
102
+ "Invalid attribute #{attribute} used for collection #{@klass}"
103
+ end
104
+ end
105
+
97
106
  def handle_timestamps_condition(equation_array)
98
107
  return nil unless equation_array[0] == 'created_at' || equation_array[0] == 'updated_at'
99
108
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weaviate_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sriram V
@@ -53,8 +53,8 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.4'
55
55
  description: An ORM for Weaviate vector database that follows the same conventions
56
- as the ActiveRecord. This gem uses weaviate-ruby internally to connect with weaviate
57
- database.
56
+ as the ActiveRecord. Bring the power of Vector database and Retrieval augmented
57
+ generation (RAG) to your Ruby application.
58
58
  email: srira.venkat@gmail.com
59
59
  executables: []
60
60
  extensions: []