Skip to content

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

Open
kenyonxu wants to merge 5 commits into
qualixar:mainfrom
kenyonxu:pr/scope-retrieval
Open

feat: scope-aware retrieval with weighted RRF fusion (PR 2/3)#43
kenyonxu wants to merge 5 commits into
qualixar:mainfrom
kenyonxu:pr/scope-retrieval

Conversation

@kenyonxu

Copy link
Copy Markdown

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

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 added 5 commits June 15, 2026 17:00
…a only)

Add scope (TEXT, default 'personal') and shared_with (TEXT, nullable)
columns to 5 core tables, plus composite indexes on (scope) and
(profile_id, scope):

  - memories
  - atomic_facts
  - canonical_entities
  - temporal_events
  - graph_edges

Models updated with scope/shared_with fields. Migration M016 handles
ALTER TABLE for existing databases — all existing data defaults to
'personal' for full backward compatibility.

This is PR 1/3 of the multi-scope memory feature — pure storage layer.
No retrieval logic or interface changes included.

Ref: qualixar#20
Add ScopeWeights dataclass (personal=1.0, shared=0.7, global=0.5) for
multi-scope RRF fusion weighting. Persisted in config.json under
scope_weights key.

Part of PR-B: Retrieval Layer for multi-scope memory (qualixar#20).
Add module-level _scope_where() function that builds scope-filtering
WHERE clauses for multi-scope retrieval (personal/global/shared).

Update 11 query methods with optional include_global/include_shared params:
- get_pinned, get_all_facts, get_facts_by_entity, get_facts_by_type
- get_facts_by_memory_id, get_fact_count, get_facts_by_ids
- search_facts_fts, get_edges_for_node, get_temporal_events
- get_temporal_events_by_range

All new params default to True (backward compatible). Existing data has
scope='personal' (column default) so the OR branches are harmless no-ops.

Part of PR-B: Retrieval Layer for multi-scope memory (qualixar#20).
- engine.recall(): add include_global/include_shared params, set on
  channel instances before parallel execution
- engine._load_facts(): pass scope flags to get_facts_by_ids()
- semantic_channel: get_facts_by_ids/get_all_facts with scope flags
- bm25_channel: get_all_facts (cold-load) with scope flags
- hopfield_channel: get_facts_by_ids/get_all_facts with scope flags
- entity_channel: get_facts_by_entity/get_edges_for_node with scope flags

All scope flags default to True via getattr(self, 'include_X', True) —
backward compatible when engine doesn't set them.

Part of PR-B: Retrieval Layer for multi-scope memory (qualixar#20).
Add include_global/include_shared keyword args to run_recall() and
forward them to retrieval_engine.recall().

Part of PR-B: Retrieval Layer for multi-scope memory (qualixar#20).
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.

1 participant