Class: RagRuby::Configuration
- Inherits:
-
Object
- Object
- RagRuby::Configuration
- Defined in:
- lib/rag_ruby/configuration.rb
Constant Summary collapse
- LOADER_REGISTRY =
{ file: -> { Loaders::File.new }, directory: -> { Loaders::Directory.new }, url: -> { Loaders::URL.new }, active_record: -> { Loaders::ActiveRecord.new } }.freeze
- EMBEDDER_REGISTRY =
{ openai: ->(opts) { Embedders::OpenAI.new(**opts) }, onnx: ->(opts) { Embedders::Onnx.new(**opts) }, cohere: ->(opts) { Embedders::Cohere.new(**opts) }, voyage: ->(opts) { Embedders::Voyage.new(**opts) }, ollama: ->(opts) { Embedders::Ollama.new(**opts) }, hugging_face: ->(opts) { Embedders::HuggingFace.new(**opts) } }.freeze
- STORE_REGISTRY =
{ zvec: ->(opts) { Stores::Zvec.new(**opts) }, memory: ->(opts) { Stores::Memory.new(**opts) } }.freeze
- GENERATOR_REGISTRY =
{ openai: ->(opts) { Generators::OpenAI.new(**opts) }, ruby_llm: ->(opts) { Generators::RubyLLM.new(**opts) }, anthropic: ->(opts) { Generators::Anthropic.new(**opts) }, gemini: ->(opts) { Generators::Gemini.new(**opts) }, ollama: ->(opts) { Generators::Ollama.new(**opts) } }.freeze
- AUTO_DETECT_EMBEDDER =
Maps API key env vars / prefixes to provider symbols for auto-detection
{ "VOYAGE_API_KEY" => :voyage, "COHERE_API_KEY" => :cohere, "HUGGINGFACE_API_KEY" => :hugging_face, "OPENAI_API_KEY" => :openai }.freeze
- AUTO_DETECT_GENERATOR =
{ "ANTHROPIC_API_KEY" => :anthropic, "GEMINI_API_KEY" => :gemini, "OPENAI_API_KEY" => :openai }.freeze
Instance Attribute Summary collapse
-
#chunk_overlap ⇒ Object
Returns the value of attribute chunk_overlap.
-
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
-
#chunk_strategy ⇒ Object
Returns the value of attribute chunk_strategy.
-
#embedder_instance ⇒ Object
Returns the value of attribute embedder_instance.
-
#generator_instance ⇒ Object
Returns the value of attribute generator_instance.
-
#http_timeout ⇒ Object
Returns the value of attribute http_timeout.
-
#loader_instance ⇒ Object
Returns the value of attribute loader_instance.
-
#mmr_fetch_k ⇒ Object
Returns the value of attribute mmr_fetch_k.
-
#mmr_lambda ⇒ Object
Returns the value of attribute mmr_lambda.
-
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
-
#reranker_instance ⇒ Object
Returns the value of attribute reranker_instance.
-
#retrieval_strategy ⇒ Object
Returns the value of attribute retrieval_strategy.
-
#store_instance ⇒ Object
Returns the value of attribute store_instance.
Class Method Summary collapse
-
.detect_embedder ⇒ Object
Auto-detect embedder from available API keys.
-
.detect_generator ⇒ Object
Auto-detect generator from available API keys.
Instance Method Summary collapse
- #callbacks_for(event) ⇒ Object
- #chunker(strategy, chunk_size: 1000, chunk_overlap: 200) ⇒ Object
- #embedder(name, **opts) ⇒ Object
- #generator(name, **opts) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #loader(name, **opts) ⇒ Object
- #on(event, &block) ⇒ Object
- #reranker(instance) ⇒ Object
- #retrieval(strategy, lambda: nil, fetch_k: nil) ⇒ Object
- #store(name, **opts) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rag_ruby/configuration.rb', line 54 def initialize @callbacks = Hash.new { |h, k| h[k] = [] } @chunk_size = 1000 @chunk_overlap = 200 @chunk_strategy = :recursive_character @retrieval_strategy = :similarity @mmr_lambda = 0.5 @mmr_fetch_k = 20 @http_timeout = 30 @read_timeout = 60 end |
Instance Attribute Details
#chunk_overlap ⇒ Object
Returns the value of attribute chunk_overlap.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def chunk_overlap @chunk_overlap end |
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def chunk_size @chunk_size end |
#chunk_strategy ⇒ Object
Returns the value of attribute chunk_strategy.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def chunk_strategy @chunk_strategy end |
#embedder_instance ⇒ Object
Returns the value of attribute embedder_instance.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def end |
#generator_instance ⇒ Object
Returns the value of attribute generator_instance.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def generator_instance @generator_instance end |
#http_timeout ⇒ Object
Returns the value of attribute http_timeout.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def http_timeout @http_timeout end |
#loader_instance ⇒ Object
Returns the value of attribute loader_instance.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def loader_instance @loader_instance end |
#mmr_fetch_k ⇒ Object
Returns the value of attribute mmr_fetch_k.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def mmr_fetch_k @mmr_fetch_k end |
#mmr_lambda ⇒ Object
Returns the value of attribute mmr_lambda.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def mmr_lambda @mmr_lambda end |
#read_timeout ⇒ Object
Returns the value of attribute read_timeout.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def read_timeout @read_timeout end |
#reranker_instance ⇒ Object
Returns the value of attribute reranker_instance.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def reranker_instance @reranker_instance end |
#retrieval_strategy ⇒ Object
Returns the value of attribute retrieval_strategy.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def retrieval_strategy @retrieval_strategy end |
#store_instance ⇒ Object
Returns the value of attribute store_instance.
48 49 50 |
# File 'lib/rag_ruby/configuration.rb', line 48 def store_instance @store_instance end |
Class Method Details
.detect_embedder ⇒ Object
Auto-detect embedder from available API keys
129 130 131 132 133 134 |
# File 'lib/rag_ruby/configuration.rb', line 129 def self. AUTO_DETECT_EMBEDDER.each do |env_var, provider| return provider if ENV[env_var] && !ENV[env_var].empty? end nil end |
.detect_generator ⇒ Object
Auto-detect generator from available API keys
137 138 139 140 141 142 |
# File 'lib/rag_ruby/configuration.rb', line 137 def self.detect_generator AUTO_DETECT_GENERATOR.each do |env_var, provider| return provider if ENV[env_var] && !ENV[env_var].empty? end nil end |
Instance Method Details
#callbacks_for(event) ⇒ Object
124 125 126 |
# File 'lib/rag_ruby/configuration.rb', line 124 def callbacks_for(event) @callbacks[event] end |
#chunker(strategy, chunk_size: 1000, chunk_overlap: 200) ⇒ Object
74 75 76 77 78 |
# File 'lib/rag_ruby/configuration.rb', line 74 def chunker(strategy, chunk_size: 1000, chunk_overlap: 200) @chunk_strategy = strategy @chunk_size = chunk_size @chunk_overlap = chunk_overlap end |
#embedder(name, **opts) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/rag_ruby/configuration.rb', line 80 def (name, **opts) = if EMBEDDER_REGISTRY.key?(name) EMBEDDER_REGISTRY[name].call(opts) elsif name.is_a?(Class) || name.respond_to?(:embed) name else raise ArgumentError, "Unknown embedder: #{name}" end end |
#generator(name, **opts) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/rag_ruby/configuration.rb', line 100 def generator(name, **opts) @generator_instance = if GENERATOR_REGISTRY.key?(name) GENERATOR_REGISTRY[name].call(opts) elsif name.is_a?(Class) || name.respond_to?(:generate) name else raise ArgumentError, "Unknown generator: #{name}" end end |
#loader(name, **opts) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/rag_ruby/configuration.rb', line 66 def loader(name, **opts) @loader_instance = if LOADER_REGISTRY.key?(name) LOADER_REGISTRY[name].call else raise ArgumentError, "Unknown loader: #{name}" end end |
#on(event, &block) ⇒ Object
120 121 122 |
# File 'lib/rag_ruby/configuration.rb', line 120 def on(event, &block) @callbacks[event] << block end |
#reranker(instance) ⇒ Object
110 111 112 |
# File 'lib/rag_ruby/configuration.rb', line 110 def reranker(instance) @reranker_instance = instance end |
#retrieval(strategy, lambda: nil, fetch_k: nil) ⇒ Object
114 115 116 117 118 |
# File 'lib/rag_ruby/configuration.rb', line 114 def retrieval(strategy, lambda: nil, fetch_k: nil) @retrieval_strategy = strategy @mmr_lambda = lambda if lambda @mmr_fetch_k = fetch_k if fetch_k end |
#store(name, **opts) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/rag_ruby/configuration.rb', line 90 def store(name, **opts) @store_instance = if STORE_REGISTRY.key?(name) STORE_REGISTRY[name].call(opts) elsif name.is_a?(Class) || name.respond_to?(:search) name else raise ArgumentError, "Unknown store: #{name}" end end |