Skip to content

Commit 5ada47d

Browse files
committed
feat(memory): phase 4 operability - 'odek memory extended stats' and 'consolidate'
- stats: store/index sizes, quarantine reason breakdown, recall timeout/failure counters with a degradation warning - makes guard false-positive rates and recall health visible to operators - consolidate: merges near-duplicate live atoms via the operator's configured LLM backend (10-minute bounded run)
1 parent 1f68b9a commit 5ada47d

1 file changed

Lines changed: 50 additions & 3 deletions

File tree

cmd/odek/memory_cmd.go

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"path/filepath"
8+
"sort"
79
"strings"
10+
"time"
811

12+
"github.com/BackendStack21/odek/internal/config"
13+
"github.com/BackendStack21/odek/internal/llm"
914
"github.com/BackendStack21/odek/internal/memory"
1015
"github.com/BackendStack21/odek/internal/memory/extended"
1116
)
@@ -70,10 +75,10 @@ func memoryCmd(args []string) error {
7075
}
7176
}
7277

73-
// extendedMemoryCmd handles `odek memory extended forget|quarantine|compact`.
78+
// extendedMemoryCmd handles `odek memory extended <subcommand>`.
7479
func extendedMemoryCmd(dir string, args []string) error {
7580
if len(args) == 0 {
76-
fmt.Fprintf(os.Stderr, "Usage: odek memory extended <forget|promote|pin|quarantine|compact|pending|confirm|reject> [args]\n")
81+
fmt.Fprintf(os.Stderr, "Usage: odek memory extended <forget|promote|pin|quarantine|compact|stats|consolidate|pending|confirm|reject> [args]\n")
7782
return nil
7883
}
7984

@@ -144,6 +149,48 @@ func extendedMemoryCmd(dir string, args []string) error {
144149
fmt.Println("odek: Extended Memory vector index compaction triggered in the background")
145150
return nil
146151

152+
case "stats":
153+
st := em.Stats()
154+
fmt.Println("Extended Memory stats:")
155+
fmt.Printf(" live atoms: %d\n", st.LiveAtoms)
156+
fmt.Printf(" quarantined atoms: %d\n", st.QuarantinedAtoms)
157+
if len(st.QuarantineReasons) > 0 {
158+
reasons := make([]string, 0, len(st.QuarantineReasons))
159+
for r := range st.QuarantineReasons {
160+
reasons = append(reasons, r)
161+
}
162+
sort.Strings(reasons)
163+
for _, r := range reasons {
164+
fmt.Printf(" %-16s %d\n", r+":", st.QuarantineReasons[r])
165+
}
166+
}
167+
fmt.Printf(" index vectors: %d (dirty: %v)\n", st.IndexVectors, st.IndexDirty)
168+
fmt.Printf(" store size: %.1f MiB\n", float64(st.StoreSizeBytes)/(1<<20))
169+
fmt.Printf(" recall timeouts: %d\n", st.RecallTimeouts)
170+
fmt.Printf(" recall failures: %d\n", st.RecallFailures)
171+
if st.RecallTimeouts+st.RecallFailures > 0 {
172+
fmt.Println(" warning: recall degraded this process — check LLM/embedding backend latency")
173+
}
174+
return nil
175+
176+
case "consolidate":
177+
// Merging near-duplicate atoms needs an LLM; resolve the operator
178+
// backend the same way the agent does.
179+
resolved := config.LoadConfig(config.CLIFlags{})
180+
if resolved.APIKey == "" {
181+
return fmt.Errorf("memory extended consolidate requires an LLM backend (no API key resolved)")
182+
}
183+
llmClient := llm.New(resolved.BaseURL, resolved.APIKey, resolved.Model, "", 0, 120*time.Second)
184+
emLLM := extended.New(extDir, llmClient, cfg)
185+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
186+
defer cancel()
187+
merged, err := emLLM.ConsolidateAtoms(ctx)
188+
if err != nil {
189+
return err
190+
}
191+
fmt.Printf("odek: consolidation complete — %d atom(s) merged into existing or new entries\n", merged)
192+
return nil
193+
147194
case "pending":
148195
pending, err := em.ListPendingReview()
149196
if err != nil {
@@ -186,6 +233,6 @@ func extendedMemoryCmd(dir string, args []string) error {
186233
return nil
187234

188235
default:
189-
return fmt.Errorf("unknown extended memory subcommand %q (expected: forget, promote, pin, quarantine, compact, pending, confirm, reject)", sub)
236+
return fmt.Errorf("unknown extended memory subcommand %q (expected: forget, promote, pin, quarantine, compact, stats, consolidate, pending, confirm, reject)", sub)
190237
}
191238
}

0 commit comments

Comments
 (0)