brain-memory 0.1.0-beta.27 → 0.1.0-beta.29

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 CHANGED
@@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/), and this
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.1.0-beta.28] - 2026-06-26
10
+
11
+ ### Fixed
12
+
13
+ - **Recall relevance after out-of-band memory changes.** `session-start` now
14
+ rebuilds its search index when it has drifted out of sync with `index.json`
15
+ (after a `sync pull`, `sleep`/consolidate, `forget`, or a manual edit), not
16
+ only when the index is missing — matching `recall`'s behavior. A stale index
17
+ silently scored every memory's relevance as 0, so newly-synced or changed
18
+ memories were surfaced by strength/context only, never by relevance.
19
+
9
20
  ## [0.1.0-beta.27] - 2026-06-10
10
21
 
11
22
  ### Security
package/README.md CHANGED
@@ -685,9 +685,9 @@ Brain Memory ships with a controlled benchmark suite grounded in the 2025-2026 S
685
685
  | **E** *Continual Coding* | "Five bugs in order — does bug 5 finish faster than bug 1?" | Forward transfer; agent writes memories between tasks |
686
686
  | **F** *Abstention* | "No deployment target in memory — does the agent ask or invent?" | Confabulation resistance |
687
687
 
688
- **Methodology highlights** — cross-family LLM judge (Claude judges Gemini and vice-versa) with explicit rubric and position-swap; deterministic 200-memory distractor haystack; real `brain session-start` / `brain recall` integration; tokens-per-successful-task as the headline efficiency metric.
688
+ **Methodology highlights** — agent under test is **DeepSeek V4 Pro** (single-shot), graded by a **cross-family judge panel** (Gemini + Gemma-4 + Qwen-3.5, majority vote — no judge shares the agent's family, [Preference Leakage 2502.01534](https://arxiv.org/abs/2502.01534), [PoLL 2404.18796](https://arxiv.org/abs/2404.18796)); deterministic distractor haystacks up to 1000 memories; real `brain session-start` / `brain recall` integration; tokens-per-successful-task as the headline efficiency metric; every scenario anchored by a no-memory floor and an oracle ceiling.
689
689
 
690
- > Preliminary smoke results (1 run × Scenario A × Gemini Flash, May 2026): `brain-real` resolves the task at **27.8K tokens-per-success**, vs **50.8K** for naïve context-dump and **86.3K** for brain with pinning disabled — a ~3× token economy improvement attributable directly to the Pinned Tier. Full multi-run results are in progress.
690
+ > Results (DeepSeek V4 Pro, 3 runs/arm, June 2026). **Scenario A — retrieval under 1000 distractors:** `brain-full` is the only retriever whose memories let the model succeed — it passes **100%** while both **BM25 (0%)** and a **vector store (0%)** fail to surface the oracle memories — and it does so at the **leanest tokens-per-success (3,199)** of any passing arm. **Scenario D — skills:** loading only the relevant skill passes 100% at **1,580 tok/success, ~31% leaner** than dumping all skill bodies. Scenarios B (continuity) shows brain efficient-and-correct; C (contradiction) and F (abstention) are honest **nulls** — the base model handles them without memory. At n=3 the token gaps are directional, not yet significant; the pass-rate gradient is the result. Full tables: [brainmemory.ai/docs/benchmarks/results](https://brainmemory.ai/docs/benchmarks/results).
691
691
 
692
692
  Run the benchmarks yourself:
693
693
 
package/bin/recall.js CHANGED
@@ -26,6 +26,7 @@ const {
26
26
  bm25Search,
27
27
  rebuildIndex,
28
28
  createSearchIndex,
29
+ isSearchIndexStale,
29
30
  } = require('../src/tfidf');
30
31
 
31
32
  const {
@@ -154,17 +155,6 @@ function main() {
154
155
  * empty-index and add/remove/rename drift cases (in-place same-id body edits
155
156
  * are not detected by count alone — acceptable until a version/mtime check).
156
157
  */
157
- function isSearchIndexStale(searchIndex, index) {
158
- if (!searchIndex || !searchIndex.documents) return true;
159
- const memIds = Object.keys((index && index.memories) || {});
160
- const docCount = searchIndex.doc_count != null
161
- ? searchIndex.doc_count
162
- : Object.keys(searchIndex.documents).length;
163
- if (docCount !== memIds.length) return true;
164
- for (const id of memIds) if (!(id in searchIndex.documents)) return true;
165
- return false;
166
- }
167
-
168
158
  /**
169
159
  * Rebuild the search index from all memories.
170
160
  */
@@ -29,6 +29,7 @@ const {
29
29
  search,
30
30
  bm25Search,
31
31
  rebuildIndex,
32
+ isSearchIndexStale,
32
33
  } = require('../src/tfidf');
33
34
 
34
35
  const {
@@ -130,9 +131,13 @@ function computeSessionStart(projectRoot, args = {}) {
130
131
  const memoryCount = Object.keys(index.memories).length;
131
132
 
132
133
  // --- Context recall (deterministic, reuses the recall engine) ---
134
+ // Rebuild when ABSENT *or* STALE — session-start is the first thing a session
135
+ // runs (e.g. right after a `sync pull`), so it is the most likely path to hit
136
+ // a search index that has drifted out of sync with index.json. A present-but-
137
+ // stale index silently zeroes every relevance score (matches recall.js).
133
138
  let searchIndex = null;
134
139
  try { searchIndex = readSearchIndex(brainDir); } catch (_) { searchIndex = null; }
135
- if (!searchIndex) {
140
+ if (isSearchIndexStale(searchIndex, index)) {
136
141
  searchIndex = rebuildIndex(brainDir, index);
137
142
  writeSearchIndex(brainDir, searchIndex);
138
143
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brain-memory",
3
- "version": "0.1.0-beta.27",
3
+ "version": "0.1.0-beta.29",
4
4
  "description": "A brain-inspired hierarchical memory system for AI coding agents. Deep nested file structure that mimics human memory with time-decay and strength-based recall.",
5
5
  "keywords": [
6
6
  "claude-code",
package/src/tfidf.js CHANGED
@@ -453,6 +453,29 @@ function rebuildIndex(brainDir, index) {
453
453
  return searchIndex;
454
454
  }
455
455
 
456
+ /**
457
+ * Is the persisted search index out of sync with index.json?
458
+ *
459
+ * The search index drifts whenever memories change outside memorize's
460
+ * addDocument path (forget, sleep/consolidate, sync pull, manual edit) — and a
461
+ * present-but-empty index silently makes every relevance score 0. Both `recall`
462
+ * and `session-start` must rebuild when the doc SET (not mere presence) drifts.
463
+ *
464
+ * @param {Object|null} searchIndex - parsed search-index.json (or null if absent)
465
+ * @param {Object} index - parsed index.json
466
+ * @returns {boolean} true when a rebuild is required
467
+ */
468
+ function isSearchIndexStale(searchIndex, index) {
469
+ if (!searchIndex || !searchIndex.documents) return true;
470
+ const memIds = Object.keys((index && index.memories) || {});
471
+ const docCount = searchIndex.doc_count != null
472
+ ? searchIndex.doc_count
473
+ : Object.keys(searchIndex.documents).length;
474
+ if (docCount !== memIds.length) return true;
475
+ for (const id of memIds) if (!(id in searchIndex.documents)) return true;
476
+ return false;
477
+ }
478
+
456
479
  module.exports = {
457
480
  // Core primitives
458
481
  tokenize,
@@ -471,6 +494,7 @@ module.exports = {
471
494
  search,
472
495
  bm25Search,
473
496
  rebuildIndex,
497
+ isSearchIndexStale,
474
498
  // Constants
475
499
  SEARCH_INDEX_FILE,
476
500
  STOPWORDS,