Module: Zvec::ActiveRecord::Vectorize::InstanceMethods
- Defined in:
- lib/zvec/active_record.rb
Overview
Instance methods mixed into the model.
Instance Method Summary collapse
-
#zvec_embedding ⇒ Zvec::Doc?
Fetch this record's stored embedding document.
-
#zvec_remove_embedding! ⇒ void
Remove this record's embedding from the vector store.
-
#zvec_update_embedding! ⇒ void
Re-embed the configured text field and store the embedding.
Instance Method Details
#zvec_embedding ⇒ Zvec::Doc?
Fetch this record's stored embedding document.
101 102 103 104 |
# File 'lib/zvec/active_record.rb', line 101 def result = self.class.zvec_store.fetch(id.to_s) result[id.to_s] end |
#zvec_remove_embedding! ⇒ void
This method returns an undefined value.
Remove this record's embedding from the vector store.
92 93 94 95 96 |
# File 'lib/zvec/active_record.rb', line 92 def self.class.zvec_store.delete(id.to_s) rescue # Silently ignore if document doesn't exist end |
#zvec_update_embedding! ⇒ void
This method returns an undefined value.
Re-embed the configured text field and store the embedding.
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/zvec/active_record.rb', line 75 def cfg = self.class.zvec_config text = send(cfg[:field]) return if text.blank? = cfg[:embed_with] raise Zvec::Error, "No embed_with function configured" unless = .call(text) store = self.class.zvec_store store.add(id.to_s, embedding: , content: text) store.flush end |