Class: Leann::Configuration
- Inherits:
-
Object
- Object
- Leann::Configuration
- Defined in:
- lib/leann/configuration.rb
Overview
Global configuration for Leann
Instance Attribute Summary collapse
-
#chunk_overlap ⇒ Integer
Default chunk overlap.
-
#chunk_size ⇒ Integer
Default chunk size for text splitting.
-
#default_embedding_model ⇒ String
Default embedding model.
-
#embedding_provider ⇒ Symbol
Embedding provider (:ruby_llm, :openai, :ollama, :fastembed) Defaults to :ruby_llm if RubyLLM gem is available, otherwise :openai.
-
#hnsw_ef_construction ⇒ Integer
HNSW ef_construction parameter.
-
#hnsw_m ⇒ Integer
HNSW M parameter (graph connectivity).
-
#index_directory ⇒ String
Index storage directory.
-
#ollama_host ⇒ String
Ollama host URL.
-
#openai_api_key ⇒ String?
OpenAI API key (only needed if not using RubyLLM).
-
#openai_base_url ⇒ String?
OpenAI base URL (for custom endpoints).
Instance Method Summary collapse
-
#embedding_model_for(provider) ⇒ String?
Get embedding model for a provider.
-
#fastembed_available? ⇒ Boolean
Check if FastEmbed gem is available.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#ruby_llm_available? ⇒ Boolean
Check if RubyLLM gem is available.
-
#validate! ⇒ Object
Validate configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/leann/configuration.rb', line 61 def initialize # Default to RubyLLM if available, otherwise OpenAI @embedding_provider = ruby_llm_available? ? :ruby_llm : :openai @openai_api_key = ENV["OPENAI_API_KEY"] @openai_base_url = ENV["OPENAI_BASE_URL"] @ollama_host = ENV.fetch("OLLAMA_HOST", "http://localhost:11434") @default_embedding_model = nil # Let provider choose default @index_directory = ".leann" @hnsw_m = 32 @hnsw_ef_construction = 200 @chunk_size = 512 @chunk_overlap = 64 end |
Instance Attribute Details
#chunk_overlap ⇒ Integer
Default chunk overlap
59 60 61 |
# File 'lib/leann/configuration.rb', line 59 def chunk_overlap @chunk_overlap end |
#chunk_size ⇒ Integer
Default chunk size for text splitting
55 56 57 |
# File 'lib/leann/configuration.rb', line 55 def chunk_size @chunk_size end |
#default_embedding_model ⇒ String
Default embedding model
39 40 41 |
# File 'lib/leann/configuration.rb', line 39 def @default_embedding_model end |
#embedding_provider ⇒ Symbol
Embedding provider (:ruby_llm, :openai, :ollama, :fastembed) Defaults to :ruby_llm if RubyLLM gem is available, otherwise :openai
23 24 25 |
# File 'lib/leann/configuration.rb', line 23 def @embedding_provider end |
#hnsw_ef_construction ⇒ Integer
HNSW ef_construction parameter
51 52 53 |
# File 'lib/leann/configuration.rb', line 51 def hnsw_ef_construction @hnsw_ef_construction end |
#hnsw_m ⇒ Integer
HNSW M parameter (graph connectivity)
47 48 49 |
# File 'lib/leann/configuration.rb', line 47 def hnsw_m @hnsw_m end |
#index_directory ⇒ String
Index storage directory
43 44 45 |
# File 'lib/leann/configuration.rb', line 43 def index_directory @index_directory end |
#ollama_host ⇒ String
Ollama host URL
35 36 37 |
# File 'lib/leann/configuration.rb', line 35 def ollama_host @ollama_host end |
#openai_api_key ⇒ String?
OpenAI API key (only needed if not using RubyLLM)
27 28 29 |
# File 'lib/leann/configuration.rb', line 27 def openai_api_key @openai_api_key end |
#openai_base_url ⇒ String?
OpenAI base URL (for custom endpoints)
31 32 33 |
# File 'lib/leann/configuration.rb', line 31 def openai_base_url @openai_base_url end |
Instance Method Details
#embedding_model_for(provider) ⇒ String?
Get embedding model for a provider
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/leann/configuration.rb', line 115 def (provider) # Return custom model if explicitly set return @default_embedding_model if @custom_embedding_model # Provider-specific defaults case provider when :ruby_llm nil # RubyLLM uses its own configured default when :openai "text-embedding-3-small" when :ollama "nomic-embed-text" when :fastembed "BAAI/bge-small-en-v1.5" else @default_embedding_model end end |
#fastembed_available? ⇒ Boolean
Check if FastEmbed gem is available
86 87 88 |
# File 'lib/leann/configuration.rb', line 86 def defined?(::Fastembed) || gem_available?("fastembed") end |
#ruby_llm_available? ⇒ Boolean
Check if RubyLLM gem is available
80 81 82 |
# File 'lib/leann/configuration.rb', line 80 def ruby_llm_available? defined?(::RubyLLM) || gem_available?("ruby_llm") end |
#validate! ⇒ Object
Validate configuration
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/leann/configuration.rb', line 92 def validate! case when :ruby_llm unless ruby_llm_available? raise ConfigurationError, "RubyLLM gem is required. Add 'ruby_llm' to your Gemfile." end when :openai raise ConfigurationError, "OpenAI API key is required" if openai_api_key.nil? || openai_api_key.empty? when :ollama # Ollama doesn't require API key, just needs to be running when :fastembed unless raise ConfigurationError, "FastEmbed gem is required. Add 'fastembed' to your Gemfile." end else raise ConfigurationError, "Unknown embedding provider: #{}" end true end |