Class: Aoororachain::Embeddings::LocalPythonEmbedding
- Inherits:
-
Object
- Object
- Aoororachain::Embeddings::LocalPythonEmbedding
- Defined in:
- lib/aoororachain/embeddings/local_python_embedding.rb
Constant Summary collapse
- MODEL_INSTRUCTOR_L =
"hkunlp/instructor-large"
- MODEL_INSTRUCTOR_XL =
"hkunlp/instructor-xl"
- MODEL_ALL_MPNET =
"sentence-transformers/all-mpnet-base-v2"
Instance Method Summary collapse
- #embed_documents(documents, include_metadata: false) ⇒ Object
- #embed_query(text) ⇒ Object
- #embed_texts(texts) ⇒ Object
-
#initialize(options = {}) ⇒ LocalPythonEmbedding
constructor
A new instance of LocalPythonEmbedding.
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ LocalPythonEmbedding
Returns a new instance of LocalPythonEmbedding.
10 11 12 13 14 15 16 |
# File 'lib/aoororachain/embeddings/local_python_embedding.rb', line 10 def initialize( = {}) @model = .delete(:model) || MODEL_ALL_MPNET @device = .delete(:device) || "cpu" Aoororachain::Util.log_info("Using", data: {model: @model, device: @device}) Aoororachain::Util.log_info("This embedding calls Python code using system call.") end |
Instance Method Details
#embed_documents(documents, include_metadata: false) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/aoororachain/embeddings/local_python_embedding.rb', line 18 def (documents, include_metadata: false) texts = documents.map { |document| "#{document.content} #{include_metadata ? document.metadata.to_json : ""}.strip" } = (texts) || [] end |
#embed_query(text) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/aoororachain/embeddings/local_python_embedding.rb', line 37 def (text) return [] if text.nil? || text.strip == "" Aoororachain::Util.log_info("First time usage might take long time due to models download.") [(text)] end |
#embed_texts(texts) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/aoororachain/embeddings/local_python_embedding.rb', line 25 def (texts) return if texts.empty? Aoororachain::Util.log_info("First time usage might take long time due to models download.") texts_file_path = save_texts_to_file(texts) = (texts_file_path) = () if !.nil? || [] end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/aoororachain/embeddings/local_python_embedding.rb', line 44 def to_s "#{self.class} : #{@model} : #{@device}" end |