agentfootprint 8.7.0 → 8.8.0
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/AGENTS.md +12 -4
- package/CLAUDE.md +4 -2
- package/ai-instructions/claude-code/SKILL.md +1 -1
- package/ai-instructions/setup.sh +0 -0
- package/bin/agentfootprint-lint-tools.mjs +0 -0
- package/dist/core/agent/buildAgentChart.js +12 -1
- package/dist/core/agent/buildAgentChart.js.map +1 -1
- package/dist/core/agent/buildDynamicAgentChart.js +12 -1
- package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/core/agent/memoryRecallInjections.js +100 -10
- package/dist/core/agent/memoryRecallInjections.js.map +1 -1
- package/dist/core/agent/stages/deliver.js.map +1 -1
- package/dist/core/slots/buildSystemPromptSlot.js +10 -0
- package/dist/core/slots/buildSystemPromptSlot.js.map +1 -1
- package/dist/core/slots/helpers.js +12 -10
- package/dist/core/slots/helpers.js.map +1 -1
- package/dist/esm/core/agent/buildAgentChart.js +13 -2
- package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
- package/dist/esm/core/agent/buildDynamicAgentChart.js +13 -2
- package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
- package/dist/esm/core/agent/memoryRecallInjections.d.ts +13 -3
- package/dist/esm/core/agent/memoryRecallInjections.js +101 -11
- package/dist/esm/core/agent/memoryRecallInjections.js.map +1 -1
- package/dist/esm/core/agent/stages/deliver.d.ts +6 -3
- package/dist/esm/core/agent/stages/deliver.js.map +1 -1
- package/dist/esm/core/slots/buildSystemPromptSlot.js +10 -0
- package/dist/esm/core/slots/buildSystemPromptSlot.js.map +1 -1
- package/dist/esm/core/slots/helpers.d.ts +11 -2
- package/dist/esm/core/slots/helpers.js +11 -9
- package/dist/esm/core/slots/helpers.js.map +1 -1
- package/dist/esm/events/payloads.d.ts +63 -0
- package/dist/esm/events/registry.d.ts +3 -1
- package/dist/esm/events/registry.js +2 -0
- package/dist/esm/events/registry.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +6 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/fnv1a.d.ts +16 -0
- package/dist/esm/lib/fnv1a.js +24 -0
- package/dist/esm/lib/fnv1a.js.map +1 -0
- package/dist/esm/lib/injection-engine/types.d.ts +17 -0
- package/dist/esm/lib/injection-engine/types.js.map +1 -1
- package/dist/esm/lib/rag/defineRAG.d.ts +126 -26
- package/dist/esm/lib/rag/defineRAG.js +112 -25
- package/dist/esm/lib/rag/defineRAG.js.map +1 -1
- package/dist/esm/lib/rag/index.d.ts +1 -1
- package/dist/esm/lib/rag/index.js +1 -1
- package/dist/esm/lib/rag/index.js.map +1 -1
- package/dist/esm/memory/define.js +38 -2
- package/dist/esm/memory/define.js.map +1 -1
- package/dist/esm/memory/define.types.d.ts +93 -1
- package/dist/esm/memory/define.types.js +18 -0
- package/dist/esm/memory/define.types.js.map +1 -1
- package/dist/esm/memory/embedding/loadRelevant.d.ts +49 -15
- package/dist/esm/memory/embedding/loadRelevant.js +136 -7
- package/dist/esm/memory/embedding/loadRelevant.js.map +1 -1
- package/dist/esm/memory/index.d.ts +2 -1
- package/dist/esm/memory/index.js +2 -1
- package/dist/esm/memory/index.js.map +1 -1
- package/dist/esm/memory/pipeline/semantic.d.ts +15 -0
- package/dist/esm/memory/pipeline/semantic.js +3 -1
- package/dist/esm/memory/pipeline/semantic.js.map +1 -1
- package/dist/esm/memory/retrieval/index.d.ts +10 -0
- package/dist/esm/memory/retrieval/index.js +3 -0
- package/dist/esm/memory/retrieval/index.js.map +1 -0
- package/dist/esm/memory/retrieval/provenance.d.ts +43 -0
- package/dist/esm/memory/retrieval/provenance.js +60 -0
- package/dist/esm/memory/retrieval/provenance.js.map +1 -0
- package/dist/esm/memory/retrieval/topK.d.ts +67 -0
- package/dist/esm/memory/retrieval/topK.js +53 -0
- package/dist/esm/memory/retrieval/topK.js.map +1 -0
- package/dist/esm/memory/retrieval/types.d.ts +189 -0
- package/dist/esm/memory/retrieval/types.js +2 -0
- package/dist/esm/memory/retrieval/types.js.map +1 -0
- package/dist/esm/memory/stages/formatDefault.d.ts +52 -26
- package/dist/esm/memory/stages/formatDefault.js +118 -28
- package/dist/esm/memory/stages/formatDefault.js.map +1 -1
- package/dist/esm/memory/stages/pickByBudget.js +53 -3
- package/dist/esm/memory/stages/pickByBudget.js.map +1 -1
- package/dist/esm/memory/stages/types.d.ts +15 -0
- package/dist/esm/memory/wire/mountMemoryPipeline.d.ts +25 -0
- package/dist/esm/memory/wire/mountMemoryPipeline.js +11 -2
- package/dist/esm/memory/wire/mountMemoryPipeline.js.map +1 -1
- package/dist/events/registry.js +2 -0
- package/dist/events/registry.js.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/fnv1a.js +28 -0
- package/dist/lib/fnv1a.js.map +1 -0
- package/dist/lib/injection-engine/types.js.map +1 -1
- package/dist/lib/rag/defineRAG.js +113 -26
- package/dist/lib/rag/defineRAG.js.map +1 -1
- package/dist/lib/rag/index.js +2 -1
- package/dist/lib/rag/index.js.map +1 -1
- package/dist/memory/define.js +38 -2
- package/dist/memory/define.js.map +1 -1
- package/dist/memory/define.types.js +21 -1
- package/dist/memory/define.types.js.map +1 -1
- package/dist/memory/embedding/loadRelevant.js +138 -8
- package/dist/memory/embedding/loadRelevant.js.map +1 -1
- package/dist/memory/index.js +5 -1
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/pipeline/semantic.js +2 -0
- package/dist/memory/pipeline/semantic.js.map +1 -1
- package/dist/memory/retrieval/index.js +9 -0
- package/dist/memory/retrieval/index.js.map +1 -0
- package/dist/memory/retrieval/provenance.js +65 -0
- package/dist/memory/retrieval/provenance.js.map +1 -0
- package/dist/memory/retrieval/topK.js +57 -0
- package/dist/memory/retrieval/topK.js.map +1 -0
- package/dist/memory/retrieval/types.js +3 -0
- package/dist/memory/retrieval/types.js.map +1 -0
- package/dist/memory/stages/formatDefault.js +118 -28
- package/dist/memory/stages/formatDefault.js.map +1 -1
- package/dist/memory/stages/pickByBudget.js +53 -3
- package/dist/memory/stages/pickByBudget.js.map +1 -1
- package/dist/memory/wire/mountMemoryPipeline.js +11 -2
- package/dist/memory/wire/mountMemoryPipeline.js.map +1 -1
- package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
- package/dist/types/core/agent/memoryRecallInjections.d.ts +13 -3
- package/dist/types/core/agent/memoryRecallInjections.d.ts.map +1 -1
- package/dist/types/core/agent/stages/deliver.d.ts +6 -3
- package/dist/types/core/agent/stages/deliver.d.ts.map +1 -1
- package/dist/types/core/slots/buildSystemPromptSlot.d.ts.map +1 -1
- package/dist/types/core/slots/helpers.d.ts +11 -2
- package/dist/types/core/slots/helpers.d.ts.map +1 -1
- package/dist/types/events/payloads.d.ts +63 -0
- package/dist/types/events/payloads.d.ts.map +1 -1
- package/dist/types/events/registry.d.ts +3 -1
- package/dist/types/events/registry.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/fnv1a.d.ts +17 -0
- package/dist/types/lib/fnv1a.d.ts.map +1 -0
- package/dist/types/lib/injection-engine/types.d.ts +17 -0
- package/dist/types/lib/injection-engine/types.d.ts.map +1 -1
- package/dist/types/lib/rag/defineRAG.d.ts +126 -26
- package/dist/types/lib/rag/defineRAG.d.ts.map +1 -1
- package/dist/types/lib/rag/index.d.ts +1 -1
- package/dist/types/lib/rag/index.d.ts.map +1 -1
- package/dist/types/memory/define.d.ts.map +1 -1
- package/dist/types/memory/define.types.d.ts +93 -1
- package/dist/types/memory/define.types.d.ts.map +1 -1
- package/dist/types/memory/embedding/loadRelevant.d.ts +49 -15
- package/dist/types/memory/embedding/loadRelevant.d.ts.map +1 -1
- package/dist/types/memory/index.d.ts +2 -1
- package/dist/types/memory/index.d.ts.map +1 -1
- package/dist/types/memory/pipeline/semantic.d.ts +15 -0
- package/dist/types/memory/pipeline/semantic.d.ts.map +1 -1
- package/dist/types/memory/retrieval/index.d.ts +11 -0
- package/dist/types/memory/retrieval/index.d.ts.map +1 -0
- package/dist/types/memory/retrieval/provenance.d.ts +44 -0
- package/dist/types/memory/retrieval/provenance.d.ts.map +1 -0
- package/dist/types/memory/retrieval/topK.d.ts +68 -0
- package/dist/types/memory/retrieval/topK.d.ts.map +1 -0
- package/dist/types/memory/retrieval/types.d.ts +190 -0
- package/dist/types/memory/retrieval/types.d.ts.map +1 -0
- package/dist/types/memory/stages/formatDefault.d.ts +52 -26
- package/dist/types/memory/stages/formatDefault.d.ts.map +1 -1
- package/dist/types/memory/stages/pickByBudget.d.ts.map +1 -1
- package/dist/types/memory/stages/types.d.ts +15 -0
- package/dist/types/memory/stages/types.d.ts.map +1 -1
- package/dist/types/memory/wire/mountMemoryPipeline.d.ts +25 -0
- package/dist/types/memory/wire/mountMemoryPipeline.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,23 +1,66 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* defineRAG —
|
|
2
|
+
* defineRAG — retrieval-augmented generation over a document corpus.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* strategy: TOP_K })` — the rename is for intent + ergonomics.
|
|
4
|
+
* Embed the user's question, retrieve the most similar chunks from a
|
|
5
|
+
* vector store, inject them into the system-prompt slot of the next LLM
|
|
6
|
+
* call. It is the same machinery as `defineMemory({ type: SEMANTIC,
|
|
7
|
+
* strategy: TOP_K })` — with three differences that are not cosmetic:
|
|
9
8
|
*
|
|
10
9
|
* defineMemory ─┬─► EPISODIC (raw conversation)
|
|
11
10
|
* ├─► SEMANTIC (extracted facts / RAG chunks)
|
|
12
11
|
* ├─► NARRATIVE (beats / summaries)
|
|
13
12
|
* └─► CAUSAL (footprintjs decision snapshots)
|
|
14
13
|
*
|
|
15
|
-
* defineRAG ─► SEMANTIC + TOP_K
|
|
16
|
-
*
|
|
14
|
+
* defineRAG ─► SEMANTIC + TOP_K, READ-ONLY, over a NAMED CORPUS,
|
|
15
|
+
* rendered as citable <source> blocks.
|
|
16
|
+
*
|
|
17
|
+
* ─── What changed in 8.8.0, and why ────────────────────────────────────
|
|
18
|
+
*
|
|
19
|
+
* **1. A corpus is read-only.** Until 8.8.0 `defineRAG` also mounted the
|
|
20
|
+
* semantic pipeline's WRITE half, which embedded every conversation turn
|
|
21
|
+
* and stored it in the same namespace as the documents. The consequence
|
|
22
|
+
* was measurable and bad: the user's own question, re-embedded, is the
|
|
23
|
+
* single best-scoring "document" in the corpus (cosine 1.0 against
|
|
24
|
+
* itself), so it came back as retrieval hit #1 and consumed a slot in
|
|
25
|
+
* the top-K budget that a real passage should have had. A corpus is not
|
|
26
|
+
* a conversation log. Nothing this retriever reads is written back.
|
|
27
|
+
*
|
|
28
|
+
* If you want conversation memory ALONGSIDE a corpus, that is what
|
|
29
|
+
* `defineMemory` is for, and the two are registered separately, each
|
|
30
|
+
* with its own store:
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const agent = Agent.create({ provider })
|
|
34
|
+
* .rag(defineRAG({ id: 'product-docs', store: corpusStore, embedder }))
|
|
35
|
+
* .memory(defineMemory({
|
|
36
|
+
* id: 'chat',
|
|
37
|
+
* type: MEMORY_TYPES.EPISODIC,
|
|
38
|
+
* strategy: { kind: MEMORY_STRATEGIES.WINDOW, size: 10 },
|
|
39
|
+
* store: conversationStore,
|
|
40
|
+
* }))
|
|
41
|
+
* .build();
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* **2. The corpus has its own namespace.** A memory reads under the
|
|
45
|
+
* identity passed to `agent.run()`. For conversation recall that is
|
|
46
|
+
* right. For a shared corpus it was the reason the documented example
|
|
47
|
+
* retrieved NOTHING: `indexDocuments` writes under
|
|
48
|
+
* `{ conversationId: '_global' }` by default, while a run with no
|
|
49
|
+
* explicit identity gets `{ conversationId: 'run-<timestamp>-<n>' }` —
|
|
50
|
+
* so the write side and the read side never met, silently. `corpus`
|
|
51
|
+
* defaults to the same `'_global'` the indexer uses, so the documented
|
|
52
|
+
* example works with no extra arguments; pass it explicitly when you
|
|
53
|
+
* index per tenant.
|
|
54
|
+
*
|
|
55
|
+
* **3. Chunks are citable.** Retrieved passages render as
|
|
56
|
+
* `<source id="refunds.md#3" doc="refunds.md" score="0.81">` under a
|
|
57
|
+
* corpus header, instead of the conversation-recall shape that printed
|
|
58
|
+
* `role="unknown" turn="0"` on a page of a PDF and gave the model
|
|
59
|
+
* nothing to cite.
|
|
17
60
|
*
|
|
18
61
|
* Pattern: Composition over duplication — defineRAG returns a
|
|
19
62
|
* MemoryDefinition produced by defineMemory. No new engine
|
|
20
|
-
* code, no new slot subflow, no new
|
|
63
|
+
* code, no new slot subflow, no new stage.
|
|
21
64
|
*
|
|
22
65
|
* Role: Layer-3 context-engineering primitive. Lives next to
|
|
23
66
|
* defineSkill / defineSteering / defineInstruction / defineFact
|
|
@@ -25,27 +68,32 @@
|
|
|
25
68
|
* (RAG content is computed at runtime via async retrieval —
|
|
26
69
|
* can't fit the synchronous Injection.inject shape).
|
|
27
70
|
*
|
|
28
|
-
* Emits:
|
|
29
|
-
*
|
|
30
|
-
*
|
|
71
|
+
* Emits: `agentfootprint.memory.retrieved` (once per retrieval, with
|
|
72
|
+
* every candidate and its score — including the rejected ones),
|
|
73
|
+
* `agentfootprint.memory.attached` (once per chunk that reached
|
|
74
|
+
* the prompt), and `agentfootprint.context.injected` with
|
|
75
|
+
* `source: 'rag'` (once per chunk).
|
|
31
76
|
*
|
|
32
77
|
* @see ./indexDocuments.ts for the seeding helper
|
|
33
78
|
* @see ../../memory/define.ts for the underlying factory
|
|
79
|
+
* @see ../../memory/retrieval/ for the retrieval seam
|
|
34
80
|
* @see ../../memory/asRoleRefusal.ts for why `asRole` is refused, not honoured
|
|
35
81
|
*
|
|
36
|
-
* @example Basic usage
|
|
82
|
+
* @example Basic usage — works with no identity argument anywhere
|
|
37
83
|
* ```ts
|
|
38
|
-
* import {
|
|
39
|
-
import { InMemoryStore, mockEmbedder } from 'agentfootprint/memory'
|
|
40
|
-
import { mock } from 'agentfootprint/
|
|
84
|
+
* import { Agent, defineRAG, indexDocuments } from 'agentfootprint';
|
|
85
|
+
* import { InMemoryStore, mockEmbedder } from 'agentfootprint/memory';
|
|
86
|
+
* import { mock } from 'agentfootprint/providers';
|
|
41
87
|
*
|
|
42
88
|
* const embedder = mockEmbedder();
|
|
43
89
|
* const store = new InMemoryStore();
|
|
44
90
|
*
|
|
45
|
-
* // Seed the
|
|
91
|
+
* // Seed the corpus once at startup (defaults to the '_global' namespace).
|
|
46
92
|
* await indexDocuments(store, embedder, [
|
|
47
|
-
* { id: '
|
|
48
|
-
*
|
|
93
|
+
* { id: 'refunds.md#0', content: 'Refunds are processed within 3 business days.',
|
|
94
|
+
* metadata: { source: 'refunds.md' } },
|
|
95
|
+
* { id: 'pricing.md#0', content: 'Pro plan costs $20/month.',
|
|
96
|
+
* metadata: { source: 'pricing.md' } },
|
|
49
97
|
* ]);
|
|
50
98
|
*
|
|
51
99
|
* const docs = defineRAG({
|
|
@@ -60,11 +108,27 @@ import { mock } from 'agentfootprint/llm-providers';
|
|
|
60
108
|
* const agent = Agent.create({ provider: mock({ reply: 'ok' }), model: 'mock' })
|
|
61
109
|
* .rag(docs)
|
|
62
110
|
* .build();
|
|
111
|
+
*
|
|
112
|
+
* agent.on('agentfootprint.memory.retrieved', (e) => {
|
|
113
|
+
* // every candidate, admitted or not, with its score and its reason
|
|
114
|
+
* console.log(e.payload.candidates);
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* await agent.run({ message: 'How long do refunds take?' });
|
|
63
118
|
* ```
|
|
64
119
|
*/
|
|
65
120
|
import type { Embedder } from '../../memory/embedding/index.js';
|
|
66
121
|
import type { MemoryStore } from '../../memory/store/index.js';
|
|
122
|
+
import type { MemoryIdentity } from '../../memory/identity/index.js';
|
|
67
123
|
import type { MemoryDefinition } from '../../memory/define.types.js';
|
|
124
|
+
import type { RetrievalStrategy } from '../../memory/retrieval/index.js';
|
|
125
|
+
/**
|
|
126
|
+
* The namespace a corpus lives in unless told otherwise — the same one
|
|
127
|
+
* `indexDocuments` writes to by default. The two defaults are one value
|
|
128
|
+
* on purpose: index with no options, retrieve with no options, and the
|
|
129
|
+
* documents are found.
|
|
130
|
+
*/
|
|
131
|
+
export declare const DEFAULT_CORPUS_IDENTITY: MemoryIdentity;
|
|
68
132
|
export interface DefineRAGOptions {
|
|
69
133
|
/** Stable id. Becomes the scope-key suffix and the Lens label. */
|
|
70
134
|
readonly id: string;
|
|
@@ -78,13 +142,13 @@ export interface DefineRAGOptions {
|
|
|
78
142
|
* Vector-capable store containing the indexed corpus. Must implement
|
|
79
143
|
* `search()`. Use `indexDocuments(store, embedder, docs)` at startup
|
|
80
144
|
* to populate it. Ships with `InMemoryStore` for dev/tests; swap to
|
|
81
|
-
*
|
|
145
|
+
* a durable adapter in production.
|
|
82
146
|
*/
|
|
83
147
|
readonly store: MemoryStore;
|
|
84
148
|
/**
|
|
85
149
|
* Embedder used for the read-side query. Pass the SAME embedder
|
|
86
|
-
* instance (or one with the same `
|
|
87
|
-
* — cross-model similarity scores are not comparable.
|
|
150
|
+
* instance (or one with the same `embedderId`) that was used for
|
|
151
|
+
* indexing — cross-model similarity scores are not comparable.
|
|
88
152
|
*/
|
|
89
153
|
readonly embedder: Embedder;
|
|
90
154
|
/**
|
|
@@ -93,10 +157,28 @@ export interface DefineRAGOptions {
|
|
|
93
157
|
* embedder swap doesn't pollute results.
|
|
94
158
|
*/
|
|
95
159
|
readonly embedderId?: string;
|
|
160
|
+
/**
|
|
161
|
+
* The namespace this corpus lives in. Default
|
|
162
|
+
* `{ conversationId: '_global' }` — the same default `indexDocuments`
|
|
163
|
+
* writes to, so the plain path needs no argument on either side.
|
|
164
|
+
*
|
|
165
|
+
* A corpus is deliberately NOT scoped to the run's identity: it is
|
|
166
|
+
* shared by every conversation, and reading it under a per-run
|
|
167
|
+
* conversation id is the bug this default fixes.
|
|
168
|
+
*
|
|
169
|
+
* **Multi-tenant:** pass the tenant's identity here AND the same one to
|
|
170
|
+
* `indexDocuments({ identity })`. A namespace that holds nothing is now
|
|
171
|
+
* reported (`corpusEmpty` on `agentfootprint.memory.retrieved`, plus a
|
|
172
|
+
* one-time warning naming the namespace), so a mismatch is loud rather
|
|
173
|
+
* than an empty answer.
|
|
174
|
+
*/
|
|
175
|
+
readonly corpus?: MemoryIdentity;
|
|
96
176
|
/**
|
|
97
177
|
* Top-K chunks to retrieve per turn. Default 3 (balanced —
|
|
98
178
|
* defends against lost-in-the-middle while giving multiple
|
|
99
179
|
* perspectives). Increase for richer context, decrease for cost.
|
|
180
|
+
*
|
|
181
|
+
* Shorthand for `retrieval: topK({ k })`; the two EXCLUDE.
|
|
100
182
|
*/
|
|
101
183
|
readonly topK?: number;
|
|
102
184
|
/**
|
|
@@ -106,12 +188,29 @@ export interface DefineRAGOptions {
|
|
|
106
188
|
*
|
|
107
189
|
* Tuning note: 0.7 is a high bar for some embedders. Sentence-BERT
|
|
108
190
|
* relatives (`all-MiniLM-L6-v2`, etc.) often score 0.4–0.6 even on
|
|
109
|
-
* relevant chunks.
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
191
|
+
* relevant chunks. You no longer have to guess: the rejected
|
|
192
|
+
* candidates and their scores are on every
|
|
193
|
+
* `agentfootprint.memory.retrieved` event, so the right threshold is
|
|
194
|
+
* a number you can read off a run.
|
|
195
|
+
*
|
|
196
|
+
* Shorthand for `retrieval: topK({ threshold })`; the two EXCLUDE.
|
|
113
197
|
*/
|
|
114
198
|
readonly threshold?: number;
|
|
199
|
+
/**
|
|
200
|
+
* The retrieval rule, spelled out. Replaces `topK` + `threshold`
|
|
201
|
+
* entirely — passing both is refused, because they could disagree
|
|
202
|
+
* and the recording would then name a `k` the run did not use.
|
|
203
|
+
*
|
|
204
|
+
* ```ts
|
|
205
|
+
* import { topK } from 'agentfootprint/memory';
|
|
206
|
+
* defineRAG({ id, store, embedder, retrieval: topK({ k: 5, threshold: 0.55 }) });
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* A cross-encoder re-ranker and a diversity (MMR) selector are the
|
|
210
|
+
* next two adapters behind this same interface; neither ships in
|
|
211
|
+
* 8.8.0, and the seam exists so that when they do, nothing else moves.
|
|
212
|
+
*/
|
|
213
|
+
readonly retrieval?: RetrievalStrategy;
|
|
115
214
|
}
|
|
116
215
|
/**
|
|
117
216
|
* Build a RAG context-engineering definition. The returned
|
|
@@ -120,6 +219,7 @@ export interface DefineRAGOptions {
|
|
|
120
219
|
*
|
|
121
220
|
* @throws when `store` does not implement `search()`. RAG requires a
|
|
122
221
|
* vector-capable adapter.
|
|
222
|
+
* @throws when `retrieval` is combined with `topK` or `threshold`.
|
|
123
223
|
*/
|
|
124
224
|
export declare function defineRAG(opts: DefineRAGOptions): MemoryDefinition;
|
|
125
225
|
//# sourceMappingURL=defineRAG.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineRAG.d.ts","sourceRoot":"","sources":["../../../../src/lib/rag/defineRAG.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"defineRAG.d.ts","sourceRoot":"","sources":["../../../../src/lib/rag/defineRAG.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsHG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAKzE;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,EAAE,cAA8C,CAAC;AAErF,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAE5B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC;IAEjC;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAE5B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAUxC;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,gBAAgB,CA0DlE"}
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* flavor. ONE factory + ONE seeding helper. Composes over the memory
|
|
4
4
|
* subsystem (semantic + top-K + strict threshold).
|
|
5
5
|
*/
|
|
6
|
-
export { defineRAG, type DefineRAGOptions } from './defineRAG.js';
|
|
6
|
+
export { defineRAG, DEFAULT_CORPUS_IDENTITY, type DefineRAGOptions } from './defineRAG.js';
|
|
7
7
|
export { indexDocuments, type IndexDocumentsOptions, type RagDocument } from './indexDocuments.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/rag/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/rag/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../../src/memory/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAaH,OAAO,EAIL,KAAK,mBAAmB,EAYzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAInF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,gBAAgB,
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../../src/memory/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAaH,OAAO,EAIL,KAAK,mBAAmB,EAYzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAInF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,gBAAgB,CA4B3E;AAkTD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,OAAO,CAErF"}
|
|
@@ -41,6 +41,8 @@
|
|
|
41
41
|
import type { LLMProvider } from '../adapters/types.js';
|
|
42
42
|
import type { Embedder } from './embedding/index.js';
|
|
43
43
|
import type { MemoryStore } from './store/index.js';
|
|
44
|
+
import type { MemoryIdentity } from './identity/index.js';
|
|
45
|
+
import type { RetrievalStrategy } from './retrieval/types.js';
|
|
44
46
|
/**
|
|
45
47
|
* What shape of memory you're keeping.
|
|
46
48
|
*
|
|
@@ -152,12 +154,44 @@ export interface SummarizeStrategy {
|
|
|
152
154
|
* STRICT threshold: when no entry meets the threshold, return EMPTY.
|
|
153
155
|
* No fallback — garbage in context is worse than no memory.
|
|
154
156
|
*/
|
|
155
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Top-K retrieval, in either of its two spellings — and never both.
|
|
159
|
+
*
|
|
160
|
+
* The arms EXCLUDE (8.8.0). `{ topK, threshold }` is the shorthand;
|
|
161
|
+
* `{ retrieval }` is the same rule written as a {@link RetrievalStrategy},
|
|
162
|
+
* which is also how a different rule gets in. Accepting both would mean
|
|
163
|
+
* one of two `k`s silently loses and the recording would name a `k` the
|
|
164
|
+
* run did not use — so the type refuses it at the keystroke, and
|
|
165
|
+
* `defineMemory` refuses it again at runtime for JavaScript callers.
|
|
166
|
+
*/
|
|
167
|
+
export type TopKStrategy = TopKShorthandStrategy | TopKRetrievalStrategy;
|
|
168
|
+
/** The historical spelling: two loose numbers. Unchanged since 2.x. */
|
|
169
|
+
export interface TopKShorthandStrategy {
|
|
156
170
|
readonly kind: typeof MEMORY_STRATEGIES.TOP_K;
|
|
157
171
|
readonly topK: number;
|
|
158
172
|
/** Min cosine similarity. Strict — no fallback below this. Default 0.7. */
|
|
159
173
|
readonly threshold?: number;
|
|
160
174
|
readonly embedder: Embedder;
|
|
175
|
+
/**
|
|
176
|
+
* Stable id of the embedder, filtered against `MemoryEntry.embeddingModel`
|
|
177
|
+
* at search time so a later embedder swap cannot silently mix two vector
|
|
178
|
+
* spaces. Pair it with the same value passed to `indexDocuments`.
|
|
179
|
+
*
|
|
180
|
+
* Wired in 8.8.0. `defineRAG` has accepted an `embedderId` since 7.x and
|
|
181
|
+
* never forwarded it — an option the run did not read.
|
|
182
|
+
*/
|
|
183
|
+
readonly embedderId?: string;
|
|
184
|
+
readonly retrieval?: never;
|
|
185
|
+
}
|
|
186
|
+
/** The spelled-out rule (8.8.0) — and the seam a re-ranker will arrive through. */
|
|
187
|
+
export interface TopKRetrievalStrategy {
|
|
188
|
+
readonly kind: typeof MEMORY_STRATEGIES.TOP_K;
|
|
189
|
+
readonly embedder: Embedder;
|
|
190
|
+
readonly retrieval: RetrievalStrategy;
|
|
191
|
+
/** See {@link TopKShorthandStrategy.embedderId}. */
|
|
192
|
+
readonly embedderId?: string;
|
|
193
|
+
readonly topK?: never;
|
|
194
|
+
readonly threshold?: never;
|
|
161
195
|
}
|
|
162
196
|
/**
|
|
163
197
|
* Extract — on WRITE, an LLM (or pattern matcher) distills entries from
|
|
@@ -234,7 +268,34 @@ export interface MemoryDefinition<T = unknown> {
|
|
|
234
268
|
readonly redact?: MemoryRedactionPolicy;
|
|
235
269
|
/** Snapshot projection — only meaningful when `type === CAUSAL`. */
|
|
236
270
|
readonly projection?: SnapshotProjection;
|
|
271
|
+
/**
|
|
272
|
+
* The namespace this memory reads and writes (8.8.0).
|
|
273
|
+
*
|
|
274
|
+
* Absent — the historical behaviour, and still the right one for
|
|
275
|
+
* conversation memory — means "whatever identity the run was given",
|
|
276
|
+
* so each conversation remembers its own turns.
|
|
277
|
+
*
|
|
278
|
+
* Present means "always this namespace, whoever is asking", which is
|
|
279
|
+
* what a shared document corpus is: a corpus does not belong to a
|
|
280
|
+
* conversation, and reading it under a per-run conversation id is why
|
|
281
|
+
* `defineRAG`'s own documented example retrieved nothing at all before
|
|
282
|
+
* 8.8.0. `defineRAG` defaults it to `{ conversationId: '_global' }`,
|
|
283
|
+
* matching `indexDocuments`'s default so the two sides meet.
|
|
284
|
+
*/
|
|
285
|
+
readonly corpus?: MemoryIdentity;
|
|
286
|
+
/**
|
|
287
|
+
* Which claim this memory's injected block makes (8.8.0). `'memory'`
|
|
288
|
+
* is conversation recall; `'rag'` is corpus retrieval, and it is the
|
|
289
|
+
* value that reaches the recording as `ContextInjectedPayload.source`.
|
|
290
|
+
*
|
|
291
|
+
* The event vocabulary has carried a `'rag'` source since 2.x and
|
|
292
|
+
* nothing ever emitted it — a declared value no run can produce is a
|
|
293
|
+
* gap in the contract, not a spare.
|
|
294
|
+
*/
|
|
295
|
+
readonly flavor?: MemoryFlavor;
|
|
237
296
|
}
|
|
297
|
+
/** What an injected memory block is claiming to be. */
|
|
298
|
+
export type MemoryFlavor = 'memory' | 'rag';
|
|
238
299
|
/**
|
|
239
300
|
* Opaque tag for the compiled flowchart the factory hands back.
|
|
240
301
|
* The actual type is `FlowChart<MemoryState>` from footprintjs but we
|
|
@@ -256,6 +317,23 @@ export interface DefineMemoryOptionsBase {
|
|
|
256
317
|
readonly strategy: Strategy;
|
|
257
318
|
readonly timing?: MemoryTiming;
|
|
258
319
|
readonly redact?: MemoryRedactionPolicy;
|
|
320
|
+
/**
|
|
321
|
+
* Read and write under THIS namespace instead of the run's identity
|
|
322
|
+
* (8.8.0). See {@link MemoryDefinition.corpus}.
|
|
323
|
+
*/
|
|
324
|
+
readonly corpus?: MemoryIdentity;
|
|
325
|
+
/**
|
|
326
|
+
* Build a read-only memory (8.8.0): no write subflow is compiled, so
|
|
327
|
+
* nothing this memory sees is ever stored back.
|
|
328
|
+
*
|
|
329
|
+
* The reason it exists: a retrieval corpus and a conversation log are
|
|
330
|
+
* two different things sharing one pipeline. Writing the conversation
|
|
331
|
+
* into the corpus makes the user's own question the best-scoring
|
|
332
|
+
* "document" in it. `defineRAG` sets this.
|
|
333
|
+
*/
|
|
334
|
+
readonly readOnly?: boolean;
|
|
335
|
+
/** Which claim the injected block makes. See {@link MemoryDefinition.flavor}. */
|
|
336
|
+
readonly flavor?: MemoryFlavor;
|
|
259
337
|
}
|
|
260
338
|
export interface DefineEpisodicOptions extends DefineMemoryOptionsBase {
|
|
261
339
|
readonly type: typeof MEMORY_TYPES.EPISODIC;
|
|
@@ -286,4 +364,18 @@ export declare function isSnapshotProjection(value: string): value is SnapshotPr
|
|
|
286
364
|
export declare const MEMORY_INJECTION_KEY_PREFIX: "memoryInjection_";
|
|
287
365
|
export declare function memoryInjectionKey(id: string): string;
|
|
288
366
|
export declare function isMemoryInjectionKey(key: string): boolean;
|
|
367
|
+
/**
|
|
368
|
+
* Scope-key prefix for the retrieval record a memory lifts to the parent
|
|
369
|
+
* scope (8.8.0), one key per memory id — the same layering rule as
|
|
370
|
+
* `memoryInjection_`.
|
|
371
|
+
*
|
|
372
|
+
* This key is the reason a backward slice can now reach a passage. It is
|
|
373
|
+
* ORDINARY root state, so `sliceForKey('finalContent')` walks the
|
|
374
|
+
* system-prompt write, and the record naming every candidate id and score
|
|
375
|
+
* is one hop away. Before 8.8.0 the scores existed only inside the memory
|
|
376
|
+
* subflow, which the root commit log never sees.
|
|
377
|
+
*/
|
|
378
|
+
export declare const RETRIEVAL_EVIDENCE_KEY_PREFIX: "retrievalEvidence_";
|
|
379
|
+
export declare function retrievalEvidenceKey(id: string): string;
|
|
380
|
+
export declare function isRetrievalEvidenceKey(key: string): boolean;
|
|
289
381
|
//# sourceMappingURL=define.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.types.d.ts","sourceRoot":"","sources":["../../../src/memory/define.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MA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;AAID;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,oBAA8B,CAAC;AAEvE,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,6BAA6B,sBAAgC,CAAC;AAE3E,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3D"}
|
|
@@ -1,29 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* loadRelevant — read-side stage that embeds a query and fetches the
|
|
3
|
-
*
|
|
3
|
+
* most similar entries from a vector-capable `MemoryStore`.
|
|
4
4
|
*
|
|
5
|
-
* Reads from scope: `identity`, `
|
|
6
|
-
* Writes to scope: `loaded` (MemoryEntry[], ordered best-first —
|
|
7
|
-
*
|
|
5
|
+
* Reads from scope: `identity`, `messages` (or `newMessages`, or custom queryFrom)
|
|
6
|
+
* Writes to scope: `loaded` (MemoryEntry[], ordered best-first — narrowed
|
|
7
|
+
* by `pickByBudget` downstream)
|
|
8
|
+
* `retrieved` (RetrievalEvidence — what was considered,
|
|
9
|
+
* what was admitted, and why about each one)
|
|
8
10
|
*
|
|
9
11
|
* Query derivation:
|
|
10
|
-
* Default: the last user message
|
|
11
|
-
*
|
|
12
|
-
* for custom retrieval (e.g., compose user + assistant content,
|
|
13
|
-
* pull a summary, etc.).
|
|
12
|
+
* Default: the last user message. That's the natural "what is the user
|
|
13
|
+
* asking about?" signal. Override with `queryFrom` for custom retrieval.
|
|
14
14
|
*
|
|
15
15
|
* Empty behavior:
|
|
16
|
-
* No query text → no search → `loaded = []`. Downstream
|
|
17
|
-
*
|
|
16
|
+
* No query text → no search → `loaded = []`. Downstream `pickByBudget`
|
|
17
|
+
* picks nothing and the formatter emits nothing — safe, and now
|
|
18
|
+
* RECORDED: the evidence still lands, saying the query was empty.
|
|
18
19
|
*
|
|
19
20
|
* Feature detection:
|
|
20
|
-
* Throws at stage build time if the store doesn't implement
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* Throws at stage build time if the store doesn't implement `search()`.
|
|
22
|
+
* Fail-loud — a semantic pipeline configured against a non-vector store
|
|
23
|
+
* is a config bug, not a runtime condition.
|
|
24
|
+
*
|
|
25
|
+
* ─── Why the threshold moved out of the store (8.8.0) ──────────────────
|
|
26
|
+
*
|
|
27
|
+
* Until 8.8.0 the quality floor was passed to `store.search({ minScore })`,
|
|
28
|
+
* so every candidate that failed it was filtered INSIDE the store and never
|
|
29
|
+
* came back. The consequence was not a small one: a retrieval that injected
|
|
30
|
+
* nothing left no trace of what it nearly injected, and "why did the agent
|
|
31
|
+
* not read that passage" had no answer anywhere in the recording.
|
|
32
|
+
*
|
|
33
|
+
* The floor is now applied here, over a pool of `k + rejectWindow`. **This
|
|
34
|
+
* does not change which entries are admitted, ever.** Proof: `search`
|
|
35
|
+
* returns score-descending, and the pool is at least `k`. Either
|
|
36
|
+
*
|
|
37
|
+
* (a) every entry in the pool clears the floor — then the admitted set is
|
|
38
|
+
* the first `k` of them, which is exactly what `{ minScore, k }` would
|
|
39
|
+
* have returned; or
|
|
40
|
+
* (b) some entry at position p fails the floor — then every entry after p
|
|
41
|
+
* fails it too, so the pool already contains EVERY entry in the
|
|
42
|
+
* namespace that clears the floor, and admitting all of them (capped
|
|
43
|
+
* at `k`) is again exactly what `{ minScore, k }` would have returned.
|
|
44
|
+
*
|
|
45
|
+
* `rejectWindow` therefore only controls how many near-misses we can SHOW.
|
|
46
|
+
* It cannot change what the model sees.
|
|
23
47
|
*/
|
|
24
48
|
import type { TypedScope } from 'footprintjs';
|
|
25
49
|
import type { MemoryStore } from '../store/index.js';
|
|
26
50
|
import type { MemoryState } from '../stages/index.js';
|
|
51
|
+
import type { RetrievalStrategy } from '../retrieval/types.js';
|
|
27
52
|
import type { Embedder } from './types.js';
|
|
28
53
|
export interface LoadRelevantConfig {
|
|
29
54
|
/** The vector-capable store. Must implement `search()`. */
|
|
@@ -43,10 +68,19 @@ export interface LoadRelevantConfig {
|
|
|
43
68
|
/** Filter results by tier. */
|
|
44
69
|
readonly tiers?: ReadonlyArray<'hot' | 'warm' | 'cold'>;
|
|
45
70
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
71
|
+
* The rule that decides which candidates reach the prompt. Defaults to
|
|
72
|
+
* `topK({ k, threshold: minScore })` — i.e. `k` and `minScore` above are
|
|
73
|
+
* the shorthand, and this is the same rule spelled out. Pass a strategy
|
|
74
|
+
* to replace the rule entirely.
|
|
75
|
+
*/
|
|
76
|
+
readonly retrieval?: RetrievalStrategy;
|
|
77
|
+
/**
|
|
78
|
+
* Extract the query text from scope. Default: the last user message.
|
|
79
|
+
* Override for custom retrieval signals.
|
|
48
80
|
*/
|
|
49
81
|
readonly queryFrom?: (scope: TypedScope<MemoryState>) => string;
|
|
50
82
|
}
|
|
51
83
|
export declare function loadRelevant(config: LoadRelevantConfig): (scope: TypedScope<MemoryState>) => Promise<void>;
|
|
84
|
+
/** Test seam — the once-per-process warning is per PROCESS, which tests must be able to reset. */
|
|
85
|
+
export declare function __resetEmptyCorpusWarnings(): void;
|
|
52
86
|
//# sourceMappingURL=loadRelevant.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadRelevant.d.ts","sourceRoot":"","sources":["../../../../src/memory/embedding/loadRelevant.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loadRelevant.d.ts","sourceRoot":"","sources":["../../../../src/memory/embedding/loadRelevant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKtD,OAAO,KAAK,EAEV,iBAAiB,EAGlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAE5B,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B,4EAA4E;IAC5E,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;IAEpB,uEAAuE;IACvE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;IAExD;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAEvC;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,MAAM,CAAC;CACjE;AA8BD,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,WAuBhC,WAAW,WAAW,CAAC,KAAG,QAAQ,IAAI,CAAC,CAgI7D;AAkBD,kGAAkG;AAClG,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD"}
|
|
@@ -15,7 +15,8 @@ export * from './pipeline/index.js';
|
|
|
15
15
|
export * from './stages/index.js';
|
|
16
16
|
export * from './store/index.js';
|
|
17
17
|
export * from './wire/index.js';
|
|
18
|
-
export
|
|
18
|
+
export * from './retrieval/index.js';
|
|
19
|
+
export { MEMORY_TYPES, MEMORY_STRATEGIES, MEMORY_TIMING, SNAPSHOT_PROJECTIONS, MEMORY_INJECTION_KEY_PREFIX, RETRIEVAL_EVIDENCE_KEY_PREFIX, isMemoryType, isMemoryStrategyKind, isMemoryTiming, isSnapshotProjection, memoryInjectionKey, isMemoryInjectionKey, retrievalEvidenceKey, isRetrievalEvidenceKey, type MemoryType, type MemoryStrategyKind, type MemoryTiming, type SnapshotProjection, type Strategy, type MemoryWindowStrategy, type BudgetStrategy, type SummarizeStrategy, type TopKStrategy, type TopKShorthandStrategy, type TopKRetrievalStrategy, type MemoryFlavor, type ExtractStrategy, type DecayStrategy, type HybridStrategy, type MemoryDefinition, type DefineMemoryOptions, type DefineEpisodicOptions, type DefineSemanticOptions, type DefineNarrativeOptions, type DefineCausalOptions, type MemoryRedactionPolicy, } from './define.types.js';
|
|
19
20
|
/**
|
|
20
21
|
* @deprecated Since 7.27.1 — use `MemoryWindowStrategy`.
|
|
21
22
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AAGrC,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,GAC3B,MAAM,mBAAmB,CAAC;AAC3B;;;;;;;;GAQG;AACH,YAAY,EAAE,oBAAoB,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type MemoryFormatFlavor } from '../stages/formatDefault.js';
|
|
2
|
+
import type { RetrievalStrategy } from '../retrieval/types.js';
|
|
1
3
|
import type { MemoryStore } from '../store/index.js';
|
|
2
4
|
import type { MemoryPipeline } from './types.js';
|
|
3
5
|
import type { Embedder } from '../embedding/types.js';
|
|
@@ -29,6 +31,19 @@ export interface SemanticPipelineConfig {
|
|
|
29
31
|
/** Forwarded to `formatDefault`. */
|
|
30
32
|
readonly formatHeader?: string;
|
|
31
33
|
readonly formatFooter?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The retrieval rule (8.8.0). Replaces `k` + `minScore` above; see
|
|
36
|
+
* {@link RetrievalStrategy}. When absent, `topK({ k, threshold: minScore })`
|
|
37
|
+
* is built from those two — the same rule, spelled the old way.
|
|
38
|
+
*/
|
|
39
|
+
readonly retrieval?: RetrievalStrategy;
|
|
40
|
+
/**
|
|
41
|
+
* Which claim the injected block makes (8.8.0). `'rag'` renders each
|
|
42
|
+
* entry as a citable `<source>` with its document, page and score;
|
|
43
|
+
* `'memory'` (default) keeps the conversation-recall `<memory>` shape
|
|
44
|
+
* byte for byte.
|
|
45
|
+
*/
|
|
46
|
+
readonly flavor?: MemoryFormatFlavor;
|
|
32
47
|
}
|
|
33
48
|
/**
|
|
34
49
|
* Build the semantic read + write pipelines sharing a single store.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../../../../src/memory/pipeline/semantic.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../../../../src/memory/pipeline/semantic.ts"],"names":[],"mappings":"AAwCA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAQjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,WAAW,sBAAsB;IACrC,uDAAuD;IACvD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAE5B,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B,8EAA8E;IAC9E,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;IAEpB,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAE3B,iCAAiC;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;IAExD,+BAA+B;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;IAE7C,oDAAoD;IACpD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B,mCAAmC;IACnC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B,oCAAoC;IACpC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAEvC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC;CACtC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,cAAc,CAsE/E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memory/retrieval — what a retrieval considered, and the seam that
|
|
3
|
+
* decides what it keeps.
|
|
4
|
+
*
|
|
5
|
+
* @see ./types.ts the record + the strategy interface
|
|
6
|
+
* @see ./topK.ts the strategy 8.7.0 had, now written down as one
|
|
7
|
+
*/
|
|
8
|
+
export type { RetrievalEvidence, RetrievalRejectReason, RetrievalStrategy, RetrievalVerdict, RetrievedCandidate, ScoredCandidate, } from './types.js';
|
|
9
|
+
export { topK, type TopKOptions } from './topK.js';
|
|
10
|
+
export { chunkProvenance, chunkText, type ChunkProvenance } from './provenance.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/memory/retrieval/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,YAAY,EACV,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* provenance — read a stored entry's coordinates back out of it.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: pure projection.
|
|
5
|
+
* Role: memory/ layer. One place that knows which metadata keys mean
|
|
6
|
+
* "which document", "which page", "which section", so the
|
|
7
|
+
* retrieval record and the citation the model sees can never
|
|
8
|
+
* disagree about a chunk's origin.
|
|
9
|
+
* Emits: N/A.
|
|
10
|
+
*
|
|
11
|
+
* The keys are the ones `indexDocuments` already accepts on
|
|
12
|
+
* `RagDocument.metadata`, and the ones a document splitter will write.
|
|
13
|
+
* Nothing is invented: an entry that carries no metadata simply has no
|
|
14
|
+
* coordinates, and the record says so by omitting the fields rather than
|
|
15
|
+
* by guessing a filename from an id.
|
|
16
|
+
*/
|
|
17
|
+
/** The document coordinates a chunk can carry. All optional — absence is honest. */
|
|
18
|
+
export interface ChunkProvenance {
|
|
19
|
+
/** Which document this text came from. Read from `docUri`, else `source`. */
|
|
20
|
+
readonly docUri?: string;
|
|
21
|
+
/** Which page, for paginated formats. */
|
|
22
|
+
readonly page?: number;
|
|
23
|
+
/** Which section heading the splitter cut under. */
|
|
24
|
+
readonly heading?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Pull the coordinates out of a stored value.
|
|
28
|
+
*
|
|
29
|
+
* Accepts metadata at the value's `metadata` key (where `indexDocuments`
|
|
30
|
+
* puts it) or directly on the value, so a hand-built entry works too.
|
|
31
|
+
*/
|
|
32
|
+
export declare function chunkProvenance(value: unknown): ChunkProvenance;
|
|
33
|
+
/**
|
|
34
|
+
* The text a stored value carries.
|
|
35
|
+
*
|
|
36
|
+
* Two shapes reach the formatter through the same pipeline: a chat
|
|
37
|
+
* `Message` (`{ role, content }`) from conversation memory, and a
|
|
38
|
+
* document (`{ id, content, metadata }`) from `indexDocuments`. Both
|
|
39
|
+
* keep their text on `content`, which is why one accessor serves both —
|
|
40
|
+
* but only the message shape has a meaningful `role`, which is why the
|
|
41
|
+
* corpus formatter does not print one.
|
|
42
|
+
*/
|
|
43
|
+
export declare function chunkText(value: unknown): string;
|
|
44
|
+
//# sourceMappingURL=provenance.d.ts.map
|