feat(memory): add TTL and auto-expiration for memory entries#1109
Open
mvanhorn wants to merge 3 commits intovolcengine:mainfrom
Open
feat(memory): add TTL and auto-expiration for memory entries#1109mvanhorn wants to merge 3 commits intovolcengine:mainfrom
mvanhorn wants to merge 3 commits intovolcengine:mainfrom
Conversation
|
Failed to generate code suggestions for PR |
Collaborator
|
/review |
|
Preparing review... |
Add an optional expires_at field to MemoryData and implement
expiration checking during memory retrieval. Expired memories
are excluded from search results.
- MemoryData.expires_at: Optional datetime, None = never expires
- MemoryData.is_expired(): timezone-aware expiration check
- MemoryConfig: default_ttl, ttl_by_type, parse_ttl() for
config-driven TTL ('7d', '24h', '30m' format)
- MemoryExtractor.create_memory(): computes expires_at from
config with per-memory metadata override
- HierarchicalRetriever: filters expired entries before return
Relates to volcengine#1027, volcengine#269
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5a2ba0f to
a4acc2e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Statement
OpenViking stores memories indefinitely. Over time, stale context accumulates and degrades retrieval quality. Users in #1027 and #269 have asked for memory forgetting and deletion.
Proposed Solution
Add an optional
expires_atfield toMemoryData. When set, expired memories are excluded from retrieval results. TTL defaults are configurable per memory type inov.conf, with per-memory overrides via metadata.Evidence
Stale memory is a known failure mode in RAG-based agent systems. TTL provides a minimal, backward-compatible mechanism to address it.
Changes
MemoryData.expires_at: Optional datetime field, None = never expiresMemoryData.is_expired(): timezone-aware check against UTC nowMemoryConfig:default_ttl,ttl_by_typeconfig fields,parse_ttl()static method ('7d', '24h', '30m' format)MemoryExtractor.create_memory(): computesexpires_atfrom config with per-memory metadata overrideHierarchicalRetriever.retrieve(): filters expired entries before returning resultsTesting
8 unit tests covering:
is_expired()with no/future/past expirationparse_ttl()with valid and invalid inputsexpires_at= works normally)Screenshots
Implementation Notes
PathLock.is_lock_stale()expiration pattern already in the codebaseparse_iso_datetime)metadata={"ttl": "7d"}in add_messageretrieve(), so they don't affect result countRelates to #1027, #269
This contribution was developed with AI assistance (Codex).
Feature Area
Session Management