lib/ollama/documents.rb in ollama-ruby-0.6.0 vs lib/ollama/documents.rb in ollama-ruby-0.7.0

- old
+ new

@@ -23,11 +23,11 @@ my_tags.empty? or my_tags = " #{my_tags}" "#<#{self.class} #{text.inspect}#{my_tags} #{similarity || 'n/a'}>" end def tags_set - Ollama::Utils::Tags.new(tags) + Ollama::Utils::Tags.new(tags, source:) end def ==(other) text == other.text end @@ -55,12 +55,14 @@ @cache.prefix = prefix end def add(inputs, batch_size: 10, source: nil, tags: []) inputs = Array(inputs) - tags = Ollama::Utils::Tags.new(tags) - source and tags.add File.basename(source).gsub(/\?.*/, '') + tags = Ollama::Utils::Tags.new(tags, source:) + if source + tags.add(File.basename(source).gsub(/\?.*/, ''), source:) + end inputs.map! { |i| text = i.respond_to?(:read) ? i.read : i.to_s text } inputs.reject! { |i| exist?(i) } @@ -68,11 +70,11 @@ if @debug puts Ollama::Utils::ColorizeTexts.new(inputs) end batches = inputs.each_slice(batch_size). with_infobar( - label: "Add #{truncate(tags.to_s, percentage: 25)}", + label: "Add #{truncate(tags.to_s(link: false), percentage: 25)}", total: inputs.size ) batches.each do |batch| embeddings = fetch_embeddings(model:, options: @model_options, input: batch) batch.zip(embeddings) do |text, embedding| @@ -157,10 +159,14 @@ def collections ([ default_collection ] + @cache.collections('%s-' % self.class)).uniq end def tags - @cache.inject(Ollama::Utils::Tags.new) { |t, (_, record)| t.merge(record.tags) } + @cache.each_with_object(Ollama::Utils::Tags.new) do |(_, record), t| + record.tags.each do |tag| + t.add(tag, source: record.source) + end + end end private def connect_cache(cache_class)