Module: Ollama::Documents::Cache::Common
- Includes:
- Utils::Math
- Included in:
- MemoryCache, RedisCache
- Defined in:
- lib/ollama/documents/cache/common.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
writeonly
current prefix defined for the cache.
Instance Method Summary collapse
-
#collections(prefix) ⇒ Array<Symbol>
Returns an array of collection names that match the given prefix.
-
#pre(key) ⇒ String
Returns a string representing the given ‘key` prefixed with the defined prefix.
-
#unpre(key) ⇒ String
Returns a string with the prefix removed from the given ‘key`.
Methods included from Utils::Math
#convert_to_vector, #cosine_similarity, #norm
Instance Attribute Details
#prefix=(value) ⇒ Object (writeonly)
current prefix defined for the cache
4 5 6 |
# File 'lib/ollama/documents/cache/common.rb', line 4 def prefix=(value) @prefix = value end |
Instance Method Details
#collections(prefix) ⇒ Array<Symbol>
Returns an array of collection names that match the given prefix.
10 11 12 13 14 |
# File 'lib/ollama/documents/cache/common.rb', line 10 def collections(prefix) unique = Set.new full_each { |key, _| unique << key[/\A#{prefix}(.*)-/, 1] } unique.map(&:to_sym) end |
#pre(key) ⇒ String
Returns a string representing the given ‘key` prefixed with the defined prefix.
21 22 23 |
# File 'lib/ollama/documents/cache/common.rb', line 21 def pre(key) [ @prefix, key ].join end |
#unpre(key) ⇒ String
Returns a string with the prefix removed from the given ‘key`.
29 30 31 |
# File 'lib/ollama/documents/cache/common.rb', line 29 def unpre(key) key.sub(/\A#@prefix/, '') end |