claude_memory 0.5.0 → 0.6.0

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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/CLAUDE.md +1 -1
  3. data/.claude/rules/claude_memory.generated.md +1 -1
  4. data/.claude/settings.json +11 -6
  5. data/.claude/settings.local.json +9 -1
  6. data/.claude-plugin/marketplace.json +5 -2
  7. data/.claude-plugin/plugin.json +16 -3
  8. data/.mcp.json +9 -0
  9. data/CHANGELOG.md +69 -0
  10. data/CLAUDE.md +27 -13
  11. data/README.md +6 -2
  12. data/Rakefile +22 -0
  13. data/db/migrations/011_add_tool_call_summaries.rb +18 -0
  14. data/db/migrations/012_add_vec_indexing_support.rb +19 -0
  15. data/docs/improvements.md +86 -66
  16. data/docs/influence/claude-mem.md +253 -0
  17. data/docs/influence/claude-supermemory.md +158 -430
  18. data/docs/influence/episodic-memory.md +217 -0
  19. data/docs/influence/grepai.md +163 -839
  20. data/docs/influence/kbs.md +437 -0
  21. data/docs/influence/qmd.md +139 -481
  22. data/hooks/hooks.json +19 -15
  23. data/lefthook.yml +4 -0
  24. data/lib/claude_memory/commands/checks/vec_check.rb +73 -0
  25. data/lib/claude_memory/commands/compact_command.rb +94 -0
  26. data/lib/claude_memory/commands/doctor_command.rb +1 -0
  27. data/lib/claude_memory/commands/export_command.rb +108 -0
  28. data/lib/claude_memory/commands/help_command.rb +2 -0
  29. data/lib/claude_memory/commands/hook_command.rb +110 -9
  30. data/lib/claude_memory/commands/index_command.rb +63 -8
  31. data/lib/claude_memory/commands/initializers/global_initializer.rb +26 -7
  32. data/lib/claude_memory/commands/initializers/project_initializer.rb +35 -12
  33. data/lib/claude_memory/commands/registry.rb +3 -1
  34. data/lib/claude_memory/hook/context_injector.rb +75 -0
  35. data/lib/claude_memory/hook/error_classifier.rb +67 -0
  36. data/lib/claude_memory/hook/handler.rb +21 -1
  37. data/lib/claude_memory/index/vector_index.rb +171 -0
  38. data/lib/claude_memory/infrastructure/schema_validator.rb +5 -1
  39. data/lib/claude_memory/ingest/ingester.rb +26 -1
  40. data/lib/claude_memory/ingest/observation_compressor.rb +177 -0
  41. data/lib/claude_memory/mcp/instructions_builder.rb +76 -0
  42. data/lib/claude_memory/mcp/server.rb +3 -1
  43. data/lib/claude_memory/mcp/tool_definitions.rb +15 -7
  44. data/lib/claude_memory/mcp/tools.rb +125 -2
  45. data/lib/claude_memory/publish.rb +28 -27
  46. data/lib/claude_memory/recall/dual_query_template.rb +1 -12
  47. data/lib/claude_memory/recall.rb +71 -17
  48. data/lib/claude_memory/store/sqlite_store.rb +95 -29
  49. data/lib/claude_memory/sweep/sweeper.rb +30 -0
  50. data/lib/claude_memory/version.rb +1 -1
  51. data/lib/claude_memory.rb +8 -0
  52. data/scripts/hook-runner.sh +14 -0
  53. data/scripts/serve-mcp.sh +14 -0
  54. data/skills/setup-memory/SKILL.md +6 -0
  55. metadata +32 -2
