Class: Omakase::Memory
- Inherits:
-
Object
- Object
- Omakase::Memory
- Defined in:
- lib/omakase/memory.rb
Overview
Recall by meaning rather than by key: text goes in, the closest of it comes
back out. The embeddings are RubyLLM's and the search is a dot product over
an array — enough for the few hundred things one agent learns about its
work. Past that it is your database's job (pgvector, the neighbor gem),
and this is the interface to reimplement against it.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #recall(query, limit: 5) ⇒ Object
-
#remember(text) ⇒ Object
Keyed by the text, so remembering the same thing twice costs one entry.
- #size ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
10 |
# File 'lib/omakase/memory.rb', line 10 def initialize = @entries = {} |
Instance Method Details
#empty? ⇒ Boolean
27 |
# File 'lib/omakase/memory.rb', line 27 def empty? = @entries.empty? |
#recall(query, limit: 5) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/omakase/memory.rb', line 18 def recall(query, limit: 5) return [] if empty? vector = unit(Omakase..call(query)) @entries.max_by(limit) { |_, remembered| dot(vector, remembered) }.map(&:first) end |
#remember(text) ⇒ Object
Keyed by the text, so remembering the same thing twice costs one entry.
13 14 15 16 |
# File 'lib/omakase/memory.rb', line 13 def remember(text) @entries[text] ||= unit(Omakase..call(text)) text end |
#size ⇒ Object
25 |
# File 'lib/omakase/memory.rb', line 25 def size = @entries.size |