lib/ollama/documents.rb in ollama-ruby-0.4.0 vs lib/ollama/documents.rb in ollama-ruby-0.5.0

- old
+ new

@@ -33,20 +33,23 @@ end alias inspect to_s end - def initialize(ollama:, model:, model_options: nil, collection: default_collection, cache: MemoryCache, redis_url: nil) - @ollama, @model, @model_options, @collection = ollama, model, model_options, collection.to_sym - @cache, @redis_url = connect_cache(cache), redis_url + def initialize(ollama:, model:, model_options: nil, collection: nil, cache: MemoryCache, redis_url: nil) + collection ||= default_collection + @ollama, @model, @model_options, @collection = + ollama, model, model_options, collection.to_sym + @redis_url = redis_url + @cache = connect_cache(cache) end def default_collection :default end - attr_reader :ollama, :model, :collection + attr_reader :ollama, :model, :collection, :cache def collection=(new_collection) @collection = new_collection.to_sym @cache.prefix = prefix end @@ -159,10 +162,10 @@ def connect_cache(cache_class) cache = nil if cache_class.instance_method(:redis) begin - cache = cache_class.new(prefix:) + cache = cache_class.new(prefix:, url: @redis_url, object_class: Record) cache.size rescue Redis::CannotConnectError STDERR.puts( "Cannot connect to redis URL #{@redis_url.inspect}, "\ "falling back to MemoryCache."