@@ -0,0 +1,437 @@
1
+ # KBS (Knowledge-Based System) Analysis
2
+
3
+ *Analysis Date: 2026-03-02*
4
+ *Repository: https://github.com/MadBomber/kbs*
5
+ *Version: v0.2.1 (commit c04561d)*
6
+
7
+ ---
8
+
9
+ ## Executive Summary
10
+
11
+ KBS is a Ruby gem implementing a Knowledge-Based System with RETE algorithm inference, Blackboard architecture, and AI integration. It provides forward-chaining rule evaluation, declarative DSL, persistent fact storage (SQLite/Redis/Hybrid), audit trails, and message-based multi-agent coordination.
12
+
13
+ **Key Innovation**: RETE algorithm implementation in Ruby with unlinking optimization, combined with a Blackboard architecture for multi-agent fact coordination.
14
+
15
+ | Attribute | Value |
16
+ |-----------|-------|
17
+ | Language | Ruby (>= 3.2.0) |
18
+ | LOC | ~2,796 (lib/) |
19
+ | Runtime deps | sqlite3 (>= 1.6) |
20
+ | Stars | 2 |
21
+ | Contributors | 1 (Dewayne VanHoozer) |
22
+ | License | MIT |
23
+ | Created | 2025-10-07 |
24
+ | Last updated | 2026-02-27 |
25
+ | Tests | 199 runs, 447 assertions (Minitest) |
26
+ | Releases | 3 (v0.0.1, v0.1.0, v0.2.1) |
27
+
28
+ **Production Readiness**: Early-stage. Low adoption (2 stars, sole maintainer), 3 releases over ~5 months. Well-documented and tested but not battle-tested in production at scale.
29
+
30
+ ---
31
+
32
+ ## Architecture Overview
33
+
34
+ ### Data Model
35
+
36
+ KBS uses two distinct fact models depending on context:
37
+
38
+ 1. **In-memory facts** (`KBS::Fact`, `fact.rb:4-42`): Mutable objects with `type` + `attributes` hash. ID is Ruby `object_id`. Pattern matching via `matches?(pattern)` supports equality, Proc predicates, and variable bindings.
39
+
40
+ 2. **Persistent facts** (`KBS::Blackboard::Fact`, `blackboard/fact.rb:1-65`): UUID-identified, backed by SQLite/Redis. Attribute mutations trigger persistence callbacks. Supports soft deletion via `retract()`.
41
+
42
+ ### Core Architecture
43
+
44
+ ```
45
+ Rules (DSL) → RETE Network → Alpha/Beta/Join/Production Nodes
46
+
47
+ WorkingMemory ← Facts ← Blackboard Memory → Persistence (SQLite/Redis)
48
+ ↓ ↓
49
+ Message Queue Audit Log
50
+ ```
51
+
52
+ ### Design Patterns
53
+
54
+ | Pattern | Implementation | File Reference |
55
+ |---------|---------------|----------------|
56
+ | RETE Algorithm | Alpha/Beta networks with unlinking | `engine.rb:1-149` |
57
+ | Observer | Fact changes trigger RETE propagation | `working_memory.rb:17-20` |
58
+ | Builder | Fluent rule configuration | `dsl/rule_builder.rb:1-115` |
59
+ | Strategy | Store abstraction (SQLite/Redis/Hybrid) | `blackboard/persistence/store.rb:7-52` |
60
+ | Interpreter | DSL via instance_eval + PatternEvaluator | `dsl/knowledge_base.rb:15-23` |
61
+ | Composite | Blackboard aggregates Engine + Memory + Queue + Audit | `blackboard/memory.rb:13-189` |
62
+
63
+ ### Module Organization (32 files)
64
+
65
+ ```
66
+ lib/kbs/
67
+ ├── engine.rb # RETE inference engine (149 LOC)
68
+ ├── fact.rb # In-memory fact model (43 LOC)
69
+ ├── rule.rb # Rule with conditions + action (46 LOC)
70
+ ├── condition.rb # Pattern condition (26 LOC)
71
+ ├── token.rb # RETE token (partial match) (37 LOC)
72
+ ├── working_memory.rb # Transient fact store (32 LOC)
73
+ ├── alpha_memory.rb # Pattern matching node (37 LOC)
74
+ ├── beta_memory.rb # Join result store (57 LOC)
75
+ ├── join_node.rb # RETE join node (117 LOC)
76
+ ├── negation_node.rb # NOT condition handling (88 LOC)
77
+ ├── production_node.rb # Rule firing terminal (28 LOC)
78
+ ├── decompiler.rb # YARV bytecode decompiler (204 LOC)
79
+ ├── dsl/
80
+ │ ├── knowledge_base.rb # DSL entry point (185 LOC)
81
+ │ ├── rule_builder.rb # Fluent rule building (115 LOC)
82
+ │ ├── condition_helpers.rb # Predicate factories (57 LOC)
83
+ │ ├── pattern_evaluator.rb # method_missing DSL (69 LOC)
84
+ │ └── variable.rb # Binding variables (35 LOC)
85
+ └── blackboard/
86
+ ├── engine.rb # Blackboard-backed RETE (83 LOC)
87
+ ├── memory.rb # Central workspace (191 LOC)
88
+ ├── fact.rb # Persistent fact model (65 LOC)
89
+ ├── message_queue.rb # SQLite message queue (96 LOC)
90
+ ├── audit_log.rb # Fact change history (115 LOC)
91
+ ├── redis_message_queue.rb # Redis messages (111 LOC)
92
+ ├── redis_audit_log.rb # Redis audit (107 LOC)
93
+ └── persistence/
94
+ ├── store.rb # Abstract interface (55 LOC)
95
+ ├── sqlite_store.rb # SQLite backend (242 LOC)
96
+ ├── redis_store.rb # Redis backend (218 LOC)
97
+ └── hybrid_store.rb # Redis+SQLite (118 LOC)
98
+ ```
99
+
100
+ ### Comparison Table vs ClaudeMemory
101
+
102
+ | Aspect | KBS | ClaudeMemory |
103
+ |--------|-----|--------------|
104
+ | **Primary purpose** | Rule-based inference | Knowledge storage & recall |
105
+ | **Fact model** | type + attributes (JSON blob) | Subject-predicate-object triples |
106
+ | **Fact identity** | object_id / UUID | Integer ID + docid |
107
+ | **Mutability** | Mutable attributes | Immutable facts |
108
+ | **Persistence** | sqlite3 gem (raw SQL) | Sequel + Extralite |
109
+ | **Schema** | Single `facts` table + JSON | Normalized (facts, entities, provenance, fact_links, conflicts) |
110
+ | **Scoping** | Session-based | Global/Project dual-database |
111
+ | **Truth maintenance** | None | Supersession + conflict resolution |
112
+ | **Temporal** | created_at/updated_at | valid_from/valid_to windows |
113
+ | **Search** | Pattern matching, raw SQL | FTS5, semantic embeddings, hybrid |
114
+ | **Provenance** | Audit log (separate table) | Linked provenance with source excerpts |
115
+ | **Conflict resolution** | Not implemented | PredicatePolicy + Resolver |
116
+ | **Message passing** | Priority queue (SQLite/Redis) | Not a core feature |
117
+ | **AI integration** | RubyLLM for LLM calls | MCP server for Claude Code |
118
+ | **Reasoning** | Forward-chaining (RETE) | Query/recall based |
119
+ | **Soft delete** | retracted flag | valid_to timestamp |
120
+
121
+ ---
122
+
123
+ ## Key Components Deep-Dive
124
+
125
+ ### 1. RETE Inference Engine
126
+
127
+ The RETE implementation is the core differentiator. It compiles rules into a discrimination network:
128
+
129
+ **Network building** (`engine.rb:99-143`):
130
+ ```ruby
131
+ def build_network_for_rule(rule)
132
+ current_beta = @root_beta_memory
133
+ rule.conditions.each_with_index do |condition, index|
134
+ pattern = condition.pattern.merge(type: condition.type)
135
+ alpha_memory = get_or_create_alpha_memory(pattern)
136
+ if condition.negated
137
+ negation_node = NegationNode.new(alpha_memory, current_beta, tests)
138
+ # ...
139
+ else
140
+ join_node = JoinNode.new(alpha_memory, current_beta, tests)
141
+ # ...
142
+ end
143
+ end
144
+ production_node = ProductionNode.new(rule)
145
+ current_beta.successors << production_node
146
+ end
147
+ ```
148
+
149
+ **Relevance to ClaudeMemory**: Low. ClaudeMemory's truth maintenance uses a different paradigm (explicit supersession/conflict resolution via `Resolver`), not forward-chaining inference. RETE would be over-engineering for our conflict detection needs.
150
+
151
+ ### 2. Store Abstraction (`persistence/store.rb:7-52`)
152
+
153
+ Clean abstract interface with 9 required methods:
154
+
155
+ ```ruby
156
+ class Store
157
+ def add_fact(uuid, type, attributes) # CRUD
158
+ def remove_fact(uuid)
159
+ def update_fact(uuid, attributes)
160
+ def get_fact(uuid)
161
+ def get_facts(type = nil, pattern = {})
162
+ def query_facts(conditions, params) # Advanced queries
163
+ def clear_session(session_id) # Session management
164
+ def stats # Monitoring
165
+ def close # Lifecycle
166
+ def vacuum # Optional maintenance
167
+ def transaction(&block) # Default: just yield
168
+ end
169
+ ```
170
+
171
+ **Relevance to ClaudeMemory**: Medium. ClaudeMemory's `SQLiteStore` combines schema management, CRUD, and query logic in one class (~800+ LOC). KBS's clean separation of the store interface from implementation is a good pattern, though our Sequel-based approach provides more abstraction already.
172
+
173
+ ### 3. Audit Log (`blackboard/audit_log.rb:8-115`)
174
+
175
+ Dedicated table for fact change history with timestamps and session isolation:
176
+
177
+ ```ruby
178
+ def log_fact_change(fact_uuid, fact_type, attributes, action)
179
+ # INSERT INTO fact_history (fact_uuid, fact_type, attributes, action, session_id)
180
+ end
181
+ ```
182
+
183
+ Schema: `fact_history` (uuid, type, attributes JSON, action [ADD/REMOVE/UPDATE], timestamp, session_id) + `rules_fired` (rule_name, fact_uuids JSON, bindings JSON, fired_at, session_id).
184
+
185
+ **Relevance to ClaudeMemory**: Low-Medium. ClaudeMemory already has provenance tracking via the `provenance` table (links facts to source content_items with excerpts). KBS's audit is simpler (action log) while ours is richer (evidence chain). However, KBS's explicit action tracking (ADD/REMOVE/UPDATE) could complement our provenance for debugging.
186
+
187
+ ### 4. Blackboard Memory (`blackboard/memory.rb:13-189`)
188
+
189
+ Central coordinator composing Store + MessageQueue + AuditLog:
190
+
191
+ ```ruby
192
+ def add_fact(type, attributes = {})
193
+ uuid = SecureRandom.uuid
194
+ @store.transaction do
195
+ @store.add_fact(uuid, type, attributes)
196
+ @audit_log.log_fact_change(uuid, type, attributes, 'ADD')
197
+ end
198
+ fact = Fact.new(uuid, type, attributes, self)
199
+ notify_observers(:add, fact)
200
+ fact
201
+ end
202
+ ```
203
+
204
+ **Relevance to ClaudeMemory**: Medium. The composition pattern (Memory = Store + Queue + Audit) is clean. ClaudeMemory's `StoreManager` manages dual databases but doesn't compose additional concerns. The message queue pattern could be interesting for coordinating between hooks.
205
+
206
+ ### 5. Declarative DSL (`dsl/rule_builder.rb:1-115`)
207
+
208
+ Fluent rule definition with instance_eval:
209
+
210
+ ```ruby
211
+ rule "momentum_breakout" do
212
+ desc "Detect stock momentum breakouts"
213
+ priority 10
214
+ on :stock, volume: greater_than(1_000_000)
215
+ on :stock, price_change_pct: greater_than(3)
216
+ without :position, status: "open"
217
+ perform do |facts, bindings|
218
+ # ...
219
+ end
220
+ end
221
+ ```
222
+
223
+ **Relevance to ClaudeMemory**: Low. ClaudeMemory doesn't need a rule DSL — its distillation and resolution logic operates differently. However, the condition helper pattern (`greater_than`, `one_of`, `matches`) is elegant and could inspire a query DSL for complex recall operations.
224
+
225
+ ### 6. SQLite Store Implementation (`persistence/sqlite_store.rb:10-242`)
226
+
227
+ Uses raw `sqlite3` gem with JSON-serialized attributes:
228
+
229
+ ```ruby
230
+ def add_fact(uuid, type, attributes)
231
+ attributes_json = JSON.generate(attributes)
232
+ @db.execute(
233
+ "INSERT INTO facts (uuid, fact_type, attributes, session_id) VALUES (?, ?, ?, ?)",
234
+ [uuid, type.to_s, attributes_json, @session_id]
235
+ )
236
+ end
237
+ ```
238
+
239
+ **Notable patterns**:
240
+ - Nested transaction support via depth counter (`sqlite_store.rb:199-214`)
241
+ - Soft delete via `retracted` flag (`sqlite_store.rb:87-104`)
242
+ - Auto-update trigger for `updated_at` (`sqlite_store.rb:68-76`)
243
+ - JSON pattern matching in Ruby, not SQL (`sqlite_store.rb:230-238`)
244
+
245
+ **Relevance to ClaudeMemory**: Low. ClaudeMemory uses Sequel + Extralite (significantly better performance than sqlite3 gem) and a normalized schema vs JSON blobs. KBS's approach is simpler but less queryable.
246
+
247
+ ---
248
+
249
+ ## Comparative Analysis
250
+
251
+ ### What KBS Does Well
252
+
253
+ 1. **Clean store abstraction** (`persistence/store.rb`): 9 methods, clear interface, easy to implement new backends
254
+ 2. **Multi-backend flexibility**: SQLite + Redis + Hybrid with auto-detection (`memory.rb:32-51`)
255
+ 3. **Audit trail as first-class concern**: Separate table with explicit action tracking
256
+ 4. **Expressive DSL**: `on`, `without`, `perform` with condition helpers reads naturally
257
+ 5. **Transaction safety**: Both fact mutation and audit logging wrapped in transactions (`memory.rb:60-63`)
258
+ 6. **Session isolation**: UUID-based sessions with cleanup (`memory.rb:160-163`)
259
+ 7. **Documentation quality**: 31 docs files, architecture guides, progressive learning path
260
+ 8. **Example coverage**: 32 executable examples across domains
261
+
262
+ ### What ClaudeMemory Does Better
263
+
264
+ 1. **Rich fact model**: Subject-predicate-object triples vs flat JSON blobs enable structured queries
265
+ 2. **Truth maintenance**: Supersession, conflict detection, PredicatePolicy — KBS has none
266
+ 3. **Dual-scope architecture**: Global/project separation is core; KBS only has session isolation
267
+ 4. **Search capabilities**: FTS5 + semantic embeddings + hybrid search vs simple pattern matching
268
+ 5. **Provenance chains**: Source-linked evidence vs simple action logs
269
+ 6. **Temporal validity**: valid_from/valid_to windows vs binary active/retracted
270
+ 7. **Performance**: Sequel + Extralite significantly outperforms sqlite3 gem
271
+ 8. **Domain fit**: Purpose-built for AI memory; KBS is general-purpose inference
272
+
273
+ ### Trade-offs
274
+
275
+ | Consideration | KBS Advantage | ClaudeMemory Advantage |
276
+ |--------------|---------------|----------------------|
277
+ | Flexibility | Multi-backend (SQLite/Redis) | Purpose-built for AI memory use case |
278
+ | Fact model | Simple, flexible JSON | Structured, queryable triples |
279
+ | Reasoning | Forward-chaining RETE | Recall-oriented search + truth maintenance |
280
+ | Complexity | 2,796 LOC, simpler architecture | Richer features, more code |
281
+ | Dependencies | Minimal (sqlite3 only) | More dependencies but better perf (Sequel + Extralite) |
282
+ | Maturity | 2 stars, 3 releases, solo maintainer | More developed, more users |
283
+
284
+ ---
285
+
286
+ ## Suitability as Upstream Dependency
287
+
288
+ ### Arguments FOR
289
+
290
+ 1. **Upstream maintenance**: Bug fixes and improvements come free
291
+ 2. **Store abstraction**: Could wrap our persistence behind KBS's interface
292
+ 3. **Audit trail**: Built-in fact change tracking
293
+ 4. **Rule engine potential**: Could formalize truth maintenance as rules
294
+
295
+ ### Arguments AGAINST (Stronger)
296
+
297
+ 1. **Architectural mismatch**: KBS solves inference (forward-chaining rules); ClaudeMemory solves knowledge management (storage, recall, truth maintenance). These are fundamentally different problems.
298
+
299
+ 2. **Schema incompatibility**: KBS stores facts as `{type, attributes_json}` in a single table. ClaudeMemory needs normalized `{subject, predicate, object}` triples with scope, temporal validity, provenance links, and entity relationships. Adapting KBS's schema would require replacing its entire persistence layer.
300
+
301
+ 3. **Performance regression**: KBS uses the `sqlite3` gem with raw SQL. ClaudeMemory uses Sequel + Extralite, which is significantly faster for our query patterns (batch loading, FTS5, embeddings).
302
+
303
+ 4. **Missing core features**: KBS has no truth maintenance (supersession/conflicts), no FTS5 indexing, no embedding/vector search, no scope system (global/project), no temporal validity windows. These are ClaudeMemory's core differentiators and would need to be built on top anyway.
304
+
305
+ 5. **Low adoption risk**: 2 stars, single maintainer. Using this as a dependency introduces supply chain risk with minimal benefit. The gem could go unmaintained.
306
+
307
+ 6. **Abstraction tax**: Wrapping KBS's store interface around our Sequel-based persistence would add indirection without benefit — we'd be using a thin wrapper around SQLite to talk to our own SQLite.
308
+
309
+ 7. **Feature surface mismatch**: KBS includes RETE engine, DSL, Blackboard, Redis support, message queuing — most of which ClaudeMemory doesn't need. This is significant dead weight as a dependency.
310
+
311
+ ### Verdict: **Do NOT use as dependency**
312
+
313
+ The architectures solve fundamentally different problems. The integration cost exceeds the benefit of upstream updates. KBS's store abstraction is the only directly useful component, but ClaudeMemory's Sequel-based approach is already more capable.
314
+
315
+ ---
316
+
317
+ ## Adoption Opportunities
318
+
319
+ ### High Priority ⭐
320
+
321
+ #### 1. Explicit Fact Action Tracking
322
+ - **Value**: Debug visibility into fact lifecycle (ADD/UPDATE/SUPERSEDE/RETRACT)
323
+ - **Evidence**: `blackboard/audit_log.rb:43-49` — `log_fact_change(uuid, type, attributes, action)`
324
+ - **Implementation**: Add `action` column to existing content change tracking. Log explicit actions (INSERT, SUPERSEDE, CONFLICT, RETRACT) alongside provenance.
325
+ - **Effort**: 0.5 day
326
+ - **Trade-off**: Minor schema change, migration needed
327
+ - **Recommendation**: CONSIDER — enhances debugging without major refactoring
328
+
329
+ ### Medium Priority
330
+
331
+ #### 2. Transaction-Wrapped Audit Logging Pattern
332
+ - **Value**: Guarantee audit completeness — fact mutation and audit log always succeed or fail together
333
+ - **Evidence**: `blackboard/memory.rb:60-63` — `@store.transaction { store.add_fact(...); audit_log.log(...) }`
334
+ - **Implementation**: Ensure our Resolver's supersession and conflict operations also log within the same transaction.
335
+ - **Effort**: 0.5 day
336
+ - **Trade-off**: Minimal — our Sequel transactions already support this
337
+ - **Recommendation**: CONSIDER — defensive improvement
338
+
339
+ #### 3. Condition Helpers for Query DSL
340
+ - **Value**: More expressive recall queries with predicate helpers
341
+ - **Evidence**: `dsl/condition_helpers.rb:1-57` — `greater_than(v)`, `one_of(*values)`, `matches(regex)`, `satisfies(&block)`
342
+ - **Implementation**: Add predicate helpers to Recall queries for filtering facts by attribute values.
343
+ - **Effort**: 1-2 days
344
+ - **Trade-off**: Adds API surface; may not be needed if FTS/embedding search is sufficient
345
+ - **Recommendation**: DEFER — current query interface sufficient for LLM use case
346
+
347
+ #### 4. Message Queue for Hook Coordination
348
+ - **Value**: Decouple hook invocations; allow async communication between ingest/sweep/publish
349
+ - **Evidence**: `blackboard/message_queue.rb:1-96` — SQLite-backed priority queue with post/consume/peek
350
+ - **Implementation**: Add simple message table for inter-hook communication (e.g., "sweep needed" flag, "publish pending" state)
351
+ - **Effort**: 1-2 days
352
+ - **Trade-off**: Adds complexity for a problem we mostly solve with hook ordering
353
+ - **Recommendation**: DEFER — hooks work sequentially; message queue adds unnecessary complexity
354
+
355
+ ### Low Priority
356
+
357
+ #### 5. Redis Store Backend
358
+ - **Value**: 100x faster fact access for high-frequency query scenarios
359
+ - **Evidence**: `blackboard/persistence/redis_store.rb:1-218` — Full Redis implementation with indexes
360
+ - **Implementation**: Add Redis as optional hot cache in front of SQLite
361
+ - **Effort**: 3-5 days
362
+ - **Trade-off**: Adds Redis dependency, operational complexity
363
+ - **Recommendation**: DEFER — SQLite + Extralite is fast enough; no user demand
364
+
365
+ #### 6. Soft Delete Pattern
366
+ - **Value**: Recoverable fact deletion, simpler than temporal validity
367
+ - **Evidence**: `persistence/sqlite_store.rb:87-103` — `retracted` flag with `retracted_at` timestamp
368
+ - **Implementation**: N/A — ClaudeMemory already uses `valid_to` timestamps which is more powerful (temporal queries, not just active/inactive)
369
+ - **Effort**: N/A
370
+ - **Trade-off**: N/A
371
+ - **Recommendation**: REJECT — our temporal validity subsumes soft delete
372
+
373
+ ### Features to Avoid
374
+
375
+ 1. **RETE Algorithm** — Forward-chaining inference is architecturally wrong for ClaudeMemory. Our truth maintenance is about detecting contradictions in stored knowledge, not evaluating rule patterns against a fact base. Adding RETE would massively over-engineer a problem we solve with ~100 lines of Resolver code.
376
+
377
+ 2. **Raw sqlite3 gem** — We use Sequel + Extralite for good reasons: dataset API, connection pooling, migration support, and significantly better performance. Downgrading to raw SQL would be a regression.
378
+
379
+ 3. **JSON blob storage** — KBS stores fact attributes as `JSON.generate(attributes)` in a TEXT column. This prevents SQL-level queries on individual attributes. Our normalized schema (subject, predicate, object columns) enables precise queries without deserializing.
380
+
381
+ 4. **KBS as a dependency** — See "Suitability as Upstream Dependency" section above. The architectural mismatch, performance regression, and feature gaps make this a poor fit.
382
+
383
+ ---
384
+
385
+ ## Implementation Recommendations
386
+
387
+ ### Phase 1: Learn, Don't Depend (Now)
388
+
389
+ - Study KBS's audit trail pattern for potential provenance enhancements
390
+ - Note the clean store abstraction pattern for future reference
391
+ - No code changes needed — the patterns are documented here for future consideration
392
+
393
+ ### Phase 2: Selective Pattern Adoption (If Needed)
394
+
395
+ - Explicit action tracking on fact changes (inspired by `audit_log.rb`)
396
+ - Transaction-wrapped audit guarantees (inspired by `memory.rb`)
397
+ - Only implement if debugging needs arise
398
+
399
+ ---
400
+
401
+ ## Architecture Decisions
402
+
403
+ ### Preserve
404
+
405
+ - **Sequel + Extralite**: Superior to KBS's raw sqlite3 approach
406
+ - **Normalized schema**: Subject-predicate-object triples vs JSON blobs
407
+ - **Truth maintenance**: Resolver with supersession/conflicts — KBS has nothing comparable
408
+ - **Dual-database scoping**: Global/project separation
409
+ - **FTS5 + embeddings**: KBS has no search capabilities beyond pattern matching
410
+
411
+ ### Reject
412
+
413
+ - **KBS as dependency**: Architectural mismatch, low adoption, feature gaps
414
+ - **RETE engine**: Wrong paradigm for knowledge recall
415
+ - **Raw SQL persistence**: Regression from Sequel
416
+ - **JSON blob storage**: Regression from normalized schema
417
+ - **Redis backend**: Unnecessary complexity for our use case
418
+ - **Message queue**: Hooks work sequentially
419
+
420
+ ### Consider (Low Priority)
421
+
422
+ - **Explicit action tracking**: Enhances debugging visibility
423
+ - **Transaction-wrapped auditing**: Defensive improvement
424
+
425
+ ---
426
+
427
+ ## Key Takeaways
428
+
429
+ 1. **KBS and ClaudeMemory solve fundamentally different problems.** KBS is an inference engine (rules → conclusions from facts). ClaudeMemory is a knowledge management system (store → recall → maintain facts). The overlap is only at the "facts stored in SQLite" level.
430
+
431
+ 2. **Do not use as a dependency.** The integration cost far exceeds the benefit. KBS's store abstraction is clean but our Sequel-based approach is already more capable. The RETE engine, DSL, and message queue are irrelevant to our use case.
432
+
433
+ 3. **Learn from the patterns.** KBS's audit trail (explicit actions), transaction-wrapped mutations, and store abstraction are well-implemented patterns. We can incorporate these ideas without taking a dependency.
434
+
435
+ 4. **ClaudeMemory is ahead on every axis that matters for AI memory**: truth maintenance, semantic search, provenance, scoping, temporal validity, and performance. KBS fills a different niche (expert systems, rule-based inference) well.
436
+
437
+ 5. **If rule-based reasoning becomes needed**, KBS could be valuable as a separate integration layer (e.g., rules that trigger based on memory state changes), but this would be an optional plugin, not a core dependency.