Class: Jekyll::ClientSearch::OllamaEmbeddingAdapter
- Inherits:
-
Object
- Object
- Jekyll::ClientSearch::OllamaEmbeddingAdapter
- Defined in:
- lib/jekyll/client_search/ollama_embedding_adapter.rb
Overview
Generates embeddings via a local Ollama server using the ollama-ruby
gem. The gem is required lazily so that users who do not enable
embeddings never need to install it.
Configuration:
embedding:
enabled: true
model: all-minilm # or nomic-embed-text, bge-m3, etc.
base_url: http://localhost:11434
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#connect_timeout ⇒ Object
readonly
Returns the value of attribute connect_timeout.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
Instance Method Summary collapse
-
#embed(text) ⇒ Object
Returns a float vector for the given text.
-
#initialize(model:, base_url: "http://localhost:11434", connect_timeout: 5, read_timeout: 120) ⇒ OllamaEmbeddingAdapter
constructor
A new instance of OllamaEmbeddingAdapter.
Constructor Details
#initialize(model:, base_url: "http://localhost:11434", connect_timeout: 5, read_timeout: 120) ⇒ OllamaEmbeddingAdapter
Returns a new instance of OllamaEmbeddingAdapter.
17 18 19 20 21 22 |
# File 'lib/jekyll/client_search/ollama_embedding_adapter.rb', line 17 def initialize(model:, base_url: "http://localhost:11434", connect_timeout: 5, read_timeout: 120) @model = model @base_url = base_url @connect_timeout = connect_timeout @read_timeout = read_timeout end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
15 16 17 |
# File 'lib/jekyll/client_search/ollama_embedding_adapter.rb', line 15 def base_url @base_url end |
#connect_timeout ⇒ Object (readonly)
Returns the value of attribute connect_timeout.
15 16 17 |
# File 'lib/jekyll/client_search/ollama_embedding_adapter.rb', line 15 def connect_timeout @connect_timeout end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
15 16 17 |
# File 'lib/jekyll/client_search/ollama_embedding_adapter.rb', line 15 def model @model end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
15 16 17 |
# File 'lib/jekyll/client_search/ollama_embedding_adapter.rb', line 15 def read_timeout @read_timeout end |
Instance Method Details
#embed(text) ⇒ Object
Returns a float vector for the given text. Raises a clear error if the ollama-ruby gem is not installed or the server is unreachable.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jekyll/client_search/ollama_embedding_adapter.rb', line 26 def (text) = client.(model: @model, input: text).&.first return if () Jekyll.logger.warn "ClientSearch:", "embedding response was empty or invalid" nil rescue LoadError, NameError raise Jekyll::Errors::FatalException, "Add gem \"ollama-ruby\" to your Gemfile to use embedding features" rescue StandardError => e Jekyll.logger.warn "ClientSearch:", "embedding failed for text: #{e.}" nil end |