ollama-ruby 0.12.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/CHANGES.md +39 -0
- data/README.md +70 -144
- data/Rakefile +5 -17
- data/bin/ollama_cli +37 -6
- data/lib/ollama/client/command.rb +2 -2
- data/lib/ollama/dto.rb +4 -0
- data/lib/ollama/version.rb +1 -1
- data/lib/ollama.rb +0 -11
- data/ollama-ruby.gemspec +11 -22
- data/spec/ollama/message_spec.rb +9 -0
- metadata +25 -255
- data/bin/ollama_chat +0 -1248
- data/config/redis.conf +0 -5
- data/docker-compose.yml +0 -10
- data/lib/ollama/documents/cache/common.rb +0 -36
- data/lib/ollama/documents/cache/memory_cache.rb +0 -44
- data/lib/ollama/documents/cache/records.rb +0 -87
- data/lib/ollama/documents/cache/redis_backed_memory_cache.rb +0 -39
- data/lib/ollama/documents/cache/redis_cache.rb +0 -68
- data/lib/ollama/documents/cache/sqlite_cache.rb +0 -215
- data/lib/ollama/documents/splitters/character.rb +0 -72
- data/lib/ollama/documents/splitters/semantic.rb +0 -91
- data/lib/ollama/documents.rb +0 -184
- data/lib/ollama/utils/cache_fetcher.rb +0 -38
- data/lib/ollama/utils/chooser.rb +0 -52
- data/lib/ollama/utils/colorize_texts.rb +0 -65
- data/lib/ollama/utils/fetcher.rb +0 -175
- data/lib/ollama/utils/file_argument.rb +0 -34
- data/lib/ollama/utils/math.rb +0 -48
- data/lib/ollama/utils/tags.rb +0 -67
- data/spec/assets/embeddings.json +0 -1
- data/spec/assets/prompt.txt +0 -1
- data/spec/ollama/documents/cache/memory_cache_spec.rb +0 -97
- data/spec/ollama/documents/cache/redis_backed_memory_cache_spec.rb +0 -118
- data/spec/ollama/documents/cache/redis_cache_spec.rb +0 -121
- data/spec/ollama/documents/cache/sqlite_cache_spec.rb +0 -141
- data/spec/ollama/documents/splitters/character_spec.rb +0 -110
- data/spec/ollama/documents/splitters/semantic_spec.rb +0 -56
- data/spec/ollama/documents_spec.rb +0 -162
- data/spec/ollama/utils/cache_fetcher_spec.rb +0 -43
- data/spec/ollama/utils/colorize_texts_spec.rb +0 -13
- data/spec/ollama/utils/fetcher_spec.rb +0 -137
- data/spec/ollama/utils/file_argument_spec.rb +0 -17
- data/spec/ollama/utils/tags_spec.rb +0 -53
data/spec/assets/embeddings.json
DELETED
@@ -1 +0,0 @@
|
|
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]]
|
data/spec/assets/prompt.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
You are a test prompt just used for testing.
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Ollama::Documents::MemoryCache do
|
4
|
-
let :prefix do
|
5
|
-
'test-'
|
6
|
-
end
|
7
|
-
|
8
|
-
let :cache do
|
9
|
-
described_class.new prefix:
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'can be instantiated' do
|
13
|
-
expect(cache).to be_a described_class
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'can get/set a key' do
|
17
|
-
key, value = 'foo', { test: true }
|
18
|
-
expect {
|
19
|
-
cache[key] = value
|
20
|
-
}.to change {
|
21
|
-
cache[key]
|
22
|
-
}.from(nil).to(value)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'can determine if key exists' do
|
26
|
-
key, value = 'foo', { test: true }
|
27
|
-
expect {
|
28
|
-
cache[key] = value
|
29
|
-
}.to change {
|
30
|
-
cache.key?(key)
|
31
|
-
}.from(false).to(true)
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'can set key with different prefixes' do
|
35
|
-
key, value = 'foo', { test: true }
|
36
|
-
expect {
|
37
|
-
cache[key] = value
|
38
|
-
}.to change {
|
39
|
-
cache.size
|
40
|
-
}.from(0).to(1)
|
41
|
-
cache2 = cache.dup
|
42
|
-
cache2.prefix = 'test2-'
|
43
|
-
expect {
|
44
|
-
cache2[key] = value
|
45
|
-
}.to change {
|
46
|
-
cache2.size
|
47
|
-
}.from(0).to(1)
|
48
|
-
expect(cache.size).to eq 1
|
49
|
-
s = 0
|
50
|
-
cache.full_each { s += 1 }
|
51
|
-
expect(s).to eq 2
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'can delete' do
|
55
|
-
key, value = 'foo', { test: true }
|
56
|
-
expect(cache.delete(key)).to be_falsy
|
57
|
-
cache[key] = value
|
58
|
-
expect {
|
59
|
-
expect(cache.delete(key)).to be_truthy
|
60
|
-
}.to change {
|
61
|
-
cache.key?(key)
|
62
|
-
}.from(true).to(false)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'can iterate over keys, values' do
|
66
|
-
key, value = 'foo', { test: true }
|
67
|
-
cache[key] = value
|
68
|
-
cache.each do |k, v|
|
69
|
-
expect(k).to eq prefix + key
|
70
|
-
expect(v).to eq value
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'returns size' do
|
75
|
-
key, value = 'foo', { test: true }
|
76
|
-
expect {
|
77
|
-
cache[key] = value
|
78
|
-
}.to change {
|
79
|
-
cache.size
|
80
|
-
}.from(0).to(1)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'can clear' do
|
84
|
-
key, value = 'foo', { test: true }
|
85
|
-
cache[key] = value
|
86
|
-
expect {
|
87
|
-
expect(cache.clear).to eq cache
|
88
|
-
}.to change {
|
89
|
-
cache.size
|
90
|
-
}.from(1).to(0)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'can iterate over keys under a prefix' do
|
94
|
-
cache['foo'] = 'bar'
|
95
|
-
expect(cache.to_a).to eq [ %W[ #{prefix}foo bar ] ]
|
96
|
-
end
|
97
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Ollama::Documents::RedisBackedMemoryCache do
|
4
|
-
let :prefix do
|
5
|
-
'test-'
|
6
|
-
end
|
7
|
-
|
8
|
-
let :cache do
|
9
|
-
described_class.new prefix: 'test-', url: 'something'
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'raises ArgumentError if url is missing' do
|
13
|
-
expect {
|
14
|
-
described_class.new prefix:, url: nil
|
15
|
-
}.to raise_error ArgumentError
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'test redis interactions' do
|
19
|
-
let :data do
|
20
|
-
cache.instance_eval { @data }
|
21
|
-
end
|
22
|
-
|
23
|
-
let :redis_cache do
|
24
|
-
cache.instance_eval { @redis_cache }
|
25
|
-
end
|
26
|
-
|
27
|
-
let :redis do
|
28
|
-
double('Redis')
|
29
|
-
end
|
30
|
-
|
31
|
-
before do
|
32
|
-
allow_any_instance_of(Ollama::Documents::RedisCache).to\
|
33
|
-
receive(:redis).and_return(redis)
|
34
|
-
allow(redis).to receive(:scan_each)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'can be instantiated and initialized' do
|
38
|
-
expect(cache).to be_a described_class
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'defaults to nil object_class' do
|
42
|
-
expect(cache.object_class).to be_nil
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'can be configured with object_class' do
|
46
|
-
object_class = Class.new(JSON::GenericObject)
|
47
|
-
cache = described_class.new(prefix: 'test-', url: 'something', object_class:)
|
48
|
-
expect(cache.object_class).to eq object_class
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'has Redis client' do
|
52
|
-
expect(cache.redis).to eq redis
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'can get a key' do
|
56
|
-
key = 'foo'
|
57
|
-
expect(data).to receive(:[]).with('test-' + key).and_return 666
|
58
|
-
expect(cache[key]).to eq 666
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'can set a value for a key' do
|
62
|
-
key, value = 'foo', { test: true }
|
63
|
-
expect(data).to receive(:[]=).with('test-' + key, { test: true }).and_call_original
|
64
|
-
expect(redis).to receive(:set).with('test-' + key, JSON(value))
|
65
|
-
cache[key] = value
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'can determine if key exists' do
|
69
|
-
key = 'foo'
|
70
|
-
expect(data).to receive(:key?).with('test-' + key).and_return(false, true)
|
71
|
-
expect(cache.key?('foo')).to eq false
|
72
|
-
expect(cache.key?('foo')).to eq true
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'can delete' do
|
76
|
-
key = 'foo'
|
77
|
-
expect(data).to receive(:delete).with('test-' + key)
|
78
|
-
expect(redis).to receive(:del).with('test-' + key)
|
79
|
-
cache.delete(key)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'can iterate over keys, values' do
|
83
|
-
key, value = 'foo', { 'test' => true }
|
84
|
-
expect(redis).to receive(:set).with('test-' + key, JSON(value))
|
85
|
-
cache[key] = value
|
86
|
-
cache.each do |k, v|
|
87
|
-
expect(k).to eq prefix + key
|
88
|
-
expect(v).to eq value
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'returns size' do
|
93
|
-
expect(cache).to receive(:count).and_return 3
|
94
|
-
expect(cache.size).to eq 3
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'can clear' do
|
98
|
-
expect(redis).to receive(:scan_each).with(match: 'test-*').and_yield(
|
99
|
-
'test-foo'
|
100
|
-
)
|
101
|
-
expect(redis).to receive(:del).with('test-foo')
|
102
|
-
expect(cache.clear).to eq cache
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'can iterate over keys under a prefix' do
|
106
|
-
data['test-foo'] = 'bar'
|
107
|
-
expect(cache.to_a).to eq [ %w[ test-foo bar ] ]
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'can compute prefix with pre' do
|
111
|
-
expect(cache.pre('foo')).to eq 'test-foo'
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'can remove prefix with unpre' do
|
115
|
-
expect(cache.unpre('test-foo')).to eq 'foo'
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Ollama::Documents::RedisCache do
|
4
|
-
let :prefix do
|
5
|
-
'test-'
|
6
|
-
end
|
7
|
-
|
8
|
-
let :cache do
|
9
|
-
described_class.new prefix:, url: 'something'
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'can be instantiated' do
|
13
|
-
expect(cache).to be_a described_class
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'defaults to nil object_class' do
|
17
|
-
expect(cache.object_class).to be_nil
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'can be configured with object_class' do
|
21
|
-
object_class = Class.new(JSON::GenericObject)
|
22
|
-
cache = described_class.new(prefix:, url: 'something', object_class:)
|
23
|
-
expect(cache.object_class).to eq object_class
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'raises ArgumentError if url is missing' do
|
27
|
-
expect {
|
28
|
-
described_class.new prefix:, url: nil
|
29
|
-
}.to raise_error ArgumentError
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'test redis interactions' do
|
33
|
-
let :redis do
|
34
|
-
double('Redis')
|
35
|
-
end
|
36
|
-
|
37
|
-
before do
|
38
|
-
allow_any_instance_of(described_class).to receive(:redis).and_return(redis)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'has Redis client' do
|
42
|
-
expect(cache.redis).to eq redis
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'can get a key' do
|
46
|
-
key = 'foo'
|
47
|
-
expect(redis).to receive(:get).with(prefix + key).and_return '"some_json"'
|
48
|
-
expect(cache[key]).to eq 'some_json'
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'can set a value for a key' do
|
52
|
-
key, value = 'foo', { test: true }
|
53
|
-
expect(redis).to receive(:set).with(prefix + key, JSON(value), ex: nil)
|
54
|
-
cache[key] = value
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'can set a value for a key with ttl' do
|
58
|
-
cache = described_class.new prefix:, url: 'something', ex: 3_600
|
59
|
-
key, value = 'foo', { test: true }
|
60
|
-
expect(redis).to receive(:set).with(prefix + key, JSON(value), ex: 3_600)
|
61
|
-
cache[key] = value
|
62
|
-
expect(redis).to receive(:ttl).with(prefix + key).and_return 3_600
|
63
|
-
expect(cache.ttl(key)).to eq 3_600
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'can determine if key exists' do
|
67
|
-
key = 'foo'
|
68
|
-
expect(redis).to receive(:exists?).with(prefix + key).and_return(false, true)
|
69
|
-
expect(cache.key?('foo')).to eq false
|
70
|
-
expect(cache.key?('foo')).to eq true
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'can delete' do
|
74
|
-
key = 'foo'
|
75
|
-
expect(redis).to receive(:del).with(prefix + key)
|
76
|
-
cache.delete(key)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'can iterate over keys, values' do
|
80
|
-
key, value = 'foo', { 'test' => true }
|
81
|
-
expect(redis).to receive(:set).with(prefix + key, JSON(value), ex: nil)
|
82
|
-
cache[key] = value
|
83
|
-
expect(redis).to receive(:scan_each).with(match: "#{prefix}*").
|
84
|
-
and_yield("#{prefix}foo")
|
85
|
-
expect(redis).to receive(:get).with(prefix + key).and_return(JSON(test: true))
|
86
|
-
cache.each do |k, v|
|
87
|
-
expect(k).to eq prefix + key
|
88
|
-
expect(v).to eq value
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'returns size' do
|
93
|
-
expect(redis).to receive(:scan_each).with(match: "#{prefix}*").
|
94
|
-
and_yield("#{prefix}foo").
|
95
|
-
and_yield("#{prefix}bar").
|
96
|
-
and_yield("#{prefix}baz")
|
97
|
-
expect(cache.size).to eq 3
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'can clear' do
|
101
|
-
expect(redis).to receive(:scan_each).with(match: 'test-*').and_yield(
|
102
|
-
'test-foo'
|
103
|
-
)
|
104
|
-
expect(redis).to receive(:del).with('test-foo')
|
105
|
-
expect(cache.clear).to eq cache
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'can iterate over keys under a prefix' do
|
109
|
-
expect(redis).to receive(:scan_each).with(match: 'test-*')
|
110
|
-
cache.to_a
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'can compute prefix with pre' do
|
114
|
-
expect(cache.pre('foo')).to eq 'test-foo'
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'can remove prefix with unpre' do
|
118
|
-
expect(cache.unpre('test-foo')).to eq 'foo'
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Ollama::Documents::SQLiteCache do
|
4
|
-
let :prefix do
|
5
|
-
'test-'
|
6
|
-
end
|
7
|
-
|
8
|
-
let :test_value do
|
9
|
-
{
|
10
|
-
key: 'test',
|
11
|
-
text: 'test text',
|
12
|
-
norm: 0.5,
|
13
|
-
source: 'for-test.txt',
|
14
|
-
tags: %w[ test ],
|
15
|
-
embedding: [ 0.5 ] * 1_024,
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
let :cache do
|
20
|
-
described_class.new prefix:
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'can be instantiated' do
|
24
|
-
expect(cache).to be_a described_class
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'defaults to :memory: mode' do
|
28
|
-
expect(cache.filename).to eq ':memory:'
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'can be switchted to file mode' do
|
32
|
-
expect(SQLite3::Database).to receive(:new).with('foo.sqlite').
|
33
|
-
and_return(double.as_null_object)
|
34
|
-
cache = described_class.new prefix:, filename: 'foo.sqlite'
|
35
|
-
expect(cache.filename).to eq 'foo.sqlite'
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'can get/set a key' do
|
39
|
-
key, value = 'foo', test_value
|
40
|
-
queried_value = nil
|
41
|
-
expect {
|
42
|
-
cache[key] = value
|
43
|
-
}.to change {
|
44
|
-
queried_value = cache[key]
|
45
|
-
}.from(nil).to(Ollama::Documents::Record[value])
|
46
|
-
expect(queried_value.embedding).to eq [ 0.5 ] * 1_024
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'can determine if key exists' do
|
50
|
-
key, value = 'foo', test_value
|
51
|
-
expect {
|
52
|
-
cache[key] = value
|
53
|
-
}.to change {
|
54
|
-
cache.key?(key)
|
55
|
-
}.from(false).to(true)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'can set key with different prefixes' do
|
59
|
-
key, value = 'foo', test_value
|
60
|
-
expect {
|
61
|
-
cache[key] = value
|
62
|
-
}.to change {
|
63
|
-
cache.size
|
64
|
-
}.from(0).to(1)
|
65
|
-
cache2 = cache.dup
|
66
|
-
cache2.prefix = 'test2-'
|
67
|
-
expect {
|
68
|
-
cache2[key] = value
|
69
|
-
}.to change {
|
70
|
-
cache2.size
|
71
|
-
}.from(0).to(1)
|
72
|
-
expect(cache.size).to eq 1
|
73
|
-
s = 0
|
74
|
-
cache.full_each { s += 1 }
|
75
|
-
expect(s).to eq 2
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'can delete' do
|
79
|
-
key, value = 'foo', test_value
|
80
|
-
expect(cache.delete(key)).to be_falsy
|
81
|
-
cache[key] = value
|
82
|
-
expect {
|
83
|
-
expect(cache.delete(key)).to be_truthy
|
84
|
-
}.to change {
|
85
|
-
cache.key?(key)
|
86
|
-
}.from(true).to(false)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'returns size' do
|
90
|
-
key, value = 'foo', test_value
|
91
|
-
expect {
|
92
|
-
cache[key] = value
|
93
|
-
}.to change {
|
94
|
-
cache.size
|
95
|
-
}.from(0).to(1)
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'can convert_to_vector' do
|
99
|
-
vector = [ 23.0, 666.0 ]
|
100
|
-
expect(cache.convert_to_vector(vector)).to eq vector
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'can clear' do
|
104
|
-
key, value = 'foo', { embedding: [ 0.5 ] * 1_024 }
|
105
|
-
cache[key] = value
|
106
|
-
expect {
|
107
|
-
expect(cache.clear).to eq cache
|
108
|
-
}.to change {
|
109
|
-
cache.size
|
110
|
-
}.from(1).to(0)
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'can clear for tags' do
|
114
|
-
key, value = 'foo', { tags: %w[ foo ], embedding: [ 0.5 ] * 1_024 }
|
115
|
-
cache[key] = value
|
116
|
-
key, value = 'bar', { embedding: [ 0.5 ] * 1_024 }
|
117
|
-
cache[key] = value
|
118
|
-
expect {
|
119
|
-
expect(cache.clear_for_tags(%w[ #foo ])).to eq cache
|
120
|
-
}.to change {
|
121
|
-
cache.size
|
122
|
-
}.from(2).to(1)
|
123
|
-
expect(cache).not_to be_key 'foo'
|
124
|
-
expect(cache).to be_key 'bar'
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'can return tags' do
|
128
|
-
key, value = 'foo', { tags: %w[ foo ], embedding: [ 0.5 ] * 1_024 }
|
129
|
-
cache[key] = value
|
130
|
-
key, value = 'bar', { tags: %w[ bar baz ], embedding: [ 0.5 ] * 1_024 }
|
131
|
-
cache[key] = value
|
132
|
-
tags = cache.tags
|
133
|
-
expect(tags).to be_a Ollama::Utils::Tags
|
134
|
-
expect(tags.to_a).to eq %w[ bar baz foo ]
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'can iterate over keys under a prefix' do
|
138
|
-
cache['foo'] = test_value
|
139
|
-
expect(cache.to_a).to eq [ [ 'test-foo', Ollama::Documents::Record[test_value] ] ]
|
140
|
-
end
|
141
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Ollama::Documents::Splitters::Character do
|
4
|
-
let :splitter do
|
5
|
-
described_class.new chunk_size: 23, combining_string: ''
|
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 combining with separation' do
|
20
|
-
splitter = described_class.new chunk_size: 25, include_separator: false,
|
21
|
-
combining_string: ?X
|
22
|
-
text = [ ?A * 10 ] * 10 * "\n\n"
|
23
|
-
result = splitter.split(text)
|
24
|
-
expect(result.count).to eq 5
|
25
|
-
expect(result.to_a.join(?B)).to eq\
|
26
|
-
"AAAAAAAAAAXAAAAAAAAAAXBAAAAAAAAAAAAAAAAAAAAXBAAAAAAAAAAAAAAAAAAAAXB"\
|
27
|
-
"AAAAAAAAAAAAAAAAAAAAXBAAAAAAAAAAAAAAAAAAAAX"
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'can split including separator' do
|
31
|
-
splitter = described_class.new chunk_size: 25, include_separator: true,
|
32
|
-
combining_string: ''
|
33
|
-
text = [ ?A * 10 ] * 10 * "\n\n"
|
34
|
-
result = splitter.split(text)
|
35
|
-
expect(result.count).to eq 5
|
36
|
-
expect(result.to_a.join('')).to eq text
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'cannot split' do
|
40
|
-
text = [ ?A * 10 ] * 10 * "\n"
|
41
|
-
result = splitter.split(text)
|
42
|
-
expect(result.count).to eq 1
|
43
|
-
expect(result.to_a.join('').count(?A)).to eq text.count(?A)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'cannot split2' do
|
47
|
-
text = ?A * 25
|
48
|
-
result = splitter.split(text)
|
49
|
-
expect(result.count).to eq 1
|
50
|
-
expect(result.to_a.join('')).to eq ?A * 25
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'can split sentences' do
|
54
|
-
text = "foo.foo. bar!bar! baz?baz? quux.\nquux."
|
55
|
-
splitter = described_class.new(separator: /[.!?]\s*(?:\b|\z)/, chunk_size: 2)
|
56
|
-
result = splitter.split(text)
|
57
|
-
expect(result.to_a).to eq %w[ foo foo bar bar baz baz quux quux ]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
RSpec.describe Ollama::Documents::Splitters::RecursiveCharacter do
|
62
|
-
let :splitter do
|
63
|
-
described_class.new chunk_size: 23, combining_string: ''
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'can be instantiated' do
|
67
|
-
expect(splitter).to be_a described_class
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'can split' do
|
71
|
-
text = [ ?A * 10 ] * 10 * "\n\n"
|
72
|
-
result = splitter.split(text)
|
73
|
-
expect(result.count).to eq 5
|
74
|
-
expect(result.to_a.join('')).to eq ?A * 100
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'cannot split' do
|
78
|
-
splitter = described_class.new chunk_size: 23, include_separator: true,
|
79
|
-
separators: described_class::DEFAULT_SEPARATORS[0..-2]
|
80
|
-
text = ?A * 25
|
81
|
-
result = splitter.split(text)
|
82
|
-
expect(result.count).to eq 1
|
83
|
-
expect(result.to_a.join('')).to eq ?A * 25
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'can split including separator' do
|
87
|
-
splitter = described_class.new chunk_size: 25, include_separator: true,
|
88
|
-
combining_string: ''
|
89
|
-
text = [ ?A * 10 ] * 10 * "\n\n"
|
90
|
-
result = splitter.split(text)
|
91
|
-
expect(result.count).to eq 5
|
92
|
-
expect(result.to_a.join('')).to eq text
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'can split single newline as well' do
|
96
|
-
text = [ ?A * 10 ] * 10 * "\n"
|
97
|
-
result = splitter.split(text)
|
98
|
-
expect(result.count).to eq 5
|
99
|
-
expect(result.to_a.join('')).to eq ?A * 100
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'can split single newline as well including separator' do
|
103
|
-
splitter = described_class.new chunk_size: 25, include_separator: true,
|
104
|
-
combining_string: ''
|
105
|
-
text = [ ?A * 10 ] * 10 * "\n"
|
106
|
-
result = splitter.split(text)
|
107
|
-
expect(result.count).to eq 5
|
108
|
-
expect(result.to_a.join('')).to eq text
|
109
|
-
end
|
110
|
-
end
|
@@ -1,56 +0,0 @@
|
|
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
|