Class: Mneme::Search
- Inherits:
-
Object
- Object
- Mneme::Search
- Defined in:
- lib/mneme/search.rb
Overview
Full-text search over long-term memory — the message history outside the caller’s current viewport. Covers user messages, agent messages, and think messages across every session Anima has ever held.
The interface is intentionally abstract — callers receive Result structs and never touch FTS5 directly. A future semantic search backend (embeddings, BM25 + re-ranking) can replace the implementation without changing callers.
Defined Under Namespace
Classes: Result
Class Method Summary collapse
-
.query(terms, caller_session:, limit: Anima::Settings.recall_max_results) ⇒ Array<Result>
Searches long-term memory for the given terms.
Instance Method Summary collapse
-
#call ⇒ Array<Result>
Ranked by relevance (best first).
-
#initialize(terms, caller_session:, limit: 5) ⇒ Search
constructor
A new instance of Search.
Constructor Details
#initialize(terms, caller_session:, limit: 5) ⇒ Search
Returns a new instance of Search.
45 46 47 48 49 50 |
# File 'lib/mneme/search.rb', line 45 def initialize(terms, caller_session:, limit: 5) @terms = sanitize_query(terms) @caller_session = caller_session @limit = limit @recency_decay = Anima::Settings.recall_recency_decay end |
Class Method Details
.query(terms, caller_session:, limit: Anima::Settings.recall_max_results) ⇒ Array<Result>
Searches long-term memory for the given terms.
Excludes messages currently in the caller’s viewport so a ‘LIMIT`-bounded search never burns its slots returning things the caller already has in front of them. A caller with no established Mneme boundary yet (fresh main session, sub-agent) treats the whole session as “in viewport” — none of its own messages surface.
41 42 43 |
# File 'lib/mneme/search.rb', line 41 def self.query(terms, caller_session:, limit: Anima::Settings.recall_max_results) new(terms, caller_session: caller_session, limit: limit).call end |
Instance Method Details
#call ⇒ Array<Result>
Returns ranked by relevance (best first).
53 54 55 56 57 58 |
# File 'lib/mneme/search.rb', line 53 def call return [] if @terms.blank? rows = execute_fts_query rows.map { |row| build_result(row) } end |