speaky 0.1.3 → 0.1.5

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: 6223b310b2223f1af3c8c2c45dc5ebe90aade3ed8cf040b9caad69a03b97e06c
4
- data.tar.gz: 77b50bfbf7925c14f78504774c7502c1018c27ef1e80bd6ebebf743310ed511a
3
+ metadata.gz: 06f3d5c76d75de0c05238c26dfc83d3707d7cc5448f83ef474249b0bd5df185b
4
+ data.tar.gz: 64cac48f6f8fcdd88512940ae3888d736f7b52890dd6cf92a7f91f6716ffee48
5
5
  SHA512:
6
- metadata.gz: cd78c665ea63fc51f7ff069e5e7eb1ee41635e9bddcdf1e5f6105762442bb5b7be12ac890742cf9d7e2d62b7aab903a12b11723b45bce6c385fc57c59a23a5eb
7
- data.tar.gz: 491775c48104c32a125934f9e8ffbd5f5960aebc357b08f135e1b78cc640409b1df5923cf0b3e0ac855c1f01ebc161f99b2981d8e6c0b886cf9c4e44e3924783
6
+ metadata.gz: 104878c920e7de1c268e727b2ff774f8a6f8c0e240be6cc5b252ee054beeb3f9ae37b36bf7f57ae5491e8d26b3af670b229304885d21f7b0bd63c3686eea5cf4
7
+ data.tar.gz: 20a27ca58c2f0184d153e5652e9a71058335a9ba1ebd1fd9281f542d95df1c38a8ac5345976f93dd9a824f89b58bdec35440eb441dbf7b443b0a7347db1ad142
data/README.md CHANGED
@@ -62,8 +62,6 @@ class MyModel < ApplicationRecord
62
62
  end
63
63
 
64
64
  # Add any callbacks that should update the model instance data in the vector store.
65
- after_create :create_for_speaky
66
- after_update :update_for_speaky
67
65
  after_save :save_for_speaky
68
66
  after_destroy :destroy_for_speaky
69
67
  end
@@ -11,9 +11,9 @@ module Speaky
11
11
  self.to_json
12
12
  end
13
13
 
14
- def create_for_speaky
14
+ def save_for_speaky
15
15
  begin
16
- Speaky.vectorstore.add(self.id, self.as_speaky)
16
+ Speaky.vectorstore.add("#{self.class.name}_#{self.id}", self.as_speaky)
17
17
  rescue StandardError => e
18
18
  Rails.logger.error(e)
19
19
  errors.add(:base, 'Failed to create for speaky')
@@ -21,34 +21,14 @@ module Speaky
21
21
  end
22
22
  end
23
23
 
24
- def update_for_speaky
25
- begin
26
- Speaky.vectorstore.update(self.id, self.as_speaky)
27
- rescue StandardError => e
28
- Rails.logger.error(e)
29
- errors.add(:base, 'Failed to update for speaky')
30
- raise ActiveRecord::Rollback
31
- end
32
- end
33
-
34
24
  def destroy_for_speaky
35
25
  begin
36
- Speaky.vectorstore.remove(self.id)
26
+ Speaky.vectorstore.remove("#{self.class.name}_#{self.id}")
37
27
  rescue StandardError => e
38
28
  Rails.logger.error(e)
39
29
  errors.add(:base, 'Failed to destroy for speaky')
40
30
  raise ActiveRecord::Rollback
41
31
  end
42
32
  end
43
-
44
- def save_for_speaky
45
- ActiveRecord::Base.transaction do
46
- if self.new_record?
47
- create_for_speaky
48
- else
49
- update_for_speaky
50
- end
51
- end
52
- end
53
33
  end
54
34
  end
@@ -17,13 +17,6 @@ module Speaky
17
17
  raise NotImplementedError
18
18
  end
19
19
 
20
- # Update a vector in the vectorstore.
21
- # NOTE: If the vector does not exist, it will be added.
22
- # Returns a boolean.
23
- def update(id, data)
24
- raise NotImplementedError
25
- end
26
-
27
20
  # Remove a vector from the vectorstore.
28
21
  # NOTE: If the vector does not exist, it will be ignored.
29
22
  # Returns a boolean.
@@ -46,10 +46,6 @@ module Speaky
46
46
  true
47
47
  end
48
48
 
49
- def update(id, data)
50
- add(id, data)
51
- end
52
-
53
49
  def remove(id)
54
50
  points_delete = @client.points.delete(
55
51
  collection_name: @config[:collection_name],
@@ -1,3 +1,3 @@
1
1
  module Speaky
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.5'
3
3
  end
data/lib/speaky.rb CHANGED
@@ -111,11 +111,11 @@ module Speaky
111
111
  Rails.application.eager_load!
112
112
  rails_models = ActiveRecord::Base.descendants
113
113
  rails_models.each do |rails_model|
114
- next unless rails_model.instance_methods.include?(:create_for_speaky)
114
+ next unless rails_model.instance_methods.include?(:save_for_speaky)
115
115
 
116
116
  rails_model.find_in_batches do |batch|
117
117
  batch.each do |record|
118
- record.create_for_speaky
118
+ record.save_for_speaky
119
119
  end
120
120
  end
121
121
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speaky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante