Skip to content

feat!: memory core rewrite for multi-agent teams (v0.1.0) - #1

Merged
vbfs merged 3 commits into
mainfrom
feat/memory-v2
Oct 13, 2026
Merged

vbfs merged 3 commits into
mainfrom
feat/memory-v2

Conversation

@vbfs

@vbfs vbfs commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Summary

Critical review and rewrite of agent-memory-store so a team of agents can rely on it: correct, safe for many processes, multilingual (PT-BR/EN), and measured with reproducible benchmarks.

Bugs fixed (all reproduced, now covered by tests)

  • search_context threw FTS5 syntax errors on almost any natural-language query (?, ', ., -, /, ,, AND/OR/NOT).
  • min_score was accepted but ignored; displayed RRF scores were meaningless.
  • Expired memories were returned until the process restarted (and the purge compared ISO vs SQL date formats).
  • No update path (delete + write); INSERT OR REPLACE left orphan FTS rows.
  • No busy_timeout → SQLITE_BUSY with several agents on one store.db.
  • Single-character digits ("phase 3") dropped from queries.
  • Models were cached inside node_modules (re-downloaded on every npx update).

What's new

  • One MemoryStore core shared by the server, tests and benchmarks (no copied search logic).
  • Update in place (write_context with id), duplicate warnings, expected_version compare-and-set on memories and state.
  • Multi-process safety: WAL, BEGIN IMMEDIATE, cross-process vector index sync via PRAGMA data_version, content-hash guard against stale embeddings, lease for background re-embedding.
  • Multilingual default model (snowflake-arctic-embed-m-v2.0) and convex score fusion chosen on held-out queries.
  • Secret detection on write, MCP tool annotations, server instructions, compact token-efficient output, automatic migration from 0.0.x stores.

Validation

  • npm test: 37 tests — unit, end-to-end over MCP stdio, 4 processes × 500 writes with a contended CAS counter, metric formulas checked against hand-computed values. AMS_MODEL_TESTS=1 adds a real-model end-to-end test (PT memory found by an EN question).
  • npm run bench (~30 s, < 1 GB RAM), Apple M2 8 GB:
Model Hit@1 Recall@5 MRR Search p50 RAM
keyword only 50.8% 70.0% 0.587 0.7 ms 64 MB
MiniLM (0.0.x) 55.0% 70.0% 0.610 2.6 ms 271 MB
arctic (default) 74.2% 95.8% 0.836 8.6 ms 628 MB
gemma-300m 74.2% 96.7% 0.841 57.9 ms 1372 MB
  • LongMemEval-S with the official protocol (n=419): keyword engine R_any@5 95.5%. The hybrid LongMemEval run is optional (≈1 h, several GB RAM) and was not run for this PR.
  • The previous "92.1% Recall@5" claim is removed: it came from a copy of the search code and a non-standard metric.

Breaking changes

  • Node ≥ 22.13. Default embedding model changed; vectors are recomputed automatically. Tool names unchanged (new optional params only).

Test plan

  • npm test (37 pass, 1 opt-in skipped)
  • AMS_MODEL_TESTS=1 node --test test/e2e-model.test.js
  • npm run bench twice — identical quality, stable latency
  • Migration from a 0.0.9 database and from the legacy markdown store (tests)
  • CI green on Node 22.13 / 22.x / 24.x

🤖 Generated with Claude Code

vbfs and others added 3 commits October 12, 2026 21:58
…marks

Correctness
- Natural-language queries no longer break FTS5 (every term is quoted);
  "What did we decide about auth?" used to throw a syntax error.
- min_score is applied; scores are normalized 0-1.
- Expired memories are hidden immediately, purged within a minute.
- write_context updates in place via id (ON CONFLICT upsert, no orphan
  FTS rows), reports likely duplicates, supports expected_version CAS.
- set_state/get_state are versioned with compare-and-set.
- Credentials are refused on write.

Multi-agent safety
- Single MemoryStore class (no global state) used by server, tests and
  benchmarks. WAL + busy_timeout + BEGIN IMMEDIATE.
- In-memory vector index synced across processes via PRAGMA data_version;
  stale vectors can never overwrite newer content (content-hash guard).
- Schema versioning with automatic migration from 0.0.x stores.

Retrieval
- Default model: multilingual snowflake-arctic-embed-m-v2.0 (PT-BR/EN),
  cached in ~/.cache/agent-memory-store instead of node_modules.
- Convex score fusion (0.7 semantic), chosen on a held-out split.

Validation
- 37 tests: unit, end-to-end over MCP stdio, 4-process concurrency,
  metric formulas, plus an opt-in real-model end-to-end test. CI added.
- npm run bench: bilingual golden set (150 memories, 120 queries) +
  latency/RAM, ~30 s, < 1 GB. LongMemEval uses the official protocol.
- Removes the previous 92.1% claim, which came from a copy of the search
  code and a non-standard metric.

BREAKING CHANGE: requires Node >= 22.13; default embedding model changed
(vectors are recomputed automatically on first start).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Node 22.13-22.15 bundle SQLite without FTS5, so the store failed to open
(caught by CI). Bump engines/CI/docs to 22.16 and fail fast with a clear
message on older builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vbfs
vbfs merged commit 9955ed2 into main Oct 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant