Skip to content

feat(memory): adaptive retrieval dispatch by query type (#1629)#1789

Merged
bug-ops merged 5 commits intomainfrom
research-memory-adaptive-retri
Mar 14, 2026
Merged

feat(memory): adaptive retrieval dispatch by query type (#1629)#1789
bug-ops merged 5 commits intomainfrom
research-memory-adaptive-retri

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 14, 2026

Summary

  • Add has_temporal_cue() heuristic classifier (word-boundary matching, zero heap allocs) checked first in HeuristicRouter::route() before relationship patterns
  • Route episodic queries (temporal keywords: "yesterday", "last week", "when did", etc.) to SQLite FTS5 + created_at timestamp range filter; semantic queries continue through existing BM25+RRF+MMR pipeline
  • strip_temporal_keywords() removes temporal tokens from the FTS5 query using LazyLock sorted patterns and a single-pass span merge (~18x fewer allocations vs naive approach)
  • resolve_temporal_range(now: DateTime<Utc>) converts temporal expressions to ISO 8601 bounds with injectable clock for deterministic tests
  • keyword_search_with_time_range() uses parameterized sqlx queries; no schema changes; same agent_visible/deleted_at/conversation access controls as existing path
  • Add clock feature to workspace chrono dep to fix isolated zeph-memory build

Test plan

  • 45 new unit tests pass: routing (8 temporal true-positives + false-positive guards including "Chicago"/"ago"), resolver (9 deterministic with injected time), strip (8 edge cases: empty, all-temporal, repeated patterns, all-occurrence removal), SQL filter (6: after-bound, both-bounds, conversation isolation, empty query), Episodic dispatch integration (2)
  • Total: 5629 tests, all pass with --features full
  • cargo +nightly fmt --check: PASS
  • cargo clippy --workspace --features full -- -D warnings: PASS
  • Security audit: PASS (parameterized SQL, no unsafe, no ReDoS, access controls preserved)

Closes #1629

bug-ops added 3 commits March 14, 2026 21:55
- README.md, zeph-llm, zeph-mcp, zeph-memory, zeph-tools: reflect
  tool overflow SQLite migration, graph memory temporal versioning,
  Gemini Phase 4 SSE tool use, cascade cost_tiers, MCP sanitization
- docs/src/advanced/tools.md: update overflow storage section
  (disk path → SQLite-backed, portable, auto-cleanup on session end)
- docs/src/reference/configuration.md: document temporal_decay_rate
  validation ([0.0, 10.0] clamp) and cost_tiers cascade config field
- graph-memory.md: document temporal edge validity (valid_from/valid_until,
  edges_at_timestamp, edge_history, bfs_at_timestamp, temporal_decay_rate)
- providers.md: add Gemini Phase 4 SSE streaming tool use
- adaptive-inference.md: document cascade cost_tiers config
- observability.md: minor updates
- security/mcp.md: document tools/list_changed sanitization
Add a lightweight query classifier to zeph-memory that routes recall
queries to the optimal retrieval path based on temporal cues:

- Episodic queries (temporal keywords: "yesterday", "last week", etc.)
  route to SQLite FTS5 + optional created_at timestamp range filter
- Semantic queries continue through the existing BM25+RRF+MMR pipeline

Implementation details:
- `has_temporal_cue()`: word-boundary heuristic (no regex, no allocs)
  checked first in HeuristicRouter::route() before relationship patterns
- `strip_temporal_keywords()`: LazyLock sorted patterns, single-pass span
  removal, single lowercase allocation — ~18x fewer allocs vs naive impl
- `resolve_temporal_range(now)`: injectable clock for deterministic tests,
  covers 12 temporal expressions with explicit branches
- `keyword_search_with_time_range()`: parameterized sqlx queries, no
  schema changes, same access control predicates as existing path
- Add chrono `clock` feature to workspace dep for isolated crate builds

45 new tests: routing (temporal + false-positive guards), resolver
(deterministic with injected time), strip (edge cases + all-occurrence
removal), SQL filter (bounds, conversation isolation), Episodic dispatch
integration.
@github-actions github-actions bot added documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) memory zeph-memory crate (SQLite) rust Rust code changes dependencies Dependency updates enhancement New feature or request size/XL Extra large PR (500+ lines) labels Mar 14, 2026
@github-actions github-actions bot removed the llm zeph-llm crate (Ollama, Claude) label Mar 14, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 14, 2026 21:41
@bug-ops bug-ops merged commit aa22b2e into main Mar 14, 2026
15 checks passed
@bug-ops bug-ops deleted the research-memory-adaptive-retri branch March 14, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Dependency updates documentation Improvements or additions to documentation enhancement New feature or request memory zeph-memory crate (SQLite) rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

research(memory): adaptive retrieval dispatch by query type (TA-Mem pattern)

1 participant