Module: Ollama::Documents::Cache::Common

Includes:
Utils::Math
Included in:
MemoryCache, RedisCache
Defined in:
lib/ollama/documents/cache/common.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • prefix (String)

    a string to search for in collection names

Returns:

  • (Array<Symbol>)

    an array of matching collection names



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.

Parameters:

  • key (String)

    the key to join with the prefix

Returns:

  • (String)

    the joined string of prefix and key



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`.

Parameters:

  • key (String)

    the input string containing the prefix.

Returns:

  • (String)

    the input string without the prefix.



29
30
31
# File 'lib/ollama/documents/cache/common.rb', line 29

def unpre(key)
  key.sub(/\A#@prefix/, '')
end