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
|
@@ -65,14 +65,21 @@ import { MEMORY_TYPES, MEMORY_STRATEGIES, MEMORY_TIMING, } from './define.types.
|
|
|
65
65
|
export function defineMemory(options) {
|
|
66
66
|
validate(options);
|
|
67
67
|
const pipeline = buildPipeline(options);
|
|
68
|
+
// `readOnly` drops the write half entirely (8.8.0). Not "writes are
|
|
69
|
+
// skipped at runtime" — the subflow is never compiled and never mounted,
|
|
70
|
+
// so a read-only memory has no write stage in its chart, no write commit
|
|
71
|
+
// in its log, and nothing to disable later by accident.
|
|
72
|
+
const write = options.readOnly === true ? undefined : pipeline.write;
|
|
68
73
|
const definition = {
|
|
69
74
|
id: options.id,
|
|
70
75
|
...(options.description !== undefined && { description: options.description }),
|
|
71
76
|
type: options.type,
|
|
72
77
|
read: brandPipeline(pipeline.read),
|
|
73
|
-
...(
|
|
78
|
+
...(write !== undefined && { write: brandPipeline(write) }),
|
|
74
79
|
timing: options.timing ?? MEMORY_TIMING.TURN_START,
|
|
75
80
|
...(options.redact !== undefined && { redact: options.redact }),
|
|
81
|
+
...(options.corpus !== undefined && { corpus: options.corpus }),
|
|
82
|
+
...(options.flavor !== undefined && { flavor: options.flavor }),
|
|
76
83
|
...(options.type === MEMORY_TYPES.CAUSAL &&
|
|
77
84
|
options.projection !== undefined && {
|
|
78
85
|
projection: options.projection,
|
|
@@ -93,6 +100,26 @@ function validate(options) {
|
|
|
93
100
|
throw new Error(`defineMemory[id=${options.id}]: \`store\` is required. ` +
|
|
94
101
|
'Pass `new InMemoryStore()` for dev/tests, or a backed store for production.');
|
|
95
102
|
}
|
|
103
|
+
// The shorthand and the spelled-out rule EXCLUDE. Accepting both would
|
|
104
|
+
// mean one of two numbers silently loses, and the recording would name
|
|
105
|
+
// a `k` the run did not use.
|
|
106
|
+
// Read through a structural shape, not the union: the union's arms
|
|
107
|
+
// declare the OTHER spelling as `never`, so intersecting them here
|
|
108
|
+
// would make the very field this check reads unreadable.
|
|
109
|
+
const strategy = options.strategy;
|
|
110
|
+
if (strategy?.retrieval !== undefined) {
|
|
111
|
+
const shorthand = [];
|
|
112
|
+
if (strategy.topK !== undefined)
|
|
113
|
+
shorthand.push('`topK`');
|
|
114
|
+
if (strategy.threshold !== undefined)
|
|
115
|
+
shorthand.push('`threshold`');
|
|
116
|
+
if (shorthand.length > 0) {
|
|
117
|
+
throw new Error(`defineMemory[id=${options.id}]: ${shorthand.join(' and ')} cannot be combined with ` +
|
|
118
|
+
'`retrieval` — they are two spellings of the same rule and could disagree. ' +
|
|
119
|
+
`Keep the strategy (\`retrieval: ${strategy.retrieval.name}({ ... })\`) and drop ` +
|
|
120
|
+
`${shorthand.join('/')}, or drop \`retrieval\`.`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
96
123
|
}
|
|
97
124
|
// ─── Pipeline dispatch ─────────────────────────────────────────────
|
|
98
125
|
function buildPipeline(options) {
|
|
@@ -177,8 +204,11 @@ function buildSemanticPipeline(options) {
|
|
|
177
204
|
const config = {
|
|
178
205
|
store: options.store,
|
|
179
206
|
embedder: t.embedder,
|
|
180
|
-
k: t.topK,
|
|
207
|
+
...(t.topK !== undefined && { k: t.topK }),
|
|
181
208
|
...(t.threshold !== undefined && { minScore: t.threshold }),
|
|
209
|
+
...(t.embedderId !== undefined && { embedderId: t.embedderId }),
|
|
210
|
+
...(t.retrieval !== undefined && { retrieval: t.retrieval }),
|
|
211
|
+
...(options.flavor !== undefined && { flavor: options.flavor }),
|
|
182
212
|
};
|
|
183
213
|
return semanticPipeline(config);
|
|
184
214
|
}
|
|
@@ -268,6 +298,12 @@ function buildCausalPipeline(options) {
|
|
|
268
298
|
'Pass `new InMemoryStore({ embedder })` for dev/tests, or a vector adapter ' +
|
|
269
299
|
'(pgvector, Pinecone, Qdrant) for production.');
|
|
270
300
|
}
|
|
301
|
+
// CAUSAL predates the retrieval seam and reads the shorthand only. A
|
|
302
|
+
// strategy passed here would be accepted and ignored, so it is refused.
|
|
303
|
+
if (s.retrieval !== undefined) {
|
|
304
|
+
throw new Error(`defineMemory[${options.id}]: CAUSAL type does not read \`retrieval\` — snapshot recall ` +
|
|
305
|
+
'matches a stored query vector, not a document pool. Use `topK` + `threshold`.');
|
|
306
|
+
}
|
|
271
307
|
const config = {
|
|
272
308
|
store: options.store,
|
|
273
309
|
embedder: s.embedder,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../../src/memory/define.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,eAAe,EAA8B,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAA+B,MAAM,wBAAwB,CAAC;AACvF,OAAO,EAAE,YAAY,EAA2B,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAgC,M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K,EAAE,OAAO,CAAC,KAAK;QACpB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,GAAG,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;QAC3D,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;KAC5E,CAAC;IACF,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,sEAAsE;AAEtE;;;;GAIG;AACH,SAAS,aAAa,CAAI,EAAW;IACnC,OAAO,EAAgC,CAAC;AAC1C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAI,OAAmC;IAC1E,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,kEAAkE;AAClE,sDAAsD;AACtD,KAAK,iBAAiB,CAAC;AACvB,iEAAiE;AACjE,KAAM,IAA4B,CAAC"}
|
|
@@ -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,3 +364,17 @@ 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;
|
|
@@ -126,4 +126,22 @@ export function memoryInjectionKey(id) {
|
|
|
126
126
|
export function isMemoryInjectionKey(key) {
|
|
127
127
|
return key.startsWith(MEMORY_INJECTION_KEY_PREFIX);
|
|
128
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Scope-key prefix for the retrieval record a memory lifts to the parent
|
|
131
|
+
* scope (8.8.0), one key per memory id — the same layering rule as
|
|
132
|
+
* `memoryInjection_`.
|
|
133
|
+
*
|
|
134
|
+
* This key is the reason a backward slice can now reach a passage. It is
|
|
135
|
+
* ORDINARY root state, so `sliceForKey('finalContent')` walks the
|
|
136
|
+
* system-prompt write, and the record naming every candidate id and score
|
|
137
|
+
* is one hop away. Before 8.8.0 the scores existed only inside the memory
|
|
138
|
+
* subflow, which the root commit log never sees.
|
|
139
|
+
*/
|
|
140
|
+
export const RETRIEVAL_EVIDENCE_KEY_PREFIX = 'retrievalEvidence_';
|
|
141
|
+
export function retrievalEvidenceKey(id) {
|
|
142
|
+
return `${RETRIEVAL_EVIDENCE_KEY_PREFIX}${id}`;
|
|
143
|
+
}
|
|
144
|
+
export function isRetrievalEvidenceKey(key) {
|
|
145
|
+
return key.startsWith(RETRIEVAL_EVIDENCE_KEY_PREFIX);
|
|
146
|
+
}
|
|
129
147
|
//# sourceMappingURL=define.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define.types.js","sourceRoot":"","sources":["../../../src/memory/define.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;
|
|
1
|
+
{"version":3,"file":"define.types.js","sourceRoot":"","sources":["../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AAU,oBAAoB,CAAC,KAAa;IAChD,OAAQ,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED,uEAAuE;AAEvE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,kBAA2B,CAAC;AAEvE,MAAM,UAAU,kBAAkB,CAAC,EAAU;IAC3C,OAAO,GAAG,2BAA2B,GAAG,EAAE,EAAE,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,OAAO,GAAG,CAAC,UAAU,CAAC,2BAA2B,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,oBAA6B,CAAC;AAE3E,MAAM,UAAU,oBAAoB,CAAC,EAAU;IAC7C,OAAO,GAAG,6BAA6B,GAAG,EAAE,EAAE,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAW;IAChD,OAAO,GAAG,CAAC,UAAU,CAAC,6BAA6B,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -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,9 +68,18 @@ 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;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { identityNamespace } from '../identity/index.js';
|
|
2
|
+
import { fnv1a } from '../../lib/fnv1a.js';
|
|
3
|
+
import { chunkProvenance } from '../retrieval/provenance.js';
|
|
4
|
+
import { topK } from '../retrieval/topK.js';
|
|
1
5
|
/**
|
|
2
6
|
* Default query extractor — last user message.
|
|
3
7
|
*
|
|
@@ -19,6 +23,12 @@ function defaultQueryFrom(scope) {
|
|
|
19
23
|
}
|
|
20
24
|
return '';
|
|
21
25
|
}
|
|
26
|
+
/** Emit through the scope's emit channel when there is one (there always is under an Agent). */
|
|
27
|
+
function emit(scope, type, payload) {
|
|
28
|
+
const emitter = scope.$emit;
|
|
29
|
+
if (typeof emitter === 'function')
|
|
30
|
+
emitter.call(scope, type, payload);
|
|
31
|
+
}
|
|
22
32
|
export function loadRelevant(config) {
|
|
23
33
|
const { store, embedder } = config;
|
|
24
34
|
if (!store.search) {
|
|
@@ -26,12 +36,43 @@ export function loadRelevant(config) {
|
|
|
26
36
|
'Use a vector-capable adapter (InMemoryStore, pgvector, Pinecone, ...).');
|
|
27
37
|
}
|
|
28
38
|
const queryFrom = config.queryFrom ?? defaultQueryFrom;
|
|
29
|
-
|
|
39
|
+
// The shorthand and the strategy are two spellings of one rule; the
|
|
40
|
+
// strategy wins when both are present, and `defineMemory` refuses the
|
|
41
|
+
// contradiction before it ever gets here.
|
|
42
|
+
const strategy = config.retrieval ??
|
|
43
|
+
topK({
|
|
44
|
+
k: config.k ?? 20,
|
|
45
|
+
threshold: config.minScore === undefined ? null : config.minScore,
|
|
46
|
+
// With no explicit strategy there is no explicit reject window
|
|
47
|
+
// either; 10 near-misses is enough to diagnose a threshold without
|
|
48
|
+
// making every retrieval read a large page.
|
|
49
|
+
});
|
|
50
|
+
const poolSize = strategy.k + strategy.rejectWindow;
|
|
30
51
|
return async (scope) => {
|
|
31
52
|
const identity = scope.identity;
|
|
53
|
+
const namespace = identityNamespace(identity);
|
|
32
54
|
const text = queryFrom(scope).trim();
|
|
55
|
+
const baseEvidence = {
|
|
56
|
+
queryHash: fnv1a(text),
|
|
57
|
+
k: strategy.k,
|
|
58
|
+
...(strategy.threshold !== undefined && { threshold: strategy.threshold }),
|
|
59
|
+
...(config.embedderId !== undefined && { embedderId: config.embedderId }),
|
|
60
|
+
selectionOrder: 'recency',
|
|
61
|
+
namespace,
|
|
62
|
+
};
|
|
33
63
|
if (text.length === 0) {
|
|
34
64
|
scope.loaded = [];
|
|
65
|
+
const emptyQuery = {
|
|
66
|
+
...baseEvidence,
|
|
67
|
+
consideredCount: 0,
|
|
68
|
+
admittedCount: 0,
|
|
69
|
+
rejectedCount: 0,
|
|
70
|
+
candidates: [],
|
|
71
|
+
candidatesComplete: true,
|
|
72
|
+
// The corpus was never asked, so it cannot be reported empty.
|
|
73
|
+
corpusEmpty: false,
|
|
74
|
+
};
|
|
75
|
+
scope.retrieved = emptyQuery;
|
|
35
76
|
return;
|
|
36
77
|
}
|
|
37
78
|
const signal = scope.$getEnv?.()?.signal;
|
|
@@ -42,15 +83,103 @@ export function loadRelevant(config) {
|
|
|
42
83
|
// store.search optional on MemoryStore but required when an embedder
|
|
43
84
|
// is configured (validated upstream by defineMemory).
|
|
44
85
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
45
|
-
const results = await store.search(identity, queryVec, {
|
|
46
|
-
k,
|
|
47
|
-
|
|
86
|
+
const results = (await store.search(identity, queryVec, {
|
|
87
|
+
k: poolSize,
|
|
88
|
+
// `minScore` is deliberately NOT forwarded — see the header proof.
|
|
48
89
|
...(config.tiers && { tiers: config.tiers }),
|
|
49
90
|
...(config.embedderId !== undefined && { embedderId: config.embedderId }),
|
|
91
|
+
text,
|
|
92
|
+
}));
|
|
93
|
+
// A store that ranks server-side may return entries without a usable
|
|
94
|
+
// score. We report that rather than printing a number we did not get.
|
|
95
|
+
const scoresUsable = results.every((r) => typeof r.score === 'number' && Number.isFinite(r.score));
|
|
96
|
+
const verdicts = scoresUsable
|
|
97
|
+
? strategy.select(results.map((r) => ({ entry: r.entry, score: r.score })))
|
|
98
|
+
: // No comparable scores to rule on. The store already ranked, so we
|
|
99
|
+
// honour its order and take the first `k` — and say in the record
|
|
100
|
+
// that we could not see the candidates ourselves.
|
|
101
|
+
results.map((_, i) => ({ admitted: i < strategy.k }));
|
|
102
|
+
const admitted = [];
|
|
103
|
+
const candidates = [];
|
|
104
|
+
results.forEach((result, i) => {
|
|
105
|
+
// `verdicts` is built from `results` above, one per element.
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
107
|
+
const verdict = verdicts[i];
|
|
108
|
+
if (verdict.admitted)
|
|
109
|
+
admitted.push(result);
|
|
110
|
+
candidates.push({
|
|
111
|
+
id: result.entry.id,
|
|
112
|
+
score: result.score,
|
|
113
|
+
rank: i + 1,
|
|
114
|
+
admitted: verdict.admitted,
|
|
115
|
+
...(verdict.reason !== undefined && { reason: verdict.reason }),
|
|
116
|
+
...chunkProvenance(result.entry.value),
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
const evidence = {
|
|
120
|
+
...baseEvidence,
|
|
121
|
+
...(queryVec.length > 0 && { dimensions: queryVec.length }),
|
|
122
|
+
consideredCount: results.length,
|
|
123
|
+
admittedCount: admitted.length,
|
|
124
|
+
rejectedCount: results.length - admitted.length,
|
|
125
|
+
...(scoresUsable
|
|
126
|
+
? { candidates }
|
|
127
|
+
: {
|
|
128
|
+
candidatesOmittedReason: 'the store ranked this query server-side and returned no comparable scores',
|
|
129
|
+
}),
|
|
130
|
+
// The pool came back full, so there may be further below-threshold
|
|
131
|
+
// entries we never saw. This never weakens the ADMITTED set (see
|
|
132
|
+
// the header proof) — only the rejected list is a sample.
|
|
133
|
+
candidatesComplete: results.length < poolSize,
|
|
134
|
+
corpusEmpty: results.length === 0,
|
|
135
|
+
};
|
|
136
|
+
scope.loaded = admitted.map((r) => r.entry);
|
|
137
|
+
scope.retrieved = evidence;
|
|
138
|
+
// Telemetry rides the emit channel, never a commit payload. The
|
|
139
|
+
// memory bridge (`memoryRecorder`) is attached on every Agent run, so
|
|
140
|
+
// this reaches `agent.on('agentfootprint.memory.retrieved')` with no
|
|
141
|
+
// extra wiring. Which retriever fired is `meta.runtimeStageId`
|
|
142
|
+
// (`sf-memory-read-<id>/load-relevant#N`) — the house correlation model.
|
|
143
|
+
emit(scope, 'agentfootprint.memory.retrieved', {
|
|
144
|
+
queryHash: evidence.queryHash,
|
|
145
|
+
k: evidence.k,
|
|
146
|
+
...(evidence.threshold !== undefined && { threshold: evidence.threshold }),
|
|
147
|
+
...(evidence.embedderId !== undefined && { embedderId: evidence.embedderId }),
|
|
148
|
+
...(evidence.dimensions !== undefined && { dimensions: evidence.dimensions }),
|
|
149
|
+
consideredCount: evidence.consideredCount,
|
|
150
|
+
admittedCount: evidence.admittedCount,
|
|
151
|
+
rejectedCount: evidence.rejectedCount,
|
|
152
|
+
...(evidence.candidates !== undefined && { candidates: evidence.candidates }),
|
|
153
|
+
...(evidence.candidatesOmittedReason !== undefined && {
|
|
154
|
+
candidatesOmittedReason: evidence.candidatesOmittedReason,
|
|
155
|
+
}),
|
|
156
|
+
candidatesComplete: evidence.candidatesComplete,
|
|
157
|
+
corpusEmpty: evidence.corpusEmpty,
|
|
158
|
+
namespace: evidence.namespace,
|
|
50
159
|
});
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
|
|
160
|
+
// An empty namespace is almost never "the corpus has nothing to say".
|
|
161
|
+
// It is almost always "the corpus was indexed under a different
|
|
162
|
+
// identity than the one being queried" — the failure that used to be
|
|
163
|
+
// completely silent. Say it once per process, naming both sides.
|
|
164
|
+
if (evidence.corpusEmpty)
|
|
165
|
+
warnEmptyCorpus(namespace);
|
|
54
166
|
};
|
|
55
167
|
}
|
|
168
|
+
const warnedNamespaces = new Set();
|
|
169
|
+
function warnEmptyCorpus(namespace) {
|
|
170
|
+
if (warnedNamespaces.has(namespace))
|
|
171
|
+
return;
|
|
172
|
+
warnedNamespaces.add(namespace);
|
|
173
|
+
console.warn(`[agentfootprint] Semantic retrieval found NO entries at all in namespace '${namespace}'.\n` +
|
|
174
|
+
` Nothing was injected, and the answer will come from the model alone.\n` +
|
|
175
|
+
` The usual cause is that the corpus was indexed under a different identity than the one\n` +
|
|
176
|
+
` being queried: indexDocuments() defaults to { conversationId: '_global' }, and a memory\n` +
|
|
177
|
+
` reads under the identity passed to agent.run() unless the retriever declares its own\n` +
|
|
178
|
+
` \`corpus\`. defineRAG() defaults \`corpus\` to { conversationId: '_global' } so the two\n` +
|
|
179
|
+
` sides meet; pass \`corpus\` explicitly when you index per tenant.`);
|
|
180
|
+
}
|
|
181
|
+
/** Test seam — the once-per-process warning is per PROCESS, which tests must be able to reset. */
|
|
182
|
+
export function __resetEmptyCorpusWarnings() {
|
|
183
|
+
warnedNamespaces.clear();
|
|
184
|
+
}
|
|
56
185
|
//# sourceMappingURL=loadRelevant.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadRelevant.js","sourceRoot":"","sources":["../../../../src/memory/embedding/loadRelevant.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadRelevant.js","sourceRoot":"","sources":["../../../../src/memory/embedding/loadRelevant.ts"],"names":[],"mappings":"AAmDA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AA+C5C;;;;;;;GAOG;AACH,SAAS,gBAAgB,CAAC,KAA8B;IACtD,MAAM,QAAQ,GAAG,KAAqD,CAAC;IACvE,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC;IACzC,MAAM,MAAM,GACV,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAE,CAAC,KAAK,CAAC,WAAW,IAAI,EAAE,CAAwB,CAAC;IAErF,KAAK,IAAI,CAAC,GAAG,MA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SAAS,eAAe,CAAC,SAAiB;IACxC,IAAI,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC;QAAE,OAAO;IAC5C,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,IAAI,CACV,6EAA6E,SAAS,MAAM;QAC1F,0EAA0E;QAC1E,4FAA4F;QAC5F,6FAA6F;QAC7F,0FAA0F;QAC1F,6FAA6F;QAC7F,qEAAqE,CACxE,CAAC;AACJ,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,0BAA0B;IACxC,gBAAgB,CAAC,KAAK,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -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
|
*
|
package/dist/esm/memory/index.js
CHANGED
|
@@ -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 * from './retrieval/index.js';
|
|
18
19
|
// Consumer-facing factory + const-objects for memory configuration.
|
|
19
|
-
export { MEMORY_TYPES, MEMORY_STRATEGIES, MEMORY_TIMING, SNAPSHOT_PROJECTIONS, MEMORY_INJECTION_KEY_PREFIX, isMemoryType, isMemoryStrategyKind, isMemoryTiming, isSnapshotProjection, memoryInjectionKey, isMemoryInjectionKey, } from './define.types.js';
|
|
20
|
+
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, } from './define.types.js';
|
|
20
21
|
export { defineMemory } from './define.js';
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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.js","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;AAErC,oEAAoE;AACpE,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,GAuBvB,MAAM,mBAAmB,CAAC;AAY3B,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.
|