Agent Memory Engine (4/10) — memcore: Rebuilding the Memory Core in SQLite, 51 Tests

memcore — Rebuilding the Memory Core in SQLite, 51 Tests Pass

bank/ 40 files → 236 curated + 4 entities + 15 topics, 0 errors


핵심 요약

  • memcore is done: SQLite + Python stdlib only, WAL mode, 9 tables, FTS5 virtual table.
  • 7 of 8 preserved assets ported. The bank/ 40-file conversion ran in one shot, zero errors.
  • A Hermes MemoryProvider adapter sits on top. 51 tests, 0 failures.
1. memcore library

1. memcore library

Two design rules: no external dependencies, single-file DB.

  • SQLite + Python stdlib only
  • WAL mode (concurrent read/write stability)
  • 9 tables: meta, u_patterns + 3 child tables, identity, curated, entities, topics, topic_curated, episodes
  • FTS5 virtual table curated_ftsunicode61 tokenizer for mixed Korean/English search

Skipping a daemon was a deliberate choice. The file, not a process, is the source of truth. Backup, rollback, verification all simplify.

2. 7-of-8 assets ported

Asset Module Status
user-pattern-stage.py memcore.dialectic
confidence-decay.py memcore.decay
bank-lint.py memcore.lint
entity-audit.py memcore.entities
topics-validate / expand memcore.topics
retain-extract / merge memcore.ingest
recall-tree / match memcore.prefetch
docs-snapshot / release-check Hermes cron payload ⏸ (OS-level, next week)

I estimated 1–2 days. Came in close. The code itself was a half-day. Tests took longer.

3. bank/ → memcore migration

3. bank/ → memcore migration

Principles I held while writing the migration script (memcore.bank_migrate):

  • READ-ONLY on source — don't touch a single character of bank/.
  • rsync snapshot — pin a point-in-time before converting.
  • 4-phase parse — identify / chunk / link / verify.
  • --incremental — same command, safe to re-run.

The actual run reduced to one line.

40 files → 236 curated + 4 entities + 15 topics + 514 links, 0 errors

Curated distribution: - knowledge 150 - pattern 28 - daily 17 - world 14 - identity 13 - experience 10 - opinion 4

This distribution shows what the system was actually remembering. Knowledge and patterns dominate. Opinions are surprisingly few.

4. Hermes MemoryProvider adapter

~/Hermes/hermes-data/plugins/memory/memcore/__init__.py

MemcoreProvider(MemoryProvider) implements every method. - prefetch: routes through memcore.prefetch.search (topic → FTS5 → LIKE fallback) - on_session_end: auto-invokes memcore.ingest

Smoke tests ran against the real memcore.db — all PASS.

5. Test suite — 51 / 51

  • 5 formal test modules: dialectic / decay / lint / entities / topics / bank_migrate
  • inline smoke: ingest (11) + prefetch (8) + plugin (9)
  • Total 51 tests, 0 failures

51 tests isn't the point. The point is a regression net exists during migration.

6. Strangler Fig operating model (locked)

A clean restatement of the strategy.

  1. OpenClaw keeps running (Reflect at 03:00, unchanged).
  2. memcore incremental sync runs on a LaunchAgent.
  3. Hermes only reads memcore.
  4. Once verified → shut OpenClaw down → memcore inherits.
  5. Rollback is simple — start OpenClaw again.

Two systems looking at the same truth at slightly different times. The fear of cutover is the moment those two clocks drift, which is why the accuracy of the incremental sync is the next week's central verification target.

Wrap-up

Week 1–2 boils down to "the data was moved once, and 51 tests confirm it didn't break." Hermes is not yet running. The next post is about an honest omission I caught before turning it on.

댓글

이 블로그의 인기 게시물

Agent Memory Engine (2/10) — Building an AI Agent Memory System with SQLite Alone

"ML Foundations (9/9) — PyTorch vs TensorFlow, and the Road to Local LLMs"

"RAG Core Study (14/26) — Evaluation Sets with RAGAS & DeepEval"

"ML Foundations (8/9) — Deep Learning Architectures: CNN, RNN, Attention"

"ML Foundations (7/9) — Deep Learning Training: Optimizers, Regularization, Initialization"

OpenClaw to Hermes Migration (2/13) — What to Preserve, Partially Port, or Discard

AI Agents I Built (5/7) — Building an Automated Blogger API Publishing System