@graphrefly/graphrefly 0.47.0 → 0.47.2
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/base/composition/index.cjs +24 -16
- package/dist/base/composition/index.cjs.map +1 -1
- package/dist/base/composition/index.js +6 -6
- package/dist/base/index.cjs +142 -86
- package/dist/base/index.cjs.map +1 -1
- package/dist/base/index.js +11 -11
- package/dist/base/io/index.cjs +114 -68
- package/dist/base/io/index.cjs.map +1 -1
- package/dist/base/io/index.js +5 -5
- package/dist/base/sources/browser/index.cjs +13 -9
- package/dist/base/sources/browser/index.cjs.map +1 -1
- package/dist/base/sources/browser/index.js +13 -9
- package/dist/base/sources/browser/index.js.map +1 -1
- package/dist/base/sources/event/index.cjs +1 -1
- package/dist/base/sources/event/index.cjs.map +1 -1
- package/dist/base/sources/event/index.js +1 -1
- package/dist/base/sources/index.cjs +21 -13
- package/dist/base/sources/index.cjs.map +1 -1
- package/dist/base/sources/index.js +3 -3
- package/dist/base/sources/node/index.cjs +43 -37
- package/dist/base/sources/node/index.cjs.map +1 -1
- package/dist/base/sources/node/index.js +43 -37
- package/dist/base/sources/node/index.js.map +1 -1
- package/dist/{chunk-VLAGJZSL.js → chunk-3O3NKZJW.js} +2 -2
- package/dist/{chunk-YJ4U2D2C.js → chunk-446I4EGD.js} +9 -7
- package/dist/chunk-446I4EGD.js.map +1 -0
- package/dist/{chunk-DKNHAICT.js → chunk-5GVURVIG.js} +14 -8
- package/dist/chunk-5GVURVIG.js.map +1 -0
- package/dist/{chunk-2OB3CEJS.js → chunk-6MRSX3YK.js} +2 -2
- package/dist/{chunk-EVYY4X5A.js → chunk-6ZLCPUXS.js} +2 -2
- package/dist/{chunk-ZVXXDWIB.js → chunk-7AVQIGF6.js} +514 -33
- package/dist/chunk-7AVQIGF6.js.map +1 -0
- package/dist/{chunk-7EGRP2VX.js → chunk-7BULJTL6.js} +2 -2
- package/dist/{chunk-7EGRP2VX.js.map → chunk-7BULJTL6.js.map} +1 -1
- package/dist/{chunk-FW23JYNQ.js → chunk-CEVNQ74M.js} +2 -2
- package/dist/{chunk-CGHORL6G.js → chunk-DDTS7F5O.js} +7 -5
- package/dist/chunk-DDTS7F5O.js.map +1 -0
- package/dist/{chunk-OCUDSN63.js → chunk-EL5VHUGK.js} +79 -47
- package/dist/chunk-EL5VHUGK.js.map +1 -0
- package/dist/{chunk-4GYMCUDZ.js → chunk-EP4WVQLX.js} +5 -5
- package/dist/{chunk-SOOKUYVM.js → chunk-F7EKHR32.js} +13 -9
- package/dist/chunk-F7EKHR32.js.map +1 -0
- package/dist/{chunk-JKTC747G.js → chunk-FQSQONOU.js} +4 -4
- package/dist/{chunk-JGFRAFDL.js → chunk-FVINAAKA.js} +3 -3
- package/dist/{chunk-RAGGHLCV.js → chunk-GUNIRPEJ.js} +8 -6
- package/dist/{chunk-RAGGHLCV.js.map → chunk-GUNIRPEJ.js.map} +1 -1
- package/dist/{chunk-BU3SEFA5.js → chunk-IOJDYUA7.js} +2 -2
- package/dist/{chunk-Y52CS6YA.js → chunk-JA67ZQG2.js} +2 -2
- package/dist/{chunk-Y52CS6YA.js.map → chunk-JA67ZQG2.js.map} +1 -1
- package/dist/{chunk-DM4OMPWK.js → chunk-KNU73RZW.js} +2 -2
- package/dist/{chunk-GWRNLJNW.js → chunk-KRFGO5QH.js} +19 -15
- package/dist/{chunk-GWRNLJNW.js.map → chunk-KRFGO5QH.js.map} +1 -1
- package/dist/{chunk-Z4YXAUDN.js → chunk-KUFXLAEY.js} +11 -7
- package/dist/{chunk-Z4YXAUDN.js.map → chunk-KUFXLAEY.js.map} +1 -1
- package/dist/{chunk-Z6EGP5D7.js → chunk-LDCSZ72P.js} +2 -2
- package/dist/{chunk-5IMMNARC.js → chunk-MS3WPRJR.js} +37 -25
- package/dist/chunk-MS3WPRJR.js.map +1 -0
- package/dist/{chunk-CXANAIZU.js → chunk-N65E26UL.js} +3 -3
- package/dist/{chunk-O3MT7DYI.js → chunk-N6MNJNHB.js} +2 -2
- package/dist/{chunk-Q3EYOCZB.js → chunk-NPRP3MCV.js} +111 -2
- package/dist/chunk-NPRP3MCV.js.map +1 -0
- package/dist/{chunk-A7KV5UK4.js → chunk-OXD5LFQP.js} +2 -2
- package/dist/{chunk-ZT4WMQW4.js → chunk-PTWADEH3.js} +9 -7
- package/dist/chunk-PTWADEH3.js.map +1 -0
- package/dist/{chunk-IHTWQEDR.js → chunk-QFE5BQH7.js} +2 -2
- package/dist/{chunk-IHTWQEDR.js.map → chunk-QFE5BQH7.js.map} +1 -1
- package/dist/{chunk-22SG74BD.js → chunk-R6ZCSXKX.js} +3 -3
- package/dist/{chunk-PZWISPIQ.js → chunk-S7HN5FHL.js} +17 -11
- package/dist/chunk-S7HN5FHL.js.map +1 -0
- package/dist/{chunk-RJOG4IJU.js → chunk-T7SP3EYR.js} +18 -12
- package/dist/chunk-T7SP3EYR.js.map +1 -0
- package/dist/{chunk-4S53H2KR.js → chunk-VAZXUK6G.js} +2 -2
- package/dist/{chunk-IJRR6YAI.js → chunk-VLDRAMP7.js} +18 -12
- package/dist/chunk-VLDRAMP7.js.map +1 -0
- package/dist/{chunk-TNX5ZGDJ.js → chunk-VNXAF2KE.js} +4 -4
- package/dist/{chunk-EHRRQ4IC.js → chunk-VP3TIUDF.js} +2 -2
- package/dist/{chunk-6XZYT4SW.js → chunk-WGDEBIP4.js} +5 -5
- package/dist/{chunk-E5OZPDIW.js → chunk-X7BA5PWG.js} +7 -5
- package/dist/chunk-X7BA5PWG.js.map +1 -0
- package/dist/compat/index.cjs +1 -1
- package/dist/compat/index.cjs.map +1 -1
- package/dist/compat/index.js +2 -2
- package/dist/compat/nestjs/index.cjs +1 -1
- package/dist/compat/nestjs/index.cjs.map +1 -1
- package/dist/compat/nestjs/index.js +2 -2
- package/dist/index.cjs +1657 -982
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +58 -36
- package/dist/index.js.map +1 -1
- package/dist/presets/ai/index.cjs +42 -26
- package/dist/presets/ai/index.cjs.map +1 -1
- package/dist/presets/ai/index.js +11 -11
- package/dist/presets/harness/index.cjs +53 -33
- package/dist/presets/harness/index.cjs.map +1 -1
- package/dist/presets/harness/index.js +22 -22
- package/dist/presets/index.cjs +76 -48
- package/dist/presets/index.cjs.map +1 -1
- package/dist/presets/index.js +28 -28
- package/dist/presets/inspect/index.cjs.map +1 -1
- package/dist/presets/inspect/index.js +4 -4
- package/dist/presets/resilience/index.cjs +35 -23
- package/dist/presets/resilience/index.cjs.map +1 -1
- package/dist/presets/resilience/index.js +5 -5
- package/dist/solutions/index.cjs +71 -45
- package/dist/solutions/index.cjs.map +1 -1
- package/dist/solutions/index.js +24 -24
- package/dist/{timeout-U5O4ESK3.js → timeout-BEABACRP.js} +2 -2
- package/dist/utils/ai/browser.cjs.map +1 -1
- package/dist/utils/ai/browser.js +9 -9
- package/dist/utils/ai/index.cjs +41 -25
- package/dist/utils/ai/index.cjs.map +1 -1
- package/dist/utils/ai/index.js +18 -18
- package/dist/utils/ai/node.js +3 -3
- package/dist/utils/domain-templates/index.cjs +1 -1
- package/dist/utils/domain-templates/index.cjs.map +1 -1
- package/dist/utils/domain-templates/index.js +2 -2
- package/dist/utils/graphspec/index.cjs +1 -1
- package/dist/utils/graphspec/index.cjs.map +1 -1
- package/dist/utils/graphspec/index.js +2 -2
- package/dist/utils/harness/index.cjs +16 -10
- package/dist/utils/harness/index.cjs.map +1 -1
- package/dist/utils/harness/index.js +1 -1
- package/dist/utils/index.cjs +1069 -452
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +2 -2
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +45 -23
- package/dist/utils/inspect/index.cjs.map +1 -1
- package/dist/utils/inspect/index.js +2 -2
- package/dist/utils/memory/index.cjs +513 -37
- package/dist/utils/memory/index.cjs.map +1 -1
- package/dist/utils/memory/index.d.cts +641 -3
- package/dist/utils/memory/index.d.ts +641 -3
- package/dist/utils/memory/index.js +19 -1
- package/dist/utils/messaging/index.cjs +109 -0
- package/dist/utils/messaging/index.cjs.map +1 -1
- package/dist/utils/messaging/index.d.cts +115 -2
- package/dist/utils/messaging/index.d.ts +115 -2
- package/dist/utils/messaging/index.js +5 -1
- package/dist/utils/orchestration/index.cjs +5 -3
- package/dist/utils/orchestration/index.cjs.map +1 -1
- package/dist/utils/orchestration/index.js +2 -2
- package/dist/utils/process/index.js +2 -2
- package/dist/utils/reduction/index.cjs +1 -1
- package/dist/utils/reduction/index.cjs.map +1 -1
- package/dist/utils/reduction/index.js +1 -1
- package/dist/utils/resilience/index.cjs +35 -23
- package/dist/utils/resilience/index.cjs.map +1 -1
- package/dist/utils/resilience/index.js +4 -4
- package/dist/utils/surface/index.cjs +1 -1
- package/dist/utils/surface/index.cjs.map +1 -1
- package/dist/utils/surface/index.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-5IMMNARC.js.map +0 -1
- package/dist/chunk-CGHORL6G.js.map +0 -1
- package/dist/chunk-DKNHAICT.js.map +0 -1
- package/dist/chunk-E5OZPDIW.js.map +0 -1
- package/dist/chunk-IJRR6YAI.js.map +0 -1
- package/dist/chunk-OCUDSN63.js.map +0 -1
- package/dist/chunk-PZWISPIQ.js.map +0 -1
- package/dist/chunk-Q3EYOCZB.js.map +0 -1
- package/dist/chunk-RJOG4IJU.js.map +0 -1
- package/dist/chunk-SOOKUYVM.js.map +0 -1
- package/dist/chunk-YJ4U2D2C.js.map +0 -1
- package/dist/chunk-ZT4WMQW4.js.map +0 -1
- package/dist/chunk-ZVXXDWIB.js.map +0 -1
- /package/dist/{chunk-VLAGJZSL.js.map → chunk-3O3NKZJW.js.map} +0 -0
- /package/dist/{chunk-2OB3CEJS.js.map → chunk-6MRSX3YK.js.map} +0 -0
- /package/dist/{chunk-EVYY4X5A.js.map → chunk-6ZLCPUXS.js.map} +0 -0
- /package/dist/{chunk-FW23JYNQ.js.map → chunk-CEVNQ74M.js.map} +0 -0
- /package/dist/{chunk-4GYMCUDZ.js.map → chunk-EP4WVQLX.js.map} +0 -0
- /package/dist/{chunk-JKTC747G.js.map → chunk-FQSQONOU.js.map} +0 -0
- /package/dist/{chunk-JGFRAFDL.js.map → chunk-FVINAAKA.js.map} +0 -0
- /package/dist/{chunk-BU3SEFA5.js.map → chunk-IOJDYUA7.js.map} +0 -0
- /package/dist/{chunk-DM4OMPWK.js.map → chunk-KNU73RZW.js.map} +0 -0
- /package/dist/{chunk-Z6EGP5D7.js.map → chunk-LDCSZ72P.js.map} +0 -0
- /package/dist/{chunk-CXANAIZU.js.map → chunk-N65E26UL.js.map} +0 -0
- /package/dist/{chunk-O3MT7DYI.js.map → chunk-N6MNJNHB.js.map} +0 -0
- /package/dist/{chunk-A7KV5UK4.js.map → chunk-OXD5LFQP.js.map} +0 -0
- /package/dist/{chunk-22SG74BD.js.map → chunk-R6ZCSXKX.js.map} +0 -0
- /package/dist/{chunk-4S53H2KR.js.map → chunk-VAZXUK6G.js.map} +0 -0
- /package/dist/{chunk-TNX5ZGDJ.js.map → chunk-VNXAF2KE.js.map} +0 -0
- /package/dist/{chunk-EHRRQ4IC.js.map → chunk-VP3TIUDF.js.map} +0 -0
- /package/dist/{chunk-6XZYT4SW.js.map → chunk-WGDEBIP4.js.map} +0 -0
- /package/dist/{timeout-U5O4ESK3.js.map → timeout-BEABACRP.js.map} +0 -0
|
@@ -20,15 +20,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/utils/memory/index.ts
|
|
21
21
|
var memory_exports = {};
|
|
22
22
|
__export(memory_exports, {
|
|
23
|
+
admissionLlmJudge: () => admissionLlmJudge,
|
|
24
|
+
bitemporalQuery: () => bitemporalQuery,
|
|
23
25
|
collection: () => collection,
|
|
26
|
+
consolidationRem: () => consolidationRem,
|
|
24
27
|
cosineSimilarity: () => cosineSimilarity,
|
|
28
|
+
decayExponential: () => decayExponential,
|
|
29
|
+
influenceAnalysis: () => influenceAnalysis,
|
|
30
|
+
invalidationTracer: () => invalidationTracer,
|
|
25
31
|
knowledgeGraph: () => knowledgeGraph,
|
|
32
|
+
persistentReactiveFactStore: () => persistentReactiveFactStore,
|
|
26
33
|
reactiveFactStore: () => reactiveFactStore,
|
|
34
|
+
scoringByOutcome: () => scoringByOutcome,
|
|
35
|
+
shardByTenant: () => shardByTenant,
|
|
27
36
|
vectorIndex: () => vectorIndex
|
|
28
37
|
});
|
|
29
38
|
module.exports = __toCommonJS(memory_exports);
|
|
30
|
-
var
|
|
31
|
-
var
|
|
39
|
+
var import_core10 = require("@graphrefly/pure-ts/core");
|
|
40
|
+
var import_extra8 = require("@graphrefly/pure-ts/extra");
|
|
32
41
|
var import_graph3 = require("@graphrefly/pure-ts/graph");
|
|
33
42
|
|
|
34
43
|
// src/base/meta/domain-meta.ts
|
|
@@ -628,6 +637,57 @@ function reactiveFactStore(config) {
|
|
|
628
637
|
);
|
|
629
638
|
graph.add(consolidated, { name: "consolidated" });
|
|
630
639
|
graph.addDisposer((0, import_extra2.keepalive)(consolidated));
|
|
640
|
+
if (config.decayTrigger) {
|
|
641
|
+
const decayProcessor = (0, import_core2.node)(
|
|
642
|
+
config.decay ? [config.decayTrigger, config.decay] : [config.decayTrigger],
|
|
643
|
+
(batchData, actions, ctx) => {
|
|
644
|
+
const policy2 = config.decay ? lastOf(batchData[1], ctx.prevData[1]) : void 0;
|
|
645
|
+
if (!policy2) {
|
|
646
|
+
actions.emit([]);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const now = BigInt((0, import_core2.monotonicNs)());
|
|
650
|
+
const changes = [];
|
|
651
|
+
for (const f of allFacts().values()) {
|
|
652
|
+
if (f.validTo !== void 0) continue;
|
|
653
|
+
const ageNs = now - f.t_ns;
|
|
654
|
+
const raw = policy2(f.confidence, ageNs);
|
|
655
|
+
if (!Number.isFinite(raw)) continue;
|
|
656
|
+
const next = raw < 0 ? 0 : raw > 1 ? 1 : raw;
|
|
657
|
+
if (next === f.confidence) continue;
|
|
658
|
+
changes.push({ id: f.id, next });
|
|
659
|
+
}
|
|
660
|
+
const decayed = [];
|
|
661
|
+
for (const { id, next } of changes) {
|
|
662
|
+
const idx = findShardOf(id);
|
|
663
|
+
const fs = idx < 0 ? void 0 : shards[idx].cache;
|
|
664
|
+
const live = fs?.byId.get(id);
|
|
665
|
+
if (!live || live.validTo !== void 0) continue;
|
|
666
|
+
replaceFragment(
|
|
667
|
+
id,
|
|
668
|
+
(prev) => prev.validTo !== void 0 ? prev : { ...prev, confidence: next }
|
|
669
|
+
);
|
|
670
|
+
decayed.push({ ...live, confidence: next });
|
|
671
|
+
}
|
|
672
|
+
if (decayed.length > 0) {
|
|
673
|
+
events.append({
|
|
674
|
+
action: "decay",
|
|
675
|
+
t_ns: (0, import_core2.wallClockNs)(),
|
|
676
|
+
seq: bumpCursor(seqCursor)
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
actions.emit(decayed);
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
name: "decay_processor",
|
|
683
|
+
describeKind: "derived",
|
|
684
|
+
initial: [],
|
|
685
|
+
meta: factMeta("decay")
|
|
686
|
+
}
|
|
687
|
+
);
|
|
688
|
+
graph.add(decayProcessor, { name: "decay_processor" });
|
|
689
|
+
graph.addDisposer((0, import_extra2.keepalive)(decayProcessor));
|
|
690
|
+
}
|
|
631
691
|
const ingestAudit = (0, import_core2.node)(
|
|
632
692
|
[extractOp],
|
|
633
693
|
(batchData, actions, ctx) => {
|
|
@@ -682,14 +742,430 @@ function reactiveFactStore(config) {
|
|
|
682
742
|
return out;
|
|
683
743
|
}
|
|
684
744
|
|
|
745
|
+
// src/utils/memory/persistent-fact-store.ts
|
|
746
|
+
var import_core3 = require("@graphrefly/pure-ts/core");
|
|
747
|
+
var import_extra3 = require("@graphrefly/pure-ts/extra");
|
|
748
|
+
function persistMeta(kind) {
|
|
749
|
+
return domainMeta("memory", kind);
|
|
750
|
+
}
|
|
751
|
+
function persistentReactiveFactStore(config) {
|
|
752
|
+
const persistName = config.persistName ?? "fact_store_ingest";
|
|
753
|
+
const codec = config.codec ?? (0, import_extra3.bigintJsonCodecFor)();
|
|
754
|
+
const tier = (0, import_extra3.appendLogStorage)(config.storage, {
|
|
755
|
+
name: persistName,
|
|
756
|
+
codec
|
|
757
|
+
});
|
|
758
|
+
const store = reactiveFactStore({ ...config, recordIngest: true });
|
|
759
|
+
const ingestLog = store.ingestLog;
|
|
760
|
+
async function* loadHistory() {
|
|
761
|
+
if (typeof tier.loadEntries !== "function") return;
|
|
762
|
+
const page = await tier.loadEntries();
|
|
763
|
+
for (const f of page.entries) yield f;
|
|
764
|
+
}
|
|
765
|
+
const replaySource = (0, import_extra3.fromAny)(loadHistory(), {
|
|
766
|
+
name: "_replay_source",
|
|
767
|
+
meta: persistMeta("persist_replay_source")
|
|
768
|
+
});
|
|
769
|
+
store.add(replaySource, { name: "_replay_source" });
|
|
770
|
+
let replayed = 0;
|
|
771
|
+
const replayPump = (0, import_core3.node)(
|
|
772
|
+
[replaySource],
|
|
773
|
+
(batchData, actions) => {
|
|
774
|
+
const b = batchData[0];
|
|
775
|
+
if (b != null && b.length > 0) {
|
|
776
|
+
for (const f of b) {
|
|
777
|
+
config.ingest.emit(f);
|
|
778
|
+
replayed += 1;
|
|
779
|
+
}
|
|
780
|
+
actions.emit(replayed);
|
|
781
|
+
}
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
name: "_replay_pump",
|
|
785
|
+
describeKind: "derived",
|
|
786
|
+
initial: 0,
|
|
787
|
+
meta: persistMeta("persist_replay_pump")
|
|
788
|
+
}
|
|
789
|
+
);
|
|
790
|
+
store.add(replayPump, { name: "_replay_pump" });
|
|
791
|
+
store.addDisposer((0, import_extra3.keepalive)(replayPump));
|
|
792
|
+
const attached = (0, import_core3.node)([], {
|
|
793
|
+
initial: false,
|
|
794
|
+
name: "_storage_attached",
|
|
795
|
+
describeKind: "state",
|
|
796
|
+
meta: persistMeta("persist_attached")
|
|
797
|
+
});
|
|
798
|
+
store.add(attached, { name: "_storage_attached" });
|
|
799
|
+
store.addDisposer((0, import_extra3.keepalive)(attached));
|
|
800
|
+
let detachStorage;
|
|
801
|
+
const replaySub = replaySource.subscribe((msgs) => {
|
|
802
|
+
for (const m of msgs) {
|
|
803
|
+
if (m[0] === import_core3.COMPLETE && detachStorage === void 0) {
|
|
804
|
+
const sizeAtAttach = ingestLog.size;
|
|
805
|
+
detachStorage = ingestLog.attachStorage([tier]);
|
|
806
|
+
if (sizeAtAttach > replayed) {
|
|
807
|
+
const slice = [];
|
|
808
|
+
for (let i = replayed; i < sizeAtAttach; i += 1) {
|
|
809
|
+
const v = ingestLog.at(i);
|
|
810
|
+
if (v === void 0) {
|
|
811
|
+
throw new Error(
|
|
812
|
+
`persistentReactiveFactStore: ingestLog hole at index ${i} in reconciliation slice [${replayed}, ${sizeAtAttach}); pre-attach-live durability cannot be guaranteed.`
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
slice.push(v);
|
|
816
|
+
}
|
|
817
|
+
if (slice.length > 0) {
|
|
818
|
+
const r = tier.appendEntries(slice);
|
|
819
|
+
if (r instanceof Promise) r.catch(() => {
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
attached.emit(true);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
store.addDisposer(() => {
|
|
828
|
+
replaySub();
|
|
829
|
+
detachStorage?.();
|
|
830
|
+
});
|
|
831
|
+
const position = (0, import_core3.node)(
|
|
832
|
+
[ingestLog.entries, attached],
|
|
833
|
+
(batchData, actions, ctx) => {
|
|
834
|
+
const eb = batchData[0];
|
|
835
|
+
const arr = eb != null && eb.length > 0 ? eb.at(-1) : ctx.prevData[0];
|
|
836
|
+
const ab = batchData[1];
|
|
837
|
+
const isAttached = ab != null && ab.length > 0 ? ab.at(-1) : ctx.prevData[1];
|
|
838
|
+
actions.emit(isAttached === true ? arr?.length ?? 0 : 0);
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
name: "_durable_position",
|
|
842
|
+
describeKind: "derived",
|
|
843
|
+
initial: 0,
|
|
844
|
+
meta: persistMeta("persist_position")
|
|
845
|
+
}
|
|
846
|
+
);
|
|
847
|
+
store.add(position, { name: "_durable_position" });
|
|
848
|
+
store.addDisposer((0, import_extra3.keepalive)(position));
|
|
849
|
+
const out = Object.assign(store, {
|
|
850
|
+
position,
|
|
851
|
+
replayedCount: replayPump,
|
|
852
|
+
tier,
|
|
853
|
+
async flush() {
|
|
854
|
+
await tier.flush?.();
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
return out;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// src/utils/memory/recipes/admission-llm-judge.ts
|
|
861
|
+
var import_core4 = require("@graphrefly/pure-ts/core");
|
|
862
|
+
function admissionLlmJudge(verdicts, opts = {}) {
|
|
863
|
+
const dflt = opts.defaultVerdict ?? false;
|
|
864
|
+
const buildFilter = (m) => (f) => m.get(f.id) ?? dflt;
|
|
865
|
+
return (0, import_core4.node)(
|
|
866
|
+
[verdicts],
|
|
867
|
+
(batchData, actions, ctx) => {
|
|
868
|
+
const m = batchData[0]?.at(-1) ?? ctx.prevData[0] ?? /* @__PURE__ */ new Map();
|
|
869
|
+
actions.emit(buildFilter(m));
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
name: opts.name ?? "admission_llm_judge",
|
|
873
|
+
describeKind: "derived",
|
|
874
|
+
// Before any verdict arrives, apply the default policy.
|
|
875
|
+
initial: buildFilter(/* @__PURE__ */ new Map())
|
|
876
|
+
}
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// src/utils/memory/recipes/bitemporal-query.ts
|
|
881
|
+
var import_core5 = require("@graphrefly/pure-ts/core");
|
|
882
|
+
|
|
883
|
+
// src/utils/memory/recipes/_shared.ts
|
|
884
|
+
function lastOf2(batch2, prev) {
|
|
885
|
+
return batch2 != null && batch2.length > 0 ? batch2.at(-1) : prev;
|
|
886
|
+
}
|
|
887
|
+
function validAt(f, asOf) {
|
|
888
|
+
if (asOf === void 0) return f.validTo === void 0;
|
|
889
|
+
if (f.validFrom !== void 0 && asOf < f.validFrom) return false;
|
|
890
|
+
if (f.validTo !== void 0 && asOf >= f.validTo) return false;
|
|
891
|
+
return true;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
// src/utils/memory/recipes/bitemporal-query.ts
|
|
895
|
+
function bitemporalQuery(mem, asOf, opts = {}) {
|
|
896
|
+
const asOfOrNull = (0, import_core5.node)(
|
|
897
|
+
[asOf],
|
|
898
|
+
(b, a, c) => a.emit(lastOf2(b[0], c.prevData[0]) ?? null),
|
|
899
|
+
{ name: `${opts.name ?? "bitemporal_query"}_asof`, describeKind: "derived", initial: null }
|
|
900
|
+
);
|
|
901
|
+
return (0, import_core5.node)(
|
|
902
|
+
[asOfOrNull, mem.factStore],
|
|
903
|
+
(batchData, actions, ctx) => {
|
|
904
|
+
const raw = lastOf2(batchData[0], ctx.prevData[0]);
|
|
905
|
+
const at = raw ?? void 0;
|
|
906
|
+
const fs = lastOf2(batchData[1], ctx.prevData[1]);
|
|
907
|
+
if (fs == null) {
|
|
908
|
+
actions.emit([]);
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
const results = [...fs.byId.values()].filter((f) => {
|
|
912
|
+
if (!validAt(f, at)) return false;
|
|
913
|
+
if (opts.tags && opts.tags.length > 0 && !opts.tags.some((t) => f.tags.includes(t))) {
|
|
914
|
+
return false;
|
|
915
|
+
}
|
|
916
|
+
if (opts.minConfidence !== void 0 && f.confidence < opts.minConfidence) return false;
|
|
917
|
+
return true;
|
|
918
|
+
});
|
|
919
|
+
results.sort((a, b) => b.confidence - a.confidence || Number(b.t_ns - a.t_ns));
|
|
920
|
+
actions.emit(results);
|
|
921
|
+
},
|
|
922
|
+
{
|
|
923
|
+
name: opts.name ?? "bitemporal_query",
|
|
924
|
+
describeKind: "derived",
|
|
925
|
+
initial: []
|
|
926
|
+
}
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// src/utils/memory/recipes/consolidation-rem.ts
|
|
931
|
+
var import_extra4 = require("@graphrefly/pure-ts/extra");
|
|
932
|
+
function consolidationRem(opts) {
|
|
933
|
+
const consolidateTrigger = (0, import_extra4.fromTimer)(opts.periodMs, { period: opts.periodMs });
|
|
934
|
+
const consolidate = (store) => {
|
|
935
|
+
const live = [...store.values()].filter((f) => f.validTo === void 0);
|
|
936
|
+
if (live.length === 0) return [];
|
|
937
|
+
let pool = live;
|
|
938
|
+
if (opts.recentWindowNs !== void 0) {
|
|
939
|
+
const newest = live.reduce((m, f) => f.t_ns > m ? f.t_ns : m, live[0].t_ns);
|
|
940
|
+
const cutoff = newest - opts.recentWindowNs;
|
|
941
|
+
pool = live.filter((f) => f.t_ns >= cutoff);
|
|
942
|
+
}
|
|
943
|
+
pool.sort((a, b) => b.confidence - a.confidence || Number(b.t_ns - a.t_ns));
|
|
944
|
+
const replayed = pool.slice(0, Math.max(0, opts.topK));
|
|
945
|
+
return replayed.length > 0 ? opts.summarize(replayed) : [];
|
|
946
|
+
};
|
|
947
|
+
return { consolidateTrigger, consolidate };
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/utils/memory/recipes/decay-exponential.ts
|
|
951
|
+
var import_core6 = require("@graphrefly/pure-ts/core");
|
|
952
|
+
var import_extra5 = require("@graphrefly/pure-ts/extra");
|
|
953
|
+
function decayExponential(mem, ingest, opts) {
|
|
954
|
+
const floor = opts.floor ?? 0;
|
|
955
|
+
const epsilon = Math.max(opts.epsilon ?? 1e-4, Number.EPSILON);
|
|
956
|
+
const half = Number(opts.halfLifeNs);
|
|
957
|
+
const lastTick = /* @__PURE__ */ new Map();
|
|
958
|
+
const timer = (0, import_extra5.fromTimer)(opts.periodMs, { period: opts.periodMs });
|
|
959
|
+
const driver = (0, import_core6.node)(
|
|
960
|
+
[timer],
|
|
961
|
+
(_batchData, actions) => {
|
|
962
|
+
const fs = mem.factStore.cache;
|
|
963
|
+
if (!fs) {
|
|
964
|
+
actions.emit([]);
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
const now = BigInt((0, import_core6.wallClockNs)());
|
|
968
|
+
const decayed = [];
|
|
969
|
+
const liveIds = /* @__PURE__ */ new Set();
|
|
970
|
+
for (const f of fs.byId.values()) {
|
|
971
|
+
liveIds.add(f.id);
|
|
972
|
+
if (f.validTo !== void 0) continue;
|
|
973
|
+
if (f.confidence <= floor) continue;
|
|
974
|
+
const lt = lastTick.get(f.id);
|
|
975
|
+
const since = lt !== void 0 && lt >= f.t_ns ? lt : f.t_ns;
|
|
976
|
+
const elapsed = Number(now - since);
|
|
977
|
+
if (elapsed <= 0) continue;
|
|
978
|
+
const factor = 0.5 ** (half > 0 ? elapsed / half : 0);
|
|
979
|
+
if (!Number.isFinite(factor)) continue;
|
|
980
|
+
let next = f.confidence * factor;
|
|
981
|
+
if (next < floor) next = floor;
|
|
982
|
+
if (f.confidence - next < epsilon) continue;
|
|
983
|
+
const liveNow = mem.factStore.cache?.byId.get(f.id);
|
|
984
|
+
if (liveNow && liveNow.validTo !== void 0) continue;
|
|
985
|
+
lastTick.set(f.id, now);
|
|
986
|
+
const drifted = { ...f, confidence: next };
|
|
987
|
+
decayed.push(drifted);
|
|
988
|
+
ingest.emit(drifted);
|
|
989
|
+
}
|
|
990
|
+
if (lastTick.size > liveIds.size) {
|
|
991
|
+
for (const id of lastTick.keys()) if (!liveIds.has(id)) lastTick.delete(id);
|
|
992
|
+
}
|
|
993
|
+
actions.emit(decayed);
|
|
994
|
+
},
|
|
995
|
+
{
|
|
996
|
+
name: opts.name ?? "decay_exponential",
|
|
997
|
+
describeKind: "derived",
|
|
998
|
+
initial: []
|
|
999
|
+
}
|
|
1000
|
+
);
|
|
1001
|
+
mem.add(driver, { name: opts.name ?? "decay_exponential" });
|
|
1002
|
+
mem.addDisposer((0, import_extra5.keepalive)(timer));
|
|
1003
|
+
mem.addDisposer((0, import_extra5.keepalive)(driver));
|
|
1004
|
+
return driver;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// src/utils/memory/recipes/influence-analysis.ts
|
|
1008
|
+
var import_core7 = require("@graphrefly/pure-ts/core");
|
|
1009
|
+
var import_extra6 = require("@graphrefly/pure-ts/extra");
|
|
1010
|
+
function closureOf(index, root) {
|
|
1011
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1012
|
+
const queue = [root];
|
|
1013
|
+
while (queue.length > 0) {
|
|
1014
|
+
const cur = queue.shift();
|
|
1015
|
+
for (const dep of index.get(cur) ?? []) {
|
|
1016
|
+
if (seen.has(dep) || dep === root) continue;
|
|
1017
|
+
seen.add(dep);
|
|
1018
|
+
queue.push(dep);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
return [...seen];
|
|
1022
|
+
}
|
|
1023
|
+
function influenceAnalysis(mem, opts = {}) {
|
|
1024
|
+
const prefix = opts.name ?? "influence";
|
|
1025
|
+
const maxRanked = Math.max(1, opts.maxRanked ?? 64);
|
|
1026
|
+
const ranked = (0, import_core7.node)(
|
|
1027
|
+
[mem.dependentsIndex],
|
|
1028
|
+
(batchData, actions, ctx) => {
|
|
1029
|
+
const index = lastOf2(batchData[0], ctx.prevData[0]);
|
|
1030
|
+
if (index == null) {
|
|
1031
|
+
actions.emit([]);
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
const rows = [];
|
|
1035
|
+
for (const key of index.keys()) {
|
|
1036
|
+
rows.push({ factId: key, influence: closureOf(index, key).length });
|
|
1037
|
+
}
|
|
1038
|
+
rows.sort((a, b) => b.influence - a.influence);
|
|
1039
|
+
actions.emit(rows.slice(0, maxRanked));
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
name: `${prefix}_ranked`,
|
|
1043
|
+
describeKind: "derived",
|
|
1044
|
+
initial: []
|
|
1045
|
+
}
|
|
1046
|
+
);
|
|
1047
|
+
mem.add(ranked, { name: `${prefix}_ranked` });
|
|
1048
|
+
mem.addDisposer((0, import_extra6.keepalive)(ranked));
|
|
1049
|
+
const builtFor = /* @__PURE__ */ new Map();
|
|
1050
|
+
function influenceOf(rootId) {
|
|
1051
|
+
const existing = builtFor.get(rootId);
|
|
1052
|
+
if (existing) return existing;
|
|
1053
|
+
const n = (0, import_core7.node)(
|
|
1054
|
+
[mem.dependentsIndex],
|
|
1055
|
+
(batchData, actions, ctx) => {
|
|
1056
|
+
const index = lastOf2(batchData[0], ctx.prevData[0]);
|
|
1057
|
+
actions.emit(index == null ? [] : closureOf(index, rootId));
|
|
1058
|
+
},
|
|
1059
|
+
{
|
|
1060
|
+
name: `${prefix}_of_${rootId}`,
|
|
1061
|
+
describeKind: "derived",
|
|
1062
|
+
initial: []
|
|
1063
|
+
}
|
|
1064
|
+
);
|
|
1065
|
+
mem.add(n, { name: `${prefix}_of_${rootId}` });
|
|
1066
|
+
mem.addDisposer((0, import_extra6.keepalive)(n));
|
|
1067
|
+
builtFor.set(rootId, n);
|
|
1068
|
+
return n;
|
|
1069
|
+
}
|
|
1070
|
+
return { influenceOf, ranked };
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// src/utils/memory/recipes/invalidation-tracer.ts
|
|
1074
|
+
var import_core8 = require("@graphrefly/pure-ts/core");
|
|
1075
|
+
var import_extra7 = require("@graphrefly/pure-ts/extra");
|
|
1076
|
+
function invalidationTracer(mem, opts = {}) {
|
|
1077
|
+
const limit = Math.max(1, opts.limit ?? 256);
|
|
1078
|
+
const ring = [];
|
|
1079
|
+
const push = (e) => {
|
|
1080
|
+
ring.push(e);
|
|
1081
|
+
if (ring.length > limit) ring.splice(0, ring.length - limit);
|
|
1082
|
+
};
|
|
1083
|
+
const tracer = (0, import_core8.node)(
|
|
1084
|
+
[mem.cascade, mem.cascadeOverflow],
|
|
1085
|
+
(batchData, actions) => {
|
|
1086
|
+
const cascadeWaves = batchData[0] ?? [];
|
|
1087
|
+
for (const wave of cascadeWaves) {
|
|
1088
|
+
for (const ev of wave) {
|
|
1089
|
+
push({
|
|
1090
|
+
kind: "cascade",
|
|
1091
|
+
factId: ev.factId,
|
|
1092
|
+
rootFactId: ev.rootFactId,
|
|
1093
|
+
reason: ev.reason,
|
|
1094
|
+
iteration: ev.iteration,
|
|
1095
|
+
causalReason: ev.causalReason
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
const overflows = batchData[1] ?? [];
|
|
1100
|
+
for (const ov of overflows) {
|
|
1101
|
+
if (ov == null) continue;
|
|
1102
|
+
push({
|
|
1103
|
+
kind: "overflow",
|
|
1104
|
+
factId: ov.sample[0] ?? "",
|
|
1105
|
+
rootFactId: ov.rootFactId,
|
|
1106
|
+
reason: "overflow",
|
|
1107
|
+
causalReason: `cascade overflow: ${ov.droppedCount} dropped (root ${ov.rootFactId})`
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
actions.emit([...ring]);
|
|
1111
|
+
},
|
|
1112
|
+
{
|
|
1113
|
+
name: opts.name ?? "invalidation_tracer",
|
|
1114
|
+
describeKind: "derived",
|
|
1115
|
+
initial: []
|
|
1116
|
+
}
|
|
1117
|
+
);
|
|
1118
|
+
mem.add(tracer, { name: opts.name ?? "invalidation_tracer" });
|
|
1119
|
+
mem.addDisposer((0, import_extra7.keepalive)(tracer));
|
|
1120
|
+
return tracer;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
// src/utils/memory/recipes/scoring-by-outcome.ts
|
|
1124
|
+
var import_core9 = require("@graphrefly/pure-ts/core");
|
|
1125
|
+
var clamp01 = (n) => n < 0 ? 0 : n > 1 ? 1 : n;
|
|
1126
|
+
function scoringByOutcome(outcomes, opts = {}) {
|
|
1127
|
+
const base = opts.base ?? ((f) => f.confidence);
|
|
1128
|
+
const learningRate = opts.learningRate ?? 1;
|
|
1129
|
+
const acc = /* @__PURE__ */ new Map();
|
|
1130
|
+
const buildPolicy = () => (fragment) => clamp01(base(fragment) + learningRate * (acc.get(fragment.id) ?? 0));
|
|
1131
|
+
return (0, import_core9.node)(
|
|
1132
|
+
[outcomes],
|
|
1133
|
+
(batchData, actions) => {
|
|
1134
|
+
const wave = batchData[0] ?? [];
|
|
1135
|
+
for (const sig of wave) acc.set(sig.factId, (acc.get(sig.factId) ?? 0) + sig.reward);
|
|
1136
|
+
actions.emit(buildPolicy());
|
|
1137
|
+
},
|
|
1138
|
+
{
|
|
1139
|
+
name: opts.name ?? "scoring_by_outcome",
|
|
1140
|
+
describeKind: "derived",
|
|
1141
|
+
// Usable scorer before any outcome arrives (base-only).
|
|
1142
|
+
initial: buildPolicy()
|
|
1143
|
+
}
|
|
1144
|
+
);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
// src/utils/memory/recipes/shard-by-tenant.ts
|
|
1148
|
+
function shardByTenant(tenantOf, opts = {}) {
|
|
1149
|
+
if (opts.tenants && opts.tenants.length > 0) {
|
|
1150
|
+
const idx = new Map(opts.tenants.map((t, i) => [t, i]));
|
|
1151
|
+
const overflow = opts.tenants.length;
|
|
1152
|
+
return {
|
|
1153
|
+
shardBy: (f) => idx.get(tenantOf(f)) ?? overflow,
|
|
1154
|
+
shardCount: opts.tenants.length + 1
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
const shardCount = Math.max(1, opts.shardCount ?? 4);
|
|
1158
|
+
return { shardBy: (f) => tenantOf(f), shardCount };
|
|
1159
|
+
}
|
|
1160
|
+
|
|
685
1161
|
// src/utils/memory/index.ts
|
|
686
1162
|
var NS_PER_SEC = 1e9;
|
|
687
1163
|
function memoryMeta(kind, extra) {
|
|
688
1164
|
return domainMeta("memory", kind, extra);
|
|
689
1165
|
}
|
|
690
1166
|
function toNode(v, name) {
|
|
691
|
-
if (v instanceof
|
|
692
|
-
return (0,
|
|
1167
|
+
if (v instanceof import_core10.NodeImpl) return v;
|
|
1168
|
+
return (0, import_core10.node)([], { initial: v, ...name ? { name } : void 0 });
|
|
693
1169
|
}
|
|
694
1170
|
function ageSeconds(now, lastNs) {
|
|
695
1171
|
return (now - lastNs) / NS_PER_SEC;
|
|
@@ -743,14 +1219,14 @@ function collection(name, opts = {}) {
|
|
|
743
1219
|
}
|
|
744
1220
|
const scoreFnDefault = () => ranked ? 1 : 0;
|
|
745
1221
|
const scoreInput = opts.score ?? scoreFnDefault;
|
|
746
|
-
const scoreNode = ranked && scoreInput instanceof
|
|
1222
|
+
const scoreNode = ranked && scoreInput instanceof import_core10.NodeImpl ? scoreInput : void 0;
|
|
747
1223
|
const readScoreFn = () => {
|
|
748
1224
|
if (scoreNode) return scoreNode.cache ?? scoreFnDefault;
|
|
749
1225
|
return scoreInput;
|
|
750
1226
|
};
|
|
751
1227
|
const graph = new import_graph3.Graph(name);
|
|
752
|
-
const retentionScore = (_k, v) => ranked ? decay(v.baseScore, ageSeconds((0,
|
|
753
|
-
const items = (0,
|
|
1228
|
+
const retentionScore = (_k, v) => ranked ? decay(v.baseScore, ageSeconds((0, import_core10.monotonicNs)(), v.lastAccessNs), decayRate, minScore) : v.lastAccessNs;
|
|
1229
|
+
const items = (0, import_extra8.reactiveMap)({
|
|
754
1230
|
name: "items",
|
|
755
1231
|
...maxSize !== void 0 ? { retention: { score: retentionScore, maxSize } } : {}
|
|
756
1232
|
});
|
|
@@ -758,16 +1234,16 @@ function collection(name, opts = {}) {
|
|
|
758
1234
|
let refreshTick;
|
|
759
1235
|
if (ranked && decayRate > 0) {
|
|
760
1236
|
const intervalMs = opts.refreshIntervalMs ?? Math.max(1, 1e3 * Math.LN2 / (10 * decayRate));
|
|
761
|
-
const tickCounter = (0,
|
|
762
|
-
refreshTick = (0,
|
|
1237
|
+
const tickCounter = (0, import_extra8.fromTimer)(intervalMs, { period: intervalMs });
|
|
1238
|
+
refreshTick = (0, import_core10.node)(
|
|
763
1239
|
[tickCounter],
|
|
764
1240
|
(_batchData, actions) => {
|
|
765
|
-
actions.emit((0,
|
|
1241
|
+
actions.emit((0, import_core10.monotonicNs)());
|
|
766
1242
|
},
|
|
767
1243
|
{
|
|
768
1244
|
name: "refresh_tick_ns",
|
|
769
1245
|
describeKind: "derived",
|
|
770
|
-
initial: (0,
|
|
1246
|
+
initial: (0, import_core10.monotonicNs)(),
|
|
771
1247
|
meta: memoryMeta("clock")
|
|
772
1248
|
}
|
|
773
1249
|
);
|
|
@@ -778,7 +1254,7 @@ function collection(name, opts = {}) {
|
|
|
778
1254
|
const rankedDeps = [items.entries];
|
|
779
1255
|
if (refreshTick) rankedDeps.push(refreshTick);
|
|
780
1256
|
if (scoreNode) rankedDeps.push(scoreNode);
|
|
781
|
-
rankedNode = (0,
|
|
1257
|
+
rankedNode = (0, import_core10.node)(
|
|
782
1258
|
rankedDeps,
|
|
783
1259
|
(batchData, actions, ctx) => {
|
|
784
1260
|
const values = batchData.map(
|
|
@@ -788,9 +1264,9 @@ function collection(name, opts = {}) {
|
|
|
788
1264
|
let now;
|
|
789
1265
|
if (refreshTick) {
|
|
790
1266
|
const tickValue = values[1];
|
|
791
|
-
now = typeof tickValue === "number" ? tickValue : (0,
|
|
1267
|
+
now = typeof tickValue === "number" ? tickValue : (0, import_core10.monotonicNs)();
|
|
792
1268
|
} else {
|
|
793
|
-
now = (0,
|
|
1269
|
+
now = (0, import_core10.monotonicNs)();
|
|
794
1270
|
}
|
|
795
1271
|
if (!snapshot || snapshot.size === 0) {
|
|
796
1272
|
actions.emit([]);
|
|
@@ -815,7 +1291,7 @@ function collection(name, opts = {}) {
|
|
|
815
1291
|
);
|
|
816
1292
|
graph.add(rankedNode, { name: "ranked" });
|
|
817
1293
|
} else {
|
|
818
|
-
rankedNode = (0,
|
|
1294
|
+
rankedNode = (0, import_core10.node)([], {
|
|
819
1295
|
initial: [],
|
|
820
1296
|
name: "ranked",
|
|
821
1297
|
describeKind: "state",
|
|
@@ -823,7 +1299,7 @@ function collection(name, opts = {}) {
|
|
|
823
1299
|
});
|
|
824
1300
|
graph.add(rankedNode, { name: "ranked" });
|
|
825
1301
|
}
|
|
826
|
-
const size = (0,
|
|
1302
|
+
const size = (0, import_core10.node)(
|
|
827
1303
|
[items.entries],
|
|
828
1304
|
(batchData, actions, ctx) => {
|
|
829
1305
|
const data = batchData.map(
|
|
@@ -840,7 +1316,7 @@ function collection(name, opts = {}) {
|
|
|
840
1316
|
}
|
|
841
1317
|
);
|
|
842
1318
|
graph.add(size, { name: "size" });
|
|
843
|
-
graph.addDisposer((0,
|
|
1319
|
+
graph.addDisposer((0, import_extra8.keepalive)(size));
|
|
844
1320
|
const events = createAuditLog({
|
|
845
1321
|
name: "events",
|
|
846
1322
|
retainedLimit: 1024,
|
|
@@ -848,7 +1324,7 @@ function collection(name, opts = {}) {
|
|
|
848
1324
|
});
|
|
849
1325
|
const seqCursor = registerCursor(graph, "seq", 0);
|
|
850
1326
|
const upsertImpl = (id, value, _opts) => {
|
|
851
|
-
const now = (0,
|
|
1327
|
+
const now = (0, import_core10.monotonicNs)();
|
|
852
1328
|
const prev = items.get(id);
|
|
853
1329
|
const baseScore = _opts?.score ?? readScoreFn()(value);
|
|
854
1330
|
items.set(id, {
|
|
@@ -904,7 +1380,7 @@ function collection(name, opts = {}) {
|
|
|
904
1380
|
});
|
|
905
1381
|
function itemNode(id) {
|
|
906
1382
|
const idN = toNode(id, "id");
|
|
907
|
-
return (0,
|
|
1383
|
+
return (0, import_core10.node)(
|
|
908
1384
|
[items.entries, idN],
|
|
909
1385
|
(batchData, actions, ctx) => {
|
|
910
1386
|
const data = batchData.map(
|
|
@@ -922,7 +1398,7 @@ function collection(name, opts = {}) {
|
|
|
922
1398
|
}
|
|
923
1399
|
function hasNode(id) {
|
|
924
1400
|
const idN = toNode(id, "id");
|
|
925
|
-
return (0,
|
|
1401
|
+
return (0, import_core10.node)(
|
|
926
1402
|
[items.entries, idN],
|
|
927
1403
|
(batchData, actions, ctx) => {
|
|
928
1404
|
const data = batchData.map(
|
|
@@ -997,7 +1473,7 @@ function vectorIndex(opts = {}) {
|
|
|
997
1473
|
graph
|
|
998
1474
|
});
|
|
999
1475
|
const seqCursor = registerCursor(graph, "seq", 0);
|
|
1000
|
-
const entries = (0,
|
|
1476
|
+
const entries = (0, import_extra8.reactiveMap)({
|
|
1001
1477
|
name: "entries",
|
|
1002
1478
|
...maxSize !== void 0 ? {
|
|
1003
1479
|
retention: {
|
|
@@ -1009,7 +1485,7 @@ function vectorIndex(opts = {}) {
|
|
|
1009
1485
|
events.append({
|
|
1010
1486
|
action: "evict",
|
|
1011
1487
|
id: key,
|
|
1012
|
-
t_ns: (0,
|
|
1488
|
+
t_ns: (0, import_core10.wallClockNs)(),
|
|
1013
1489
|
seq: bumpCursor(seqCursor)
|
|
1014
1490
|
});
|
|
1015
1491
|
}
|
|
@@ -1017,7 +1493,7 @@ function vectorIndex(opts = {}) {
|
|
|
1017
1493
|
} : {}
|
|
1018
1494
|
});
|
|
1019
1495
|
graph.add(entries.entries, { name: "entries" });
|
|
1020
|
-
graph.addDisposer((0,
|
|
1496
|
+
graph.addDisposer((0, import_extra8.keepalive)(entries.entries));
|
|
1021
1497
|
if (hnsw?.dispose) {
|
|
1022
1498
|
const disposeAdapter = hnsw.dispose.bind(hnsw);
|
|
1023
1499
|
graph.addDisposer(() => disposeAdapter());
|
|
@@ -1034,7 +1510,7 @@ function vectorIndex(opts = {}) {
|
|
|
1034
1510
|
id,
|
|
1035
1511
|
vector: [...vector],
|
|
1036
1512
|
...copiedMeta !== void 0 ? { meta: copiedMeta } : {},
|
|
1037
|
-
upsertedAtNs: (0,
|
|
1513
|
+
upsertedAtNs: (0, import_core10.monotonicNs)()
|
|
1038
1514
|
};
|
|
1039
1515
|
entries.set(id, record);
|
|
1040
1516
|
};
|
|
@@ -1090,7 +1566,7 @@ function vectorIndex(opts = {}) {
|
|
|
1090
1566
|
});
|
|
1091
1567
|
function searchNode(query, k = 5) {
|
|
1092
1568
|
const kN = toNode(k, "k");
|
|
1093
|
-
return (0,
|
|
1569
|
+
return (0, import_core10.node)(
|
|
1094
1570
|
[entries.entries, query, kN],
|
|
1095
1571
|
(batchData, actions, ctx) => {
|
|
1096
1572
|
const values = batchData.map(
|
|
@@ -1196,17 +1672,17 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1196
1672
|
throw new RangeError("knowledgeGraph: edgesMaxSize must be >= 1");
|
|
1197
1673
|
}
|
|
1198
1674
|
const graph = new import_graph3.Graph(name);
|
|
1199
|
-
const entitiesMap = (0,
|
|
1675
|
+
const entitiesMap = (0, import_extra8.reactiveMap)({
|
|
1200
1676
|
name: "entities",
|
|
1201
1677
|
...opts.entitiesMaxSize !== void 0 ? { maxSize: opts.entitiesMaxSize } : {}
|
|
1202
1678
|
});
|
|
1203
|
-
const edgesMap = (0,
|
|
1679
|
+
const edgesMap = (0, import_extra8.reactiveMap)({
|
|
1204
1680
|
name: "edges",
|
|
1205
1681
|
...opts.edgesMaxSize !== void 0 ? { maxSize: opts.edgesMaxSize } : {}
|
|
1206
1682
|
});
|
|
1207
1683
|
graph.add(entitiesMap.entries, { name: "entities" });
|
|
1208
1684
|
graph.add(edgesMap.entries, { name: "edges" });
|
|
1209
|
-
const adjacencyOut = (0,
|
|
1685
|
+
const adjacencyOut = (0, import_core10.node)(
|
|
1210
1686
|
[edgesMap.entries],
|
|
1211
1687
|
(batchData, actions, ctx) => {
|
|
1212
1688
|
const data = batchData.map(
|
|
@@ -1223,7 +1699,7 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1223
1699
|
meta: memoryMeta("adjacency_out")
|
|
1224
1700
|
}
|
|
1225
1701
|
);
|
|
1226
|
-
const adjacencyIn = (0,
|
|
1702
|
+
const adjacencyIn = (0, import_core10.node)(
|
|
1227
1703
|
[edgesMap.entries],
|
|
1228
1704
|
(batchData, actions, ctx) => {
|
|
1229
1705
|
const data = batchData.map(
|
|
@@ -1242,9 +1718,9 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1242
1718
|
);
|
|
1243
1719
|
graph.add(adjacencyOut, { name: "adjacencyOut" });
|
|
1244
1720
|
graph.add(adjacencyIn, { name: "adjacencyIn" });
|
|
1245
|
-
graph.addDisposer((0,
|
|
1246
|
-
graph.addDisposer((0,
|
|
1247
|
-
const entityCount = (0,
|
|
1721
|
+
graph.addDisposer((0, import_extra8.keepalive)(adjacencyOut));
|
|
1722
|
+
graph.addDisposer((0, import_extra8.keepalive)(adjacencyIn));
|
|
1723
|
+
const entityCount = (0, import_core10.node)(
|
|
1248
1724
|
[entitiesMap.entries],
|
|
1249
1725
|
(batchData, actions, ctx) => {
|
|
1250
1726
|
const data = batchData.map(
|
|
@@ -1255,7 +1731,7 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1255
1731
|
},
|
|
1256
1732
|
{ name: "entityCount", describeKind: "derived", initial: 0, meta: memoryMeta("entity_count") }
|
|
1257
1733
|
);
|
|
1258
|
-
const edgeCount = (0,
|
|
1734
|
+
const edgeCount = (0, import_core10.node)(
|
|
1259
1735
|
[edgesMap.entries],
|
|
1260
1736
|
(batchData, actions, ctx) => {
|
|
1261
1737
|
const data = batchData.map(
|
|
@@ -1268,8 +1744,8 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1268
1744
|
);
|
|
1269
1745
|
graph.add(entityCount, { name: "entityCount" });
|
|
1270
1746
|
graph.add(edgeCount, { name: "edgeCount" });
|
|
1271
|
-
graph.addDisposer((0,
|
|
1272
|
-
graph.addDisposer((0,
|
|
1747
|
+
graph.addDisposer((0, import_extra8.keepalive)(entityCount));
|
|
1748
|
+
graph.addDisposer((0, import_extra8.keepalive)(edgeCount));
|
|
1273
1749
|
const events = createAuditLog({
|
|
1274
1750
|
name: "events",
|
|
1275
1751
|
retainedLimit: 1024,
|
|
@@ -1292,7 +1768,7 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1292
1768
|
events.append({
|
|
1293
1769
|
action: "orphanRemove",
|
|
1294
1770
|
id: candidate,
|
|
1295
|
-
t_ns: (0,
|
|
1771
|
+
t_ns: (0, import_core10.wallClockNs)(),
|
|
1296
1772
|
seq: bumpCursor(seqCursor)
|
|
1297
1773
|
});
|
|
1298
1774
|
}
|
|
@@ -1387,7 +1863,7 @@ function knowledgeGraph(name, opts = {}) {
|
|
|
1387
1863
|
const idN = toNode(id, "id");
|
|
1388
1864
|
const relN = relation !== void 0 ? toNode(relation, "relation") : void 0;
|
|
1389
1865
|
const deps = relN ? [adjacencyOut, adjacencyIn, idN, relN] : [adjacencyOut, adjacencyIn, idN];
|
|
1390
|
-
return (0,
|
|
1866
|
+
return (0, import_core10.node)(
|
|
1391
1867
|
deps,
|
|
1392
1868
|
(batchData, actions, ctx) => {
|
|
1393
1869
|
const values = batchData.map(
|