Class: Mneme::Search

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

Examples:

Mneme’s recall muse searching for the main session

Mneme::Search.query("authentication flow", caller_session: session)

Aoide searching actively from her own session

Mneme::Search.query("OAuth config", caller_session: session)

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • terms (String)

    search query (FTS5 syntax: words, phrases, OR/AND/NOT)

  • caller_session (Session)

    the session doing the search — used to exclude its own viewport from the results. Required; search always happens from the perspective of a specific session.

  • limit (Integer) (defaults to: Anima::Settings.recall_max_results)

    maximum results

Returns:

  • (Array<Result>)

    ranked by relevance (best first)



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

#callArray<Result>

Returns ranked by relevance (best first).

Returns:

  • (Array<Result>)

    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