superlocalmemory 3.4.21 → 3.4.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/package.json +1 -1
  3. package/pyproject.toml +2 -2
  4. package/scripts/build_entry.py +1 -1
  5. package/scripts/release_manifest.py +2 -2
  6. package/skills/slm-build-graph/SKILL.md +1 -1
  7. package/skills/slm-list-recent/SKILL.md +1 -1
  8. package/skills/slm-recall/SKILL.md +3 -3
  9. package/skills/slm-remember/SKILL.md +1 -1
  10. package/skills/slm-status/SKILL.md +1 -1
  11. package/skills/slm-switch-profile/SKILL.md +1 -1
  12. package/src/superlocalmemory/cli/commands.py +40 -5
  13. package/src/superlocalmemory/cli/context_commands.py +1 -1
  14. package/src/superlocalmemory/cli/db_migrate.py +1 -1
  15. package/src/superlocalmemory/cli/escape_hatch.py +1 -1
  16. package/src/superlocalmemory/cli/main.py +3 -3
  17. package/src/superlocalmemory/core/context_cache.py +2 -2
  18. package/src/superlocalmemory/core/ram_lock.py +1 -1
  19. package/src/superlocalmemory/core/recall_pipeline.py +5 -5
  20. package/src/superlocalmemory/core/security_primitives.py +2 -2
  21. package/src/superlocalmemory/core/shadow_router.py +2 -2
  22. package/src/superlocalmemory/core/slm_disabled.py +1 -1
  23. package/src/superlocalmemory/core/slmignore.py +1 -1
  24. package/src/superlocalmemory/core/topic_signature.py +3 -3
  25. package/src/superlocalmemory/evolution/budget.py +1 -1
  26. package/src/superlocalmemory/evolution/llm_dispatch.py +2 -2
  27. package/src/superlocalmemory/hooks/_outcome_common.py +1 -1
  28. package/src/superlocalmemory/hooks/adapter_base.py +1 -1
  29. package/src/superlocalmemory/hooks/antigravity_adapter.py +1 -1
  30. package/src/superlocalmemory/hooks/context_payload.py +2 -2
  31. package/src/superlocalmemory/hooks/copilot_adapter.py +1 -1
  32. package/src/superlocalmemory/hooks/cross_platform_connector.py +1 -1
  33. package/src/superlocalmemory/hooks/cursor_adapter.py +1 -1
  34. package/src/superlocalmemory/hooks/hook_handlers.py +1 -1
  35. package/src/superlocalmemory/hooks/ide_connector.py +2 -2
  36. package/src/superlocalmemory/hooks/post_tool_async_hook.py +1 -1
  37. package/src/superlocalmemory/hooks/post_tool_outcome_hook.py +1 -1
  38. package/src/superlocalmemory/hooks/prewarm_auth.py +1 -1
  39. package/src/superlocalmemory/hooks/session_registry.py +1 -1
  40. package/src/superlocalmemory/hooks/stop_outcome_hook.py +1 -1
  41. package/src/superlocalmemory/hooks/sync_loop.py +2 -2
  42. package/src/superlocalmemory/hooks/user_prompt_hook.py +1 -1
  43. package/src/superlocalmemory/hooks/user_prompt_rehash_hook.py +1 -1
  44. package/src/superlocalmemory/learning/arm_catalog.py +1 -1
  45. package/src/superlocalmemory/learning/bandit.py +1 -1
  46. package/src/superlocalmemory/learning/bandit_cache.py +1 -1
  47. package/src/superlocalmemory/learning/consolidation_cycle.py +4 -4
  48. package/src/superlocalmemory/learning/consolidation_worker.py +1 -1
  49. package/src/superlocalmemory/learning/database.py +5 -5
  50. package/src/superlocalmemory/learning/dedup_hnsw.py +1 -1
  51. package/src/superlocalmemory/learning/ensemble.py +2 -2
  52. package/src/superlocalmemory/learning/fact_outcome_joins.py +1 -1
  53. package/src/superlocalmemory/learning/forgetting_scheduler.py +2 -2
  54. package/src/superlocalmemory/learning/hnsw_dedup.py +2 -2
  55. package/src/superlocalmemory/learning/labeler.py +3 -3
  56. package/src/superlocalmemory/learning/legacy_migration.py +1 -1
  57. package/src/superlocalmemory/learning/memory_merge.py +1 -1
  58. package/src/superlocalmemory/learning/model_cache.py +1 -1
  59. package/src/superlocalmemory/learning/model_rollback.py +2 -2
  60. package/src/superlocalmemory/learning/outcome_queue.py +2 -2
  61. package/src/superlocalmemory/learning/pattern_miner.py +1 -1
  62. package/src/superlocalmemory/learning/pattern_miner_constants.py +1 -1
  63. package/src/superlocalmemory/learning/ranker.py +3 -3
  64. package/src/superlocalmemory/learning/ranker_common.py +1 -1
  65. package/src/superlocalmemory/learning/ranker_retrain_legacy.py +3 -3
  66. package/src/superlocalmemory/learning/ranker_retrain_online.py +4 -4
  67. package/src/superlocalmemory/learning/reward.py +1 -1
  68. package/src/superlocalmemory/learning/reward_archive.py +2 -2
  69. package/src/superlocalmemory/learning/reward_boost.py +2 -2
  70. package/src/superlocalmemory/learning/reward_proxy.py +4 -4
  71. package/src/superlocalmemory/learning/shadow_test.py +1 -1
  72. package/src/superlocalmemory/learning/signal_worker.py +2 -2
  73. package/src/superlocalmemory/learning/signals.py +2 -2
  74. package/src/superlocalmemory/learning/trigram_index.py +1 -1
  75. package/src/superlocalmemory/mcp/tools_context.py +1 -1
  76. package/src/superlocalmemory/mcp/tools_core.py +2 -2
  77. package/src/superlocalmemory/parameterization/soft_prompt_generator.py +3 -3
  78. package/src/superlocalmemory/server/bandit_loops.py +2 -2
  79. package/src/superlocalmemory/server/middleware/__init__.py +2 -2
  80. package/src/superlocalmemory/server/middleware/security_headers.py +3 -3
  81. package/src/superlocalmemory/server/routes/brain.py +10 -10
  82. package/src/superlocalmemory/server/routes/prewarm.py +1 -1
  83. package/src/superlocalmemory/server/security_middleware.py +1 -1
  84. package/src/superlocalmemory/server/unified_daemon.py +4 -4
  85. package/src/superlocalmemory/skills/slm-build-graph/SKILL.md +423 -0
  86. package/src/superlocalmemory/skills/slm-list-recent/SKILL.md +348 -0
  87. package/src/superlocalmemory/skills/slm-recall/SKILL.md +343 -0
  88. package/src/superlocalmemory/skills/slm-remember/SKILL.md +194 -0
  89. package/src/superlocalmemory/skills/slm-show-patterns/SKILL.md +224 -0
  90. package/src/superlocalmemory/skills/slm-status/SKILL.md +363 -0
  91. package/src/superlocalmemory/skills/slm-switch-profile/SKILL.md +442 -0
  92. package/src/superlocalmemory/storage/migration_runner.py +4 -4
  93. package/src/superlocalmemory/storage/migrations/M001_add_signal_features_columns.py +1 -1
  94. package/src/superlocalmemory/storage/migrations/M002_model_state_history.py +2 -2
  95. package/src/superlocalmemory/storage/migrations/M003_migration_log.py +1 -1
  96. package/src/superlocalmemory/storage/migrations/M004_cross_platform_sync_log.py +1 -1
  97. package/src/superlocalmemory/storage/migrations/M005_bandit_tables.py +1 -1
  98. package/src/superlocalmemory/storage/migrations/M006_action_outcomes_reward.py +1 -1
  99. package/src/superlocalmemory/storage/migrations/M007_pending_outcomes.py +1 -1
  100. package/src/superlocalmemory/storage/migrations/M009_model_lineage.py +1 -1
  101. package/src/superlocalmemory/storage/migrations/M010_evolution_config.py +2 -2
  102. package/src/superlocalmemory/storage/migrations/M011_archive_and_merge.py +1 -1
  103. package/src/superlocalmemory/storage/migrations/M012_shadow_observations.py +1 -1
  104. package/src/superlocalmemory/storage/migrations/M013_bi_temporal_columns.py +2 -2
  105. package/src/superlocalmemory/storage/migrations/__init__.py +3 -3
