Class: SemanticCache::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/semantic_cache/configuration.rb

Constant Summary collapse

DEFAULT_MODEL_COSTS =

Cost per 1K tokens (USD)

{
  # OpenAI
  "gpt-4" => { input: 0.03, output: 0.06 },
  "gpt-4-turbo" => { input: 0.01, output: 0.03 },
  "gpt-4o" => { input: 0.005, output: 0.015 },
  "gpt-4o-mini" => { input: 0.00015, output: 0.0006 },
  "gpt-3.5-turbo" => { input: 0.0005, output: 0.0015 },
  # Anthropic
  "claude-sonnet-4-20250514" => { input: 0.003, output: 0.015 },
  "claude-3-5-haiku-20241022" => { input: 0.001, output: 0.005 },
  # Gemini
  "gemini-pro" => { input: 0.0005, output: 0.0015 },
  "gemini-1.5-pro" => { input: 0.00125, output: 0.005 },
  # Embedding (cost per 1K tokens)
  "text-embedding-3-small" => { input: 0.00002, output: 0.0 },
  "text-embedding-3-large" => { input: 0.00013, output: 0.0 }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/semantic_cache/configuration.rb', line 36

def initialize
  @similarity_threshold = 0.85
  @embedding_model = "text-embedding-3-small"
  @openai_api_key = ENV["OPENAI_API_KEY"]
  @default_ttl = nil # No expiry by default
  @store = :memory
  @store_options = {}
  @track_costs = true
  @model_costs = DEFAULT_MODEL_COSTS.dup
  @namespace = "semantic_cache"
  @embedding_timeout = 30       # seconds
  @max_cache_size = nil         # nil = unlimited
end

Instance Attribute Details

#default_ttlObject

Returns the value of attribute default_ttl.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def default_ttl
  @default_ttl
end

#embedding_modelObject

Returns the value of attribute embedding_model.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def embedding_model
  @embedding_model
end

#embedding_timeoutObject

Returns the value of attribute embedding_timeout.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def embedding_timeout
  @embedding_timeout
end

#max_cache_sizeObject

Returns the value of attribute max_cache_size.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def max_cache_size
  @max_cache_size
end

#model_costsObject

Returns the value of attribute model_costs.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def model_costs
  @model_costs
end

#namespaceObject

Returns the value of attribute namespace.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def namespace
  @namespace
end

#openai_api_keyObject

Returns the value of attribute openai_api_key.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def openai_api_key
  @openai_api_key
end

#similarity_thresholdObject

Returns the value of attribute similarity_threshold.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def similarity_threshold
  @similarity_threshold
end

#storeObject

Returns the value of attribute store.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def store
  @store
end

#store_optionsObject

Returns the value of attribute store_options.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def store_options
  @store_options
end

#track_costsObject

Returns the value of attribute track_costs.



5
6
7
# File 'lib/semantic_cache/configuration.rb', line 5

def track_costs
  @track_costs
end

Instance Method Details

#cost_for(model) ⇒ Object



50
51
52
# File 'lib/semantic_cache/configuration.rb', line 50

def cost_for(model)
  model_costs[model] || { input: 0.001, output: 0.002 }
end