Skip to content

Commit dfe8ff8

Browse files
authored
Merge pull request #58 from redis/feature/make-compaction-schedule
Make compaction schedule configurable
2 parents 36f0bad + 04565a6 commit dfe8ff8

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

agent_memory_server/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ class Settings(BaseSettings):
158158
# Keep only top N most recent (by recency score) when budget is set
159159
forgetting_budget_keep_top_n: int | None = None
160160

161+
# Compaction settings
162+
compaction_every_minutes: int = 10
163+
161164
class Config:
162165
env_file = ".env"
163166
env_file_encoding = "utf-8"

agent_memory_server/long_term_memory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,9 @@ async def compact_long_term_memories(
428428
vector_distance_threshold: float = 0.12,
429429
compact_hash_duplicates: bool = True,
430430
compact_semantic_duplicates: bool = True,
431-
perpetual: Perpetual = Perpetual(every=timedelta(minutes=10), automatic=True),
431+
perpetual: Perpetual = Perpetual(
432+
every=timedelta(minutes=settings.compaction_every_minutes), automatic=True
433+
),
432434
) -> int:
433435
"""
434436
Compact long-term memories by merging duplicates and semantically similar memories.

docs/configuration.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ QUERY_OPTIMIZATION_PROMPT_TEMPLATE="Transform this query for semantic search..."
114114

115115
## Memory Lifecycle
116116

117-
### Forgetting Configuration
117+
### Memory Management Configuration
118118
```bash
119+
# Forgetting settings
119120
FORGETTING_ENABLED=false # Enable automatic forgetting (default: false)
120121
FORGETTING_EVERY_MINUTES=60 # Run forgetting every N minutes (default: 60)
121122
FORGETTING_MAX_AGE_DAYS=30 # Delete memories older than N days
122123
FORGETTING_MAX_INACTIVE_DAYS=7 # Delete memories inactive for N days
123124
FORGETTING_BUDGET_KEEP_TOP_N=1000 # Keep only top N most recent memories
125+
126+
# Compaction settings
127+
COMPACTION_EVERY_MINUTES=10 # Run memory compaction every N minutes (default: 10)
124128
```
125129

126130
## Background Tasks
@@ -209,6 +213,7 @@ enable_topic_extraction: true
209213
enable_ner: true
210214
forgetting_enabled: true
211215
forgetting_max_age_days: 90
216+
compaction_every_minutes: 15
212217
```
213218
214219
### High-Performance Setup

docs/memory-lifecycle.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ async def cleanup_working_memory(client: MemoryAPIClient):
357357

358358
### Background Compaction
359359

360-
The system automatically runs compaction tasks every 10 minutes to:
360+
The system automatically runs compaction tasks (configurable, default every 10 minutes) to:
361361

362362
- Merge similar memories
363363
- Update embeddings for improved accuracy
@@ -378,6 +378,18 @@ await client.schedule_compaction(
378378
)
379379
```
380380

381+
#### Configuring Compaction Schedule
382+
383+
The frequency of automatic compaction can be configured:
384+
385+
```bash
386+
# Environment variable (minutes)
387+
COMPACTION_EVERY_MINUTES=15
388+
389+
# Or in configuration file
390+
compaction_every_minutes: 15
391+
```
392+
381393
### Compaction Strategies
382394

383395
#### Similarity-Based Merging

0 commit comments

Comments
 (0)