superlocalmemory icon indicating copy to clipboard operation
superlocalmemory copied to clipboard

feat: scope-aware retrieval with weighted RRF fusion (PR 2/3)

Open kenyonxu opened this issue 5 months ago • 0 comments

Summary

PR 2/3 of the multi-scope memory feature (RFC #20).

Adds scope filtering to all retrieval channels and implements multi-scope parallel retrieval with configurable RRF fusion weights.

Changes

File Change
core/config.py Add ScopeWeights dataclass (personal=1.0, shared=0.7, global=0.5) with load/save persistence
storage/database.py Add _scope_where() helper + scope params (include_global/include_shared) on 11 query methods
retrieval/engine.py Add include_global/include_shared to recall(), set on channels before parallel execution
retrieval/semantic_channel.py Pass scope flags to get_facts_by_ids/get_all_facts
retrieval/bm25_channel.py Pass scope flags to get_all_facts cold-load
retrieval/hopfield_channel.py Pass scope flags to get_facts_by_ids/get_all_facts
retrieval/entity_channel.py Pass scope flags to get_facts_by_entity/get_edges_for_node
core/recall_pipeline.py Pass include_global/include_shared through to engine

Design

  • All new parameters default to True (backward compatible)
  • _scope_where() builds SQL: (profile_id = ?) OR (scope = 'global') OR (scope = 'shared' AND shared_with LIKE ?)
  • Scope flags set on channel instances before ThreadPoolExecutor dispatch (thread-safe)
  • Existing data has scope='personal' (PR 1/3 column default) — OR branches are no-ops

Dependencies

  • Requires PR #42 (schema + migration)
  • PR 3/3 (external interface) builds on this

Test Results

  • 755 passed on Ubuntu (all 3 Python versions)
  • 75 passed on macOS (all 3 Python versions)
  • Pre-existing failures only — no regressions from scope changes

Ref: #20

kenyonxu avatar Jun 15 '26 10:06 kenyonxu