feat: Add salience-aware memory with reinforcement tracking (#186)#206
feat: Add salience-aware memory with reinforcement tracking (#186)#206evan-ak merged 10 commits intoNevaMind-AI:mainfrom
Conversation
- Add content hash deduplication to prevent duplicate memories - Add reinforcement tracking (count + last_reinforced_at) for repeated facts - Add salience-aware ranking: similarity × log(reinforcement+1) × recency_decay - Add agent_id and session_id fields for multi-agent scoping - Add configurable ranking strategy (similarity vs salience) in settings - Add comprehensive tests for all new features Closes NevaMind-AI#186
56e76bc to
a903597
Compare
a903597 to
b00ed4f
Compare
|
Hi, thank you very much for your contribution. We are actively working on merging this feature into MemU. Given that there are multiple PRs introducing various kinds of fields to the memory item, and that some of them are exclusively used by specific memory types or applications, we’ve decided to consolidate these attributes into a single "extra" field to keep the memory item’s structure clear and concise. At the same time, we want to ensure that this feature remains fully optional in the memorization and retrieval process, so we are about to implement a handy switch for it in the settings. As a result, we are still working on a few minor revisions to the current commits and will proceed with the merge once these adjustments are complete. Thanks again for the great work! |
771b49f to
dd26dbe
Compare
Summary
Implements a memory lifecycle layer with deduplication, reinforcement tracking, salience-aware retrieval, and an optional LLM client wrapper for memU.
Closes #186
Features Implemented
1. Content Hash Deduplication
compute_content_hash()generates unique hash for memory items2. Reinforcement Tracking
reinforcement_count- tracks how often a memory is reinforcedlast_reinforced_at- timestamp of last reinforcement3. Salience-Aware Retrieval
similarity × log(reinforcement+1) × recency_decayranking="salience"andrecency_decay_days4. Agent/Session Scoping
agent_idandsession_idtoDefaultUserModel5. LLM Client Wrapper (Stretch Goal)
wrap_openai()convenience functionFiles Changed (9 files, +909 lines)
src/memu/database/models.pycompute_content_hash, reinforcement fieldssrc/memu/database/inmemory/vector.pysalience_score,cosine_topk_saliencesrc/memu/database/inmemory/repositories/memory_item_repo.pysrc/memu/database/postgres/repositories/memory_item_repo.pysrc/memu/app/settings.pysrc/memu/client/__init__.pysrc/memu/client/openai_wrapper.pytests/test_salience.pytests/test_client_wrapper.pyTests
Backward Compatibility
All features are opt-in. Default behavior unchanged.
Usage Examples