ollama-ruby 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,105 @@
1
+ require 'tempfile'
2
+ require 'tins/unit'
3
+ require 'infobar'
4
+ require 'mime-types'
5
+
6
+ class Ollama::Utils::Fetcher
7
+ module ContentType
8
+ attr_accessor :content_type
9
+ end
10
+
11
+ class RetryWithoutStreaming < StandardError; end
12
+
13
+ def initialize
14
+ @started = false
15
+ @streaming = true
16
+ end
17
+
18
+ def self.get(url, &block)
19
+ new.get(url, &block)
20
+ end
21
+
22
+ def get(url, &block)
23
+ response = nil
24
+ Tempfile.open do |tmp|
25
+ infobar.label = 'Getting'
26
+ if @streaming
27
+ response = Excon.get(url, headers:, response_block: callback(tmp))
28
+ response.status != 200 || !@started and raise RetryWithoutStreaming
29
+ decorate_io(tmp, response)
30
+ infobar.finish
31
+ block.(tmp)
32
+ else
33
+ response = Excon.get(url, headers:, middlewares:)
34
+ if response.status != 200
35
+ raise "invalid response status code"
36
+ end
37
+ body = response.body
38
+ tmp.print body
39
+ infobar.update(message: message(body.size, body.size), force: true)
40
+ decorate_io(tmp, response)
41
+ infobar.finish
42
+ block.(tmp)
43
+ end
44
+ end
45
+ rescue RetryWithoutStreaming
46
+ @streaming = false
47
+ retry
48
+ rescue => e
49
+ STDERR.puts "Cannot get #{url.to_s.inspect} (#{e}): #{response&.status_line}"
50
+ unless e.is_a?(RuntimeError)
51
+ STDERR.puts "#{e.backtrace * ?\n}"
52
+ end
53
+ yield nil
54
+ end
55
+
56
+ def headers
57
+ {
58
+ 'User-Agent' => Ollama::Client.user_agent,
59
+ }
60
+ end
61
+
62
+ def middlewares
63
+ (Excon.defaults[:middlewares] + [ Excon::Middleware::RedirectFollower ]).uniq
64
+ end
65
+
66
+ def decorate_io(tmp, response)
67
+ tmp.rewind
68
+ tmp.extend(ContentType)
69
+ if content_type = MIME::Types[response.headers['content-type']].first
70
+ tmp.content_type = content_type
71
+ end
72
+ end
73
+
74
+ def callback(tmp)
75
+ -> chunk, remaining_bytes, total_bytes do
76
+ total = total_bytes or next
77
+ current = total_bytes - remaining_bytes
78
+ if @started
79
+ infobar.counter.progress(by: total - current)
80
+ else
81
+ @started = true
82
+ infobar.counter.reset(total:, current:)
83
+ end
84
+ infobar.update(message: message(current, total), force: true)
85
+ tmp.print(chunk)
86
+ end
87
+ end
88
+
89
+ def message(current, total)
90
+ progress = '%s/%s' % [ current, total ].map {
91
+ Tins::Unit.format(_1, format: '%.2f %U')
92
+ }
93
+ '%l ' + progress + ' in %te, ETA %e @%E'
94
+ end
95
+
96
+ def self.read(filename, &block)
97
+ if File.exist?(filename)
98
+ File.open(filename) do |file|
99
+ file.extend(Ollama::Utils::Fetcher::ContentType)
100
+ file.content_type = MIME::Types.type_for(filename).first
101
+ block.(file)
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,48 @@
1
+ module Ollama::Utils::Math
2
+ # Returns the cosine similarity between two vectors +a+ and +b+, 1.0 is
3
+ # exactly the same, 0.0 means decorrelated.
4
+ #
5
+ # @param [Vector] a The first vector
6
+ # @param [Vector] b The second vector
7
+ # @option a_norm [Float] a The Euclidean norm of vector a (default: calculated from a)
8
+ # @option b_norm [Float] b The Euclidean norm of vector b (default: calculated from b)
9
+ #
10
+ # @return [Float] The cosine similarity between the two vectors
11
+ #
12
+ # @example Calculate the cosine similarity between two vectors
13
+ # cosine_similarity(a: [1, 2], b: [3, 4])
14
+ #
15
+ # @see #convert_to_vector
16
+ # @see #norm
17
+ def cosine_similarity(a:, b:, a_norm: norm(a), b_norm: norm(b))
18
+ a, b = convert_to_vector(a), convert_to_vector(b)
19
+ a.dot(b) / (a_norm * b_norm)
20
+ end
21
+
22
+ # Returns the Euclidean norm (magnitude) of a vector.
23
+ #
24
+ # @param vector [Array] The input vector.
25
+ #
26
+ # @return [Float] The magnitude of the vector.
27
+ #
28
+ # @example
29
+ # norm([3, 4]) # => 5.0
30
+ def norm(vector)
31
+ s = 0.0
32
+ vector.each { s += _1.abs2 }
33
+ Math.sqrt(s)
34
+ end
35
+
36
+ # Converts an array to a Numo NArray.
37
+ #
38
+ # @param [Array] vector The input array to be converted.
39
+ #
40
+ # @return [Numo::NArray] The converted NArray, or the original if it's already a Numo NArray.
41
+ #
42
+ # @example Convert an array to a Numo NArray
43
+ # convert_to_vector([1, 2, 3]) # => Numo::NArray[1, 2, 3]
44
+ def convert_to_vector(vector)
45
+ vector.is_a?(Numo::NArray) and return vector
46
+ Numo::NArray[*vector]
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ require 'sorted_set'
2
+
3
+ class Ollama::Utils::Tags < SortedSet
4
+ def to_s
5
+ map { |t| '#%s' % t } * ' '
6
+ end
7
+ end
@@ -1,6 +1,6 @@
1
1
  module Ollama
2
2
  # Ollama version
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/lib/ollama.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'excon'
2
3
 
3
4
  module Ollama
4
5
  end
@@ -8,6 +9,16 @@ module Ollama
8
9
  include Ollama::Handlers
9
10
  end
10
11
 
12
+ module Ollama::Utils
13
+ end
14
+ require 'ollama/utils/width'
15
+ require 'ollama/utils/ansi_markdown'
16
+ require 'ollama/utils/tags'
17
+ require 'ollama/utils/math'
18
+ require 'ollama/utils/colorize_texts'
19
+ require 'ollama/utils/fetcher'
20
+ require 'ollama/utils/chooser'
21
+
11
22
  require 'ollama/version'
12
23
  require 'ollama/errors'
13
24
  require 'ollama/dto'
@@ -19,11 +30,7 @@ require 'ollama/tool/function/parameters'
19
30
  require 'ollama/tool/function/parameters/property'
20
31
  require 'ollama/response'
21
32
  require 'ollama/options'
22
-
23
- module Ollama::Utils
24
- end
25
- require 'ollama/utils/width'
26
- require 'ollama/utils/ansi_markdown'
33
+ require 'ollama/documents'
27
34
 
28
35
  class Ollama::Commands
29
36
  end
data/ollama-ruby.gemspec CHANGED
@@ -1,36 +1,46 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama-ruby 0.0.1 ruby lib
2
+ # stub: ollama-ruby 0.1.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama-ruby".freeze
6
- s.version = "0.0.1".freeze
6
+ s.version = "0.1.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2024-08-16"
11
+ s.date = "2024-08-30"
12
12
  s.description = "Library that allows interacting with the Ollama API".freeze
13
13
  s.email = "flori@ping.de".freeze
