Module: Chromable::InstanceMethods
- Defined in:
- lib/chromable.rb
Overview
Methods to be added to the model instances.
Class Method Summary collapse
Instance Method Summary collapse
- #chroma_destroy_embedding ⇒ Object
- #chroma_embedding ⇒ Object
- #chroma_neighbors(results: 10, where: {}, where_document: {}) ⇒ Object
- #chroma_upsert_embedding ⇒ Object
Class Method Details
.included(base) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/chromable.rb', line 72 def self.included(base) base.instance_eval do # rubocop:disable Style/Alias alias_method :embedding, :chroma_embedding unless method_defined? :embedding alias_method :upsert_embedding, :chroma_upsert_embedding unless method_defined? :upsert_embedding alias_method :destroy_embedding, :chroma_destroy_embedding unless method_defined? :destroy_embedding alias_method :neighbors, :chroma_neighbors unless method_defined? :neighbors # rubocop:enable Style/Alias end end |
Instance Method Details
#chroma_destroy_embedding ⇒ Object
91 92 93 |
# File 'lib/chromable.rb', line 91 def self.class.chroma_collection.delete(ids: [id.to_s]) end |
#chroma_embedding ⇒ Object
83 84 85 |
# File 'lib/chromable.rb', line 83 def self.class.chroma_collection.get(ids: [id.to_s])[0] end |
#chroma_neighbors(results: 10, where: {}, where_document: {}) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/chromable.rb', line 95 def chroma_neighbors(results: 10, where: {}, where_document: {}) collection = self.class.chroma_collection = collection.get(ids: [id.to_s], include: [:embeddings])[0]. self.class.find(collection.query( query_embeddings: [], results: results, where: where, where_document: where_document ).map(&:id)) end |
#chroma_upsert_embedding ⇒ Object
87 88 89 |
# File 'lib/chromable.rb', line 87 def self.class.chroma_collection.upsert() end |