Class: RubyLLM::SemanticCache::Configuration
- Inherits:
-
Object
- Object
- RubyLLM::SemanticCache::Configuration
- Defined in:
- lib/ruby_llm/semantic_cache/configuration.rb
Constant Summary collapse
- VALID_VECTOR_STORES =
i[memory redis].freeze
- VALID_CACHE_STORES =
i[memory redis].freeze
Instance Attribute Summary collapse
-
#cache_store ⇒ Object
Cache store backend: :redis, :memory.
-
#embedding_dimensions ⇒ Object
Embedding dimensions (default: 1536 for text-embedding-3-small).
-
#embedding_model ⇒ Object
Embedding model to use (default: text-embedding-3-small).
-
#instrumentation_callback ⇒ Object
Instrumentation callback for metrics/observability Called with event_name and payload hash.
-
#max_messages ⇒ Object
Maximum conversation messages before skipping cache (excluding system messages) - Integer: skip cache after N messages (default: 1, only first message cached) - :unlimited or false: cache all messages regardless of conversation length.
-
#namespace ⇒ Object
Namespace for cache keys (useful for multi-tenant apps).
-
#redis_client ⇒ Object
Redis client instance (alternative to redis_url).
-
#redis_url ⇒ Object
Redis connection URL (if using Redis backend).
-
#similarity_threshold ⇒ Object
Similarity threshold (0.0 to 1.0) Higher = stricter matching, fewer cache hits Lower = looser matching, more cache hits but potential mismatches.
-
#ttl ⇒ Object
TTL for cached entries in seconds (nil = no expiration).
-
#vector_store ⇒ Object
Vector store backend: :redis, :memory.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #ttl_seconds ⇒ Object
-
#valid? ⇒ Boolean
Check if configuration is valid without raising.
-
#validate! ⇒ Object
Validate the configuration and raise errors for invalid settings.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 51 def initialize @vector_store = :memory @cache_store = :memory @redis_url = nil @redis_client = nil = "text-embedding-3-small" = 1536 @similarity_threshold = 0.92 @ttl = nil @namespace = "ruby_llm_semantic_cache" @instrumentation_callback = nil = 1 end |
Instance Attribute Details
#cache_store ⇒ Object
Cache store backend: :redis, :memory
17 18 19 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 17 def cache_store @cache_store end |
#embedding_dimensions ⇒ Object
Embedding dimensions (default: 1536 for text-embedding-3-small)
29 30 31 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 29 def end |
#embedding_model ⇒ Object
Embedding model to use (default: text-embedding-3-small)
26 27 28 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 26 def end |
#instrumentation_callback ⇒ Object
Instrumentation callback for metrics/observability Called with event_name and payload hash
44 45 46 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 44 def instrumentation_callback @instrumentation_callback end |
#max_messages ⇒ Object
Maximum conversation messages before skipping cache (excluding system messages)
-
Integer: skip cache after N messages (default: 1, only first message cached)
-
:unlimited or false: cache all messages regardless of conversation length
49 50 51 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 49 def end |
#namespace ⇒ Object
Namespace for cache keys (useful for multi-tenant apps)
40 41 42 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 40 def namespace @namespace end |
#redis_client ⇒ Object
Redis client instance (alternative to redis_url)
23 24 25 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 23 def redis_client @redis_client end |
#redis_url ⇒ Object
Redis connection URL (if using Redis backend)
20 21 22 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 20 def redis_url @redis_url end |
#similarity_threshold ⇒ Object
Similarity threshold (0.0 to 1.0) Higher = stricter matching, fewer cache hits Lower = looser matching, more cache hits but potential mismatches
34 35 36 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 34 def similarity_threshold @similarity_threshold end |
#ttl ⇒ Object
TTL for cached entries in seconds (nil = no expiration)
37 38 39 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 37 def ttl @ttl end |
#vector_store ⇒ Object
Vector store backend: :redis, :memory
14 15 16 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 14 def vector_store @vector_store end |
Instance Method Details
#ttl_seconds ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 65 def ttl_seconds return nil if @ttl.nil? case @ttl when Numeric then @ttl.to_i when ->(t) { t.respond_to?(:to_i) } then @ttl.to_i else nil end end |
#valid? ⇒ Boolean
Check if configuration is valid without raising
87 88 89 90 91 92 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 87 def valid? validate! true rescue ConfigurationError false end |
#validate! ⇒ Object
Validate the configuration and raise errors for invalid settings
77 78 79 80 81 82 83 |
# File 'lib/ruby_llm/semantic_cache/configuration.rb', line 77 def validate! validate_stores! validate_threshold! validate_dimensions! validate_redis_config! true end |