@@ -1,10 +1,10 @@
1
1
  # Copyright (c) 2026 Varun Pratap Bhardwaj / Qualixar
2
2
  # Licensed under AGPL-3.0-or-later - see LICENSE file
3
- # Part of SuperLocalMemory v3.4.21 — LLD-04 §4.1 + §3
3
+ # Part of SuperLocalMemory v3.4.22 — LLD-04 §4.1 + §3
4
4
 
5
5
  """``/api/v3/brain`` — unified Brain endpoint (LLD-04 v2).
6
6
 
7
- Merges the pre-3.4.21 Patterns / Learning / Behavioral dashboard tabs
7
+ Merges the pre-3.4.22 Patterns / Learning / Behavioral dashboard tabs
8
8
  into one auth-gated, honestly-labelled JSON payload. Every metric has
9
9
  an ``is_real`` (numeric counters) or ``is_real_ml`` (ML-derived) flag
10
10
  and points at the real table it was computed from. No metric is
@@ -24,7 +24,7 @@ Design notes (LLD-04 §7 hard rules):
24
24
  * **U2** — every metric section carries ``is_real`` or ``is_real_ml``.
25
25
  * **U3** — ``learning.phase`` never returns ``3`` without an active
26
26
  model row AND passing SHA check. Both conditions computed here.
27
- * **U4** — response shape must not contain the three pre-3.4.21
27
+ * **U4** — response shape must not contain the three pre-3.4.22
28
28
  fabricated metrics (24h hit-rate, avg age on hit, skill-evolution
29
29
  row counts). A static test greps this file to verify; therefore we
30
30
  never spell those names anywhere in this module.
@@ -64,7 +64,7 @@ router = APIRouter(prefix="/api/v3", tags=["brain"])
64
64
  # LLD-03 v2 stratum space = 4 query types × 3 entity bins × 4 time buckets.
65
65
  _STRATA_TOTAL: int = 48
66
66
 
67
- _VERSION: str = "3.4.21"
67
+ _VERSION: str = "3.4.22"
68
68
 
69
69
  # Banned metric names (LLD-04 U4). Kept as a tuple for grep visibility;
70
70
  # the source-level test asserts we don't accidentally reintroduce them.
@@ -246,7 +246,7 @@ def _compute_learning_status(profile_id: str,
246
246
  """Section ``learning`` — LLD-02 §4.10 phase truth + counters."""
247
247
  signals_total = _safe_count(lrn_db, "learning_signals", profile_id)
248
248
  features_total = _safe_count(lrn_db, "learning_features", profile_id)
249
- # Raw count of historic pre-v3.4.21 feedback rows (the source table)
249
+ # Raw count of historic pre-v3.4.22 feedback rows (the source table)
250
250
  legacy_feedback_rows = _safe_count(lrn_db, "learning_feedback", profile_id)
251
251
  # Count of rows actually copied forward into learning_signals by
252
252
  # legacy_migration.migrate_legacy_feedback (signal_type='legacy_feedback').
@@ -289,7 +289,7 @@ def _compute_learning_status(profile_id: str,
289
289
  "signals_last_hour": signals_last_hour,
290
290
  "features_total": features_total,
291
291
  "feature_count_expected": FEATURE_DIM,
292
- # Honest split (v3.4.21+): raw historic table count vs rows
292
+ # Honest split (v3.4.22+): raw historic table count vs rows
293
293
  # actually copied forward via the migrate-legacy flow.
294
294
  "legacy_feedback_rows": legacy_feedback_rows,
295
295
  "legacy_migrated_count": legacy_migrated,
@@ -356,7 +356,7 @@ def _top_query_types(
356
356
  ``query_type_od`` (features.py FEATURE_NAMES). We aggregate by the
357
357
  active one-hot slot. Missing table or zero rows → empty list.
358
358
  """
