Class: Omakase::Memory

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeMemory

Returns a new instance of Memory.



10
# File 'lib/omakase/memory.rb', line 10

def initialize = @entries = {}

Instance Method Details

#empty?Boolean

Returns:

  • (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.embedder.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.embedder.call(text))
  text
end

#sizeObject



25
# File 'lib/omakase/memory.rb', line 25

def size = @entries.size