Skip to content

feat(#181): agent recall optimization with caching and context output - #307

Merged
ajianaz merged 3 commits into
developfrom
feat/181-agent-recall-optimization
Jun 12, 2026
Merged

ajianaz merged 3 commits into
developfrom
feat/181-agent-recall-optimization

Conversation

@ajianaz

@ajianaz ajianaz commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Multi-layered recall optimization for AI agent integration.

# Standard recall
uteke recall "query" --limit 5

# Context mode — formatted for prompt injection
uteke recall "query" --limit 5 --context

# Cache metrics
uteke stats  # shows cache_hits, cache_misses, hit_rate

Recall cache: LRU (256 entries, 5min TTL), auto-invalidated on mutations.
Context output: Compact structured format optimized for LLM consumption.

Closes #181

Recall cache:
- LRU cache (256 entries, 5min TTL) avoids redundant embedding computation
- Auto-invalidation on remember/forget mutations
- Cache metrics exposed in uteke stats (hits, misses, hit rate)
- Effective for server/MCP mode where process is long-lived

Context output:
- uteke recall --context formats results for AI prompt injection
- Compact structured summary: score, content, tags, importance markers
- recall_context() library API for direct prompt injection

Closes #181
@github-actions

github-actions Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (2)

  • crates/uteke-core/src/operations.rs:457 — In forget, the cache is invalidated before the actual SQLite/index deletion is attempted: self.recall_cache.invalidate_namespace(&memory.namespace); runs before acquiring the index lock and before the delete work completes. If a later step in forget fails and the method returns Err, the cache has already been cleared even though the memory still exists. Subsequent recalls can repopulate the cache with the still-present memory, and callers observing the failed delete get behavior that does not match the attempted mutation point. Invalidation should happen only after the delete succeeds, or be rolled back on failure.
  • crates/uteke-core/src/operations.rs:242 — The new cache is invalidated on remember and forget, but there is no invalidation for updates to existing memories in this diff. recall_hybrid now serves cached Vec<SearchResult> from self.recall_cache.get(...), and those results contain cloned Memory payloads. If another operation modifies a memory's content, tags, pinned flag, importance, or relationships without calling invalidate_namespace, recall can keep returning stale copies until TTL expiry. The diff adds mutation-driven invalidation only in remember and forget, so cached data freshness is not preserved for other mutation paths.

Review powered by cora-cli · BYOK · MIT

- Cache key now includes RecallStrategy (vector/fts5/hybrid)
  to prevent wrong results when strategy differs between calls
- min_score is intentionally NOT in cache key: cached results
  store unfiltered results and caller re-applies threshold
- Renamed from 'LRU' to 'FIFO' — eviction uses insert-time,
  not access-time (accurate documentation)
- forget() now uses targeted namespace invalidation instead
  of full cache clear, preventing cross-namespace regression
…rget

- Cache moved from recall() to recall_hybrid() — strategy-aware key
  ensures Hybrid/Fts5/Vector paths get separate cache entries
- Tag hash collision fixed: added count sentinel + per-tag separator
  to prevent ['a','bc'] vs ['ab','c'] hash ambiguity
- forget() no longer clears entire cache on lookup failure — only
  invalidates the specific namespace when memory is found
- Removed dead cache.clear() usage, kept as public API
@ajianaz
ajianaz merged commit d1d70b4 into develop Jun 12, 2026
9 checks passed
@ajianaz
ajianaz deleted the feat/181-agent-recall-optimization branch June 12, 2026 09:38
ajianaz added a commit that referenced this pull request Aug 13, 2026
…#307)

* feat(#181): agent recall optimization with caching and context output

Recall cache:
- LRU cache (256 entries, 5min TTL) avoids redundant embedding computation
- Auto-invalidation on remember/forget mutations
- Cache metrics exposed in uteke stats (hits, misses, hit rate)
- Effective for server/MCP mode where process is long-lived

Context output:
- uteke recall --context formats results for AI prompt injection
- Compact structured summary: score, content, tags, importance markers
- recall_context() library API for direct prompt injection

Closes #181

* fix(#181): address Cora review findings on recall cache

- Cache key now includes RecallStrategy (vector/fts5/hybrid)
  to prevent wrong results when strategy differs between calls
- min_score is intentionally NOT in cache key: cached results
  store unfiltered results and caller re-applies threshold
- Renamed from 'LRU' to 'FIFO' — eviction uses insert-time,
  not access-time (accurate documentation)
- forget() now uses targeted namespace invalidation instead
  of full cache clear, preventing cross-namespace regression

* fix(#181): address all Cora review findings — cache key, strategy, forget

- Cache moved from recall() to recall_hybrid() — strategy-aware key
  ensures Hybrid/Fts5/Vector paths get separate cache entries
- Tag hash collision fixed: added count sentinel + per-tag separator
  to prevent ['a','bc'] vs ['ab','c'] hash ambiguity
- forget() no longer clears entire cache on lookup failure — only
  invalidates the specific namespace when memory is found
- Removed dead cache.clear() usage, kept as public API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🧠 [P1] Agent recall optimization — ensure memories are actually used by Hermes agents

2 participants