359
- # E.1 (v3.4.21 perf): push the query-type classification into SQL via
359
+ # E.1 (v3.4.22 perf): push the query-type classification into SQL via
360
360
  # json_extract so we don't drag 10k rows' worth of JSON through Python.
361
361
  # SQLite's json1 extension treats json_extract as an ordinary scalar
362
362
  # function, so the whole aggregation becomes a single COUNT(*)
@@ -601,7 +601,7 @@ def _compute_cross_platform() -> dict:
601
601
  reports ``active: false`` with ``reason: error:<ExcName>`` rather
602
602
  than crashing the whole Brain endpoint (LLD-04 §2 — "honest, never
603
603
  fake"). An unimportable adapter means the install is missing Wave 2C
604
- components, which is legitimate for an older 3.4.20 → 3.4.21 upgrade
604
+ components, which is legitimate for an older 3.4.20 → 3.4.22 upgrade
605
605
  mid-migration.
606
606
  """
607
607
  out: dict = {}
@@ -871,7 +871,7 @@ def _action_outcomes_count(lrn_db: LearningDatabase,
871
871
  profile_id: str) -> int:
872
872
  """Row count in ``action_outcomes`` for ``profile_id``.
873
873
 
874
- ``action_outcomes`` ships in v3.4.21 (M006). While absent, returns 0.
874
+ ``action_outcomes`` ships in v3.4.22 (M006). While absent, returns 0.
875
875
  """
876
876
  try:
877
877
  conn = sqlite3.connect(lrn_db.path, timeout=5.0)
@@ -963,7 +963,7 @@ async def get_brain(profile_id: str = "default") -> dict:
963
963
  "outcomes_preview": {
964
964
  "action_outcomes_rows":
965
965
  0 if isinstance(outcomes_rows, Exception) else outcomes_rows,
966
- "ships_in": "3.4.21",
966
+ "ships_in": "3.4.22",
967
967
  },
968
968
  # S9-defer H-22: live tile data for the Reward / Shadow /
969
969
  # Evolution-Cost dashboard tiles. Each block is a honest-empty
@@ -1,6 +1,6 @@
1
1
  # Copyright (c) 2026 Varun Pratap Bhardwaj / Qualixar
2
2
  # Licensed under AGPL-3.0-or-later - see LICENSE file
3
- # Part of SuperLocalMemory v3.4.21 — LLD-01 §4.4 / §4.5
3
+ # Part of SuperLocalMemory v3.4.22 — LLD-01 §4.4 / §4.5
4
4
 
5
5
  """POST /internal/prewarm — populates the context cache for a session.
6
6
 
@@ -33,7 +33,7 @@ class SecurityHeadersMiddleware(BaseHTTPMiddleware):
33
33
  # Enable browser XSS filter (legacy, but doesn't hurt)
34
34
  response.headers["X-XSS-Protection"] = "1; mode=block"
35
35
 
36
- # Content Security Policy (v3.4.21 — vendored assets, no CDN hosts).
36
+ # Content Security Policy (v3.4.22 — vendored assets, no CDN hosts).
37
37
  # All Bootstrap/D3/Sigma/graphology/Inter assets ship locally under
38
38
  # /static/vendor/, so we drop every CDN host from the allow-list.
39
39
  # 'unsafe-inline' stays on script-src/style-src for the legacy inline
@@ -369,7 +369,7 @@ async def lifespan(application: FastAPI):
369
369
  )
