Module: Chromable::ClassMethods
- Defined in:
- lib/chromable.rb
Overview
Methods to be added to the model class.
Class Method Summary collapse
Instance Method Summary collapse
- #chroma_collection ⇒ Object
- #chroma_delete_collection ⇒ Object
- #chroma_query(text:, results: 10, where: {}, where_document: {}, **embedder_options) ⇒ Object
- #chromable(**options) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/chromable.rb', line 34 def self.extended(base) class << base alias_method :collection, :chroma_collection unless method_defined? :collection alias_method :delete_collection, :chroma_delete_collection unless method_defined? :delete_collection alias_method :query, :chroma_query unless method_defined? :query end base.cattr_accessor :chromable_settings end |
Instance Method Details
#chroma_collection ⇒ Object
50 51 52 |
# File 'lib/chromable.rb', line 50 def chroma_collection Chroma::Resources::Collection.get_or_create(chromable_settings.collection_name) end |
#chroma_delete_collection ⇒ Object
54 55 56 57 58 |
# File 'lib/chromable.rb', line 54 def chroma_delete_collection Chroma::Resources::Collection.delete(chromable_settings.collection_name) rescue Chroma::InvalidRequestError Chroma::Util.log_debug("Collection #{chromable_settings.collection_name} does not exist.") end |
#chroma_query(text:, results: 10, where: {}, where_document: {}, **embedder_options) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/chromable.rb', line 60 def chroma_query(text:, results: 10, where: {}, where_document: {}, **) find(chroma_collection.query( query_embeddings: [send(chromable_settings., text, **)], results: results, where: where, where_document: where_document ).map(&:id)) end |