@remnic/core 10.0.150 → 10.0.151
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/dist/access-admin-ops-surface.js +2 -2
- package/dist/access-cli.js +2 -2
- package/dist/access-extraction-force-flush-preempt.js +2 -2
- package/dist/access-extraction-force-flush.js +2 -2
- package/dist/access-http-briefing.js +2 -2
- package/dist/access-http-query.js +2 -2
- package/dist/access-http.js +2 -2
- package/dist/access-identity-continuity-surface.js +2 -2
- package/dist/access-lcm-surface.js +2 -2
- package/dist/access-mcp.js +2 -2
- package/dist/access-observe-write-surface.js +2 -2
- package/dist/access-operations-batch.js +2 -2
- package/dist/access-operations.js +2 -2
- package/dist/access-recall-concurrency.js +2 -2
- package/dist/access-recall-response.js +2 -2
- package/dist/access-recall-surface.js +2 -2
- package/dist/access-service.js +2 -2
- package/dist/{chunk-3JZZ6WTA.js → chunk-2ZYU76CG.js} +2 -2
- package/dist/{chunk-XYW5HHFS.js → chunk-5Y3UVK6S.js} +59 -22
- package/dist/chunk-5Y3UVK6S.js.map +1 -0
- package/dist/{chunk-65B3XGQR.js → chunk-VI5ECVDF.js} +2 -2
- package/dist/cli.js +2 -2
- package/dist/explicit-capture.js +2 -2
- package/dist/harmonic-retrieval.d.ts +3 -0
- package/dist/harmonic-retrieval.d.ts.map +1 -1
- package/dist/harmonic-retrieval.js +3 -1
- package/dist/index.js +2 -2
- package/dist/orchestration/backlog-scheduler.js +3 -3
- package/dist/orchestration/buffer-drain-runner.js +3 -3
- package/dist/orchestrator.js +2 -2
- package/dist/recall-navigation.js +2 -2
- package/package.json +2 -2
- package/src/harmonic-retrieval-index.test.ts +183 -1
- package/src/harmonic-retrieval.ts +96 -25
- package/dist/chunk-XYW5HHFS.js.map +0 -1
- /package/dist/{chunk-3JZZ6WTA.js.map → chunk-2ZYU76CG.js.map} +0 -0
- /package/dist/{chunk-65B3XGQR.js.map → chunk-VI5ECVDF.js.map} +0 -0
package/dist/cli.js
CHANGED
|
@@ -91,7 +91,7 @@ import {
|
|
|
91
91
|
runWorkProductStatusCliCommand,
|
|
92
92
|
runWorkProjectCliCommand,
|
|
93
93
|
runWorkTaskCliCommand
|
|
94
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-2ZYU76CG.js";
|
|
95
95
|
import "./chunk-TH6OYP6I.js";
|
|
96
96
|
import "./chunk-PQM3B54K.js";
|
|
97
97
|
import "./chunk-ZZYJNT2J.js";
|
|
@@ -272,7 +272,7 @@ import "./chunk-UOBPK2OS.js";
|
|
|
272
272
|
import "./chunk-2YA5N2BY.js";
|
|
273
273
|
import "./chunk-3HSRWJTC.js";
|
|
274
274
|
import "./chunk-FJEYZSJD.js";
|
|
275
|
-
import "./chunk-
|
|
275
|
+
import "./chunk-5Y3UVK6S.js";
|
|
276
276
|
import "./chunk-GXL52YZA.js";
|
|
277
277
|
import "./chunk-AZEZSQ5R.js";
|
|
278
278
|
import "./chunk-JA2GJCOS.js";
|
package/dist/explicit-capture.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
shouldSkipImplicitExtraction,
|
|
9
9
|
stripInlineExplicitCaptureNotes,
|
|
10
10
|
validateExplicitCaptureInput
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-2ZYU76CG.js";
|
|
12
12
|
import "./chunk-TH6OYP6I.js";
|
|
13
13
|
import "./chunk-PQM3B54K.js";
|
|
14
14
|
import "./chunk-ZZYJNT2J.js";
|
|
@@ -189,7 +189,7 @@ import "./chunk-UOBPK2OS.js";
|
|
|
189
189
|
import "./chunk-2YA5N2BY.js";
|
|
190
190
|
import "./chunk-3HSRWJTC.js";
|
|
191
191
|
import "./chunk-FJEYZSJD.js";
|
|
192
|
-
import "./chunk-
|
|
192
|
+
import "./chunk-5Y3UVK6S.js";
|
|
193
193
|
import "./chunk-GXL52YZA.js";
|
|
194
194
|
import "./chunk-AZEZSQ5R.js";
|
|
195
195
|
import "./chunk-JA2GJCOS.js";
|
|
@@ -13,6 +13,9 @@ export interface HarmonicRetrievalResult {
|
|
|
13
13
|
matchedFields: string[];
|
|
14
14
|
matchedAnchors: HarmonicMatchedAnchor[];
|
|
15
15
|
}
|
|
16
|
+
export declare const harmonicSearchIndexStats: {
|
|
17
|
+
builds: number;
|
|
18
|
+
};
|
|
16
19
|
export declare function readAbstractionNodes(options: {
|
|
17
20
|
memoryDir: string;
|
|
18
21
|
abstractionNodeStoreDir?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"harmonic-retrieval.d.ts","sourceRoot":"","sources":["../src/harmonic-retrieval.ts"],"names":[],"mappings":"AAOC,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AACjC,OAAO,EAA+C,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAiQnH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,aAAa,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,EAAE,qBAAqB,EAAE,CAAC;CACzC;
|
|
1
|
+
{"version":3,"file":"harmonic-retrieval.d.ts","sourceRoot":"","sources":["../src/harmonic-retrieval.ts"],"names":[],"mappings":"AAOC,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AACjC,OAAO,EAA+C,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAiQnH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,aAAa,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,EAAE,qBAAqB,EAAE,CAAC;CACzC;AAuCD,eAAO,MAAM,wBAAwB;;CAAgB,CAAC;AA8GtD,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAY7B;AAED,wBAAsB,cAAc,CAAC,OAAO,EAAE;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAavB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,OAAO,EAAE,SAAS,EAAE,CAAC;CACtB;AAyKD,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB;;;;;;CAAgE,CAAC;AAErG,yFAAyF;AACzF,eAAO,MAAM,6BAA6B,OAAQ,CAAC;AAInD,qBAAa,8BAA+B,SAAQ,KAAK;;CAKxD;AAED,UAAU,2BAA2B;IACnC,6DAA6D;IAC7D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,2BAA2B,GAAG,IAAI,GAAG,IAAI,CAE9F;AAWD,wBAAgB,uBAAuB,IAAI,IAAI,CAI9C;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE/D;AA0ED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,0BAA0B,CAAC,OAAO,EAAE;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;8EAE0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAyClC;AAED,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,yHAAyH;IACzH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;+EAG2E;IAC3E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAuFrC"}
|
|
@@ -3,13 +3,14 @@ import {
|
|
|
3
3
|
HarmonicGraphWaitDeadlineError,
|
|
4
4
|
clearHarmonicGraphCache,
|
|
5
5
|
harmonicGraphCacheStats,
|
|
6
|
+
harmonicSearchIndexStats,
|
|
6
7
|
readAbstractionNodes,
|
|
7
8
|
readCueAnchors,
|
|
8
9
|
readProjectedHarmonicGraph,
|
|
9
10
|
searchHarmonicRetrieval,
|
|
10
11
|
setHarmonicGraphBuildTestHooks,
|
|
11
12
|
settleHarmonicGraphBuilds
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-5Y3UVK6S.js";
|
|
13
14
|
import "./chunk-GXL52YZA.js";
|
|
14
15
|
import "./chunk-AZEZSQ5R.js";
|
|
15
16
|
import "./chunk-JA2GJCOS.js";
|
|
@@ -136,6 +137,7 @@ export {
|
|
|
136
137
|
HarmonicGraphWaitDeadlineError,
|
|
137
138
|
clearHarmonicGraphCache,
|
|
138
139
|
harmonicGraphCacheStats,
|
|
140
|
+
harmonicSearchIndexStats,
|
|
139
141
|
readAbstractionNodes,
|
|
140
142
|
readCueAnchors,
|
|
141
143
|
readProjectedHarmonicGraph,
|
package/dist/index.js
CHANGED
|
@@ -259,7 +259,7 @@ import {
|
|
|
259
259
|
writeManifest,
|
|
260
260
|
writeMeetingEpisodeMemory,
|
|
261
261
|
writeTimelineState
|
|
262
|
-
} from "./chunk-
|
|
262
|
+
} from "./chunk-2ZYU76CG.js";
|
|
263
263
|
import "./chunk-TH6OYP6I.js";
|
|
264
264
|
import "./chunk-PQM3B54K.js";
|
|
265
265
|
import {
|
|
@@ -725,7 +725,7 @@ import "./chunk-UOBPK2OS.js";
|
|
|
725
725
|
import "./chunk-2YA5N2BY.js";
|
|
726
726
|
import "./chunk-3HSRWJTC.js";
|
|
727
727
|
import "./chunk-FJEYZSJD.js";
|
|
728
|
-
import "./chunk-
|
|
728
|
+
import "./chunk-5Y3UVK6S.js";
|
|
729
729
|
import "./chunk-GXL52YZA.js";
|
|
730
730
|
import "./chunk-AZEZSQ5R.js";
|
|
731
731
|
import "./chunk-JA2GJCOS.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BufferDrainRunner
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-VI5ECVDF.js";
|
|
4
|
+
import "../chunk-2ZYU76CG.js";
|
|
5
5
|
import "../chunk-TH6OYP6I.js";
|
|
6
6
|
import "../chunk-PQM3B54K.js";
|
|
7
7
|
import "../chunk-ZZYJNT2J.js";
|
|
@@ -182,7 +182,7 @@ import "../chunk-UOBPK2OS.js";
|
|
|
182
182
|
import "../chunk-2YA5N2BY.js";
|
|
183
183
|
import "../chunk-3HSRWJTC.js";
|
|
184
184
|
import "../chunk-FJEYZSJD.js";
|
|
185
|
-
import "../chunk-
|
|
185
|
+
import "../chunk-5Y3UVK6S.js";
|
|
186
186
|
import "../chunk-GXL52YZA.js";
|
|
187
187
|
import "../chunk-AZEZSQ5R.js";
|
|
188
188
|
import "../chunk-JA2GJCOS.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BufferDrainRunner,
|
|
3
3
|
ClaimBufferStorage
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-VI5ECVDF.js";
|
|
5
|
+
import "../chunk-2ZYU76CG.js";
|
|
6
6
|
import "../chunk-TH6OYP6I.js";
|
|
7
7
|
import "../chunk-PQM3B54K.js";
|
|
8
8
|
import "../chunk-ZZYJNT2J.js";
|
|
@@ -183,7 +183,7 @@ import "../chunk-UOBPK2OS.js";
|
|
|
183
183
|
import "../chunk-2YA5N2BY.js";
|
|
184
184
|
import "../chunk-3HSRWJTC.js";
|
|
185
185
|
import "../chunk-FJEYZSJD.js";
|
|
186
|
-
import "../chunk-
|
|
186
|
+
import "../chunk-5Y3UVK6S.js";
|
|
187
187
|
import "../chunk-GXL52YZA.js";
|
|
188
188
|
import "../chunk-AZEZSQ5R.js";
|
|
189
189
|
import "../chunk-JA2GJCOS.js";
|
package/dist/orchestrator.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
mergeGraphExpandedResults,
|
|
7
7
|
qmdStartupCollectionChecksWithTimeout,
|
|
8
8
|
resolveEffectiveIdentityInjectionMode
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-2ZYU76CG.js";
|
|
10
10
|
import "./chunk-TH6OYP6I.js";
|
|
11
11
|
import "./chunk-PQM3B54K.js";
|
|
12
12
|
import "./chunk-ZZYJNT2J.js";
|
|
@@ -191,7 +191,7 @@ import "./chunk-UOBPK2OS.js";
|
|
|
191
191
|
import "./chunk-2YA5N2BY.js";
|
|
192
192
|
import "./chunk-3HSRWJTC.js";
|
|
193
193
|
import "./chunk-FJEYZSJD.js";
|
|
194
|
-
import "./chunk-
|
|
194
|
+
import "./chunk-5Y3UVK6S.js";
|
|
195
195
|
import "./chunk-GXL52YZA.js";
|
|
196
196
|
import "./chunk-AZEZSQ5R.js";
|
|
197
197
|
import "./chunk-JA2GJCOS.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runRecallNavigation
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2ZYU76CG.js";
|
|
4
4
|
import "./chunk-TH6OYP6I.js";
|
|
5
5
|
import "./chunk-PQM3B54K.js";
|
|
6
6
|
import "./chunk-ZZYJNT2J.js";
|
|
@@ -181,7 +181,7 @@ import "./chunk-UOBPK2OS.js";
|
|
|
181
181
|
import "./chunk-2YA5N2BY.js";
|
|
182
182
|
import "./chunk-3HSRWJTC.js";
|
|
183
183
|
import "./chunk-FJEYZSJD.js";
|
|
184
|
-
import "./chunk-
|
|
184
|
+
import "./chunk-5Y3UVK6S.js";
|
|
185
185
|
import "./chunk-GXL52YZA.js";
|
|
186
186
|
import "./chunk-AZEZSQ5R.js";
|
|
187
187
|
import "./chunk-JA2GJCOS.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remnic/core",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.151",
|
|
4
4
|
"description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -3396,7 +3396,7 @@
|
|
|
3396
3396
|
"core"
|
|
3397
3397
|
],
|
|
3398
3398
|
"peerDependencies": {
|
|
3399
|
-
"@remnic/coding-graph": "^10.0.
|
|
3399
|
+
"@remnic/coding-graph": "^10.0.151"
|
|
3400
3400
|
},
|
|
3401
3401
|
"peerDependenciesMeta": {
|
|
3402
3402
|
"@remnic/coding-graph": {
|
|
@@ -6,7 +6,8 @@ import test from "node:test";
|
|
|
6
6
|
import { getMemoryProjectionPath } from "./memory-projection-store.js";
|
|
7
7
|
import { openBetterSqlite3 } from "./runtime/better-sqlite.js";
|
|
8
8
|
import { recordAbstractionNode } from "./abstraction-nodes.js";
|
|
9
|
-
import {
|
|
9
|
+
import { recordCueAnchor } from "./cue-anchors.js";
|
|
10
|
+
import { harmonicSearchIndexStats, readProjectedHarmonicGraph, searchHarmonicRetrieval, type HarmonicRetrievalResult } from "./harmonic-retrieval.js";
|
|
10
11
|
import { rebuildMemoryProjection } from "./maintenance/rebuild-memory-projection.js";
|
|
11
12
|
import { StorageManager } from "./storage.js";
|
|
12
13
|
|
|
@@ -440,3 +441,184 @@ test("indexed source resolution overlaps per-source file reads (#3450)", async (
|
|
|
440
441
|
await rm(memoryDir, { recursive: true, force: true });
|
|
441
442
|
}
|
|
442
443
|
});
|
|
444
|
+
|
|
445
|
+
test("cached graph searches share one scoring index across recalls (#3450)", async (t) => {
|
|
446
|
+
const memoryDir = await mkdtemp(path.join(tmpdir(), "remnic-harmonic-index-reuse-"));
|
|
447
|
+
try {
|
|
448
|
+
const storage = new StorageManager(memoryDir);
|
|
449
|
+
await storage.ensureDirectories();
|
|
450
|
+
const a = await storage.writeMemory("fact", "shared index source payload", { source: "test" });
|
|
451
|
+
await recordAbstractionNode({
|
|
452
|
+
memoryDir,
|
|
453
|
+
node: {
|
|
454
|
+
schemaVersion: 1,
|
|
455
|
+
nodeId: "shared-index-node",
|
|
456
|
+
recordedAt: "2026-11-19T00:00:00.000Z",
|
|
457
|
+
sessionKey: "agent:index",
|
|
458
|
+
kind: "topic",
|
|
459
|
+
abstractionLevel: "meso",
|
|
460
|
+
title: "shared index source payload",
|
|
461
|
+
summary: "shared index summary",
|
|
462
|
+
sourceMemoryIds: [a.id],
|
|
463
|
+
},
|
|
464
|
+
});
|
|
465
|
+
await rebuildMemoryProjection({ memoryDir, storage, dryRun: false });
|
|
466
|
+
|
|
467
|
+
const run = () =>
|
|
468
|
+
searchHarmonicRetrieval({
|
|
469
|
+
memoryDir,
|
|
470
|
+
query: "shared index source payload",
|
|
471
|
+
maxResults: 5,
|
|
472
|
+
anchorsEnabled: false,
|
|
473
|
+
useGraphCache: true,
|
|
474
|
+
});
|
|
475
|
+
const first = await run();
|
|
476
|
+
const buildsBefore = harmonicSearchIndexStats.builds;
|
|
477
|
+
const second = await run();
|
|
478
|
+
const third = await run();
|
|
479
|
+
assert.equal(
|
|
480
|
+
harmonicSearchIndexStats.builds,
|
|
481
|
+
buildsBefore,
|
|
482
|
+
"repeat searches over a cached graph must reuse the same scoring index (re-tokenizing every recall costs ~750 ms on a real corpus)",
|
|
483
|
+
);
|
|
484
|
+
assert.deepEqual(third, second);
|
|
485
|
+
assert.deepEqual(second.map((r) => r.node.nodeId), first.map((r) => r.node.nodeId));
|
|
486
|
+
} finally {
|
|
487
|
+
t.mock.restoreAll();
|
|
488
|
+
await rm(memoryDir, { recursive: true, force: true });
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
test("anchors sharing an anchorId across types keep their own cues (#3450)", async (t) => {
|
|
493
|
+
const memoryDir = await mkdtemp(path.join(tmpdir(), "remnic-harmonic-dup-anchor-"));
|
|
494
|
+
try {
|
|
495
|
+
const storage = new StorageManager(memoryDir);
|
|
496
|
+
await storage.ensureDirectories();
|
|
497
|
+
const alpha = await storage.writeMemory("fact", "alpha source body", { source: "test" });
|
|
498
|
+
const beta = await storage.writeMemory("fact", "beta source body", { source: "test" });
|
|
499
|
+
await recordAbstractionNode({
|
|
500
|
+
memoryDir,
|
|
501
|
+
node: {
|
|
502
|
+
schemaVersion: 1,
|
|
503
|
+
nodeId: "dup-anchor-alpha",
|
|
504
|
+
recordedAt: "2026-11-19T00:00:00.000Z",
|
|
505
|
+
sessionKey: "agent:index",
|
|
506
|
+
kind: "topic",
|
|
507
|
+
abstractionLevel: "meso",
|
|
508
|
+
title: "unmatched alpha title",
|
|
509
|
+
summary: "unmatched alpha summary",
|
|
510
|
+
sourceMemoryIds: [alpha.id],
|
|
511
|
+
},
|
|
512
|
+
});
|
|
513
|
+
await recordAbstractionNode({
|
|
514
|
+
memoryDir,
|
|
515
|
+
node: {
|
|
516
|
+
schemaVersion: 1,
|
|
517
|
+
nodeId: "dup-anchor-beta",
|
|
518
|
+
recordedAt: "2026-11-19T00:00:00.000Z",
|
|
519
|
+
sessionKey: "agent:index",
|
|
520
|
+
kind: "topic",
|
|
521
|
+
abstractionLevel: "meso",
|
|
522
|
+
title: "unmatched beta title",
|
|
523
|
+
summary: "unmatched beta summary",
|
|
524
|
+
sourceMemoryIds: [beta.id],
|
|
525
|
+
},
|
|
526
|
+
});
|
|
527
|
+
// The anchor store dedups by (anchorType, anchorId), so one anchorId can
|
|
528
|
+
// legitimately recur under a second type — each keeps its own cue.
|
|
529
|
+
await recordCueAnchor({
|
|
530
|
+
memoryDir,
|
|
531
|
+
anchor: {
|
|
532
|
+
schemaVersion: 1,
|
|
533
|
+
anchorId: "shared-anchor-id",
|
|
534
|
+
anchorType: "entity",
|
|
535
|
+
anchorValue: "zebra wobble",
|
|
536
|
+
normalizedCue: "zebra wobble",
|
|
537
|
+
recordedAt: "2026-11-19T00:00:00.000Z",
|
|
538
|
+
sessionKey: "agent:index",
|
|
539
|
+
nodeRefs: ["dup-anchor-alpha"],
|
|
540
|
+
sourceMemoryIdsByNodeRef: { "dup-anchor-alpha": [alpha.id] },
|
|
541
|
+
},
|
|
542
|
+
});
|
|
543
|
+
await recordCueAnchor({
|
|
544
|
+
memoryDir,
|
|
545
|
+
anchor: {
|
|
546
|
+
schemaVersion: 1,
|
|
547
|
+
anchorId: "shared-anchor-id",
|
|
548
|
+
anchorType: "file",
|
|
549
|
+
anchorValue: "quartz tumble",
|
|
550
|
+
normalizedCue: "quartz tumble",
|
|
551
|
+
recordedAt: "2026-11-19T00:00:00.000Z",
|
|
552
|
+
sessionKey: "agent:index",
|
|
553
|
+
nodeRefs: ["dup-anchor-beta"],
|
|
554
|
+
sourceMemoryIdsByNodeRef: { "dup-anchor-beta": [beta.id] },
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
await rebuildMemoryProjection({ memoryDir, storage, dryRun: false });
|
|
558
|
+
|
|
559
|
+
const zebra = await searchHarmonicRetrieval({
|
|
560
|
+
memoryDir,
|
|
561
|
+
query: "zebra wobble",
|
|
562
|
+
maxResults: 5,
|
|
563
|
+
anchorsEnabled: true,
|
|
564
|
+
useGraphCache: true,
|
|
565
|
+
});
|
|
566
|
+
assert.deepEqual(zebra.map((r) => r.node.nodeId), ["dup-anchor-alpha"]);
|
|
567
|
+
const quartz = await searchHarmonicRetrieval({
|
|
568
|
+
memoryDir,
|
|
569
|
+
query: "quartz tumble",
|
|
570
|
+
maxResults: 5,
|
|
571
|
+
anchorsEnabled: true,
|
|
572
|
+
useGraphCache: true,
|
|
573
|
+
});
|
|
574
|
+
assert.deepEqual(quartz.map((r) => r.node.nodeId), ["dup-anchor-beta"]);
|
|
575
|
+
} finally {
|
|
576
|
+
t.mock.restoreAll();
|
|
577
|
+
await rm(memoryDir, { recursive: true, force: true });
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
test("nodes sharing a nodeId across record days keep their own tokens (#3450)", async (t) => {
|
|
582
|
+
const memoryDir = await mkdtemp(path.join(tmpdir(), "remnic-harmonic-dup-node-"));
|
|
583
|
+
try {
|
|
584
|
+
const storage = new StorageManager(memoryDir);
|
|
585
|
+
await storage.ensureDirectories();
|
|
586
|
+
const a = await storage.writeMemory("fact", "zebra wobble retained source", { source: "test" });
|
|
587
|
+
const b = await storage.writeMemory("fact", "quartz tumble retained source", { source: "test" });
|
|
588
|
+
// Node records live under nodes/<day>/<nodeId>.json, so one nodeId can
|
|
589
|
+
// legitimately recur on a second day as a distinct projected node.
|
|
590
|
+
for (const [recordedAt, title, id] of [
|
|
591
|
+
["2026-11-17T00:00:00.000Z", "zebra wobble", a.id],
|
|
592
|
+
["2026-11-18T00:00:00.000Z", "quartz tumble", b.id],
|
|
593
|
+
] as const) {
|
|
594
|
+
await recordAbstractionNode({
|
|
595
|
+
memoryDir,
|
|
596
|
+
node: {
|
|
597
|
+
schemaVersion: 1,
|
|
598
|
+
nodeId: "shared-id",
|
|
599
|
+
recordedAt,
|
|
600
|
+
sessionKey: "agent:index",
|
|
601
|
+
kind: "topic",
|
|
602
|
+
abstractionLevel: "meso",
|
|
603
|
+
title,
|
|
604
|
+
summary: title,
|
|
605
|
+
sourceMemoryIds: [id],
|
|
606
|
+
},
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
await rebuildMemoryProjection({ memoryDir, storage, dryRun: false });
|
|
610
|
+
|
|
611
|
+
const got = await searchHarmonicRetrieval({
|
|
612
|
+
memoryDir,
|
|
613
|
+
query: "zebra wobble",
|
|
614
|
+
maxResults: 5,
|
|
615
|
+
anchorsEnabled: false,
|
|
616
|
+
useGraphCache: true,
|
|
617
|
+
});
|
|
618
|
+
assert.equal(got.length, 1);
|
|
619
|
+
assert.equal(got[0].node.sourceMemoryIds?.[0], a.id);
|
|
620
|
+
} finally {
|
|
621
|
+
t.mock.restoreAll();
|
|
622
|
+
await rm(memoryDir, { recursive: true, force: true });
|
|
623
|
+
}
|
|
624
|
+
});
|
|
@@ -13,7 +13,7 @@ import { inferMemoryStatus, toMemoryPathRel } from "./memory-lifecycle-ledger-ut
|
|
|
13
13
|
} from "./abstraction-nodes.js";
|
|
14
14
|
import { resolveCueAnchorStoreDir, validateCueAnchor, type CueAnchor, type CueAnchorType } from "./cue-anchors.js";
|
|
15
15
|
import { compareDeterministicStrings } from "./deterministic-order.js";
|
|
16
|
-
import {
|
|
16
|
+
import { normalizeRecallTokenSet, normalizeRecallTokens } from "./recall-tokenization.js";
|
|
17
17
|
import { stripAttributesSuffix } from "./structured-attributes.js";
|
|
18
18
|
import { isValidityExpiredNow } from "./temporal-validity.js";
|
|
19
19
|
import { assertSafePathSegment, isRecord } from "./store-contract.js";
|
|
@@ -291,35 +291,109 @@ interface HarmonicCandidate {
|
|
|
291
291
|
matchedAnchors: Map<string, HarmonicMatchedAnchor>;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
function
|
|
294
|
+
function tokenOverlap(queryTokens: Set<string>, fieldTokens: ReadonlySet<string>): number {
|
|
295
|
+
let matches = 0;
|
|
296
|
+
for (const token of queryTokens) {
|
|
297
|
+
if (fieldTokens.has(token)) matches += 1;
|
|
298
|
+
}
|
|
299
|
+
return matches;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
interface HarmonicNodeTokens {
|
|
303
|
+
title: ReadonlySet<string>;
|
|
304
|
+
summary: ReadonlySet<string>;
|
|
305
|
+
tags: ReadonlySet<string>;
|
|
306
|
+
entities: ReadonlySet<string>;
|
|
307
|
+
kind: ReadonlySet<string>;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
interface HarmonicAnchorTokens {
|
|
311
|
+
value: ReadonlySet<string>;
|
|
312
|
+
normalized: ReadonlySet<string>;
|
|
313
|
+
type: ReadonlySet<string>;
|
|
314
|
+
eligibleTags: ReadonlySet<string>;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
interface HarmonicSearchIndex {
|
|
318
|
+
nodesById: Map<string, AbstractionNode>;
|
|
319
|
+
nodeTokens: HarmonicNodeTokens[];
|
|
320
|
+
anchorTokens: HarmonicAnchorTokens[];
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export const harmonicSearchIndexStats = { builds: 0 };
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Per-graph scoring index, keyed on the frozen graph object itself. Scoring a
|
|
327
|
+
* recall tokenizes every node's title/summary/tags/entities/kind and every
|
|
328
|
+
* anchor's value/cue/type/eligible tags; on a cache hit that repeated the
|
|
329
|
+
* whole normalization for each recall (~0.75 s on a ~2.5k node, ~10k anchor
|
|
330
|
+
* corpus, issue #3450). The sets are identical to what `countRecallTokenOverlap`
|
|
331
|
+
* computed from the raw fields, so scores and matchedFields are unchanged.
|
|
332
|
+
* For an uncached graph the index is built per call — the same work the old
|
|
333
|
+
* code did inline.
|
|
334
|
+
*/
|
|
335
|
+
const harmonicSearchIndexes = new WeakMap<ProjectedHarmonicGraph, HarmonicSearchIndex>();
|
|
336
|
+
|
|
337
|
+
function getHarmonicSearchIndex(graph: ProjectedHarmonicGraph): HarmonicSearchIndex {
|
|
338
|
+
const cached = harmonicSearchIndexes.get(graph);
|
|
339
|
+
if (cached) return cached;
|
|
340
|
+
harmonicSearchIndexStats.builds += 1;
|
|
341
|
+
const nodesById = new Map(graph.nodes.map((node) => [node.nodeId, node]));
|
|
342
|
+
// Node ids are only unique per record day (nodes/<day>/<nodeId>.json), so
|
|
343
|
+
// tokens are indexed by position in graph.nodes.
|
|
344
|
+
const nodeTokens = graph.nodes.map((node) => ({
|
|
345
|
+
title: normalizeRecallTokenSet(node.title ?? ""),
|
|
346
|
+
summary: normalizeRecallTokenSet(node.summary ?? ""),
|
|
347
|
+
tags: normalizeRecallTokenSet(node.tags?.join(" ") ?? ""),
|
|
348
|
+
entities: normalizeRecallTokenSet(node.entityRefs?.join(" ") ?? ""),
|
|
349
|
+
kind: normalizeRecallTokenSet(`${node.kind} ${node.abstractionLevel}`),
|
|
350
|
+
}));
|
|
351
|
+
// Anchor ids are only unique per anchorType (cue-anchors dedups by
|
|
352
|
+
// type+id), so tokens are indexed by position in graph.anchors.
|
|
353
|
+
const anchorTokens = graph.anchors.map((anchor) => {
|
|
354
|
+
const eligibleNodeTags = new Set(anchor.nodeRefs.flatMap((nodeRef) => nodesById.get(nodeRef)?.tags ?? []));
|
|
355
|
+
const eligibleAnchorTags = anchor.tags?.filter((tag) => eligibleNodeTags.has(tag)) ?? [];
|
|
356
|
+
return {
|
|
357
|
+
value: normalizeRecallTokenSet(anchor.anchorValue ?? ""),
|
|
358
|
+
normalized: normalizeRecallTokenSet(anchor.normalizedCue ?? ""),
|
|
359
|
+
type: normalizeRecallTokenSet(anchor.anchorType),
|
|
360
|
+
eligibleTags: normalizeRecallTokenSet(eligibleAnchorTags.join(" ")),
|
|
361
|
+
};
|
|
362
|
+
});
|
|
363
|
+
const index: HarmonicSearchIndex = { nodesById, nodeTokens, anchorTokens };
|
|
364
|
+
harmonicSearchIndexes.set(graph, index);
|
|
365
|
+
return index;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function scoreNode(tokens: HarmonicNodeTokens, queryTokens: Set<string>): { score: number; matchedFields: string[] } {
|
|
295
369
|
const matchedFields: string[] = [];
|
|
296
370
|
let score = 0;
|
|
297
371
|
|
|
298
|
-
const titleMatches =
|
|
372
|
+
const titleMatches = tokenOverlap(queryTokens, tokens.title);
|
|
299
373
|
if (titleMatches > 0) {
|
|
300
374
|
score += titleMatches * 3;
|
|
301
375
|
matchedFields.push("title");
|
|
302
376
|
}
|
|
303
377
|
|
|
304
|
-
const summaryMatches =
|
|
378
|
+
const summaryMatches = tokenOverlap(queryTokens, tokens.summary);
|
|
305
379
|
if (summaryMatches > 0) {
|
|
306
380
|
score += summaryMatches * 3;
|
|
307
381
|
matchedFields.push("summary");
|
|
308
382
|
}
|
|
309
383
|
|
|
310
|
-
const tagMatches =
|
|
384
|
+
const tagMatches = tokenOverlap(queryTokens, tokens.tags);
|
|
311
385
|
if (tagMatches > 0) {
|
|
312
386
|
score += tagMatches * 2;
|
|
313
387
|
matchedFields.push("tags");
|
|
314
388
|
}
|
|
315
389
|
|
|
316
|
-
const entityMatches =
|
|
390
|
+
const entityMatches = tokenOverlap(queryTokens, tokens.entities);
|
|
317
391
|
if (entityMatches > 0) {
|
|
318
392
|
score += entityMatches * 2;
|
|
319
393
|
matchedFields.push("entityRefs");
|
|
320
394
|
}
|
|
321
395
|
|
|
322
|
-
const kindMatches =
|
|
396
|
+
const kindMatches = tokenOverlap(queryTokens, tokens.kind);
|
|
323
397
|
if (kindMatches > 0) {
|
|
324
398
|
score += kindMatches;
|
|
325
399
|
matchedFields.push("kind");
|
|
@@ -328,16 +402,12 @@ function scoreNode(node: AbstractionNode, queryTokens: Set<string>): { score: nu
|
|
|
328
402
|
return { score, matchedFields };
|
|
329
403
|
}
|
|
330
404
|
|
|
331
|
-
function scoreAnchor(
|
|
332
|
-
anchor: CueAnchor,
|
|
333
|
-
queryTokens: Set<string>,
|
|
334
|
-
eligibleNodeTags: readonly string[]
|
|
335
|
-
): { score: number; matchedFields: string[] } {
|
|
405
|
+
function scoreAnchor(tokens: HarmonicAnchorTokens, queryTokens: Set<string>): { score: number; matchedFields: string[] } {
|
|
336
406
|
const matchedFields: string[] = [];
|
|
337
407
|
let score = 0;
|
|
338
408
|
|
|
339
|
-
const valueMatches =
|
|
340
|
-
const normalizedMatches =
|
|
409
|
+
const valueMatches = tokenOverlap(queryTokens, tokens.value);
|
|
410
|
+
const normalizedMatches = tokenOverlap(queryTokens, tokens.normalized);
|
|
341
411
|
const cueMatches = Math.max(valueMatches, normalizedMatches);
|
|
342
412
|
if (cueMatches > 0) {
|
|
343
413
|
score += cueMatches * 4;
|
|
@@ -345,13 +415,13 @@ function scoreAnchor(
|
|
|
345
415
|
if (normalizedMatches > 0) matchedFields.push("anchor");
|
|
346
416
|
}
|
|
347
417
|
|
|
348
|
-
const typeMatches =
|
|
418
|
+
const typeMatches = tokenOverlap(queryTokens, tokens.type);
|
|
349
419
|
if (typeMatches > 0) {
|
|
350
420
|
score += typeMatches;
|
|
351
421
|
matchedFields.push("anchorType");
|
|
352
422
|
}
|
|
353
423
|
|
|
354
|
-
const tagMatches =
|
|
424
|
+
const tagMatches = tokenOverlap(queryTokens, tokens.eligibleTags);
|
|
355
425
|
if (tagMatches > 0) {
|
|
356
426
|
score += tagMatches * 2;
|
|
357
427
|
matchedFields.push("anchorTags");
|
|
@@ -780,17 +850,20 @@ export async function searchHarmonicRetrieval(options: {
|
|
|
780
850
|
|
|
781
851
|
// One projection for every graph reader: nodes and anchors both arrive
|
|
782
852
|
// already narrowed to the namespace's current active memories.
|
|
783
|
-
const
|
|
853
|
+
const graph = await readProjectedHarmonicGraph({
|
|
784
854
|
...options,
|
|
785
855
|
useCache: options.useGraphCache === true,
|
|
786
856
|
waitBudgetMs:
|
|
787
857
|
options.waitBudgetMs === undefined ? HARMONIC_GRAPH_WAIT_BUDGET_MS : options.waitBudgetMs,
|
|
788
858
|
});
|
|
859
|
+
const { nodes: eligibleNodes, anchors } = graph;
|
|
860
|
+
const searchIndex = getHarmonicSearchIndex(graph);
|
|
789
861
|
const candidates = new Map<string, HarmonicCandidate>();
|
|
790
862
|
|
|
791
|
-
for (const node of eligibleNodes) {
|
|
863
|
+
for (const [nodeIndexPos, node] of eligibleNodes.entries()) {
|
|
792
864
|
throwIfAborted(options.abortSignal, "harmonic retrieval aborted");
|
|
793
|
-
const
|
|
865
|
+
const tokens = searchIndex.nodeTokens[nodeIndexPos];
|
|
866
|
+
const { score, matchedFields } = scoreNode(tokens, queryTokens);
|
|
794
867
|
if (score <= 0) continue;
|
|
795
868
|
candidates.set(node.nodeId, {
|
|
796
869
|
node,
|
|
@@ -803,17 +876,15 @@ export async function searchHarmonicRetrieval(options: {
|
|
|
803
876
|
|
|
804
877
|
if (options.anchorsEnabled) {
|
|
805
878
|
throwIfAborted(options.abortSignal, "harmonic retrieval aborted");
|
|
806
|
-
const
|
|
807
|
-
for (const anchor of anchors) {
|
|
879
|
+
for (const [anchorIndex, anchor] of anchors.entries()) {
|
|
808
880
|
throwIfAborted(options.abortSignal, "harmonic retrieval aborted");
|
|
809
881
|
// `nodeRefs` are the projection's surviving references already.
|
|
810
882
|
const eligibleNodeRefs = anchor.nodeRefs;
|
|
811
|
-
const
|
|
812
|
-
const
|
|
813
|
-
const { score, matchedFields } = scoreAnchor(anchor, queryTokens, eligibleAnchorTags);
|
|
883
|
+
const anchorTokens = searchIndex.anchorTokens[anchorIndex];
|
|
884
|
+
const { score, matchedFields } = scoreAnchor(anchorTokens, queryTokens);
|
|
814
885
|
if (score <= 0) continue;
|
|
815
886
|
for (const nodeRef of eligibleNodeRefs) {
|
|
816
|
-
const node =
|
|
887
|
+
const node = searchIndex.nodesById.get(nodeRef);
|
|
817
888
|
if (!node) continue;
|
|
818
889
|
const existing = candidates.get(nodeRef) ?? {
|
|
819
890
|
node,
|