370
370
 
371
371
  # S9-DASH-02: start the outcome-queue worker so recall →
372
- # pending_outcomes is actually produced. Before v3.4.21 this
372
+ # pending_outcomes is actually produced. Before v3.4.22 this
373
373
  # producer had zero callers and the closed-loop pipeline was
374
374
  # dark. Worker drains at 250 ms cadence; one SQLite INSERT per
375
375
  # event via EngagementRewardModel.record_recall.
@@ -457,7 +457,7 @@ async def lifespan(application: FastAPI):
457
457
  if enable_legacy:
458
458
  asyncio.create_task(_start_legacy_redirect(_DEFAULT_PORT, _LEGACY_PORT))
459
459
 
460
- # V3.4.21 LLD-02: signal-worker background drainer (S8-SK-01 fix).
460
+ # V3.4.22 LLD-02: signal-worker background drainer (S8-SK-01 fix).
461
461
  # Without this, ``signals.enqueue`` fills a bounded queue and drops
462
462
  # silently after ~250 recalls — learning_signals never populates,
463
463
  # Phase 3 never activates, the whole Living Brain stays cold.
@@ -473,7 +473,7 @@ async def lifespan(application: FastAPI):
473
473
  logger.warning("signal_worker failed to start: %s", exc)
474
474
  application.state.signal_worker_started = False
475
475
 
476
- # V3.4.21 LLD-05: cross-platform adapter sync loop
476
+ # V3.4.22 LLD-05: cross-platform adapter sync loop
477
477
  if os.environ.get("SLM_CROSS_PLATFORM_SYNC_DISABLED", "").lower() not in ("1", "true"):
478
478
  try:
479
479
  from superlocalmemory.cli.context_commands import build_default_adapters
@@ -482,7 +482,7 @@ async def lifespan(application: FastAPI):
482
482
  except Exception as exc: # pragma: no cover — defensive
483
483
  logger.warning("cross-platform sync loop failed to start: %s", exc)
484
484
 
485
- # V3.4.21 LLD-03: bandit reward proxy settler + retention sweep loops
485
+ # V3.4.22 LLD-03: bandit reward proxy settler + retention sweep loops
486
486
  if os.environ.get("SLM_BANDIT_DISABLED", "0") != "1":
487
487
  try:
488
488
  from superlocalmemory.server.bandit_loops import (
@@ -0,0 +1,423 @@
1
+ ---
2
+ name: slm-build-graph
3
+ description: Build or rebuild the knowledge graph from existing memories using TF-IDF entity extraction and Leiden clustering. Use when search results seem poor, after bulk imports, or to optimize performance. Automatically discovers relationships between memories and creates topic clusters.
4
+ version: "3.4.22"
5
+ license: AGPL-3.0-or-later
6
+ compatibility: "Requires SuperLocalMemory V2 installed at ~/.claude-memory/, optional dependencies: python-igraph, leidenalg"
7
+ attribution:
8
+ creator: Varun Pratap Bhardwaj
9
+ role: Solution Architect & Original Creator
10
+ project: SuperLocalMemory V2
11
+ ---
12
+
13
+ # SuperLocalMemory: Build Knowledge Graph
14
+
15
+ Build or rebuild the knowledge graph from existing memories to improve search quality and discover hidden relationships.
16
+
17
+ ## Usage
18
+
19
+ ```bash
20
+ slm build-graph [--force] [--clustering]
21
+ ```
22
+
23
+ ## What It Does
24
+
25
+ ### 1. Entity Extraction (TF-IDF)
26
+ - Scans all memories
27
+ - Identifies important terms (entities)
28
+ - Creates nodes in knowledge graph
29
+ - Examples: "FastAPI", "JWT", "PostgreSQL", "React hooks"
30
+
31
+ ### 2. Relationship Discovery
32
+ - Finds memories sharing entities
33
+ - Calculates similarity scores
34
+ - Creates edges between related nodes
35
+ - Discovers indirect connections
36
+
37
+ ### 3. Topic Clustering (Optional)
38
+ - Groups related memories into clusters
39
+ - Uses Leiden algorithm (community detection)
40
+ - Creates semantic topic groups
41
+ - Examples: "Authentication cluster", "Database cluster"
42
+
43
+ ## Examples
44
+
45
+ ### Example 1: Basic Graph Build
46
+ ```bash
47
+ $ slm build-graph
48
+ ```
49
+
50
+ **Output:**
51
+ ```
52
+ 🔄 Building Knowledge Graph...
53
+
54
+ Phase 1: Entity Extraction
55
+ Scanning 1,247 memories...
56
+ Extracted 892 unique entities
57
+ Created 892 graph nodes
58
+ ✓ Complete (3.2s)
59
+
60
+ Phase 2: Relationship Discovery
61
+ Computing similarity scores...
62
+ Created 3,456 edges (relationships)
63
+ Avg edges per node: 3.9
64
+ ✓ Complete (5.1s)
65
+
66
+ Phase 3: Optimization
67
+ Indexing graph structure...
68
+ Pruning weak edges (score < 0.3)...
69
+ Final edge count: 2,134
70
+ ✓ Complete (1.2s)
71
+
72
+ ✅ Knowledge graph built successfully!
73
+
74
+ Graph Statistics:
75
+ Nodes: 892
76
+ Edges: 2,134
77
+ Density: 0.27%
78
+ Largest Component: 856 nodes (96%)
79
+
80
+ Next: Use `slm recall` to see improved search results
81
+ ```
82
+
83
+ ### Example 2: Force Rebuild
84
+ ```bash
85
+ $ slm build-graph --force
86
+ ```
87
+
88
+ **Rebuilds from scratch** (deletes existing graph first)
89
+
90
+ **Use when:**
91
+ - Graph seems corrupted
92
+ - Major bulk import completed
93
+ - Want fresh start
94
+
95
+ ### Example 3: With Clustering
96
+ ```bash
97
+ $ slm build-graph --clustering
98
+ ```
99
+
100
+ **Requires optional dependencies:**
101
+ ```bash
102
+ pip3 install python-igraph leidenalg
103
+ ```
104
+
105
+ **Additional output:**
106
+ ```
107
+ Phase 4: Topic Clustering (Leiden)
108
+ Detecting communities...
109
+ Found 47 clusters
110
+ Largest cluster: 89 memories
111
+ Smallest cluster: 3 memories
112
+ Modularity score: 0.82 (excellent)
113
+ ✓ Complete (2.3s)
114
+
115
+ Discovered Clusters:
116
+ Cluster 1 (89 memories): "Authentication & Security"
117
+ Top entities: JWT, OAuth, tokens, auth, security
118
+
119
+ Cluster 2 (76 memories): "Database & PostgreSQL"
120
+ Top entities: PostgreSQL, database, SQL, queries, indexes
121
+
122
+ Cluster 3 (54 memories): "React & Frontend"
123
+ Top entities: React, hooks, components, state, props
124
+
125
+ ...
126
+ ```
127
+
128
+ ## Arguments
129
+
130
+ | Argument | Description | When to Use |
131
+ |----------|-------------|-------------|
132
+ | `--force` | Delete existing graph and rebuild | Corruption, fresh start |
133
+ | `--clustering` | Run topic clustering | Want to discover topic groups |
134
+ | `--verbose` | Show detailed progress | Debugging, understanding process |
135
+ | `--dry-run` | Preview without saving | Testing, analysis |
136
+
137
+ ## When to Run
138
+
139
+ ### Always Run After:
140
+ 1. **Bulk imports** - Added 50+ memories at once
141
+ 2. **Database restore** - Restored from backup
142
+ 3. **Major project milestone** - Sprint complete, project phase done
143
+
144
+ ### Run Periodically:
145
+ 4. **Monthly** - Keep graph optimized
146
+ 5. **After 500 new memories** - Maintain quality
147
+ 6. **When search feels slow** - Rebuild indexes
148
+
149
+ ### Run on Issues:
150
+ 7. **Poor search results** - Graph may be stale
151
+ 8. **Missing relationships** - Rebuild connections
152
+ 9. **Corrupted graph errors** - Force rebuild
153
+
154
+ ## What Gets Built
155
+
156
+ ### Graph Nodes
157
+ **Entities extracted from memories:**
158
+ - Technologies: "FastAPI", "PostgreSQL", "React"
159
+ - Concepts: "authentication", "performance", "testing"
160
+ - Patterns: "TDD", "async", "REST API"
161
+ - Decisions: "prefer X over Y"
162
+
163
+ **Node properties:**
164
+ - Entity text
165
+ - Frequency (how many memories mention it)
166
+ - Importance score
167
+ - First seen / last seen
168
+
169
+ ### Graph Edges
170
+ **Relationships between entities:**
171
+ - **Similarity edge:** Memories share similar content
172
+ - **Co-occurrence edge:** Entities appear together
173
+ - **Sequential edge:** Memories created close in time
174
+
175
+ **Edge properties:**
176
+ - Similarity score (0.0 - 1.0)
177
+ - Shared entities list
178
+ - Edge type
179
+
180
+ ### Clusters (if --clustering)
181
+ **Topic groups discovered:**
182
+ - Cluster ID
183
+ - Cluster name (auto-generated from top entities)
184
+ - Member memories (which memories belong)
185
+ - Top entities in cluster
186
+ - Modularity score (how well-defined)
187
+
188
+ ## Performance
189
+
190
+ | Memory Count | Build Time | Notes |
191
+ |--------------|------------|-------|
192
+ | 100 | ~1s | Instant |
193
+ | 1,000 | ~10s | Fast |
194
+ | 10,000 | ~2min | Acceptable |
195
+ | 50,000+ | ~15min | Plan accordingly |
196
+
197
+ **With clustering (add ~50%):**
198
+ - 1,000 memories: ~15s
199
+ - 10,000 memories: ~3min
200
+
201
+ **Factors affecting speed:**
202
+ - Memory content length
203
+ - Vocabulary size (unique words)
204
+ - Hardware (CPU, RAM)
205
+
206
+ ## Advanced Usage
207
+
208
+ ### Incremental Updates
209
+
210
+ ```bash
211
+ # Add new memories
212
+ slm remember "New content..." --tags new
213
+
214
+ # Incremental graph update (fast)
215
+ slm build-graph # Only processes new memories
216
+
217
+ # Force full rebuild (slower, thorough)
218
+ slm build-graph --force
219
+ ```
220
+
221
+ ### Monitoring Quality
222
+
223
+ ```bash
224
+ # Check graph stats before
225
+ slm status | grep "Knowledge Graph"
226
+
227
+ # Build graph
228
+ slm build-graph --verbose
229
+
230
+ # Check stats after
231
+ slm status | grep "Knowledge Graph"
232
+ ```
233
+
234
+ ### Scripting & Automation
235
+
236
+ **Weekly rebuild (cron job):**
237
+ ```bash
238
+ #!/bin/bash
239
+ # Every Sunday at 3 AM
240
+
241
+ echo "$(date): Starting graph rebuild"
242
+ slm build-graph --clustering >> /var/log/slm-build.log 2>&1
243
+ echo "$(date): Graph rebuild complete"
244
+ ```
245
+
246
+ **Post-import hook:**
247
+ ```bash
248
+ #!/bin/bash
249
+ # After bulk import
250
+
251
+ memories_added=$1
252
+
253
+ if [ "$memories_added" -gt 50 ]; then
254
+ echo "Large import detected, rebuilding graph..."
255
+ slm build-graph
256
+ fi
257
+ ```
258
+
259
+ ### Clustering Analysis
260
+
261
+ ```bash
262
+ # Build with clustering
263
+ slm build-graph --clustering
264
+
265
+ # Check discovered clusters
266
+ slm status --verbose | grep -A 20 "Topic Clusters"
267
+
268
+ # Search within specific cluster
269
+ slm recall "FastAPI" --cluster "Backend & APIs"
270
+ ```
271
+
272
+ ## Troubleshooting
273
+
274
+ ### "Build failed: Memory error"
275
+
276
+ **Cause:** Not enough RAM for large graph
277
+
278
+ **Solution:**
279
+ ```bash
280
+ # Build in chunks (process fewer memories at once)
281
+ slm build-graph --chunk-size 1000
282
+
283
+ # Or increase system memory
284
+ # Or archive old memories
285
+ ```
286
+
287
+ ### "Clustering requires python-igraph"
288
+
289
+ **Cause:** Optional dependencies not installed
290
+
291
+ **Solution:**
292
+ ```bash
293
+ pip3 install python-igraph leidenalg
294
+
295
+ # Verify
296
+ python3 -c "import igraph; import leidenalg"
297
+
298
+ # Try again
299
+ slm build-graph --clustering
300
+ ```
301
+
302
+ ### "Graph build slow"
303
+
304
+ **Causes:**
305
+ - Large database
306
+ - Slow disk I/O
307
+ - Complex memory content
308
+
309
+ **Solutions:**
310
+ ```bash
311
+ # Show progress
312
+ slm build-graph --verbose
313
+
314
+ # Skip clustering (faster)
315
+ slm build-graph # No --clustering flag
316
+
317
+ # Check disk space
318
+ df -h ~/.claude-memory/
319
+ ```
320
+
321
+ ### "Edges seem wrong"
322
+
323
+ **Cause:** Stale graph or poor similarity threshold
324
+
325
+ **Solution:**
326
+ ```bash
327
+ # Force complete rebuild
328
+ slm build-graph --force
329
+
330
+ # Adjust similarity threshold (advanced)
331
+ slm build-graph --min-similarity 0.4 # Default: 0.3
332
+ ```
333
+
334
+ ## Graph Metrics Explained
335
+
336
+ ### Node Count
337
+ **Total unique entities found**
338
+ - Good: > 100 for 1,000 memories
339
+ - Poor: < 10 for 1,000 memories
340
+
341
+ **Why matters:** More nodes = richer semantic understanding
342
+
343
+ ### Edge Count
344
+ **Total relationships discovered**
345
+ - Good: Edges/Nodes ratio > 2
346
+ - Poor: Ratio < 1 (disconnected graph)
347
+
348
+ **Why matters:** More edges = better search via relationships
349
+
350
+ ### Density
351
+ **How connected the graph is**
352
+ - Formula: (Edges / Possible Edges) × 100
353
+ - Typical: 0.1% - 1%
354
+ - Too low (<0.05%): Memories very disconnected
355
+ - Too high (>5%): May indicate poor entity extraction
356
+
357
+ ### Largest Component
358
+ **Size of biggest connected subgraph**
359
+ - Good: >80% of nodes
360
+ - Poor: <50% (fragmented knowledge)
361
+
362
+ **Why matters:** Smaller component = isolated knowledge islands
363
+
364
+ ### Modularity (Clustering)
365
+ **How well-defined clusters are**
366
+ - Excellent: >0.7
367
+ - Good: 0.5 - 0.7
368
+ - Poor: <0.3
369
+
370
+ **Why matters:** Higher = clearer topic separation
371
+
372
+ ## Impact on Other Commands
373
+
374
+ ### slm recall (Search)
375
+ **Before graph build:**
376
+ - Relies mainly on keyword matching
377
+ - May miss related memories
378
+
379
+ **After graph build:**
380
+ - Discovers indirect relationships
381
+ - Finds conceptually similar memories
382
+ - Better ranked results
383
+
384
+ **Example:**
385
+ ```
386
+ Query: "authentication"
387
+
388
+ Before:
389
+ - Direct matches only (JWT, auth, login)
390
+
391
+ After:
392
+ - Direct matches (JWT, auth, login)
393
+ - + Related concepts (security, tokens, OAuth)
394
+ - + Connected memories (API design, user management)
395
+ ```
396
+
397
+ ### slm status
398
+ Shows updated graph statistics
399
+
400
+ ### slm switch-profile
401
+ Each profile has separate graph
402
+
403
+ ## Notes
404
+
405
+ - **Non-destructive:** Original memories never modified
406
+ - **Idempotent:** Can run multiple times safely
407
+ - **Automatic:** Search uses graph automatically after build
408
+ - **Privacy:** All processing local
409
+
410
+ ## Related Commands
411
+
412
+ - `slm recall` - Search uses the graph
413
+ - `slm status` - Check graph stats
414
+ - `slm remember` - Add memories (triggers incremental update)
415
+
416
+ ---
417
+
418
+ **Created by:** [Varun Pratap Bhardwaj](https://github.com/varun369) (Solution Architect)
419
+ **Project:** SuperLocalMemory V2
420
+ **License:** MIT (see [LICENSE](../../LICENSE))
421
+ **Repository:** https://github.com/varun369/SuperLocalMemoryV2
422
+
423
+ *Open source doesn't mean removing credit. Attribution must be preserved per MIT License terms.*