Class: Rubino::Memory::Retriever
- Inherits:
-
Object
- Object
- Rubino::Memory::Retriever
- Defined in:
- lib/rubino/memory/retriever.rb
Overview
Retrieves relevant memories for inclusion in prompts. Handles user profile, project context, and session-relevant memories.
Instance Method Summary collapse
-
#for_prompt ⇒ Object
Returns all memories formatted for prompt inclusion.
-
#initialize(store: nil, config: nil) ⇒ Retriever
constructor
A new instance of Retriever.
-
#project_context ⇒ Object
Returns project context memories.
-
#relevant_for_session(_session_id) ⇒ Object
Returns memories relevant to the current session context.
-
#user_profile ⇒ Object
Returns the user profile text (concatenated user_profile memories).
Constructor Details
#initialize(store: nil, config: nil) ⇒ Retriever
Returns a new instance of Retriever.
8 9 10 11 |
# File 'lib/rubino/memory/retriever.rb', line 8 def initialize(store: nil, config: nil) @store = store || Store.new @config = config || Rubino.configuration end |
Instance Method Details
#for_prompt ⇒ Object
Returns all memories formatted for prompt inclusion
41 42 43 44 45 46 47 |
# File 'lib/rubino/memory/retriever.rb', line 41 def for_prompt { user_profile: user_profile, project_context: project_context, general: @store.within_limit(char_limit: @config.memory_char_limit) } end |
#project_context ⇒ Object
Returns project context memories
25 26 27 28 29 30 31 32 |
# File 'lib/rubino/memory/retriever.rb', line 25 def project_context return nil unless @config.dig("memory", "project_context_enabled") memories = @store.by_kind("project_context", limit: 10) return nil if memories.empty? memories.map { |m| m[:content] }.join("\n") end |
#relevant_for_session(_session_id) ⇒ Object
Returns memories relevant to the current session context
35 36 37 38 |
# File 'lib/rubino/memory/retriever.rb', line 35 def relevant_for_session(_session_id) char_limit = @config.memory_char_limit @store.within_limit(char_limit: char_limit) end |
#user_profile ⇒ Object
Returns the user profile text (concatenated user_profile memories)
14 15 16 17 18 19 20 21 22 |
# File 'lib/rubino/memory/retriever.rb', line 14 def user_profile return nil unless @config.dig("memory", "user_profile_enabled") char_limit = @config.memory_user_char_limit memories = @store.by_kind("user_profile") text = memories.map { |m| m[:content] }.join("\n") text.length > char_limit ? text[0...char_limit] : text end |