Class: RobotLab::Durable::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/robot_lab/durable/adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(robot_name:) ⇒ Adapter

Returns a new instance of Adapter.



10
11
12
# File 'lib/robot_lab/durable/adapter.rb', line 10

def initialize(robot_name:)
  @htm = HTM.new(robot_name: robot_name)
end

Instance Attribute Details

#htmObject (readonly)

Returns the value of attribute htm.



8
9
10
# File 'lib/robot_lab/durable/adapter.rb', line 8

def htm
  @htm
end

Instance Method Details

#recall(query:, limit: 20, strategy: :hybrid) ⇒ Array<Entry>

Recall entries relevant to a query using HTM hybrid search.

Parameters:

  • query (String)

    Natural-language search string

  • limit (Integer) (defaults to: 20)

    Maximum number of results

  • strategy (Symbol) (defaults to: :hybrid)

    :vector, :fulltext, or :hybrid

Returns:



20
21
22
23
# File 'lib/robot_lab/durable/adapter.rb', line 20

def recall(query:, limit: 20, strategy: :hybrid)
  nodes = @htm.recall(query, limit: limit, strategy: strategy, raw: true)
  nodes.map { |node| Entry.from_node(node) }
end

#record(content:, reasoning: nil, category: 'fact') ⇒ Integer

Store content in HTM long-term memory.

Parameters:

  • content (String)
  • reasoning (String, nil) (defaults to: nil)

    Why this is worth remembering

  • category (String, Symbol) (defaults to: 'fact')

    fact, preference, pattern, correction, or observation

Returns:

  • (Integer)

    HTM node_id



31
32
33
34
35
36
37
38
39
# File 'lib/robot_lab/durable/adapter.rb', line 31

def record(content:, reasoning: nil, category: 'fact')
  @htm.remember(
    content,
    metadata: {
      'reasoning' => reasoning,
      'category'  => category.to_s
    }
  )
end