MCPcopy Create free account
hub / github.com/astercloud/aster / pruningExample

Function pruningExample

examples/logic-memory/main.go:382–451  ·  view source on GitHub ↗

pruningExample demonstrates memory pruning

(ctx context.Context)

Source from the content-addressed store, hash-verified

380
381// pruningExample demonstrates memory pruning
382func pruningExample(ctx context.Context) {
383 fmt.Println("--- Example 5: Memory Pruning ---")
384
385 store := logic.NewInMemoryStore()
386 manager, _ := logic.NewManager(&logic.ManagerConfig{Store: store})
387
388 // Create memories with varying quality
389 now := time.Now()
390 memories := []*logic.LogicMemory{
391 {
392 Namespace: "user:eve",
393 Key: "high_quality",
394 Description: "High confidence, recently accessed",
395 Provenance: &memory.MemoryProvenance{Confidence: 0.9},
396 AccessCount: 10,
397 LastAccessed: now,
398 CreatedAt: now.Add(-24 * time.Hour),
399 },
400 {
401 Namespace: "user:eve",
402 Key: "low_confidence",
403 Description: "Low confidence memory",
404 Provenance: &memory.MemoryProvenance{Confidence: 0.3},
405 AccessCount: 1,
406 LastAccessed: now.Add(-48 * time.Hour),
407 CreatedAt: now.Add(-72 * time.Hour),
408 },
409 {
410 Namespace: "user:eve",
411 Key: "old_unused",
412 Description: "Old and rarely accessed",
413 Provenance: &memory.MemoryProvenance{Confidence: 0.6},
414 AccessCount: 0,
415 LastAccessed: now.Add(-168 * time.Hour), // 7 days ago
416 CreatedAt: now.Add(-240 * time.Hour), // 10 days ago
417 },
418 }
419
420 for _, m := range memories {
421 _ = store.Save(ctx, m)
422 }
423
424 fmt.Printf("Created %d memories\n", len(memories))
425
426 // Define pruning criteria
427 criteria := logic.PruneCriteria{
428 MinConfidence: 0.5, // Remove if confidence < 50%
429 SinceLastAccess: 72 * time.Hour, // Remove if not accessed in 3 days
430 MinAccessCount: 1, // Minimum access count to keep
431 MaxAge: 168 * time.Hour, // Maximum age: 7 days
432 }
433
434 // Execute pruning
435 count, err := manager.PruneMemories(ctx, criteria)
436 if err != nil {
437 log.Fatalf("Failed to prune: %v", err)
438 }
439

Callers 1

mainFunction · 0.85

Calls 7

SaveMethod · 0.95
PruneMemoriesMethod · 0.95
RetrieveMemoriesMethod · 0.95
NewInMemoryStoreFunction · 0.92
NewManagerFunction · 0.92
PrintfMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected