Class: RagRuby::Embedders::Onnx
- Defined in:
- lib/rag_ruby/embedders/onnx.rb
Instance Method Summary collapse
- #dimension ⇒ Object
- #embed(text) ⇒ Object
- #embed_batch(texts) ⇒ Object
-
#initialize(model: "all-MiniLM-L6-v2", model_path: nil) ⇒ Onnx
constructor
A new instance of Onnx.
Constructor Details
#initialize(model: "all-MiniLM-L6-v2", model_path: nil) ⇒ Onnx
Returns a new instance of Onnx.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rag_ruby/embedders/onnx.rb', line 6 def initialize(model: "all-MiniLM-L6-v2", model_path: nil) @model = model @model_path = model_path begin require "onnx_ruby" rescue LoadError raise LoadError, "onnx-ruby gem is required for ONNX embeddings. Add `gem 'onnx-ruby'` to your Gemfile." end @session = create_session end |
Instance Method Details
#dimension ⇒ Object
27 28 29 |
# File 'lib/rag_ruby/embedders/onnx.rb', line 27 def dimension 384 # all-MiniLM-L6-v2 default end |
#embed(text) ⇒ Object
19 20 21 |
# File 'lib/rag_ruby/embedders/onnx.rb', line 19 def (text) @session.(text) end |
#embed_batch(texts) ⇒ Object
23 24 25 |
# File 'lib/rag_ruby/embedders/onnx.rb', line 23 def (texts) texts.map { |t| (t) } end |