Class: ClaudeMemory::Commands::Checks::FtsRankCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_memory/commands/checks/fts_rank_check.rb

Overview

Probes the FTS5 BM25 ranking path (‘MATCH … ORDER BY rank`) — exactly what recall issues. A contentless FTS5 index can corrupt such that plain MATCH, `SELECT count(*)`, and `PRAGMA integrity_check` all pass but `ORDER BY rank` raises “database disk image is malformed”, silently breaking recall while every other check reports healthy (issue #7, Finding 2). Recoverable with `claude-memory compact`.

Constant Summary collapse

PROBE_TERM =

extremely common; matches any non-trivial English corpus

"the"

Instance Method Summary collapse

Constructor Details

#initialize(db_path, label) ⇒ FtsRankCheck

Returns a new instance of FtsRankCheck.



15
16
17
18
# File 'lib/claude_memory/commands/checks/fts_rank_check.rb', line 15

def initialize(db_path, label)
  @db_path = db_path
  @label = label
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/claude_memory/commands/checks/fts_rank_check.rb', line 20

def call
  return skip_result unless File.exist?(@db_path)

  store = Store::SQLiteStore.new(@db_path)
  begin
    Index::LexicalFTS.new(store).search(PROBE_TERM, limit: 1)
    ok_result
  ensure
    store.close
  end
rescue Index::LexicalFTS::CorruptRankIndexError
  corrupt_result
rescue => e
  # Anything unrelated (e.g. no FTS table) is not this check's concern.
  {status: :ok, label: fts_label, message: "#{@label} FTS5 rank probe skipped: #{e.message}", details: {}}
end