14
- s.executables = ["ollama_console".freeze, "ollama_chat".freeze]
15
- s.extra_rdoc_files = ["README.md".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze]
16
- s.files = ["Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_console".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze, "ollama-ruby.gemspec".freeze, "spec/assets/kitten.jpg".freeze, "spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/spec_helper.rb".freeze]
14
+ s.executables = ["ollama_console".freeze, "ollama_chat".freeze, "ollama_update".freeze]
15
+ s.extra_rdoc_files = ["README.md".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/documents.rb".freeze, "lib/ollama/documents/memory_cache.rb".freeze, "lib/ollama/documents/redis_cache.rb".freeze, "lib/ollama/documents/splitters/character.rb".freeze, "lib/ollama/documents/splitters/semantic.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/chooser.rb".freeze, "lib/ollama/utils/colorize_texts.rb".freeze, "lib/ollama/utils/fetcher.rb".freeze, "lib/ollama/utils/math.rb".freeze, "lib/ollama/utils/tags.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze]
16
+ s.files = [".envrc".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_console".freeze, "bin/ollama_update".freeze, "config/redis.conf".freeze, "docker-compose.yml".freeze, "lib/ollama.rb".freeze, "lib/ollama/client.rb".freeze, "lib/ollama/client/command.rb".freeze, "lib/ollama/client/doc.rb".freeze, "lib/ollama/commands/chat.rb".freeze, "lib/ollama/commands/copy.rb".freeze, "lib/ollama/commands/create.rb".freeze, "lib/ollama/commands/delete.rb".freeze, "lib/ollama/commands/embed.rb".freeze, "lib/ollama/commands/embeddings.rb".freeze, "lib/ollama/commands/generate.rb".freeze, "lib/ollama/commands/ps.rb".freeze, "lib/ollama/commands/pull.rb".freeze, "lib/ollama/commands/push.rb".freeze, "lib/ollama/commands/show.rb".freeze, "lib/ollama/commands/tags.rb".freeze, "lib/ollama/documents.rb".freeze, "lib/ollama/documents/memory_cache.rb".freeze, "lib/ollama/documents/redis_cache.rb".freeze, "lib/ollama/documents/splitters/character.rb".freeze, "lib/ollama/documents/splitters/semantic.rb".freeze, "lib/ollama/dto.rb".freeze, "lib/ollama/errors.rb".freeze, "lib/ollama/handlers.rb".freeze, "lib/ollama/handlers/collector.rb".freeze, "lib/ollama/handlers/concern.rb".freeze, "lib/ollama/handlers/dump_json.rb".freeze, "lib/ollama/handlers/dump_yaml.rb".freeze, "lib/ollama/handlers/markdown.rb".freeze, "lib/ollama/handlers/nop.rb".freeze, "lib/ollama/handlers/print.rb".freeze, "lib/ollama/handlers/progress.rb".freeze, "lib/ollama/handlers/say.rb".freeze, "lib/ollama/handlers/single.rb".freeze, "lib/ollama/image.rb".freeze, "lib/ollama/message.rb".freeze, "lib/ollama/options.rb".freeze, "lib/ollama/response.rb".freeze, "lib/ollama/tool.rb".freeze, "lib/ollama/tool/function.rb".freeze, "lib/ollama/tool/function/parameters.rb".freeze, "lib/ollama/tool/function/parameters/property.rb".freeze, "lib/ollama/utils/ansi_markdown.rb".freeze, "lib/ollama/utils/chooser.rb".freeze, "lib/ollama/utils/colorize_texts.rb".freeze, "lib/ollama/utils/fetcher.rb".freeze, "lib/ollama/utils/math.rb".freeze, "lib/ollama/utils/tags.rb".freeze, "lib/ollama/utils/width.rb".freeze, "lib/ollama/version.rb".freeze, "ollama-ruby.gemspec".freeze, "spec/assets/embeddings.json".freeze, "spec/assets/kitten.jpg".freeze, "spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/documents/memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_cache_spec.rb".freeze, "spec/ollama/documents/splitters/character_spec.rb".freeze, "spec/ollama/documents/splitters/semantic_spec.rb".freeze, "spec/ollama/documents_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/spec_helper.rb".freeze]
17
17
  s.homepage = "https://github.com/flori/ollama-ruby".freeze
18
18
  s.licenses = ["MIT".freeze]
19
19
  s.rdoc_options = ["--title".freeze, "Ollama-ruby - Interacting with the Ollama API".freeze, "--main".freeze, "README.md".freeze]
20
20
  s.required_ruby_version = Gem::Requirement.new("~> 3.1".freeze)
21
21
  s.rubygems_version = "3.5.16".freeze
22
22
  s.summary = "Interacting with the Ollama API".freeze
23
- s.test_files = ["spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/spec_helper.rb".freeze]
23
+ s.test_files = ["spec/ollama/client/doc_spec.rb".freeze, "spec/ollama/client_spec.rb".freeze, "spec/ollama/commands/chat_spec.rb".freeze, "spec/ollama/commands/copy_spec.rb".freeze, "spec/ollama/commands/create_spec.rb".freeze, "spec/ollama/commands/delete_spec.rb".freeze, "spec/ollama/commands/embed_spec.rb".freeze, "spec/ollama/commands/embeddings_spec.rb".freeze, "spec/ollama/commands/generate_spec.rb".freeze, "spec/ollama/commands/ps_spec.rb".freeze, "spec/ollama/commands/pull_spec.rb".freeze, "spec/ollama/commands/push_spec.rb".freeze, "spec/ollama/commands/show_spec.rb".freeze, "spec/ollama/commands/tags_spec.rb".freeze, "spec/ollama/documents/memory_cache_spec.rb".freeze, "spec/ollama/documents/redis_cache_spec.rb".freeze, "spec/ollama/documents/splitters/character_spec.rb".freeze, "spec/ollama/documents/splitters/semantic_spec.rb".freeze, "spec/ollama/documents_spec.rb".freeze, "spec/ollama/handlers/collector_spec.rb".freeze, "spec/ollama/handlers/dump_json_spec.rb".freeze, "spec/ollama/handlers/dump_yaml_spec.rb".freeze, "spec/ollama/handlers/markdown_spec.rb".freeze, "spec/ollama/handlers/nop_spec.rb".freeze, "spec/ollama/handlers/print_spec.rb".freeze, "spec/ollama/handlers/progress_spec.rb".freeze, "spec/ollama/handlers/say_spec.rb".freeze, "spec/ollama/handlers/single_spec.rb".freeze, "spec/ollama/image_spec.rb".freeze, "spec/ollama/message_spec.rb".freeze, "spec/ollama/options_spec.rb".freeze, "spec/ollama/tool_spec.rb".freeze, "spec/ollama/utils/ansi_markdown_spec.rb".freeze, "spec/ollama/utils/fetcher_spec.rb".freeze, "spec/ollama/utils/tags_spec.rb".freeze, "spec/spec_helper.rb".freeze]
24
24
 
25
25
  s.specification_version = 4
26
26
 
27
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.16.1".freeze])
27
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.17.0".freeze])
28
28
  s.add_development_dependency(%q<all_images>.freeze, ["~> 0.4".freeze])
29
29
  s.add_development_dependency(%q<rspec>.freeze, ["~> 3.2".freeze])
30
30
  s.add_development_dependency(%q<utils>.freeze, [">= 0".freeze])
31
+ s.add_development_dependency(%q<webmock>.freeze, [">= 0".freeze])
31
32
  s.add_runtime_dependency(%q<excon>.freeze, ["~> 0.111".freeze])
32
33
  s.add_runtime_dependency(%q<infobar>.freeze, ["~> 0.7".freeze])
33
34
  s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
34
35
  s.add_runtime_dependency(%q<kramdown-parser-gfm>.freeze, ["~> 1.1".freeze])
35
36
  s.add_runtime_dependency(%q<terminal-table>.freeze, ["~> 3.0".freeze])
37
+ s.add_runtime_dependency(%q<redis>.freeze, ["~> 5.0".freeze])
38
+ s.add_runtime_dependency(%q<numo-narray>.freeze, ["~> 0.9".freeze])
39
+ s.add_runtime_dependency(%q<more_math>.freeze, ["~> 1.1".freeze])
40
+ s.add_runtime_dependency(%q<sorted_set>.freeze, ["~> 1.0".freeze])
41
+ s.add_runtime_dependency(%q<mime-types>.freeze, ["~> 3.0".freeze])
42
+ s.add_runtime_dependency(%q<reverse_markdown>.freeze, ["~> 2.0".freeze])
43
+ s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.20".freeze])
44
+ s.add_runtime_dependency(%q<search_ui>.freeze, ["~> 0.0".freeze])
45
+ s.add_runtime_dependency(%q<amatch>.freeze, ["~> 0.4.1".freeze])
36
46
  end
@@ -0,0 +1 @@
1
+ [[-0.009,-0.0,-0.035,-0.002,-0.044,-0.063,0.1,0.03,0.052,-0.06,-0.027,0.012,0.03,-0.04,-0.013,0.023,-0.028,0.015,-0.066,-0.032,0.052,0.028,0.063,0.037,-0.005,-0.024,0.006,0.008,0.014,-0.007,-0.042,-0.018,0.012,-0.061,-0.03,0.004,-0.019,0.003,0.065,0.058,0.004,-0.032,0.023,-0.016,0.03,-0.009,-0.022,-0.026,0.057,-0.013,0.002,0.004,-0.059,-0.047,0.084,0.085,0.048,-0.008,0.11,0.041,-0.018,0.071,-0.022,-0.067,0.015,-0.031,0.037,-0.034,0.032,0.121,0.063,0.003,-0.016,-0.007,0.011,0.093,0.056,-0.054,0.028,0.014,-0.008,-0.102,-0.072,-0.042,0.025,0.005,-0.005,-0.083,-0.008,0.018,-0.076,0.07,0.03,0.003,-0.029,0.021,0.016,0.036,-0.101,0.194,-0.01,-0.014,0.07,-0.004,0.001,-0.087,0.001,-0.0,0.02,0.0,-0.061,-0.108,-0.039,0.068,-0.015,0.033,0.008,0.044,0.016,-0.017,-0.034,-0.018,0.023,-0.018,-0.031,-0.068,0.021,0.0,-0.006,0.032,-0.019,0.019,-0.004,0.063,-0.018,-0.057,0.021,-0.054,-0.047,0.035,-0.113,-0.005,0.065,0.033,-0.018,0.055,-0.033,0.01,-0.095,0.008,0.008,0.053,-0.03,-0.036,0.068,-0.128,-0.011,0.034,-0.022,0.01,-0.012,0.033,-0.016,0.127,0.081,-0.028,-0.07,0.004,-0.067,0.063,-0.056,0.025,-0.014,0.094,-0.012,-0.016,0.065,0.045,0.082,0.001,-0.023,0.014,-0.04,-0.002,0.024,0.001,0.03,0.051,-0.017,-0.071,0.108,-0.028,0.004,-0.048,-0.026,0.041,-0.038,0.05,0.002,-0.027,-0.005,0.019,-0.045,-0.077,-0.16,0.021,0.05,-0.068,0.069,-0.045,0.041,-0.091,-0.024,0.025,-0.052,-0.046,0.066,-0.114,-0.002,0.004,0.063,-0.056,-0.004,0.0,0.071,0.08,0.022,-0.087,-0.02,-0.078,0.002,0.081,-0.038,-0.001,-0.072,0.003,0.014,0.005,0.022,-0.008,0.094,0.011,0.068,-0.013,-0.015,-0.046,0.055,0.013,-0.004,-0.001,-0.015,0.01,-0.014,0.013,-0.036,-0.007,-0.07,-0.061,-0.08,0.018,0.005,-0.001,-0.017,0.027,0.031,-0.023,0.001,0.167,-0.007,-0.031,0.035,0.032,-0.009,0.122,-0.037,-0.032,-0.011,0.018,-0.042,0.051,-0.002,-0.081,0.06,-0.009,0.061,0.065,-0.037,0.076,0.05,0.083,-0.026,0.034,-0.097,-0.016,0.116,0.026,-0.173,0.011,0.051,-0.055,0.013,0.045,-0.017,-0.121,-0.071,-0.025,0.075,-0.031,0.047,0.062,0.05,0.101,-0.036,-0.018,0.051,-0.072,0.004,-0.023,0.019,0.0,-0.024,0.073,0.018,-0.063,0.079,0.012,-0.076,-0.006,-0.009,0.002,-0.025,0.063,-0.011,0.104,0.004,0.025,0.009,-0.071,-0.032,-0.051,-0.096,-0.072,-0.116,-0.06,-0.035,-0.021,0.016,0.045,0.014,0.036,-0.03,0.009,-0.091,-0.045,0.02,-0.105,-0.006,0.046,-0.028,-0.116,-0.078,-0.013,0.019,0.004,-0.05,0.023,0.046,-0.03,-0.021,0.001,0.022,0.02,-0.015,0.059,0.132,0.022,-0.01,-0.003,-0.002,0.021,0.052,-0.023,0.017,0.009],[-0.009,-0.0,-0.035,-0.002,-0.044,-0.063,0.1,0.03,0.052,-0.06,-0.027,0.012,0.03,-0.04,-0.013,0.023,-0.028,0.015,-0.066,-0.032,0.052,0.028,0.063,0.037,-0.005,-0.024,0.006,0.008,0.014,-0.007,-0.042,-0.018,0.012,-0.061,-0.03,0.004,-0.019,0.003,0.065,0.058,0.004,-0.032,0.023,-0.016,0.03,-0.009,-0.022,-0.026,0.057,-0.013,0.002,0.004,-0.059,-0.047,0.084,0.085,0.048,-0.008,0.11,0.041,-0.018,0.071,-0.022,-0.067,0.015,-0.031,0.037,-0.034,0.032,0.121,0.063,0.003,-0.016,-0.007,0.011,0.093,0.056,-0.054,0.028,0.014,-0.008,-0.102,-0.072,-0.042,0.025,0.005,-0.005,-0.083,-0.008,0.018,-0.076,0.07,0.03,0.003,-0.029,0.021,0.016,0.036,-0.101,0.194,-0.01,-0.014,0.07,-0.004,0.001,-0.087,0.001,-0.0,0.02,0.0,-0.061,-0.108,-0.039,0.068,-0.015,0.033,0.008,0.044,0.016,-0.017,-0.034,-0.018,0.023,-0.018,-0.031,-0.068,0.021,0.0,-0.006,0.032,-0.019,0.019,-0.004,0.063,-0.018,-0.057,0.021,-0.054,-0.047,0.035,-0.113,-0.005,0.065,0.033,-0.018,0.055,-0.033,0.01,-0.095,0.008,0.008,0.053,-0.03,-0.036,0.068,-0.128,-0.011,0.034,-0.022,0.01,-0.012,0.033,-0.016,0.127,0.081,-0.028,-0.07,0.004,-0.067,0.063,-0.056,0.025,-0.014,0.094,-0.012,-0.016,0.065,0.045,0.082,0.001,-0.023,0.014,-0.04,-0.002,0.024,0.001,0.03,0.051,-0.017,-0.071,0.108,-0.028,0.004,-0.048,-0.026,0.041,-0.038,0.05,0.002,-0.027,-0.005,0.019,-0.045,-0.077,-0.16,0.021,0.05,-0.068,0.069,-0.045,0.041,-0.091,-0.024,0.025,-0.052,-0.046,0.066,-0.114,-0.002,0.004,0.063,-0.056,-0.004,0.0,0.071,0.08,0.022,-0.087,-0.02,-0.078,0.002,0.081,-0.038,-0.001,-0.072,0.003,0.014,0.005,0.022,-0.008,0.094,0.011,0.068,-0.013,-0.015,-0.046,0.055,0.013,-0.004,-0.001,-0.015,0.01,-0.014,0.013,-0.036,-0.007,-0.07,-0.061,-0.08,0.018,0.005,-0.001,-0.017,0.027,0.031,-0.023,0.001,0.167,-0.007,-0.031,0.035,0.032,-0.009,0.122,-0.037,-0.032,-0.011,0.018,-0.042,0.051,-0.002,-0.081,0.06,-0.009,0.061,0.065,-0.037,0.076,0.05,0.083,-0.026,0.034,-0.097,-0.016,0.116,0.026,-0.173,0.011,0.051,-0.055,0.013,0.045,-0.017,-0.121,-0.071,-0.025,0.075,-0.031,0.047,0.062,0.05,0.101,-0.036,-0.018,0.051,-0.072,0.004,-0.023,0.019,0.0,-0.024,0.073,0.018,-0.063,0.079,0.012,-0.076,-0.006,-0.009,0.002,-0.025,0.063,-0.011,0.104,0.004,0.025,0.009,-0.071,-0.032,-0.051,-0.096,-0.072,-0.116,-0.06,-0.035,-0.021,0.016,0.045,0.014,0.036,-0.03,0.009,-0.091,-0.045,0.02,-0.105,-0.006,0.046,-0.028,-0.116,-0.078,-0.013,0.019,0.004,-0.05,0.023,0.046,-0.03,-0.021,0.001,0.022,0.02,-0.015,0.059,0.132,0.022,-0.01,-0.003,-0.002,0.021,0.052,-0.023,0.017,0.009],[-0.009,-0.0,-0.035,-0.002,-0.044,-0.063,0.1,0.03,0.052,-0.06,-0.027,0.012,0.03,-0.04,-0.013,0.023,-0.028,0.015,-0.066,-0.032,0.052,0.028,0.063,0.037,-0.005,-0.024,0.006,0.008,0.014,-0.007,-0.042,-0.018,0.012,-0.061,-0.03,0.004,-0.019,0.003,0.065,0.058,0.004,-0.032,0.023,-0.016,0.03,-0.009,-0.022,-0.026,0.057,-0.013,0.002,0.004,-0.059,-0.047,0.084,0.085,0.048,-0.008,0.11,0.041,-0.018,0.071,-0.022,-0.067,0.015,-0.031,0.037,-0.034,0.032,0.121,0.063,0.003,-0.016,-0.007,0.011,0.093,0.056,-0.054,0.028,0.014,-0.008,-0.102,-0.072,-0.042,0.025,0.005,-0.005,-0.083,-0.008,0.018,-0.076,0.07,0.03,0.003,-0.029,0.021,0.016,0.036,-0.101,0.194,-0.01,-0.014,0.07,-0.004,0.001,-0.087,0.001,-0.0,0.02,0.0,-0.061,-0.108,-0.039,0.068,-0.015,0.033,0.008,0.044,0.016,-0.017,-0.034,-0.018,0.023,-0.018,-0.031,-0.068,0.021,0.0,-0.006,0.032,-0.019,0.019,-0.004,0.063,-0.018,-0.057,0.021,-0.054,-0.047,0.035,-0.113,-0.005,0.065,0.033,-0.018,0.055,-0.033,0.01,-0.095,0.008,0.008,0.053,-0.03,-0.036,0.068,-0.128,-0.011,0.034,-0.022,0.01,-0.012,0.033,-0.016,0.127,0.081,-0.028,-0.07,0.004,-0.067,0.063,-0.056,0.025,-0.014,0.094,-0.012,-0.016,0.065,0.045,0.082,0.001,-0.023,0.014,-0.04,-0.002,0.024,0.001,0.03,0.051,-0.017,-0.071,0.108,-0.028,0.004,-0.048,-0.026,0.041,-0.038,0.05,0.002,-0.027,-0.005,0.019,-0.045,-0.077,-0.16,0.021,0.05,-0.068,0.069,-0.045,0.041,-0.091,-0.024,0.025,-0.052,-0.046,0.066,-0.114,-0.002,0.004,0.063,-0.056,-0.004,0.0,0.071,0.08,0.022,-0.087,-0.02,-0.078,0.002,0.081,-0.038,-0.001,-0.072,0.003,0.014,0.005,0.022,-0.008,0.094,0.011,0.068,-0.013,-0.015,-0.046,0.055,0.013,-0.004,-0.001,-0.015,0.01,-0.014,0.013,-0.036,-0.007,-0.07,-0.061,-0.08,0.018,0.005,-0.001,-0.017,0.027,0.031,-0.023,0.001,0.167,-0.007,-0.031,0.035,0.032,-0.009,0.122,-0.037,-0.032,-0.011,0.018,-0.042,0.051,-0.002,-0.081,0.06,-0.009,0.061,0.065,-0.037,0.076,0.05,0.083,-0.026,0.034,-0.097,-0.016,0.116,0.026,-0.173,0.011,0.051,-0.055,0.013,0.045,-0.017,-0.121,-0.071,-0.025,0.075,-0.031,0.047,0.062,0.05,0.101,-0.036,-0.018,0.051,-0.072,0.004,-0.023,0.019,0.0,-0.024,0.073,0.018,-0.063,0.079,0.012,-0.076,-0.006,-0.009,0.002,-0.025,0.063,-0.011,0.104,0.004,0.025,0.009,-0.071,-0.032,-0.051,-0.096,-0.072,-0.116,-0.06,-0.035,-0.021,0.016,0.045,0.014,0.036,-0.03,0.009,-0.091,-0.045,0.02,-0.105,-0.006,0.046,-0.028,-0.116,-0.078,-0.013,0.019,0.004,-0.05,0.023,0.046,-0.03,-0.021,0.001,0.022,0.02,-0.015,0.059,0.132,0.022,-0.01,-0.003,-0.002,0.021,0.052,-0.023,0.017,0.009],[-0.003,-0.038,-0.045,0.046,-0.102,-0.023,0.163,0.003,0.041,-0.042,-0.026,-0.083,0.078,-0.014,-0.057,-0.018,0.034,0.022,-0.025,-0.026,-0.071,0.043,-0.062,0.067,-0.012,0.032,0.025,-0.009,-0.046,-0.135,0.026,0.067,0.036,-0.041,0.038,-0.023,0.021,0.026,0.025,-0.019,-0.01,-0.081,0.029,0.08,-0.012,-0.001,0.067,-0.012,0.044,-0.042,-0.009,-0.039,-0.065,0.078,0.041,0.087,-0.023,0.046,0.056,-0.025,-0.047,0.068,0.01,0.019,0.0,0.036,-0.061,-0.014,-0.012,-0.019,0.033,0.033,0.023,0.072,0.037,0.016,0.064,0.038,0.129,-0.029,-0.119,-0.086,-0.025,-0.006,-0.011,0.028,-0.016,-0.061,-0.08,0.019,0.026,0.045,0.058,0.002,-0.123,-0.047,-0.0,-0.029,-0.029,0.163,0.016,0.011,-0.031,-0.029,0.05,-0.093,0.036,-0.011,-0.008,0.014,0.003,-0.074,-0.017,0.004,0.039,-0.053,-0.025,0.031,0.047,-0.023,-0.009,0.08,-0.031,-0.049,-0.15,0.012,-0.007,0.0,0.02,-0.068,0.069,0.07,-0.043,0.048,-0.092,-0.012,-0.027,0.017,-0.026,0.008,-0.006,0.02,0.132,0.001,-0.086,-0.017,-0.021,0.039,-0.083,0.04,-0.021,0.122,-0.01,-0.053,0.057,-0.07,-0.041,0.062,0.004,-0.033,-0.041,-0.018,0.008,-0.074,0.024,-0.012,-0.052,-0.039,0.011,-0.062,-0.087,-0.064,0.048,0.061,0.074,0.073,-0.044,0.04,-0.002,-0.034,0.037,0.051,-0.001,-0.005,0.016,0.009,-0.001,0.12,0.061,0.094,0.037,-0.052,-0.037,-0.028,0.016,-0.075,-0.006,-0.128,-0.031,-0.026,0.061,0.017,-0.038,0.021,-0.045,-0.055,-0.066,-0.007,-0.03,-0.019,0.044,-0.018,-0.036,0.04,-0.007,-0.102,0.008,0.049,-0.135,-0.006,0.079,-0.002,-0.039,0.0,0.029,-0.087,-0.023,0.024,-0.036,-0.038,0.027,-0.04,0.064,0.028,-0.056,-0.043,0.044,-0.041,0.033,0.004,0.015,0.007,-0.019,0.056,-0.04,0.012,-0.089,0.063,-0.071,0.088,0.027,0.014,0.09,0.006,0.013,0.017,-0.016,-0.001,-0.082,0.079,0.053,0.0,-0.03,-0.044,-0.061,0.033,-0.03,0.081,0.05,0.013,0.036,0.029,-0.01,0.048,-0.106,-0.021,-0.049,0.043,-0.047,-0.043,-0.037,0.027,0.098,-0.017,0.04,0.024,0.049,0.036,-0.005,-0.005,-0.01,-0.002,-0.05,-0.049,0.105,0.077,-0.073,0.042,0.028,0.074,-0.001,0.002,-0.05,0.087,-0.02,0.029,-0.018,0.066,-0.027,-0.015,0.039,0.031,0.001,-0.055,-0.018,0.021,-0.031,-0.061,0.029,0.0,0.014,0.031,0.003,0.033,0.071,-0.007,0.077,0.067,0.014,0.004,0.055,0.038,-0.009,0.091,0.073,0.028,-0.006,-0.04,-0.008,0.027,0.006,0.0,0.016,-0.056,-0.052,-0.055,-0.032,0.024,0.071,0.023,0.055,0.107,-0.057,-0.124,0.001,0.004,-0.013,0.077,0.02,-0.007,-0.029,-0.037,0.006,-0.052,-0.046,-0.113,0.037,0.002,-0.02,-0.036,-0.059,0.1,0.042,0.007,0.068,0.047,-0.036,-0.011,-0.078,0.084,0.033,-0.053,0.011,-0.054],[-0.003,-0.038,-0.045,0.046,-0.102,-0.023,0.163,0.003,0.041,-0.042,-0.026,-0.083,0.078,-0.014,-0.057,-0.018,0.034,0.022,-0.025,-0.026,-0.071,0.043,-0.062,0.067,-0.012,0.032,0.025,-0.009,-0.046,-0.135,0.026,0.067,0.036,-0.041,0.038,-0.023,0.021,0.026,0.025,-0.019,-0.01,-0.081,0.029,0.08,-0.012,-0.001,0.067,-0.012,0.044,-0.042,-0.009,-0.039,-0.065,0.078,0.041,0.087,-0.023,0.046,0.056,-0.025,-0.047,0.068,0.01,0.019,0.0,0.036,-0.061,-0.014,-0.012,-0.019,0.033,0.033,0.023,0.072,0.037,0.016,0.064,0.038,0.129,-0.029,-0.119,-0.086,-0.025,-0.006,-0.011,0.028,-0.016,-0.061,-0.08,0.019,0.026,0.045,0.058,0.002,-0.123,-0.047,-0.0,-0.029,-0.029,0.163,0.016,0.011,-0.031,-0.029,0.05,-0.093,0.036,-0.011,-0.008,0.014,0.003,-0.074,-0.017,0.004,0.039,-0.053,-0.025,0.031,0.047,-0.023,-0.009,0.08,-0.031,-0.049,-0.15,0.012,-0.007,0.0,0.02,-0.068,0.069,0.07,-0.043,0.048,-0.092,-0.012,-0.027,0.017,-0.026,0.008,-0.006,0.02,0.132,0.001,-0.086,-0.017,-0.021,0.039,-0.083,0.04,-0.021,0.122,-0.01,-0.053,0.057,-0.07,-0.041,0.062,0.004,-0.033,-0.041,-0.018,0.008,-0.074,0.024,-0.012,-0.052,-0.039,0.011,-0.062,-0.087,-0.064,0.048,0.061,0.074,0.073,-0.044,0.04,-0.002,-0.034,0.037,0.051,-0.001,-0.005,0.016,0.009,-0.001,0.12,0.061,0.094,0.037,-0.052,-0.037,-0.028,0.016,-0.075,-0.006,-0.128,-0.031,-0.026,0.061,0.017,-0.038,0.021,-0.045,-0.055,-0.066,-0.007,-0.03,-0.019,0.044,-0.018,-0.036,0.04,-0.007,-0.102,0.008,0.049,-0.135,-0.006,0.079,-0.002,-0.039,0.0,0.029,-0.087,-0.023,0.024,-0.036,-0.038,0.027,-0.04,0.064,0.028,-0.056,-0.043,0.044,-0.041,0.033,0.004,0.015,0.007,-0.019,0.056,-0.04,0.012,-0.089,0.063,-0.071,0.088,0.027,0.014,0.09,0.006,0.013,0.017,-0.016,-0.001,-0.082,0.079,0.053,0.0,-0.03,-0.044,-0.061,0.033,-0.03,0.081,0.05,0.013,0.036,0.029,-0.01,0.048,-0.106,-0.021,-0.049,0.043,-0.047,-0.043,-0.037,0.027,0.098,-0.017,0.04,0.024,0.049,0.036,-0.005,-0.005,-0.01,-0.002,-0.05,-0.049,0.105,0.077,-0.073,0.042,0.028,0.074,-0.001,0.002,-0.05,0.087,-0.02,0.029,-0.018,0.066,-0.027,-0.015,0.039,0.031,0.001,-0.055,-0.018,0.021,-0.031,-0.061,0.029,0.0,0.014,0.031,0.003,0.033,0.071,-0.007,0.077,0.067,0.014,0.004,0.055,0.038,-0.009,0.091,0.073,0.028,-0.006,-0.04,-0.008,0.027,0.006,0.0,0.016,-0.056,-0.052,-0.055,-0.032,0.024,0.071,0.023,0.055,0.107,-0.057,-0.124,0.001,0.004,-0.013,0.077,0.02,-0.007,-0.029,-0.037,0.006,-0.052,-0.046,-0.113,0.037,0.002,-0.02,-0.036,-0.059,0.1,0.042,0.007,0.068,0.047,-0.036,-0.011,-0.078,0.084,0.033,-0.053,0.011,-0.054],[-0.003,-0.038,-0.045,0.046,-0.102,-0.023,0.163,0.003,0.041,-0.042,-0.026,-0.083,0.078,-0.014,-0.057,-0.018,0.034,0.022,-0.025,-0.026,-0.071,0.043,-0.062,0.067,-0.012,0.032,0.025,-0.009,-0.046,-0.135,0.026,0.067,0.036,-0.041,0.038,-0.023,0.021,0.026,0.025,-0.019,-0.01,-0.081,0.029,0.08,-0.012,-0.001,0.067,-0.012,0.044,-0.042,-0.009,-0.039,-0.065,0.078,0.041,0.087,-0.023,0.046,0.056,-0.025,-0.047,0.068,0.01,0.019,0.0,0.036,-0.061,-0.014,-0.012,-0.019,0.033,0.033,0.023,0.072,0.037,0.016,0.064,0.038,0.129,-0.029,-0.119,-0.086,-0.025,-0.006,-0.011,0.028,-0.016,-0.061,-0.08,0.019,0.026,0.045,0.058,0.002,-0.123,-0.047,-0.0,-0.029,-0.029,0.163,0.016,0.011,-0.031,-0.029,0.05,-0.093,0.036,-0.011,-0.008,0.014,0.003,-0.074,-0.017,0.004,0.039,-0.053,-0.025,0.031,0.047,-0.023,-0.009,0.08,-0.031,-0.049,-0.15,0.012,-0.007,0.0,0.02,-0.068,0.069,0.07,-0.043,0.048,-0.092,-0.012,-0.027,0.017,-0.026,0.008,-0.006,0.02,0.132,0.001,-0.086,-0.017,-0.021,0.039,-0.083,0.04,-0.021,0.122,-0.01,-0.053,0.057,-0.07,-0.041,0.062,0.004,-0.033,-0.041,-0.018,0.008,-0.074,0.024,-0.012,-0.052,-0.039,0.011,-0.062,-0.087,-0.064,0.048,0.061,0.074,0.073,-0.044,0.04,-0.002,-0.034,0.037,0.051,-0.001,-0.005,0.016,0.009,-0.001,0.12,0.061,0.094,0.037,-0.052,-0.037,-0.028,0.016,-0.075,-0.006,-0.128,-0.031,-0.026,0.061,0.017,-0.038,0.021,-0.045,-0.055,-0.066,-0.007,-0.03,-0.019,0.044,-0.018,-0.036,0.04,-0.007,-0.102,0.008,0.049,-0.135,-0.006,0.079,-0.002,-0.039,0.0,0.029,-0.087,-0.023,0.024,-0.036,-0.038,0.027,-0.04,0.064,0.028,-0.056,-0.043,0.044,-0.041,0.033,0.004,0.015,0.007,-0.019,0.056,-0.04,0.012,-0.089,0.063,-0.071,0.088,0.027,0.014,0.09,0.006,0.013,0.017,-0.016,-0.001,-0.082,0.079,0.053,0.0,-0.03,-0.044,-0.061,0.033,-0.03,0.081,0.05,0.013,0.036,0.029,-0.01,0.048,-0.106,-0.021,-0.049,0.043,-0.047,-0.043,-0.037,0.027,0.098,-0.017,0.04,0.024,0.049,0.036,-0.005,-0.005,-0.01,-0.002,-0.05,-0.049,0.105,0.077,-0.073,0.042,0.028,0.074,-0.001,0.002,-0.05,0.087,-0.02,0.029,-0.018,0.066,-0.027,-0.015,0.039,0.031,0.001,-0.055,-0.018,0.021,-0.031,-0.061,0.029,0.0,0.014,0.031,0.003,0.033,0.071,-0.007,0.077,0.067,0.014,0.004,0.055,0.038,-0.009,0.091,0.073,0.028,-0.006,-0.04,-0.008,0.027,0.006,0.0,0.016,-0.056,-0.052,-0.055,-0.032,0.024,0.071,0.023,0.055,0.107,-0.057,-0.124,0.001,0.004,-0.013,0.077,0.02,-0.007,-0.029,-0.037,0.006,-0.052,-0.046,-0.113,0.037,0.002,-0.02,-0.036,-0.059,0.1,0.042,0.007,0.068,0.047,-0.036,-0.011,-0.078,0.084,0.033,-0.053,0.011,-0.054],[-0.009,-0.0,-0.035,-0.002,-0.044,-0.063,0.1,0.03,0.052,-0.06,-0.027,0.012,0.03,-0.04,-0.013,0.023,-0.028,0.015,-0.066,-0.032,0.052,0.028,0.063,0.037,-0.005,-0.024,0.006,0.008,0.014,-0.007,-0.042,-0.018,0.012,-0.061,-0.03,0.004,-0.019,0.003,0.065,0.058,0.004,-0.032,0.023,-0.016,0.03,-0.009,-0.022,-0.026,0.057,-0.013,0.002,0.004,-0.059,-0.047,0.084,0.085,0.048,-0.008,0.11,0.041,-0.018,0.071,-0.022,-0.067,0.015,-0.031,0.037,-0.034,0.032,0.121,0.063,0.003,-0.016,-0.007,0.011,0.093,0.056,-0.054,0.028,0.014,-0.008,-0.102,-0.072,-0.042,0.025,0.005,-0.005,-0.083,-0.008,0.018,-0.076,0.07,0.03,0.003,-0.029,0.021,0.016,0.036,-0.101,0.194,-0.01,-0.014,0.07,-0.004,0.001,-0.087,0.001,-0.0,0.02,0.0,-0.061,-0.108,-0.039,0.068,-0.015,0.033,0.008,0.044,0.016,-0.017,-0.034,-0.018,0.023,-0.018,-0.031,-0.068,0.021,0.0,-0.006,0.032,-0.019,0.019,-0.004,0.063,-0.018,-0.057,0.021,-0.054,-0.047,0.035,-0.113,-0.005,0.065,0.033,-0.018,0.055,-0.033,0.01,-0.095,0.008,0.008,0.053,-0.03,-0.036,0.068,-0.128,-0.011,0.034,-0.022,0.01,-0.012,0.033,-0.016,0.127,0.081,-0.028,-0.07,0.004,-0.067,0.063,-0.056,0.025,-0.014,0.094,-0.012,-0.016,0.065,0.045,0.082,0.001,-0.023,0.014,-0.04,-0.002,0.024,0.001,0.03,0.051,-0.017,-0.071,0.108,-0.028,0.004,-0.048,-0.026,0.041,-0.038,0.05,0.002,-0.027,-0.005,0.019,-0.045,-0.077,-0.16,0.021,0.05,-0.068,0.069,-0.045,0.041,-0.091,-0.024,0.025,-0.052,-0.046,0.066,-0.114,-0.002,0.004,0.063,-0.056,-0.004,0.0,0.071,0.08,0.022,-0.087,-0.02,-0.078,0.002,0.081,-0.038,-0.001,-0.072,0.003,0.014,0.005,0.022,-0.008,0.094,0.011,0.068,-0.013,-0.015,-0.046,0.055,0.013,-0.004,-0.001,-0.015,0.01,-0.014,0.013,-0.036,-0.007,-0.07,-0.061,-0.08,0.018,0.005,-0.001,-0.017,0.027,0.031,-0.023,0.001,0.167,-0.007,-0.031,0.035,0.032,-0.009,0.122,-0.037,-0.032,-0.011,0.018,-0.042,0.051,-0.002,-0.081,0.06,-0.009,0.061,0.065,-0.037,0.076,0.05,0.083,-0.026,0.034,-0.097,-0.016,0.116,0.026,-0.173,0.011,0.051,-0.055,0.013,0.045,-0.017,-0.121,-0.071,-0.025,0.075,-0.031,0.047,0.062,0.05,0.101,-0.036,-0.018,0.051,-0.072,0.004,-0.023,0.019,0.0,-0.024,0.073,0.018,-0.063,0.079,0.012,-0.076,-0.006,-0.009,0.002,-0.025,0.063,-0.011,0.104,0.004,0.025,0.009,-0.071,-0.032,-0.051,-0.096,-0.072,-0.116,-0.06,-0.035,-0.021,0.016,0.045,0.014,0.036,-0.03,0.009,-0.091,-0.045,0.02,-0.105,-0.006,0.046,-0.028,-0.116,-0.078,-0.013,0.019,0.004,-0.05,0.023,0.046,-0.03,-0.021,0.001,0.022,0.02,-0.015,0.059,0.132,0.022,-0.01,-0.003,-0.002,0.021,0.052,-0.023,0.017,0.009],[-0.009,-0.0,-0.035,-0.002,-0.044,-0.063,0.1,0.03,0.052,-0.06,-0.027,0.012,0.03,-0.04,-0.013,0.023,-0.028,0.015,-0.066,-0.032,0.052,0.028,0.063,0.037,-0.005,-0.024,0.006,0.008,0.014,-0.007,-0.042,-0.018,0.012,-0.061,-0.03,0.004,-0.019,0.003,0.065,0.058,0.004,-0.032,0.023,-0.016,0.03,-0.009,-0.022,-0.026,0.057,-0.013,0.002,0.004,-0.059,-0.047,0.084,0.085,0.048,-0.008,0.11,0.041,-0.018,0.071,-0.022,-0.067,0.015,-0.031,0.037,-0.034,0.032,0.121,0.063,0.003,-0.016,-0.007,0.011,0.093,0.056,-0.054,0.028,0.014,-0.008,-0.102,-0.072,-0.042,0.025,0.005,-0.005,-0.083,-0.008,0.018,-0.076,0.07,0.03,0.003,-0.029,0.021,0.016,0.036,-0.101,0.194,-0.01,-0.014,0.07,-0.004,0.001,-0.087,0.001,-0.0,0.02,0.0,-0.061,-0.108,-0.039,0.068,-0.015,0.033,0.008,0.044,0.016,-0.017,-0.034,-0.018,0.023,-0.018,-0.031,-0.068,0.021,0.0,-0.006,0.032,-0.019,0.019,-0.004,0.063,-0.018,-0.057,0.021,-0.054,-0.047,0.035,-0.113,-0.005,0.065,0.033,-0.018,0.055,-0.033,0.01,-0.095,0.008,0.008,0.053,-0.03,-0.036,0.068,-0.128,-0.011,0.034,-0.022,0.01,-0.012,0.033,-0.016,0.127,0.081,-0.028,-0.07,0.004,-0.067,0.063,-0.056,0.025,-0.014,0.094,-0.012,-0.016,0.065,0.045,0.082,0.001,-0.023,0.014,-0.04,-0.002,0.024,0.001,0.03,0.051,-0.017,-0.071,0.108,-0.028,0.004,-0.048,-0.026,0.041,-0.038,0.05,0.002,-0.027,-0.005,0.019,-0.045,-0.077,-0.16,0.021,0.05,-0.068,0.069,-0.045,0.041,-0.091,-0.024,0.025,-0.052,-0.046,0.066,-0.114,-0.002,0.004,0.063,-0.056,-0.004,0.0,0.071,0.08,0.022,-0.087,-0.02,-0.078,0.002,0.081,-0.038,-0.001,-0.072,0.003,0.014,0.005,0.022,-0.008,0.094,0.011,0.068,-0.013,-0.015,-0.046,0.055,0.013,-0.004,-0.001,-0.015,0.01,-0.014,0.013,-0.036,-0.007,-0.07,-0.061,-0.08,0.018,0.005,-0.001,-0.017,0.027,0.031,-0.023,0.001,0.167,-0.007,-0.031,0.035,0.032,-0.009,0.122,-0.037,-0.032,-0.011,0.018,-0.042,0.051,-0.002,-0.081,0.06,-0.009,0.061,0.065,-0.037,0.076,0.05,0.083,-0.026,0.034,-0.097,-0.016,0.116,0.026,-0.173,0.011,0.051,-0.055,0.013,0.045,-0.017,-0.121,-0.071,-0.025,0.075,-0.031,0.047,0.062,0.05,0.101,-0.036,-0.018,0.051,-0.072,0.004,-0.023,0.019,0.0,-0.024,0.073,0.018,-0.063,0.079,0.012,-0.076,-0.006,-0.009,0.002,-0.025,0.063,-0.011,0.104,0.004,0.025,0.009,-0.071,-0.032,-0.051,-0.096,-0.072,-0.116,-0.06,-0.035,-0.021,0.016,0.045,0.014,0.036,-0.03,0.009,-0.091,-0.045,0.02,-0.105,-0.006,0.046,-0.028,-0.116,-0.078,-0.013,0.019,0.004,-0.05,0.023,0.046,-0.03,-0.021,0.001,0.022,0.02,-0.015,0.059,0.132,0.022,-0.01,-0.003,-0.002,0.021,0.052,-0.023,0.017,0.009],[-0.009,-0.0,-0.035,-0.002,-0.044,-0.063,0.1,0.03,0.052,-0.06,-0.027,0.012,0.03,-0.04,-0.013,0.023,-0.028,0.015,-0.066,-0.032,0.052,0.028,0.063,0.037,-0.005,-0.024,0.006,0.008,0.014,-0.007,-0.042,-0.018,0.012,-0.061,-0.03,0.004,-0.019,0.003,0.065,0.058,0.004,-0.032,0.023,-0.016,0.03,-0.009,-0.022,-0.026,0.057,-0.013,0.002,0.004,-0.059,-0.047,0.084,0.085,0.048,-0.008,0.11,0.041,-0.018,0.071,-0.022,-0.067,0.015,-0.031,0.037,-0.034,0.032,0.121,0.063,0.003,-0.016,-0.007,0.011,0.093,0.056,-0.054,0.028,0.014,-0.008,-0.102,-0.072,-0.042,0.025,0.005,-0.005,-0.083,-0.008,0.018,-0.076,0.07,0.03,0.003,-0.029,0.021,0.016,0.036,-0.101,0.194,-0.01,-0.014,0.07,-0.004,0.001,-0.087,0.001,-0.0,0.02,0.0,-0.061,-0.108,-0.039,0.068,-0.015,0.033,0.008,0.044,0.016,-0.017,-0.034,-0.018,0.023,-0.018,-0.031,-0.068,0.021,0.0,-0.006,0.032,-0.019,0.019,-0.004,0.063,-0.018,-0.057,0.021,-0.054,-0.047,0.035,-0.113,-0.005,0.065,0.033,-0.018,0.055,-0.033,0.01,-0.095,0.008,0.008,0.053,-0.03,-0.036,0.068,-0.128,-0.011,0.034,-0.022,0.01,-0.012,0.033,-0.016,0.127,0.081,-0.028,-0.07,0.004,-0.067,0.063,-0.056,0.025,-0.014,0.094,-0.012,-0.016,0.065,0.045,0.082,0.001,-0.023,0.014,-0.04,-0.002,0.024,0.001,0.03,0.051,-0.017,-0.071,0.108,-0.028,0.004,-0.048,-0.026,0.041,-0.038,0.05,0.002,-0.027,-0.005,0.019,-0.045,-0.077,-0.16,0.021,0.05,-0.068,0.069,-0.045,0.041,-0.091,-0.024,0.025,-0.052,-0.046,0.066,-0.114,-0.002,0.004,0.063,-0.056,-0.004,0.0,0.071,0.08,0.022,-0.087,-0.02,-0.078,0.002,0.081,-0.038,-0.001,-0.072,0.003,0.014,0.005,0.022,-0.008,0.094,0.011,0.068,-0.013,-0.015,-0.046,0.055,0.013,-0.004,-0.001,-0.015,0.01,-0.014,0.013,-0.036,-0.007,-0.07,-0.061,-0.08,0.018,0.005,-0.001,-0.017,0.027,0.031,-0.023,0.001,0.167,-0.007,-0.031,0.035,0.032,-0.009,0.122,-0.037,-0.032,-0.011,0.018,-0.042,0.051,-0.002,-0.081,0.06,-0.009,0.061,0.065,-0.037,0.076,0.05,0.083,-0.026,0.034,-0.097,-0.016,0.116,0.026,-0.173,0.011,0.051,-0.055,0.013,0.045,-0.017,-0.121,-0.071,-0.025,0.075,-0.031,0.047,0.062,0.05,0.101,-0.036,-0.018,0.051,-0.072,0.004,-0.023,0.019,0.0,-0.024,0.073,0.018,-0.063,0.079,0.012,-0.076,-0.006,-0.009,0.002,-0.025,0.063,-0.011,0.104,0.004,0.025,0.009,-0.071,-0.032,-0.051,-0.096,-0.072,-0.116,-0.06,-0.035,-0.021,0.016,0.045,0.014,0.036,-0.03,0.009,-0.091,-0.045,0.02,-0.105,-0.006,0.046,-0.028,-0.116,-0.078,-0.013,0.019,0.004,-0.05,0.023,0.046,-0.03,-0.021,0.001,0.022,0.02,-0.015,0.059,0.132,0.022,-0.01,-0.003,-0.002,0.021,0.052,-0.023,0.017,0.009]]
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Ollama::Documents::MemoryCache do
4
+ let :memory_cache do
5
+ described_class.new prefix: 'test-'
6
+ end
7
+
8
+ it 'can be instantiated' do
9
+ expect(memory_cache).to be_a described_class
10
+ end
11
+
12
+ it 'can get/set a key' do
13
+ key, value = 'foo', { test: true }
14
+ expect {
15
+ memory_cache[key] = value
16
+ }.to change {
17
+ memory_cache[key]
18
+ }.from(nil).to(value)
19
+ end
20
+
21
+ it 'can determine if key exists' do
22
+ key, value = 'foo', { test: true }
23
+ expect {
24
+ memory_cache[key] = value
25
+ }.to change {
26
+ memory_cache.key?(key)
27
+ }.from(false).to(true)
28
+ end
29
+
30
+ it 'can delete' do
31
+ key, value = 'foo', { test: true }
32
+ memory_cache[key] = value
33
+ expect {
34
+ memory_cache.delete(key)
35
+ }.to change {
36
+ memory_cache.key?(key)
37
+ }.from(true).to(false)
38
+ end
39
+
40
+ it 'returns size' do
41
+ key, value = 'foo', { test: true }
42
+ expect {
43
+ memory_cache[key] = value
44
+ }.to change {
45
+ memory_cache.size
46
+ }.from(0).to(1)
47
+ end
48
+
49
+ it 'can clear' do
50
+ key, value = 'foo', { test: true }
51
+ memory_cache[key] = value
52
+ expect {
53
+ expect(memory_cache.clear).to eq memory_cache
54
+ }.to change {
55
+ memory_cache.size
56
+ }.from(1).to(0)
57
+ end
58
+
59
+ it 'can iterate over keys under a prefix' do
60
+ memory_cache['foo'] = 'bar'
61
+ expect(memory_cache.to_a).to eq [ %w[ test-foo bar ] ]
62
+ end
63
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Ollama::Documents::RedisCache do
4
+ it 'can be instantiated' do
5
+ redis_cache = described_class.new prefix: 'test-', url: 'something'
6
+ expect(redis_cache).to be_a described_class
7
+ end
8
+
9
+ it 'raises ArgumentError if url is missing' do
10
+ expect {
11
+ described_class.new prefix: 'test-', url: nil
12
+ }.to raise_error ArgumentError
13
+ end
14
+
15
+ context 'test redis interactions' do
16
+ let :redis_cache do
17
+ described_class.new prefix: 'test-', url: 'something'
18
+ end
19
+
20
+ let :redis do
21
+ double('Redis')
22
+ end
23
+
24
+ before do
25
+ allow_any_instance_of(described_class).to receive(:redis).and_return(redis)
26
+ end
27
+
28
+ it 'has Redis client' do
29
+ expect(redis_cache.redis).to eq redis
30
+ end
31
+
32
+ it 'can get a key' do
33
+ key = 'foo'
34
+ expect(redis).to receive(:get).with('test-' + key).and_return 666
35
+ redis_cache[key]
36
+ end
37
+
38
+ it 'can set a value for a key' do
39
+ key, value = 'foo', { test: true }
40
+ expect(redis).to receive(:set).with('test-' + key, JSON(value))
41
+ redis_cache[key] = value
42
+ end
43
+
44
+ it 'can determine if key exists' do
45
+ key = 'foo'
46
+ expect(redis).to receive(:exists?).with('test-' + key).and_return(false, true)
47
+ expect(redis_cache.key?('foo')).to eq false
48
+ expect(redis_cache.key?('foo')).to eq true
49
+ end
50
+
51
+ it 'can delete' do
52
+ key = 'foo'
53
+ expect(redis).to receive(:del).with('test-' + key)
54
+ redis_cache.delete(key)
55
+ end
56
+
57
+ it 'returns size' do
58
+ allow(redis).to receive(:scan_each).with(match: 'test-*').
59
+ and_yield('test-foo').
60
+ and_yield('test-bar').
61
+ and_yield('test-baz')
62
+ expect(redis_cache.size).to eq 3
63
+ end
64
+
65
+ it 'can clear' do
66
+ expect(redis).to receive(:scan_each).with(match: 'test-*').and_yield(
67
+ 'test-foo'
68
+ )
69
+ expect(redis).to receive(:del).with('test-foo')
70
+ expect(redis_cache.clear).to eq redis_cache
71
+ end
72
+
73
+ it 'can iterate over keys under a prefix' do
74
+ expect(redis).to receive(:scan_each).with(match: 'test-*')
75
+ redis_cache.to_a
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Ollama::Documents::Splitters::Character do
4
+ let :splitter do
5
+ described_class.new chunk_size: 23
6
+ end
7
+
8
+ it 'can be instantiated' do
9
+ expect(splitter).to be_a described_class
10
+ end
11
+
12
+ it 'can split' do
13
+ text = [ "A" * 10 ] * 10 * "\n\n"
14
+ result = splitter.split(text)
15
+ expect(result.count).to eq 5
16
+ expect(result.to_a.join('')).to eq ?A * 100
17
+ end
18
+
19
+ it 'can split including separator' do
20
+ splitter = described_class.new chunk_size: 25, include_separator: true
21
+ text = [ "A" * 10 ] * 10 * "\n\n"
22
+ result = splitter.split(text)
23
+ expect(result.count).to eq 5
24
+ expect(result.to_a.join('')).to eq text
25
+ end
26
+
27
+ it 'cannot split' do
28
+ text = [ "A" * 10 ] * 10 * "\n"
29
+ result = splitter.split(text)
30
+ expect(result.count).to eq 1
31
+ expect(result.to_a.join('').count(?A)).to eq text.count(?A)
32
+ end
33
+
34
+ it 'cannot split2' do
35
+ text = "A" * 25
36
+ result = splitter.split(text)
37
+ expect(result.count).to eq 1
38
+ expect(result.to_a.join('')).to eq ?A * 25
39
+ end
40
+
41
+ it 'can split sentences' do
42
+ text = "foo.foo. bar!bar! baz?baz? quux.\nquux."
43
+ splitter = described_class.new(separator: /[.!?]\s*(?:\b|\z)/, chunk_size: 2)
44
+ result = splitter.split(text)
45
+ expect(result.to_a).to eq %w[ foo foo bar bar baz baz quux quux ]
46
+ end
47
+ end
48
+
49
+ RSpec.describe Ollama::Documents::Splitters::RecursiveCharacter do
50
+ let :splitter do
51
+ described_class.new chunk_size: 23
52
+ end
53
+
54
+ it 'can be instantiated' do
55
+ expect(splitter).to be_a described_class
56
+ end
57
+
58
+ it 'can split' do
59
+ text = [ "A" * 10 ] * 10 * "\n\n"
60
+ result = splitter.split(text)
61
+ expect(result.count).to eq 5
62
+ expect(result.to_a.join('')).to eq ?A * 100
63
+ end
64
+
65
+ it 'cannot split' do
66
+ splitter = described_class.new chunk_size: 23, include_separator: true,
67
+ separators: described_class::DEFAULT_SEPARATORS[0..-2]
68
+ text = "A" * 25
69
+ result = splitter.split(text)
70
+ expect(result.count).to eq 1
71
+ expect(result.to_a.join('')).to eq ?A * 25
72
+ end
73
+
74
+ it 'can split including separator' do
75
+ splitter = described_class.new chunk_size: 25, include_separator: true
76
+ text = [ "A" * 10 ] * 10 * "\n\n"
77
+ result = splitter.split(text)
78
+ expect(result.count).to eq 5
79
+ expect(result.to_a.join('')).to eq text
80
+ end
81
+
82
+ it 'can split single newline as well' do
83
+ text = [ "A" * 10 ] * 10 * "\n"
84
+ result = splitter.split(text)
85
+ expect(result.count).to eq 5
86
+ expect(result.to_a.join('')).to eq ?A * 100
87
+ end
88
+
89
+ it 'can split single newline as well including separator' do
90
+ splitter = described_class.new chunk_size: 25, include_separator: true
91
+ text = [ "A" * 10 ] * 10 * "\n"
92
+ result = splitter.split(text)
93
+ expect(result.count).to eq 5
94
+ expect(result.to_a.join('')).to eq text
95
+ end
96
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Ollama::Documents::Splitters::Semantic do
4
+ let :ollama do
5
+ double('Ollama::Client')
6
+ end
7
+
8
+ let :splitter do
9
+ described_class.new ollama:, model: 'mxbai-embed-large'
10
+ end
11
+
12
+ let :embeddings do
13
+ JSON(File.read(asset('embeddings.json')))
14
+ end
15
+
16
+ it 'can be instantiated' do
17
+ expect(splitter).to be_a described_class
18
+ end
19
+
20
+ before do
21
+ allow(ollama).to receive(:embed).and_return(double(embeddings:))
22
+ end
23
+
24
+ it 'can split with breakpoint :percentile' do
25
+ text = ([ "A" * 10 ] * 3 + [ "B" * 10 ] * 3 + [ "A" * 10 ] * 3) * ". "
26
+ result = splitter.split(text, breakpoint: :percentile, percentile: 75)
27
+ expect(result.count).to eq 3
28
+ expect(result.to_a.join('').count(?A)).to eq text.count(?A)
29
+ expect(result.to_a.join('').count(?B)).to eq text.count(?B)
30
+ end
31
+
32
+ it 'can split with breakpoint :percentile' do
33
+ described_class.new ollama:, model: 'mxbai-embed-large', chunk_size: 50
34
+ text = ([ "A" * 10 ] * 6 + [ "B" * 10 ] * 3 + [ "A" * 10 ] * 3) * ". "
35
+ result = splitter.split(text, breakpoint: :percentile, percentile: 75)
36
+ expect(result.count).to eq 4
37
+ expect(result.to_a.join('').count(?A)).to eq text.count(?A)
38
+ expect(result.to_a.join('').count(?B)).to eq text.count(?B)
39
+ end
40
+
41
+ it 'can split with breakpoint :standard_deviation' do
42
+ text = ([ "A" * 10 ] * 3 + [ "B" * 10 ] * 3 + [ "A" * 10 ] * 3) * ". "
43
+ result = splitter.split(text, breakpoint: :standard_deviation, percentage: 100)
44
+ expect(result.count).to eq 3
45
+ expect(result.to_a.join('').count(?A)).to eq text.count(?A)
46
+ expect(result.to_a.join('').count(?B)).to eq text.count(?B)
47
+ end
48
+
49
+ it 'can split with breakpoint :interquartile' do
50
+ text = ([ "A" * 10 ] * 3 + [ "B" * 10 ] * 3 + [ "A" * 10 ] * 3) * ". "
51
+ result = splitter.split(text, breakpoint: :interquartile, percentage: 75)
52
+ expect(result.count).to eq 3
53
+ expect(result.to_a.join('').count(?A)).to eq text.count(?A)
54
+ expect(result.to_a.join('').count(?B)).to eq text.count(?B)
55
+ end
56
+ end