Skip to content

fix: increment retrieval_count in FactRetriever (closes #17899) - #24527

Closed
plhiggins wants to merge 1 commit into
NousResearch:mainfrom
plhiggins:fix/holographic-retrieval-count
Closed

fix: increment retrieval_count in FactRetriever (closes #17899)#24527
plhiggins wants to merge 1 commit into
NousResearch:mainfrom
plhiggins:fix/holographic-retrieval-count

Conversation

@plhiggins

Copy link
Copy Markdown

Problem

The retrieval_count column in the facts table is never incremented during normal operation, making it useless as a usage metric. All 44 facts in my store show retrieval_count = 0 despite weeks of active use.

Root Cause

Two search paths exist, but only store.search_facts() increments the counter — and nothing calls it:

  • store.search_facts() (store.py:191) — has UPDATE facts SET retrieval_count = retrieval_count + 1. Nobody calls this method.
  • FactRetriever.search/probe/related/reason() (retrieval.py) — the actual retrieval layer used by prefetch() and fact_store tool calls. Queries the DB directly, never increments the counter.

Reported in #17899.

Fix

  • Add store.touch_facts(fact_ids) as a shared helper that increments retrieval_count for given fact IDs (with lock, noop on empty list).
  • Call touch_facts() in all 5 return paths across the 4 retrieval methods: search(), probe() (2 paths — bank-hit and direct), related(), and reason().

The existing search_facts() increment logic in store.py is untouched — no behavior change for any code that does call it directly.

Testing

  • Verified touch_facts exists on MemoryStore and is referenced in all 4 retrieval methods via inspect.getsource().
  • The fix is minimal and additive — no existing code paths are modified, only extended with a post-retrieval counter bump.

Files Changed

  • plugins/memory/holographic/store.py — add touch_facts() method
  • plugins/memory/holographic/retrieval.py — call touch_facts() after scoring in all return paths

…reason

The retrieval_count column in the facts table was never incremented during
normal operation because FactRetriever bypasses store.search_facts() (the
only method with the increment logic). All four retrieval methods — search(),
probe(), related(), reason() — query the database directly via _fts_candidates
or _score_facts_by_vector and never update retrieval_count.

Add store.touch_facts() as a shared helper and call it in all five return
paths across the four retrieval methods. This enables trust scoring and
usage metrics to reflect actual access patterns.

Closes #17899
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/plugins Plugin system and bundled plugins tool/memory Memory tool and memory providers labels May 12, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #21022 — same retrieval_count fix for #17899. PR #21022 covers all retrieval methods with an equivalent approach. Also overlaps with omnibus PR #23221.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants