Skip to content

feat: recallMode with adaptive intent routing and tiered injection#313

Open
AliceLJY wants to merge 11 commits intoCortexReach:masterfrom
AliceLJY:feat/recall-mode
Open

feat: recallMode with adaptive intent routing and tiered injection#313
AliceLJY wants to merge 11 commits intoCortexReach:masterfrom
AliceLJY:feat/recall-mode

Conversation

@AliceLJY
Copy link
Collaborator

@AliceLJY AliceLJY commented Mar 23, 2026

Summary

  • Adds recallMode config option (full | summary | adaptive | off) for granular control over auto-recall behavior
  • Adaptive mode (new): automatically analyzes query intent to determine category routing and injection depth — inspired by OpenViking's hierarchical retrieval intent routing
  • Intent detection is pure pattern matching (no LLM calls) for zero extra latency
  • Supports both English and Chinese query patterns

How adaptive mode works

Query type Example Category filter Injection depth
Preference "What's my coding style?" preference L0 (one-line)
Decision "Why did we choose Postgres?" decision L1 (medium)
Entity "Who is the auth team lead?" entity L1 (medium)
Event "What happened last deploy?" event Full text
Fact "How does the API work?" fact L1 (medium)
Ambiguous "Write a sort function" No filter L0 (compact)

Automatic fallback: if category filtering yields zero results, retries without filter.

New files

  • src/intent-analyzer.tsanalyzeIntent(), applyCategoryBoost(), formatAtDepth()
  • test/intent-analyzer.test.mjs — 20 tests (all passing)

Config example

{
  "recallMode": "adaptive"
}

Test plan

  • 20 unit tests for intent analysis, category boost, and tiered formatting
  • Manual test with OpenClaw agent: verify adaptive recall injects correct depth
  • Verify fallback works when category filter yields zero results
  • Verify backward compat: existing recallMode: "full" unchanged

References

🤖 Generated with Claude Code

furedericca-lab and others added 8 commits March 8, 2026 10:43
…focus-note-handoff

feat(refactor): rework reflection handoff note and drop legacy combined rows
…command-hook-lifecycle

fix(reflection): restore /new-/reset trigger reliability after startup hook reset
Co-authored-by: furedericca <263020793+furedericca-lab@users.noreply.github.com>
Co-authored-by: furedericca <263020793+furedericca-lab@users.noreply.github.com>
…ntrol

Rebase onto current main with orchestrateDynamicRecall architecture.

- Add recallMode: "full" | "summary" | "off" config option
- full: existing autoRecall behavior (inject matching memories)
- summary: lightweight count hint only (saves context budget)
- off: disable auto-recall entirely
- Backward compatible: recallMode takes precedence, falls back to autoRecall boolean

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… tiered injection

Extends the recallMode config with a new "adaptive" option that automatically
analyzes query intent to determine which memory categories to prioritize and
how much detail to inject into agent context.

Intent detection is rule-based (no LLM calls) for zero extra latency:
- preference queries → filter to preference category, inject L0 (compact)
- decision/fact queries → filter to decision/fact, inject L1 (medium)
- event/timeline queries → inject full text for complete context
- ambiguous queries → no filter, L0 depth to minimize token cost

Includes automatic fallback: if category filtering yields zero results,
retries without filter to ensure the agent always gets relevant context.

Inspired by OpenViking's hierarchical retrieval intent routing, adapted
for memory-lancedb-pro's flat category + scope model.

New files:
- src/intent-analyzer.ts: analyzeIntent(), applyCategoryBoost(), formatAtDepth()
- test/intent-analyzer.test.mjs: 20 tests covering intent detection, category
  boost, and tiered formatting (all passing)

Config: recallMode now accepts "full" | "summary" | "adaptive" | "off"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AliceLJY AliceLJY changed the title feat: add recallMode config (full/summary/off) for granular recall control feat: recallMode with adaptive intent routing and tiered injection Mar 23, 2026
Fixes 6 issues identified by Codex code review:

1. [High] Security: add sanitizeForContext() to formatAtDepth() and
   [UNTRUSTED DATA] wrapper to prevent prompt injection from stored memories
2. [High] Remove "event" from MemoryCategoryIntent — it's not a stored
   category; event queries now route to entity+decision instead
3. [Medium] Add session dedup to adaptive recall (autoRecallMinRepeated)
   to prevent spamming same memories every turn
4. [Medium] Narrow entity regex patterns to avoid misclassifying
   "tool"/"component"/"关于" queries as entity intent
5. [Medium] Tests updated for all fixes + new CJK/sanitize test cases
6. [Low] Fix CJK sentence splitting: recognize 。!? without trailing space

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants