superlocalmemory 3.4.19 → 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.
- package/CHANGELOG.md +24 -0
- package/README.md +42 -34
- package/bin/slm +11 -0
- package/bin/slm.bat +12 -0
- package/package.json +4 -3
- package/pyproject.toml +4 -3
- package/scripts/build-slm-hook.ps1 +40 -0
- package/scripts/build-slm-hook.sh +45 -0
- package/scripts/build_entry.py +452 -0
- package/scripts/ci/stage5b_gate.sh +50 -0
- package/scripts/postinstall/validation.js +187 -0
- package/scripts/postinstall-interactive.js +756 -0
- package/scripts/postinstall_binary.js +287 -0
- package/scripts/release_manifest.py +273 -0
- package/scripts/slm-hook.spec +56 -0
- package/skills/slm-build-graph/SKILL.md +423 -0
- package/skills/slm-list-recent/SKILL.md +348 -0
- package/skills/slm-recall/SKILL.md +343 -0
- package/skills/slm-remember/SKILL.md +194 -0
- package/skills/slm-show-patterns/SKILL.md +224 -0
- package/skills/slm-status/SKILL.md +363 -0
- package/skills/slm-switch-profile/SKILL.md +442 -0
- package/src/superlocalmemory/cli/commands.py +254 -79
- package/src/superlocalmemory/cli/context_commands.py +192 -0
- package/src/superlocalmemory/cli/daemon.py +15 -1
- package/src/superlocalmemory/cli/db_migrate.py +80 -0
- package/src/superlocalmemory/cli/escape_hatch.py +220 -0
- package/src/superlocalmemory/cli/main.py +72 -1
- package/src/superlocalmemory/core/context_cache.py +397 -0
- package/src/superlocalmemory/core/engine.py +38 -2
- package/src/superlocalmemory/core/engine_wiring.py +1 -1
- package/src/superlocalmemory/core/ram_lock.py +111 -0
- package/src/superlocalmemory/core/recall_pipeline.py +433 -3
- package/src/superlocalmemory/core/recall_worker.py +8 -3
- package/src/superlocalmemory/core/security_primitives.py +635 -0
- package/src/superlocalmemory/core/shadow_router.py +319 -0
- package/src/superlocalmemory/core/slm_disabled.py +87 -0
- package/src/superlocalmemory/core/slmignore.py +125 -0
- package/src/superlocalmemory/core/topic_signature.py +143 -0
- package/src/superlocalmemory/core/worker_pool.py +14 -3
- package/src/superlocalmemory/encoding/cognitive_consolidator.py +2 -2
- package/src/superlocalmemory/evolution/budget.py +321 -0
- package/src/superlocalmemory/evolution/llm_dispatch.py +508 -0
- package/src/superlocalmemory/evolution/skill_evolver.py +144 -94
- package/src/superlocalmemory/hooks/_outcome_common.py +506 -0
- package/src/superlocalmemory/hooks/adapter_base.py +317 -0
- package/src/superlocalmemory/hooks/antigravity_adapter.py +192 -0
- package/src/superlocalmemory/hooks/claude_code_hooks.py +33 -1
- package/src/superlocalmemory/hooks/context_payload.py +312 -0
- package/src/superlocalmemory/hooks/copilot_adapter.py +154 -0
- package/src/superlocalmemory/hooks/cross_platform_connector.py +90 -0
- package/src/superlocalmemory/hooks/cursor_adapter.py +195 -0
- package/src/superlocalmemory/hooks/hook_handlers.py +109 -8
- package/src/superlocalmemory/hooks/ide_connector.py +25 -2
- package/src/superlocalmemory/hooks/post_tool_async_hook.py +165 -0
- package/src/superlocalmemory/hooks/post_tool_outcome_hook.py +223 -0
- package/src/superlocalmemory/hooks/prewarm_auth.py +170 -0
- package/src/superlocalmemory/hooks/session_registry.py +186 -0
- package/src/superlocalmemory/hooks/stop_outcome_hook.py +134 -0
- package/src/superlocalmemory/hooks/sync_loop.py +114 -0
- package/src/superlocalmemory/hooks/user_prompt_hook.py +128 -0
- package/src/superlocalmemory/hooks/user_prompt_rehash_hook.py +202 -0
- package/src/superlocalmemory/infra/backup.py +3 -3
- package/src/superlocalmemory/infra/cloud_backup.py +2 -2
- package/src/superlocalmemory/infra/event_bus.py +2 -2
- package/src/superlocalmemory/infra/webhook_dispatcher.py +3 -3
- package/src/superlocalmemory/learning/arm_catalog.py +99 -0
- package/src/superlocalmemory/learning/bandit.py +526 -0
- package/src/superlocalmemory/learning/bandit_cache.py +133 -0
- package/src/superlocalmemory/learning/behavioral.py +53 -1
- package/src/superlocalmemory/learning/consolidation_cycle.py +381 -0
- package/src/superlocalmemory/learning/consolidation_worker.py +188 -520
- package/src/superlocalmemory/learning/database.py +256 -0
- package/src/superlocalmemory/learning/dedup_hnsw.py +413 -0
- package/src/superlocalmemory/learning/ensemble.py +300 -0
- package/src/superlocalmemory/learning/fact_outcome_joins.py +207 -0
- package/src/superlocalmemory/learning/forgetting_scheduler.py +55 -0
- package/src/superlocalmemory/learning/hnsw_dedup.py +69 -0
- package/src/superlocalmemory/learning/labeler.py +87 -0
- package/src/superlocalmemory/learning/legacy_migration.py +277 -0
- package/src/superlocalmemory/learning/memory_merge.py +160 -0
- package/src/superlocalmemory/learning/model_cache.py +269 -0
- package/src/superlocalmemory/learning/model_rollback.py +278 -0
- package/src/superlocalmemory/learning/outcome_queue.py +284 -0
- package/src/superlocalmemory/learning/pattern_miner.py +415 -0
- package/src/superlocalmemory/learning/pattern_miner_constants.py +47 -0
- package/src/superlocalmemory/learning/ranker.py +225 -81
- package/src/superlocalmemory/learning/ranker_common.py +163 -0
- package/src/superlocalmemory/learning/ranker_retrain_legacy.py +202 -0
- package/src/superlocalmemory/learning/ranker_retrain_online.py +411 -0
- package/src/superlocalmemory/learning/reward.py +777 -0
- package/src/superlocalmemory/learning/reward_archive.py +210 -0
- package/src/superlocalmemory/learning/reward_boost.py +201 -0
- package/src/superlocalmemory/learning/reward_proxy.py +326 -0
- package/src/superlocalmemory/learning/shadow_test.py +524 -0
- package/src/superlocalmemory/learning/signal_worker.py +270 -0
- package/src/superlocalmemory/learning/signals.py +314 -0
- package/src/superlocalmemory/learning/trigram_index.py +547 -0
- package/src/superlocalmemory/mcp/server.py +5 -5
- package/src/superlocalmemory/mcp/tools_context.py +183 -0
- package/src/superlocalmemory/mcp/tools_core.py +92 -27
- package/src/superlocalmemory/parameterization/soft_prompt_generator.py +13 -0
- package/src/superlocalmemory/retrieval/engine.py +52 -0
- package/src/superlocalmemory/server/api.py +2 -2
- package/src/superlocalmemory/server/bandit_loops.py +140 -0
- package/src/superlocalmemory/server/middleware/__init__.py +11 -0
- package/src/superlocalmemory/server/middleware/security_headers.py +144 -0
- package/src/superlocalmemory/server/routes/backup.py +36 -13
- package/src/superlocalmemory/server/routes/behavioral.py +50 -19
- package/src/superlocalmemory/server/routes/brain.py +1234 -0
- package/src/superlocalmemory/server/routes/data_io.py +4 -4
- package/src/superlocalmemory/server/routes/events.py +2 -2
- package/src/superlocalmemory/server/routes/helpers.py +1 -1
- package/src/superlocalmemory/server/routes/learning.py +192 -7
- package/src/superlocalmemory/server/routes/memories.py +189 -1
- package/src/superlocalmemory/server/routes/prewarm.py +171 -0
- package/src/superlocalmemory/server/routes/profiles.py +3 -3
- package/src/superlocalmemory/server/routes/token.py +88 -0
- package/src/superlocalmemory/server/routes/ws.py +5 -5
- package/src/superlocalmemory/server/security_middleware.py +13 -7
- package/src/superlocalmemory/server/ui.py +2 -2
- package/src/superlocalmemory/server/unified_daemon.py +335 -3
- package/src/superlocalmemory/skills/slm-build-graph/SKILL.md +423 -0
- package/src/superlocalmemory/skills/slm-list-recent/SKILL.md +348 -0
- package/src/superlocalmemory/skills/slm-recall/SKILL.md +343 -0
- package/src/superlocalmemory/skills/slm-remember/SKILL.md +194 -0
- package/src/superlocalmemory/skills/slm-show-patterns/SKILL.md +224 -0
- package/src/superlocalmemory/skills/slm-status/SKILL.md +363 -0
- package/src/superlocalmemory/skills/slm-switch-profile/SKILL.md +442 -0
- package/src/superlocalmemory/storage/migration_runner.py +545 -0
- package/src/superlocalmemory/storage/migrations/M001_add_signal_features_columns.py +67 -0
- package/src/superlocalmemory/storage/migrations/M002_model_state_history.py +132 -0
- package/src/superlocalmemory/storage/migrations/M003_migration_log.py +38 -0
- package/src/superlocalmemory/storage/migrations/M004_cross_platform_sync_log.py +46 -0
- package/src/superlocalmemory/storage/migrations/M005_bandit_tables.py +75 -0
- package/src/superlocalmemory/storage/migrations/M006_action_outcomes_reward.py +75 -0
- package/src/superlocalmemory/storage/migrations/M007_pending_outcomes.py +63 -0
- package/src/superlocalmemory/storage/migrations/M009_model_lineage.py +54 -0
- package/src/superlocalmemory/storage/migrations/M010_evolution_config.py +75 -0
- package/src/superlocalmemory/storage/migrations/M011_archive_and_merge.py +87 -0
- package/src/superlocalmemory/storage/migrations/M012_shadow_observations.py +72 -0
- package/src/superlocalmemory/storage/migrations/M013_bi_temporal_columns.py +55 -0
- package/src/superlocalmemory/storage/migrations/__init__.py +81 -0
- package/src/superlocalmemory/storage/models.py +4 -0
- package/src/superlocalmemory/ui/css/brain.css +409 -0
- package/src/superlocalmemory/ui/css/legacy-dashboard.css +645 -0
- package/src/superlocalmemory/ui/index.html +459 -1345
- package/src/superlocalmemory/ui/js/brain.js +1321 -0
- package/src/superlocalmemory/ui/js/clusters.js +123 -4
- package/src/superlocalmemory/ui/js/init.js +48 -39
- package/src/superlocalmemory/ui/js/memories.js +88 -2
- package/src/superlocalmemory/ui/js/modal.js +71 -1
- package/src/superlocalmemory/ui/js/ng-shell.js +101 -88
- package/src/superlocalmemory/ui/js/trust-dashboard.js +168 -25
- package/src/superlocalmemory/ui/vendor/bootstrap-icons/bootstrap-icons.css +2018 -0
- package/src/superlocalmemory/ui/vendor/bootstrap-icons/fonts/bootstrap-icons.woff +0 -0
- package/src/superlocalmemory/ui/vendor/bootstrap-icons/fonts/bootstrap-icons.woff2 +0 -0
- package/src/superlocalmemory/ui/vendor/bootstrap.bundle.min.js +7 -0
- package/src/superlocalmemory/ui/vendor/bootstrap.min.css +6 -0
- package/src/superlocalmemory/ui/vendor/d3.v7.min.js +2 -0
- package/src/superlocalmemory/ui/vendor/graphology-library.min.js +2 -0
- package/src/superlocalmemory/ui/vendor/graphology.umd.min.js +2 -0
- package/src/superlocalmemory/ui/vendor/inter-ui/inter-variable.min.css +8 -0
- package/src/superlocalmemory/ui/vendor/inter-ui/variable/InterVariable-Italic.woff2 +0 -0
- package/src/superlocalmemory/ui/vendor/inter-ui/variable/InterVariable.woff2 +0 -0
- package/src/superlocalmemory/ui/vendor/sigma.min.js +1 -0
- package/src/superlocalmemory/ui/js/behavioral.js +0 -447
- package/src/superlocalmemory/ui/js/graph-core.js +0 -447
- package/src/superlocalmemory/ui/js/graph-interactions.js +0 -351
- package/src/superlocalmemory/ui/js/learning.js +0 -435
- package/src/superlocalmemory/ui/js/patterns.js +0 -93
- package/src/superlocalmemory.egg-info/PKG-INFO +0 -647
- package/src/superlocalmemory.egg-info/SOURCES.txt +0 -335
- package/src/superlocalmemory.egg-info/dependency_links.txt +0 -1
- package/src/superlocalmemory.egg-info/entry_points.txt +0 -2
- package/src/superlocalmemory.egg-info/requires.txt +0 -58
- package/src/superlocalmemory.egg-info/top_level.txt +0 -1
|
@@ -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.*
|