@framers/agentos 0.3.0 → 0.3.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/memory/retrieval/store/Brain.d.ts +6 -11
- package/dist/memory/retrieval/store/Brain.d.ts.map +1 -1
- package/dist/memory/retrieval/store/Brain.js +122 -68
- package/dist/memory/retrieval/store/Brain.js.map +1 -1
- package/dist/memory/retrieval/store/migrations/MigrationRunner.d.ts +50 -0
- package/dist/memory/retrieval/store/migrations/MigrationRunner.d.ts.map +1 -0
- package/dist/memory/retrieval/store/migrations/MigrationRunner.js +100 -0
- package/dist/memory/retrieval/store/migrations/MigrationRunner.js.map +1 -0
- package/dist/memory/retrieval/store/migrations/index.d.ts +20 -0
- package/dist/memory/retrieval/store/migrations/index.d.ts.map +1 -0
- package/dist/memory/retrieval/store/migrations/index.js +19 -0
- package/dist/memory/retrieval/store/migrations/index.js.map +1 -0
- package/dist/memory/retrieval/store/migrations/types.d.ts +28 -0
- package/dist/memory/retrieval/store/migrations/types.d.ts.map +1 -0
- package/dist/memory/retrieval/store/migrations/types.js +7 -0
- package/dist/memory/retrieval/store/migrations/types.js.map +1 -0
- package/dist/memory/retrieval/store/migrations/v1-to-v2.d.ts +9 -0
- package/dist/memory/retrieval/store/migrations/v1-to-v2.d.ts.map +1 -1
- package/dist/memory/retrieval/store/migrations/v1-to-v2.js +72 -4
- package/dist/memory/retrieval/store/migrations/v1-to-v2.js.map +1 -1
- package/dist/memory/retrieval/store/portable-tables.d.ts +27 -0
- package/dist/memory/retrieval/store/portable-tables.d.ts.map +1 -0
- package/dist/memory/retrieval/store/portable-tables.js +56 -0
- package/dist/memory/retrieval/store/portable-tables.js.map +1 -0
- package/dist/memory/retrieval/typed-network/FourWayRrf.d.ts +51 -0
- package/dist/memory/retrieval/typed-network/FourWayRrf.d.ts.map +1 -0
- package/dist/memory/retrieval/typed-network/FourWayRrf.js +47 -0
- package/dist/memory/retrieval/typed-network/FourWayRrf.js.map +1 -0
- package/dist/memory/retrieval/typed-network/TemporalIntervalOverlap.d.ts +34 -0
- package/dist/memory/retrieval/typed-network/TemporalIntervalOverlap.d.ts.map +1 -0
- package/dist/memory/retrieval/typed-network/TemporalIntervalOverlap.js +86 -0
- package/dist/memory/retrieval/typed-network/TemporalIntervalOverlap.js.map +1 -0
- package/dist/memory/retrieval/typed-network/TypedNetworkObserver.d.ts +67 -0
- package/dist/memory/retrieval/typed-network/TypedNetworkObserver.d.ts.map +1 -0
- package/dist/memory/retrieval/typed-network/TypedNetworkObserver.js +78 -0
- package/dist/memory/retrieval/typed-network/TypedNetworkObserver.js.map +1 -0
- package/dist/memory/retrieval/typed-network/TypedNetworkStore.d.ts +83 -0
- package/dist/memory/retrieval/typed-network/TypedNetworkStore.d.ts.map +1 -0
- package/dist/memory/retrieval/typed-network/TypedNetworkStore.js +109 -0
- package/dist/memory/retrieval/typed-network/TypedNetworkStore.js.map +1 -0
- package/dist/memory/retrieval/typed-network/TypedSpreadingActivation.d.ts +80 -0
- package/dist/memory/retrieval/typed-network/TypedSpreadingActivation.d.ts.map +1 -0
- package/dist/memory/retrieval/typed-network/TypedSpreadingActivation.js +97 -0
- package/dist/memory/retrieval/typed-network/TypedSpreadingActivation.js.map +1 -0
- package/dist/memory/retrieval/typed-network/index.d.ts +18 -0
- package/dist/memory/retrieval/typed-network/index.d.ts.map +1 -0
- package/dist/memory/retrieval/typed-network/index.js +18 -0
- package/dist/memory/retrieval/typed-network/index.js.map +1 -0
- package/dist/memory/retrieval/typed-network/prompts/extraction-prompt.d.ts +30 -0
- package/dist/memory/retrieval/typed-network/prompts/extraction-prompt.d.ts.map +1 -0
- package/dist/memory/retrieval/typed-network/prompts/extraction-prompt.js +47 -0
- package/dist/memory/retrieval/typed-network/prompts/extraction-prompt.js.map +1 -0
- package/dist/memory/retrieval/typed-network/prompts/extraction-schema.d.ts +71 -0
- package/dist/memory/retrieval/typed-network/prompts/extraction-schema.d.ts.map +1 -0
- package/dist/memory/retrieval/typed-network/prompts/extraction-schema.js +39 -0
- package/dist/memory/retrieval/typed-network/prompts/extraction-schema.js.map +1 -0
- package/dist/memory/retrieval/typed-network/types.d.ts +123 -0
- package/dist/memory/retrieval/typed-network/types.d.ts.map +1 -0
- package/dist/memory/retrieval/typed-network/types.js +48 -0
- package/dist/memory/retrieval/typed-network/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file TypedNetworkObserver.ts
|
|
3
|
+
* @description LLM-driven extractor that turns a conversation block
|
|
4
|
+
* into 0+ {@link TypedFact}s. Wraps the 6-step extraction prompt and
|
|
5
|
+
* the zod-validated parsing of the LLM's structured-output response.
|
|
6
|
+
*
|
|
7
|
+
* Production wiring: a typical caller constructs the observer once per
|
|
8
|
+
* pipeline (re-using the same `gpt-5-mini` adapter), then invokes
|
|
9
|
+
* {@link TypedNetworkObserver.extract} per session. The returned facts
|
|
10
|
+
* are then upserted into a {@link TypedNetworkStore} and embedded by
|
|
11
|
+
* the host's {@link IEmbeddingManager}.
|
|
12
|
+
*
|
|
13
|
+
* @module @framers/agentos/memory/retrieval/typed-network/TypedNetworkObserver
|
|
14
|
+
*/
|
|
15
|
+
import { TypedExtractionSchema } from './prompts/extraction-schema.js';
|
|
16
|
+
import { TYPED_EXTRACTION_SYSTEM_PROMPT, buildExtractionUserPrompt, } from './prompts/extraction-prompt.js';
|
|
17
|
+
/**
|
|
18
|
+
* The 6-step extractor. Stateless aside from its constructor options;
|
|
19
|
+
* safe to share across concurrent extractions.
|
|
20
|
+
*/
|
|
21
|
+
export class TypedNetworkObserver {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.llm = options.llm;
|
|
24
|
+
this.maxTokens = options.maxTokens ?? 4096;
|
|
25
|
+
this.temperature = options.temperature ?? 0;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Extract typed facts from a conversation block. Uses the 6-step
|
|
29
|
+
* prompt + zod-validated parsing. The resulting facts have stable
|
|
30
|
+
* IDs of the form `<sessionId>-fact-<index>` so re-extraction
|
|
31
|
+
* against the same content reproduces the same IDs.
|
|
32
|
+
*
|
|
33
|
+
* @param sessionText - Full conversation text. Will be wrapped in
|
|
34
|
+
* the user prompt's delimiters automatically.
|
|
35
|
+
* @param sessionId - Stable identifier used to namespace the
|
|
36
|
+
* resulting fact IDs.
|
|
37
|
+
* @returns Array of {@link TypedFact}s, possibly empty.
|
|
38
|
+
* @throws ZodError if the LLM output fails schema validation.
|
|
39
|
+
* @throws SyntaxError if the LLM output is not valid JSON.
|
|
40
|
+
*/
|
|
41
|
+
async extract(sessionText, sessionId) {
|
|
42
|
+
const raw = await this.llm.invoke({
|
|
43
|
+
system: TYPED_EXTRACTION_SYSTEM_PROMPT,
|
|
44
|
+
user: buildExtractionUserPrompt(sessionText),
|
|
45
|
+
maxTokens: this.maxTokens,
|
|
46
|
+
temperature: this.temperature,
|
|
47
|
+
});
|
|
48
|
+
// Strip markdown code fences if the LLM wraps the JSON in them
|
|
49
|
+
// (some models do this even with explicit "no commentary" prompts).
|
|
50
|
+
const stripped = stripCodeFence(raw);
|
|
51
|
+
const json = JSON.parse(stripped);
|
|
52
|
+
const parsed = TypedExtractionSchema.parse(json);
|
|
53
|
+
return parsed.facts.map((f, idx) => ({
|
|
54
|
+
id: `${sessionId}-fact-${idx}`,
|
|
55
|
+
bank: f.bank,
|
|
56
|
+
text: f.text,
|
|
57
|
+
embedding: [],
|
|
58
|
+
temporal: f.temporal,
|
|
59
|
+
participants: f.participants,
|
|
60
|
+
reasoningMarkers: f.reasoning_markers,
|
|
61
|
+
entities: f.entities,
|
|
62
|
+
confidence: f.confidence,
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Strip leading/trailing markdown code fences. Tolerates both
|
|
68
|
+
* triple-backtick-with-language and bare triple-backtick wrappers.
|
|
69
|
+
*/
|
|
70
|
+
function stripCodeFence(s) {
|
|
71
|
+
const trimmed = s.trim();
|
|
72
|
+
if (!trimmed.startsWith('```'))
|
|
73
|
+
return trimmed;
|
|
74
|
+
// Drop the opening ``` (with or without language tag) and any trailing ```
|
|
75
|
+
const withoutOpen = trimmed.replace(/^```(?:json|JSON)?\s*\n?/, '');
|
|
76
|
+
return withoutOpen.replace(/\n?```\s*$/, '');
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=TypedNetworkObserver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedNetworkObserver.js","sourceRoot":"","sources":["../../../../src/memory/retrieval/typed-network/TypedNetworkObserver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EACL,8BAA8B,EAC9B,yBAAyB,GAC1B,MAAM,gCAAgC,CAAC;AA+BxC;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IAK/B,YAAY,OAAoC;QAC9C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,OAAO,CAAC,WAAmB,EAAE,SAAiB;QAClD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;YAChC,MAAM,EAAE,8BAA8B;YACtC,IAAI,EAAE,yBAAyB,CAAC,WAAW,CAAC;YAC5C,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC,CAAC;QACH,+DAA+D;QAC/D,oEAAoE;QACpE,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,qBAAqB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;YACnC,EAAE,EAAE,GAAG,SAAS,SAAS,GAAG,EAAE;YAC9B,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,SAAS,EAAE,EAAE;YACb,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,YAAY,EAAE,CAAC,CAAC,YAAY;YAC5B,gBAAgB,EAAE,CAAC,CAAC,iBAAiB;YACrC,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,UAAU,EAAE,CAAC,CAAC,UAAU;SACzB,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,CAAS;IAC/B,MAAM,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACzB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IAC/C,2EAA2E;IAC3E,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC,CAAC;IACpE,OAAO,WAAW,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file TypedNetworkStore.ts
|
|
3
|
+
* @description In-memory 4-bank store for typed facts plus a
|
|
4
|
+
* bidirectional edge index. Stage E primary data structure.
|
|
5
|
+
*
|
|
6
|
+
* The store is independent of persistence — it holds the working set
|
|
7
|
+
* of typed facts and their edges for a single retrieval session. A
|
|
8
|
+
* future SQL-backed extension can wrap the same interface for cross-
|
|
9
|
+
* session persistence.
|
|
10
|
+
*
|
|
11
|
+
* Insertion semantics:
|
|
12
|
+
* - {@link addFact} routes by `fact.bank` into the correct bank set.
|
|
13
|
+
* - {@link addEdge} stores the forward edge AND a paired reverse edge
|
|
14
|
+
* for {@link EdgeKind} entries that are bidirectional in Hindsight
|
|
15
|
+
* §2.4.1 (entity, semantic, temporal). Causal edges are directional
|
|
16
|
+
* in the paper; this implementation stores both directions for
|
|
17
|
+
* simplicity at small graph sizes — the consumer can filter by
|
|
18
|
+
* `kind === 'causal'` + edge ordering if direction-sensitive queries
|
|
19
|
+
* are needed.
|
|
20
|
+
*
|
|
21
|
+
* @module @framers/agentos/memory/retrieval/typed-network/TypedNetworkStore
|
|
22
|
+
*/
|
|
23
|
+
import type { BankId, TypedFact, TypedEdge } from './types.js';
|
|
24
|
+
/**
|
|
25
|
+
* In-memory 4-bank store. Holds facts indexed by ID + per-bank ID set
|
|
26
|
+
* + outgoing-edge map. Constructed empty; populate via {@link addFact}
|
|
27
|
+
* and {@link addEdge}.
|
|
28
|
+
*/
|
|
29
|
+
export declare class TypedNetworkStore {
|
|
30
|
+
private readonly facts;
|
|
31
|
+
private readonly banks;
|
|
32
|
+
private readonly edgesFrom;
|
|
33
|
+
/**
|
|
34
|
+
* Construct an empty store with one entry per bank in
|
|
35
|
+
* {@link BANK_IDS}. Pre-allocating avoids null-checks in the
|
|
36
|
+
* insertion path.
|
|
37
|
+
*/
|
|
38
|
+
constructor();
|
|
39
|
+
/**
|
|
40
|
+
* Insert a fact. Routes into `fact.bank` by membership in the
|
|
41
|
+
* appropriate `banks[bank]` set. Re-inserting the same ID overwrites
|
|
42
|
+
* the prior fact and leaves bank membership unchanged.
|
|
43
|
+
*/
|
|
44
|
+
addFact(fact: TypedFact): void;
|
|
45
|
+
/**
|
|
46
|
+
* Lookup a fact by ID. Returns `undefined` if not present.
|
|
47
|
+
*/
|
|
48
|
+
getFact(id: string): TypedFact | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Return the set of fact IDs in a given bank. Live reference — do
|
|
51
|
+
* not mutate the returned `Set` directly.
|
|
52
|
+
*/
|
|
53
|
+
getBank(bank: BankId): Set<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Total fact count across all banks. Useful for debugging /
|
|
56
|
+
* consolidation pruning thresholds.
|
|
57
|
+
*/
|
|
58
|
+
size(): number;
|
|
59
|
+
/**
|
|
60
|
+
* Insert a typed edge. Stores both the forward edge (`from → to`)
|
|
61
|
+
* and a paired reverse edge (`to → from`) so spreading activation
|
|
62
|
+
* traverses bidirectionally per Hindsight §2.4.1. Identical reverse-
|
|
63
|
+
* edge insertion is what makes entity, semantic, and temporal links
|
|
64
|
+
* bidirectional by construction.
|
|
65
|
+
*/
|
|
66
|
+
addEdge(edge: TypedEdge): void;
|
|
67
|
+
/**
|
|
68
|
+
* Outgoing edges from a fact. Empty array if the fact has no
|
|
69
|
+
* outgoing edges or is unknown.
|
|
70
|
+
*/
|
|
71
|
+
getEdges(factId: string): TypedEdge[];
|
|
72
|
+
/**
|
|
73
|
+
* Iterate every fact in the store. Useful for export and
|
|
74
|
+
* persistence.
|
|
75
|
+
*/
|
|
76
|
+
iterateFacts(): IterableIterator<TypedFact>;
|
|
77
|
+
/**
|
|
78
|
+
* Append an edge to the outgoing-edge map for `fromId`, allocating
|
|
79
|
+
* the inner array on first insertion.
|
|
80
|
+
*/
|
|
81
|
+
private appendEdge;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=TypedNetworkStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedNetworkStore.d.ts","sourceRoot":"","sources":["../../../../src/memory/retrieval/typed-network/TypedNetworkStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG/D;;;;GAIG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgC;IACtD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA8B;IACpD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkC;IAE5D;;;;OAIG;;IAOH;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAK9B;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAI1C;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAIlC;;;OAGG;IACH,IAAI,IAAI,MAAM;IAId;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAU9B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE;IAIrC;;;OAGG;IACF,YAAY,IAAI,gBAAgB,CAAC,SAAS,CAAC;IAI5C;;;OAGG;IACH,OAAO,CAAC,UAAU;CAKnB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file TypedNetworkStore.ts
|
|
3
|
+
* @description In-memory 4-bank store for typed facts plus a
|
|
4
|
+
* bidirectional edge index. Stage E primary data structure.
|
|
5
|
+
*
|
|
6
|
+
* The store is independent of persistence — it holds the working set
|
|
7
|
+
* of typed facts and their edges for a single retrieval session. A
|
|
8
|
+
* future SQL-backed extension can wrap the same interface for cross-
|
|
9
|
+
* session persistence.
|
|
10
|
+
*
|
|
11
|
+
* Insertion semantics:
|
|
12
|
+
* - {@link addFact} routes by `fact.bank` into the correct bank set.
|
|
13
|
+
* - {@link addEdge} stores the forward edge AND a paired reverse edge
|
|
14
|
+
* for {@link EdgeKind} entries that are bidirectional in Hindsight
|
|
15
|
+
* §2.4.1 (entity, semantic, temporal). Causal edges are directional
|
|
16
|
+
* in the paper; this implementation stores both directions for
|
|
17
|
+
* simplicity at small graph sizes — the consumer can filter by
|
|
18
|
+
* `kind === 'causal'` + edge ordering if direction-sensitive queries
|
|
19
|
+
* are needed.
|
|
20
|
+
*
|
|
21
|
+
* @module @framers/agentos/memory/retrieval/typed-network/TypedNetworkStore
|
|
22
|
+
*/
|
|
23
|
+
import { BANK_IDS } from './types.js';
|
|
24
|
+
/**
|
|
25
|
+
* In-memory 4-bank store. Holds facts indexed by ID + per-bank ID set
|
|
26
|
+
* + outgoing-edge map. Constructed empty; populate via {@link addFact}
|
|
27
|
+
* and {@link addEdge}.
|
|
28
|
+
*/
|
|
29
|
+
export class TypedNetworkStore {
|
|
30
|
+
/**
|
|
31
|
+
* Construct an empty store with one entry per bank in
|
|
32
|
+
* {@link BANK_IDS}. Pre-allocating avoids null-checks in the
|
|
33
|
+
* insertion path.
|
|
34
|
+
*/
|
|
35
|
+
constructor() {
|
|
36
|
+
this.facts = new Map();
|
|
37
|
+
this.edgesFrom = new Map();
|
|
38
|
+
this.banks = Object.fromEntries(BANK_IDS.map((b) => [b, new Set()]));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Insert a fact. Routes into `fact.bank` by membership in the
|
|
42
|
+
* appropriate `banks[bank]` set. Re-inserting the same ID overwrites
|
|
43
|
+
* the prior fact and leaves bank membership unchanged.
|
|
44
|
+
*/
|
|
45
|
+
addFact(fact) {
|
|
46
|
+
this.facts.set(fact.id, fact);
|
|
47
|
+
this.banks[fact.bank].add(fact.id);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Lookup a fact by ID. Returns `undefined` if not present.
|
|
51
|
+
*/
|
|
52
|
+
getFact(id) {
|
|
53
|
+
return this.facts.get(id);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Return the set of fact IDs in a given bank. Live reference — do
|
|
57
|
+
* not mutate the returned `Set` directly.
|
|
58
|
+
*/
|
|
59
|
+
getBank(bank) {
|
|
60
|
+
return this.banks[bank];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Total fact count across all banks. Useful for debugging /
|
|
64
|
+
* consolidation pruning thresholds.
|
|
65
|
+
*/
|
|
66
|
+
size() {
|
|
67
|
+
return this.facts.size;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Insert a typed edge. Stores both the forward edge (`from → to`)
|
|
71
|
+
* and a paired reverse edge (`to → from`) so spreading activation
|
|
72
|
+
* traverses bidirectionally per Hindsight §2.4.1. Identical reverse-
|
|
73
|
+
* edge insertion is what makes entity, semantic, and temporal links
|
|
74
|
+
* bidirectional by construction.
|
|
75
|
+
*/
|
|
76
|
+
addEdge(edge) {
|
|
77
|
+
this.appendEdge(edge.fromFactId, edge);
|
|
78
|
+
this.appendEdge(edge.toFactId, {
|
|
79
|
+
fromFactId: edge.toFactId,
|
|
80
|
+
toFactId: edge.fromFactId,
|
|
81
|
+
kind: edge.kind,
|
|
82
|
+
weight: edge.weight,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Outgoing edges from a fact. Empty array if the fact has no
|
|
87
|
+
* outgoing edges or is unknown.
|
|
88
|
+
*/
|
|
89
|
+
getEdges(factId) {
|
|
90
|
+
return this.edgesFrom.get(factId) ?? [];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Iterate every fact in the store. Useful for export and
|
|
94
|
+
* persistence.
|
|
95
|
+
*/
|
|
96
|
+
*iterateFacts() {
|
|
97
|
+
yield* this.facts.values();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Append an edge to the outgoing-edge map for `fromId`, allocating
|
|
101
|
+
* the inner array on first insertion.
|
|
102
|
+
*/
|
|
103
|
+
appendEdge(fromId, edge) {
|
|
104
|
+
const list = this.edgesFrom.get(fromId) ?? [];
|
|
105
|
+
list.push(edge);
|
|
106
|
+
this.edgesFrom.set(fromId, list);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=TypedNetworkStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedNetworkStore.js","sourceRoot":"","sources":["../../../../src/memory/retrieval/typed-network/TypedNetworkStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAK5B;;;;OAIG;IACH;QATiB,UAAK,GAAG,IAAI,GAAG,EAAqB,CAAC;QAErC,cAAS,GAAG,IAAI,GAAG,EAAuB,CAAC;QAQ1D,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,WAAW,CAC7B,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,EAAU,CAAC,CAAC,CACb,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,IAAe;QACrB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,EAAU;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,IAAY;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,IAAe;QACrB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE;YAC7B,UAAU,EAAE,IAAI,CAAC,QAAQ;YACzB,QAAQ,EAAE,IAAI,CAAC,UAAU;YACzB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,MAAc;QACrB,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACH,CAAC,YAAY;QACX,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACK,UAAU,CAAC,MAAc,EAAE,IAAe;QAChD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC9C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file TypedSpreadingActivation.ts
|
|
3
|
+
* @description Spreading activation across the typed-network graph
|
|
4
|
+
* per Hindsight Equation 12 (§2.4.1):
|
|
5
|
+
*
|
|
6
|
+
* A(fj, t+1) = max[(fi,fj,w,ℓ)∈E] [A(fi,t) · w · δ · μ(ℓ)]
|
|
7
|
+
*
|
|
8
|
+
* Where:
|
|
9
|
+
* - `δ ∈ (0, 1)` — decay factor per hop
|
|
10
|
+
* - `μ(ℓ)` — link-type multiplier (one of: temporal, semantic,
|
|
11
|
+
* entity, causal)
|
|
12
|
+
* - `A(fi,t)` — activation of node fi at hop t
|
|
13
|
+
* - `w` — edge weight
|
|
14
|
+
*
|
|
15
|
+
* The implementation is a bounded BFS with the max-aggregator over
|
|
16
|
+
* incoming edges (per the `max[...]` in Eq. 12) and an early-exit
|
|
17
|
+
* when no node's activation exceeds the threshold. Default depth=3
|
|
18
|
+
* matches the existing untyped {@link SpreadingActivation} primitive
|
|
19
|
+
* in agentos.
|
|
20
|
+
*
|
|
21
|
+
* @module @framers/agentos/memory/retrieval/typed-network/TypedSpreadingActivation
|
|
22
|
+
*/
|
|
23
|
+
import type { TypedNetworkStore } from './TypedNetworkStore.js';
|
|
24
|
+
import type { EdgeKind } from './types.js';
|
|
25
|
+
/**
|
|
26
|
+
* Per-edge-kind activation multipliers `μ(ℓ)` from Hindsight §2.4.1.
|
|
27
|
+
* - **entity**: 1.0 (the strongest link, bidirectional shared-entity)
|
|
28
|
+
* - **causal**: 1.0 (LLM-extracted reasoning chain — high signal)
|
|
29
|
+
* - **temporal**: 0.7 (loose proximity in time)
|
|
30
|
+
* - **semantic**: 0.6 (cosine ≥ θs threshold; treat as supporting,
|
|
31
|
+
* not primary, since the embedding path also runs separately at
|
|
32
|
+
* the four-way RRF fusion)
|
|
33
|
+
*
|
|
34
|
+
* These default values are tunable per-deployment; pass an override
|
|
35
|
+
* map via {@link TypedSpreadingActivationOptions.edgeMultipliers}.
|
|
36
|
+
*/
|
|
37
|
+
export declare const DEFAULT_EDGE_MULTIPLIERS: Record<EdgeKind, number>;
|
|
38
|
+
/**
|
|
39
|
+
* Construction options for spreading activation.
|
|
40
|
+
*/
|
|
41
|
+
export interface TypedSpreadingActivationOptions {
|
|
42
|
+
/** Per-hop decay factor δ ∈ (0, 1). Default 0.5. */
|
|
43
|
+
decay: number;
|
|
44
|
+
/** Override the default {@link DEFAULT_EDGE_MULTIPLIERS}. */
|
|
45
|
+
edgeMultipliers?: Record<EdgeKind, number>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Per-call options.
|
|
49
|
+
*/
|
|
50
|
+
export interface SpreadOptions {
|
|
51
|
+
/** Maximum hops from a seed node. Default cap on graph traversal. */
|
|
52
|
+
maxDepth: number;
|
|
53
|
+
/** Activation cutoff. Nodes below this threshold are not propagated. */
|
|
54
|
+
activationThreshold?: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Spreading-activation primitive over a typed network. Constructed
|
|
58
|
+
* once per pipeline; safe to share across queries (all per-call state
|
|
59
|
+
* lives in the local activation map).
|
|
60
|
+
*/
|
|
61
|
+
export declare class TypedSpreadingActivation {
|
|
62
|
+
private readonly decay;
|
|
63
|
+
private readonly μ;
|
|
64
|
+
constructor(options: TypedSpreadingActivationOptions);
|
|
65
|
+
/**
|
|
66
|
+
* Run spreading activation from a set of seed fact IDs. Returns a
|
|
67
|
+
* map from fact ID to activation level, including the seeds (at
|
|
68
|
+
* activation 1.0) and every reachable fact above the threshold.
|
|
69
|
+
*
|
|
70
|
+
* Uses Eq. 12's max-aggregation: each step computes the candidate
|
|
71
|
+
* activation `current · weight · δ · μ(kind)` for every outgoing
|
|
72
|
+
* edge, then keeps the max across paths into a node.
|
|
73
|
+
*
|
|
74
|
+
* @param store - The typed network to traverse.
|
|
75
|
+
* @param seedIds - Initial seed fact IDs (activated at 1.0).
|
|
76
|
+
* @param options - maxDepth + activationThreshold.
|
|
77
|
+
*/
|
|
78
|
+
spread(store: TypedNetworkStore, seedIds: string[], options: SpreadOptions): Map<string, number>;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=TypedSpreadingActivation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedSpreadingActivation.d.ts","sourceRoot":"","sources":["../../../../src/memory/retrieval/typed-network/TypedSpreadingActivation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAK7D,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,eAAe,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,wEAAwE;IACxE,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;GAIG;AACH,qBAAa,wBAAwB;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,CAAC,CAA2B;gBAEjC,OAAO,EAAE,+BAA+B;IAKpD;;;;;;;;;;;;OAYG;IACH,MAAM,CACJ,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,aAAa,GACrB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAkCvB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file TypedSpreadingActivation.ts
|
|
3
|
+
* @description Spreading activation across the typed-network graph
|
|
4
|
+
* per Hindsight Equation 12 (§2.4.1):
|
|
5
|
+
*
|
|
6
|
+
* A(fj, t+1) = max[(fi,fj,w,ℓ)∈E] [A(fi,t) · w · δ · μ(ℓ)]
|
|
7
|
+
*
|
|
8
|
+
* Where:
|
|
9
|
+
* - `δ ∈ (0, 1)` — decay factor per hop
|
|
10
|
+
* - `μ(ℓ)` — link-type multiplier (one of: temporal, semantic,
|
|
11
|
+
* entity, causal)
|
|
12
|
+
* - `A(fi,t)` — activation of node fi at hop t
|
|
13
|
+
* - `w` — edge weight
|
|
14
|
+
*
|
|
15
|
+
* The implementation is a bounded BFS with the max-aggregator over
|
|
16
|
+
* incoming edges (per the `max[...]` in Eq. 12) and an early-exit
|
|
17
|
+
* when no node's activation exceeds the threshold. Default depth=3
|
|
18
|
+
* matches the existing untyped {@link SpreadingActivation} primitive
|
|
19
|
+
* in agentos.
|
|
20
|
+
*
|
|
21
|
+
* @module @framers/agentos/memory/retrieval/typed-network/TypedSpreadingActivation
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Per-edge-kind activation multipliers `μ(ℓ)` from Hindsight §2.4.1.
|
|
25
|
+
* - **entity**: 1.0 (the strongest link, bidirectional shared-entity)
|
|
26
|
+
* - **causal**: 1.0 (LLM-extracted reasoning chain — high signal)
|
|
27
|
+
* - **temporal**: 0.7 (loose proximity in time)
|
|
28
|
+
* - **semantic**: 0.6 (cosine ≥ θs threshold; treat as supporting,
|
|
29
|
+
* not primary, since the embedding path also runs separately at
|
|
30
|
+
* the four-way RRF fusion)
|
|
31
|
+
*
|
|
32
|
+
* These default values are tunable per-deployment; pass an override
|
|
33
|
+
* map via {@link TypedSpreadingActivationOptions.edgeMultipliers}.
|
|
34
|
+
*/
|
|
35
|
+
export const DEFAULT_EDGE_MULTIPLIERS = {
|
|
36
|
+
entity: 1.0,
|
|
37
|
+
causal: 1.0,
|
|
38
|
+
temporal: 0.7,
|
|
39
|
+
semantic: 0.6,
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Spreading-activation primitive over a typed network. Constructed
|
|
43
|
+
* once per pipeline; safe to share across queries (all per-call state
|
|
44
|
+
* lives in the local activation map).
|
|
45
|
+
*/
|
|
46
|
+
export class TypedSpreadingActivation {
|
|
47
|
+
constructor(options) {
|
|
48
|
+
this.decay = options.decay;
|
|
49
|
+
this.μ = options.edgeMultipliers ?? DEFAULT_EDGE_MULTIPLIERS;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Run spreading activation from a set of seed fact IDs. Returns a
|
|
53
|
+
* map from fact ID to activation level, including the seeds (at
|
|
54
|
+
* activation 1.0) and every reachable fact above the threshold.
|
|
55
|
+
*
|
|
56
|
+
* Uses Eq. 12's max-aggregation: each step computes the candidate
|
|
57
|
+
* activation `current · weight · δ · μ(kind)` for every outgoing
|
|
58
|
+
* edge, then keeps the max across paths into a node.
|
|
59
|
+
*
|
|
60
|
+
* @param store - The typed network to traverse.
|
|
61
|
+
* @param seedIds - Initial seed fact IDs (activated at 1.0).
|
|
62
|
+
* @param options - maxDepth + activationThreshold.
|
|
63
|
+
*/
|
|
64
|
+
spread(store, seedIds, options) {
|
|
65
|
+
const threshold = options.activationThreshold ?? 0.05;
|
|
66
|
+
const activations = new Map();
|
|
67
|
+
for (const id of seedIds)
|
|
68
|
+
activations.set(id, 1.0);
|
|
69
|
+
let frontier = new Set(seedIds);
|
|
70
|
+
for (let depth = 0; depth < options.maxDepth; depth++) {
|
|
71
|
+
const nextFrontier = new Set();
|
|
72
|
+
let updated = false;
|
|
73
|
+
for (const factId of frontier) {
|
|
74
|
+
const currentAct = activations.get(factId);
|
|
75
|
+
if (currentAct === undefined)
|
|
76
|
+
continue;
|
|
77
|
+
for (const edge of store.getEdges(factId)) {
|
|
78
|
+
const candidate = currentAct * edge.weight * this.decay * this.μ[edge.kind];
|
|
79
|
+
if (candidate < threshold)
|
|
80
|
+
continue;
|
|
81
|
+
// Eq. 12: max-aggregate over incoming edges.
|
|
82
|
+
const existing = activations.get(edge.toFactId) ?? 0;
|
|
83
|
+
if (candidate > existing) {
|
|
84
|
+
activations.set(edge.toFactId, candidate);
|
|
85
|
+
nextFrontier.add(edge.toFactId);
|
|
86
|
+
updated = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!updated)
|
|
91
|
+
break;
|
|
92
|
+
frontier = nextFrontier;
|
|
93
|
+
}
|
|
94
|
+
return activations;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=TypedSpreadingActivation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedSpreadingActivation.js","sourceRoot":"","sources":["../../../../src/memory/retrieval/typed-network/TypedSpreadingActivation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA6B;IAChE,MAAM,EAAE,GAAG;IACX,MAAM,EAAE,GAAG;IACX,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,GAAG;CACd,CAAC;AAsBF;;;;GAIG;AACH,MAAM,OAAO,wBAAwB;IAInC,YAAY,OAAwC;QAClD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,CAAC,GAAG,OAAO,CAAC,eAAe,IAAI,wBAAwB,CAAC;IAC/D,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CACJ,KAAwB,EACxB,OAAiB,EACjB,OAAsB;QAEtB,MAAM,SAAS,GAAG,OAAO,CAAC,mBAAmB,IAAI,IAAI,CAAC;QACtD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC9C,KAAK,MAAM,EAAE,IAAI,OAAO;YAAE,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QAEnD,IAAI,QAAQ,GAAG,IAAI,GAAG,CAAS,OAAO,CAAC,CAAC;QACxC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC;YACtD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;YACvC,IAAI,OAAO,GAAG,KAAK,CAAC;YAEpB,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE,CAAC;gBAC9B,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBAC3C,IAAI,UAAU,KAAK,SAAS;oBAAE,SAAS;gBAEvC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC1C,MAAM,SAAS,GACb,UAAU,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAC5D,IAAI,SAAS,GAAG,SAAS;wBAAE,SAAS;oBACpC,6CAA6C;oBAC7C,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;oBACrD,IAAI,SAAS,GAAG,QAAQ,EAAE,CAAC;wBACzB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;wBAC1C,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;wBAChC,OAAO,GAAG,IAAI,CAAC;oBACjB,CAAC;gBACH,CAAC;YACH,CAAC;YAED,IAAI,CAAC,OAAO;gBAAE,MAAM;YACpB,QAAQ,GAAG,YAAY,CAAC;QAC1B,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Barrel exports for the Hindsight 4-network typed
|
|
4
|
+
* observer module. The new agentos primitive for typed graph
|
|
5
|
+
* traversal at retrieval time. Imported by the bench wiring and by
|
|
6
|
+
* any consumer building a Hindsight-style memory pipeline.
|
|
7
|
+
*
|
|
8
|
+
* @module @framers/agentos/memory/retrieval/typed-network
|
|
9
|
+
*/
|
|
10
|
+
export { BANK_IDS, EDGE_KINDS, isBankId, type BankId, type EdgeKind, type TypedFact, type TypedEdge, type FactTemporal, type Participant, } from './types.js';
|
|
11
|
+
export { TypedNetworkStore } from './TypedNetworkStore.js';
|
|
12
|
+
export { rankByTemporalOverlap } from './TemporalIntervalOverlap.js';
|
|
13
|
+
export { TypedNetworkObserver, type ITypedExtractionLLM, type TypedNetworkObserverOptions, } from './TypedNetworkObserver.js';
|
|
14
|
+
export { TYPED_EXTRACTION_SYSTEM_PROMPT, buildExtractionUserPrompt, } from './prompts/extraction-prompt.js';
|
|
15
|
+
export { TypedExtractionSchema, TypedExtractionFactSchema, type TypedExtractionOutput, type TypedExtractionFact, } from './prompts/extraction-schema.js';
|
|
16
|
+
export { TypedSpreadingActivation, DEFAULT_EDGE_MULTIPLIERS, type TypedSpreadingActivationOptions, type SpreadOptions, } from './TypedSpreadingActivation.js';
|
|
17
|
+
export { fourWayRrf, type FourWayRrfInput, type FourWayRrfOptions, } from './FourWayRrf.js';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/memory/retrieval/typed-network/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EACL,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,2BAA2B,GACjC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,8BAA8B,EAC9B,yBAAyB,GAC1B,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,GACzB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,KAAK,+BAA+B,EACpC,KAAK,aAAa,GACnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,UAAU,EACV,KAAK,eAAe,EACpB,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Barrel exports for the Hindsight 4-network typed
|
|
4
|
+
* observer module. The new agentos primitive for typed graph
|
|
5
|
+
* traversal at retrieval time. Imported by the bench wiring and by
|
|
6
|
+
* any consumer building a Hindsight-style memory pipeline.
|
|
7
|
+
*
|
|
8
|
+
* @module @framers/agentos/memory/retrieval/typed-network
|
|
9
|
+
*/
|
|
10
|
+
export { BANK_IDS, EDGE_KINDS, isBankId, } from './types.js';
|
|
11
|
+
export { TypedNetworkStore } from './TypedNetworkStore.js';
|
|
12
|
+
export { rankByTemporalOverlap } from './TemporalIntervalOverlap.js';
|
|
13
|
+
export { TypedNetworkObserver, } from './TypedNetworkObserver.js';
|
|
14
|
+
export { TYPED_EXTRACTION_SYSTEM_PROMPT, buildExtractionUserPrompt, } from './prompts/extraction-prompt.js';
|
|
15
|
+
export { TypedExtractionSchema, TypedExtractionFactSchema, } from './prompts/extraction-schema.js';
|
|
16
|
+
export { TypedSpreadingActivation, DEFAULT_EDGE_MULTIPLIERS, } from './TypedSpreadingActivation.js';
|
|
17
|
+
export { fourWayRrf, } from './FourWayRrf.js';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/memory/retrieval/typed-network/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,GAOT,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EACL,oBAAoB,GAGrB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,8BAA8B,EAC9B,yBAAyB,GAC1B,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,qBAAqB,EACrB,yBAAyB,GAG1B,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GAGzB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,UAAU,GAGX,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file extraction-prompt.ts
|
|
3
|
+
* @description The 6-step extraction prompt for the Hindsight 4-network
|
|
4
|
+
* typed observer. The system prompt defines the six decomposition
|
|
5
|
+
* steps verbatim from Hindsight §2.3 (coreference resolution, temporal
|
|
6
|
+
* normalization, participant attribution, reasoning preservation, fact
|
|
7
|
+
* type classification, entity extraction). The user prompt frames the
|
|
8
|
+
* conversation as a single block and asks the model to emit structured
|
|
9
|
+
* JSON conforming to {@link TypedExtractionSchema}.
|
|
10
|
+
*
|
|
11
|
+
* @module @framers/agentos/memory/retrieval/typed-network/prompts/extraction-prompt
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* System prompt for the 6-step extraction. Verbatim from Hindsight
|
|
15
|
+
* §2.3 with one omission: the spec doesn't include the "do not
|
|
16
|
+
* commentate" line, but the LLM tends to drift into prose without it,
|
|
17
|
+
* which breaks JSON parsing. Included.
|
|
18
|
+
*/
|
|
19
|
+
export declare const TYPED_EXTRACTION_SYSTEM_PROMPT = "You are an information extractor for a typed memory network. Process the conversation below into structured facts.\n\nFor each fact, perform these six steps:\n\n1. COREFERENCE: resolve \"he/she/they/it/this/that\" to the actual referent.\n2. TEMPORAL: normalize times to ISO 8601. Extract ranges as (start, end) when applicable.\n3. PARTICIPANTS: list every named participant and their role.\n4. REASONING: preserve any explicit reasoning marker (because, since, therefore, etc.) verbatim.\n5. FACT TYPE: classify into ONE of:\n - WORLD: objective facts about the external world\n - EXPERIENCE: biographical / first-person events\n - OPINION: claims with confidence < 1.0\n - OBSERVATION: preference-neutral summaries of entities\n6. ENTITIES: list every named entity (proper nouns, organizations, places, products).\n\nOutput JSON matching the schema strictly. Do not add commentary.";
|
|
20
|
+
/**
|
|
21
|
+
* Build the user prompt for a single conversation block. Wraps the
|
|
22
|
+
* source text in delimiters that resist accidental inline-injection
|
|
23
|
+
* if the conversation contains JSON-looking content.
|
|
24
|
+
*
|
|
25
|
+
* @param sessionText - The conversation text to extract from. Whole
|
|
26
|
+
* session passed as one block; the model decomposes per turn
|
|
27
|
+
* internally.
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildExtractionUserPrompt(sessionText: string): string;
|
|
30
|
+
//# sourceMappingURL=extraction-prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extraction-prompt.d.ts","sourceRoot":"","sources":["../../../../../src/memory/retrieval/typed-network/prompts/extraction-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,i4BAesB,CAAC;AAElE;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAErE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file extraction-prompt.ts
|
|
3
|
+
* @description The 6-step extraction prompt for the Hindsight 4-network
|
|
4
|
+
* typed observer. The system prompt defines the six decomposition
|
|
5
|
+
* steps verbatim from Hindsight §2.3 (coreference resolution, temporal
|
|
6
|
+
* normalization, participant attribution, reasoning preservation, fact
|
|
7
|
+
* type classification, entity extraction). The user prompt frames the
|
|
8
|
+
* conversation as a single block and asks the model to emit structured
|
|
9
|
+
* JSON conforming to {@link TypedExtractionSchema}.
|
|
10
|
+
*
|
|
11
|
+
* @module @framers/agentos/memory/retrieval/typed-network/prompts/extraction-prompt
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* System prompt for the 6-step extraction. Verbatim from Hindsight
|
|
15
|
+
* §2.3 with one omission: the spec doesn't include the "do not
|
|
16
|
+
* commentate" line, but the LLM tends to drift into prose without it,
|
|
17
|
+
* which breaks JSON parsing. Included.
|
|
18
|
+
*/
|
|
19
|
+
export const TYPED_EXTRACTION_SYSTEM_PROMPT = `You are an information extractor for a typed memory network. Process the conversation below into structured facts.
|
|
20
|
+
|
|
21
|
+
For each fact, perform these six steps:
|
|
22
|
+
|
|
23
|
+
1. COREFERENCE: resolve "he/she/they/it/this/that" to the actual referent.
|
|
24
|
+
2. TEMPORAL: normalize times to ISO 8601. Extract ranges as (start, end) when applicable.
|
|
25
|
+
3. PARTICIPANTS: list every named participant and their role.
|
|
26
|
+
4. REASONING: preserve any explicit reasoning marker (because, since, therefore, etc.) verbatim.
|
|
27
|
+
5. FACT TYPE: classify into ONE of:
|
|
28
|
+
- WORLD: objective facts about the external world
|
|
29
|
+
- EXPERIENCE: biographical / first-person events
|
|
30
|
+
- OPINION: claims with confidence < 1.0
|
|
31
|
+
- OBSERVATION: preference-neutral summaries of entities
|
|
32
|
+
6. ENTITIES: list every named entity (proper nouns, organizations, places, products).
|
|
33
|
+
|
|
34
|
+
Output JSON matching the schema strictly. Do not add commentary.`;
|
|
35
|
+
/**
|
|
36
|
+
* Build the user prompt for a single conversation block. Wraps the
|
|
37
|
+
* source text in delimiters that resist accidental inline-injection
|
|
38
|
+
* if the conversation contains JSON-looking content.
|
|
39
|
+
*
|
|
40
|
+
* @param sessionText - The conversation text to extract from. Whole
|
|
41
|
+
* session passed as one block; the model decomposes per turn
|
|
42
|
+
* internally.
|
|
43
|
+
*/
|
|
44
|
+
export function buildExtractionUserPrompt(sessionText) {
|
|
45
|
+
return `CONVERSATION:\n<<<\n${sessionText}\n>>>`;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=extraction-prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extraction-prompt.js","sourceRoot":"","sources":["../../../../../src/memory/retrieval/typed-network/prompts/extraction-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG;;;;;;;;;;;;;;;iEAemB,CAAC;AAElE;;;;;;;;GAQG;AACH,MAAM,UAAU,yBAAyB,CAAC,WAAmB;IAC3D,OAAO,uBAAuB,WAAW,OAAO,CAAC;AACnD,CAAC"}
|