agentfootprint 8.19.0 → 8.20.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/bin/agentfootprint-index.mjs +28 -3
- package/dist/esm/lib/rag/defineRAG.d.ts +9 -6
- package/dist/esm/lib/rag/defineRAG.js.map +1 -1
- package/dist/esm/memory/retrieval/topK.d.ts +12 -6
- package/dist/esm/memory/retrieval/topK.js.map +1 -1
- package/dist/esm/memory/store/index.d.ts +1 -0
- package/dist/esm/memory/store/index.js +1 -0
- package/dist/esm/memory/store/index.js.map +1 -1
- package/dist/esm/memory/store/staticVectorStore.d.ts +83 -0
- package/dist/esm/memory/store/staticVectorStore.js +224 -0
- package/dist/esm/memory/store/staticVectorStore.js.map +1 -0
- package/dist/esm/observe.d.ts +1 -0
- package/dist/esm/observe.js +5 -0
- package/dist/esm/observe.js.map +1 -1
- package/dist/esm/rag/exportCorpus.d.ts +64 -0
- package/dist/esm/rag/exportCorpus.js +172 -0
- package/dist/esm/rag/exportCorpus.js.map +1 -0
- package/dist/esm/rag/index.d.ts +3 -1
- package/dist/esm/rag/index.js +8 -1
- package/dist/esm/rag/index.js.map +1 -1
- package/dist/esm/rag/splitters/byHeading.d.ts +39 -0
- package/dist/esm/rag/splitters/byHeading.js +133 -15
- package/dist/esm/rag/splitters/byHeading.js.map +1 -1
- package/dist/esm/rag/splitters/byParagraph.d.ts +14 -0
- package/dist/esm/rag/splitters/byParagraph.js +4 -2
- package/dist/esm/rag/splitters/byParagraph.js.map +1 -1
- package/dist/esm/rag/splitters/constants.d.ts +24 -1
- package/dist/esm/rag/splitters/constants.js +24 -1
- package/dist/esm/rag/splitters/constants.js.map +1 -1
- package/dist/esm/rag/splitters/index.d.ts +15 -1
- package/dist/esm/rag/splitters/index.js +15 -1
- package/dist/esm/rag/splitters/index.js.map +1 -1
- package/dist/esm/rag/splitters/shared.d.ts +32 -0
- package/dist/esm/rag/splitters/shared.js +77 -1
- package/dist/esm/rag/splitters/shared.js.map +1 -1
- package/dist/esm/recorders/observability/BoundaryRecorder.d.ts +24 -0
- package/dist/esm/recorders/observability/BoundaryRecorder.js +19 -6
- package/dist/esm/recorders/observability/BoundaryRecorder.js.map +1 -1
- package/dist/esm/recorders/observability/embeddingSummary.d.ts +56 -0
- package/dist/esm/recorders/observability/embeddingSummary.js +114 -0
- package/dist/esm/recorders/observability/embeddingSummary.js.map +1 -0
- package/dist/esm/recorders/observability/recordRun.d.ts +16 -0
- package/dist/esm/recorders/observability/recordRun.js +17 -3
- package/dist/esm/recorders/observability/recordRun.js.map +1 -1
- package/dist/lib/rag/defineRAG.js.map +1 -1
- package/dist/memory/retrieval/topK.js.map +1 -1
- package/dist/memory/store/index.js +6 -1
- package/dist/memory/store/index.js.map +1 -1
- package/dist/memory/store/staticVectorStore.js +230 -0
- package/dist/memory/store/staticVectorStore.js.map +1 -0
- package/dist/observe.js +8 -1
- package/dist/observe.js.map +1 -1
- package/dist/rag/exportCorpus.js +177 -0
- package/dist/rag/exportCorpus.js.map +1 -0
- package/dist/rag/index.js +13 -1
- package/dist/rag/index.js.map +1 -1
- package/dist/rag/splitters/byHeading.js +132 -14
- package/dist/rag/splitters/byHeading.js.map +1 -1
- package/dist/rag/splitters/byParagraph.js +3 -1
- package/dist/rag/splitters/byParagraph.js.map +1 -1
- package/dist/rag/splitters/constants.js +25 -2
- package/dist/rag/splitters/constants.js.map +1 -1
- package/dist/rag/splitters/index.js +16 -1
- package/dist/rag/splitters/index.js.map +1 -1
- package/dist/rag/splitters/shared.js +79 -1
- package/dist/rag/splitters/shared.js.map +1 -1
- package/dist/recorders/observability/BoundaryRecorder.js +19 -6
- package/dist/recorders/observability/BoundaryRecorder.js.map +1 -1
- package/dist/recorders/observability/embeddingSummary.js +119 -0
- package/dist/recorders/observability/embeddingSummary.js.map +1 -0
- package/dist/recorders/observability/recordRun.js +17 -3
- package/dist/recorders/observability/recordRun.js.map +1 -1
- package/dist/types/lib/rag/defineRAG.d.ts +9 -6
- package/dist/types/lib/rag/defineRAG.d.ts.map +1 -1
- package/dist/types/memory/retrieval/topK.d.ts +12 -6
- package/dist/types/memory/retrieval/topK.d.ts.map +1 -1
- package/dist/types/memory/store/index.d.ts +1 -0
- package/dist/types/memory/store/index.d.ts.map +1 -1
- package/dist/types/memory/store/staticVectorStore.d.ts +84 -0
- package/dist/types/memory/store/staticVectorStore.d.ts.map +1 -0
- package/dist/types/observe.d.ts +1 -0
- package/dist/types/observe.d.ts.map +1 -1
- package/dist/types/rag/exportCorpus.d.ts +65 -0
- package/dist/types/rag/exportCorpus.d.ts.map +1 -0
- package/dist/types/rag/index.d.ts +3 -1
- package/dist/types/rag/index.d.ts.map +1 -1
- package/dist/types/rag/splitters/byHeading.d.ts +39 -0
- package/dist/types/rag/splitters/byHeading.d.ts.map +1 -1
- package/dist/types/rag/splitters/byParagraph.d.ts +14 -0
- package/dist/types/rag/splitters/byParagraph.d.ts.map +1 -1
- package/dist/types/rag/splitters/constants.d.ts +24 -1
- package/dist/types/rag/splitters/constants.d.ts.map +1 -1
- package/dist/types/rag/splitters/index.d.ts +15 -1
- package/dist/types/rag/splitters/index.d.ts.map +1 -1
- package/dist/types/rag/splitters/shared.d.ts +32 -0
- package/dist/types/rag/splitters/shared.d.ts.map +1 -1
- package/dist/types/recorders/observability/BoundaryRecorder.d.ts +24 -0
- package/dist/types/recorders/observability/BoundaryRecorder.d.ts.map +1 -1
- package/dist/types/recorders/observability/embeddingSummary.d.ts +57 -0
- package/dist/types/recorders/observability/embeddingSummary.d.ts.map +1 -0
- package/dist/types/recorders/observability/recordRun.d.ts +16 -0
- package/dist/types/recorders/observability/recordRun.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -26,11 +26,15 @@ const USAGE = `
|
|
|
26
26
|
agentfootprint-index — build a corpus index
|
|
27
27
|
|
|
28
28
|
USAGE
|
|
29
|
-
agentfootprint-index <dir> --to <file.db> [options]
|
|
29
|
+
agentfootprint-index <dir> --to <file.db|file.json> [options]
|
|
30
30
|
|
|
31
31
|
REQUIRED
|
|
32
32
|
<dir> Directory of documents to index
|
|
33
33
|
--to <file.db> SQLite index file (created if missing)
|
|
34
|
+
--to <file.json> Corpus BUNDLE instead: index in memory, export a
|
|
35
|
+
plain-JSON artifact for staticVectorStore() — the
|
|
36
|
+
build-time half of serving a corpus on a runtime
|
|
37
|
+
with no durable disk
|
|
34
38
|
|
|
35
39
|
OPTIONS
|
|
36
40
|
--embedder <name> static (default) | local | openai | mock
|
|
@@ -53,6 +57,7 @@ EXAMPLES
|
|
|
53
57
|
agentfootprint-index ./docs --to ./corpus.db
|
|
54
58
|
agentfootprint-index ./docs --to ./corpus.db --embedder local --chars 800
|
|
55
59
|
agentfootprint-index ./docs --to ./corpus.db --dry-run --json
|
|
60
|
+
agentfootprint-index ./docs --to ./corpus.json --embedder local
|
|
56
61
|
`;
|
|
57
62
|
|
|
58
63
|
function fail(message) {
|
|
@@ -100,7 +105,7 @@ if (!values.to && !values['dry-run']) {
|
|
|
100
105
|
|
|
101
106
|
// Imported through the package's own entry points, so the CLI exercises the
|
|
102
107
|
// same doors a consumer does — a break in the export map fails here too.
|
|
103
|
-
const { indexCorpus } = await import('../dist/esm/doors/rag.js');
|
|
108
|
+
const { indexCorpus, exportCorpus } = await import('../dist/esm/doors/rag.js');
|
|
104
109
|
const { byHeading, byParagraph, fixedWithOverlap, wholeDocument } = await import(
|
|
105
110
|
'../dist/esm/doors/rag.js'
|
|
106
111
|
);
|
|
@@ -143,10 +148,18 @@ try {
|
|
|
143
148
|
fail(err instanceof Error ? err.message : String(err));
|
|
144
149
|
}
|
|
145
150
|
|
|
151
|
+
// A `.json` target builds a corpus BUNDLE: index into a throwaway in-memory
|
|
152
|
+
// store, export with exportCorpus, write one plain-JSON artifact for
|
|
153
|
+
// staticVectorStore() to serve on a runtime with no durable disk.
|
|
154
|
+
const jsonTarget = !values['dry-run'] && values.to !== undefined && values.to.endsWith('.json');
|
|
155
|
+
|
|
146
156
|
// --dry-run writes to a throwaway in-memory index, so it reports real chunk
|
|
147
157
|
// counts and real splitting without touching the file. It still EMBEDS —
|
|
148
158
|
// the alternative is reporting a count that the real run might not match.
|
|
149
|
-
const store =
|
|
159
|
+
const store =
|
|
160
|
+
values['dry-run'] || jsonTarget
|
|
161
|
+
? new InMemoryStore()
|
|
162
|
+
: sqliteVectorStore({ file: resolve(values.to) });
|
|
150
163
|
|
|
151
164
|
try {
|
|
152
165
|
const report = await indexCorpus({
|
|
@@ -162,6 +175,18 @@ try {
|
|
|
162
175
|
...(values.corpus && { corpus: { conversationId: values.corpus } }),
|
|
163
176
|
});
|
|
164
177
|
|
|
178
|
+
if (jsonTarget) {
|
|
179
|
+
const { writeFileSync } = await import('node:fs');
|
|
180
|
+
const target = resolve(values.to);
|
|
181
|
+
const bundle = await exportCorpus(store, values.corpus ? { conversationId: values.corpus } : undefined);
|
|
182
|
+
writeFileSync(target, JSON.stringify(bundle));
|
|
183
|
+
process.stdout.write(
|
|
184
|
+
`wrote corpus bundle: ${target} — ${bundle.entries.length} entries, ` +
|
|
185
|
+
`'${bundle.embedder.id}@${bundle.embedder.dimensions}'. Serve it with ` +
|
|
186
|
+
`staticVectorStore(JSON.parse(readFileSync(...)), embedder).\n`,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
165
190
|
if (values.json) {
|
|
166
191
|
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
167
192
|
} else {
|
|
@@ -186,12 +186,15 @@ export interface DefineRAGOptions {
|
|
|
186
186
|
* meets the threshold, NO injection happens (no fallback that would
|
|
187
187
|
* pollute the prompt with weak matches). Default 0.7.
|
|
188
188
|
*
|
|
189
|
-
* Tuning note:
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
189
|
+
* Tuning note: the right threshold is a property of the EMBEDDER. 0.7
|
|
190
|
+
* is a high bar for some of them. Sentence-BERT relatives
|
|
191
|
+
* (`all-MiniLM-L6-v2`, etc.) often score 0.4–0.6 even on relevant
|
|
192
|
+
* chunks; Amazon Titan Text V2 was field-measured at 0.55–0.57 for a
|
|
193
|
+
* direct hit, ~0.49 for the right section diluted, 0.36–0.42 for
|
|
194
|
+
* noise — on that embedder the 0.7 default retrieves NOTHING,
|
|
195
|
+
* silently. You no longer have to guess: the rejected candidates and
|
|
196
|
+
* their scores are on every `agentfootprint.memory.retrieved` event,
|
|
197
|
+
* so the right threshold is a number you can read off a run.
|
|
195
198
|
*
|
|
196
199
|
* Shorthand for `retrieval: topK({ threshold })`; the two EXCLUDE.
|
|
197
200
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineRAG.js","sourceRoot":"","sources":["../../../../src/lib/rag/defineRAG.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsHG;AAOH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAmB,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"defineRAG.js","sourceRoot":"","sources":["../../../../src/lib/rag/defineRAG.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsHG;AAOH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC/E,OAAO,EAAE,YA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CAAC;aAChE;YACH,CAAC,CAAC;gBACE,IAAI,EAAE,iBAAiB,CAAC,KAAK;gBAC7B,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC;gBACpB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,GAAG;gBAChC,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;gBACrE,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;aAChE;QACP,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,uDAAuD;QACvD,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,uBAAuB;QAC9C,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -31,13 +31,19 @@ export interface TopKOptions {
|
|
|
31
31
|
* Minimum similarity to admit, in the store's score space ([-1, 1]
|
|
32
32
|
* cosine for every shipped store). Default 0.7.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* **The right threshold is a property of the EMBEDDER, not of this
|
|
35
|
+
* library.** 0.7 is a high bar for some embedders. Sentence-transformer
|
|
36
|
+
* relatives (`all-MiniLM-L6-v2` and family, which `localEmbedder` uses by
|
|
36
37
|
* default) often score 0.4–0.6 on genuinely relevant chunks; OpenAI
|
|
37
|
-
* `text-embedding-3-*` sits comfortably at 0.7.
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
38
|
+
* `text-embedding-3-*` sits comfortably at 0.7. Amazon Titan Text V2
|
|
39
|
+
* (`bedrockEmbedder`'s default) was measured in a production corpus at
|
|
40
|
+
* 0.55–0.57 for a direct hit, ~0.49 for the right section diluted by its
|
|
41
|
+
* neighbours, and 0.36–0.42 for noise — **on that embedder the 0.7
|
|
42
|
+
* default retrieves NOTHING, silently**; ~0.5 separates its signal from
|
|
43
|
+
* its noise. If retrievals come back empty, read the
|
|
44
|
+
* `agentfootprint.memory.retrieved` event: it carries the rejected
|
|
45
|
+
* candidates and their scores, so the right threshold is a number you
|
|
46
|
+
* can see rather than one you guess.
|
|
41
47
|
*
|
|
42
48
|
* Pass `null` for no floor — every candidate up to `k` is admitted.
|
|
43
49
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topK.js","sourceRoot":"","sources":["../../../../src/memory/retrieval/topK.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"topK.js","sourceRoot":"","sources":["../../../../src/memory/retrieval/topK.ts"],"names":[],"mappings":"AA2DA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,IAAI,CAAC,UAAuB,EAAE;IAC5C,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;IACzB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,qDAAqD,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC7F,CAAC;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;IAChD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,KAAK,CACb,oEAAoE,MAAM,CACxE,OAAO,CAAC,YAAY,CACrB,GAAG,CACL,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,IAAI,GAAG,CAAC;IACpF,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CACb,kEAAkE,MAAM,CACtE,OAAO,CAAC,SAAS,CAClB,GAAG,CACL,CAAC;IACJ,CAAC;IAED,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,CAAC;QACD,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC;QAC7C,YAAY;QACZ,MAAM,CAAC,IAAgC;YACrC,MAAM,QAAQ,GAAuB,EAAE,CAAC;YACxC,IAAI,QAAQ,GAAG,CAAC,CAAC;YACjB,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE,CAAC;gBAC7B,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,CAAC,KAAK,GAAG,SAAS,EAAE,CAAC;oBAC3D,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAC;oBAC9D,SAAS;gBACX,CAAC;gBACD,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;oBAClB,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC;oBAC/D,SAAS;gBACX,CAAC;gBACD,QAAQ,IAAI,CAAC,CAAC;gBACd,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;YACpC,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export type { MemoryStore, ListOptions, ListResult, MemoryCursor, PutIfVersionResult, SearchOptions, ScoredEntry, } from './types.js';
|
|
2
2
|
export { InMemoryStore } from './InMemoryStore.js';
|
|
3
|
+
export { staticVectorStore, assertCorpusBundle, bundleEntryToMemoryEntry, CORPUS_BUNDLE_FORMAT, type CorpusBundle, type CorpusBundleEntry, type EmbedderFingerprint, } from './staticVectorStore.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/memory/store/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/memory/store/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,GAIrB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { MemoryEntry } from '../entry/index.js';
|
|
2
|
+
import type { MemoryStore } from './types.js';
|
|
3
|
+
/** The bundle format marker. Version the FORMAT, not the library. */
|
|
4
|
+
export declare const CORPUS_BUNDLE_FORMAT: "agentfootprint-corpus-v1";
|
|
5
|
+
/** One exported corpus entry: the passage, its vector, and its coordinates. */
|
|
6
|
+
export interface CorpusBundleEntry {
|
|
7
|
+
/** The chunk id, e.g. `'refunds.md#3'` — what the model cites. */
|
|
8
|
+
readonly id: string;
|
|
9
|
+
/** The passage text. */
|
|
10
|
+
readonly text: string;
|
|
11
|
+
/** The embedding vector, in the bundle embedder's space. */
|
|
12
|
+
readonly vector: readonly number[];
|
|
13
|
+
/**
|
|
14
|
+
* Everything else the stored value carried — provenance (`docUri`,
|
|
15
|
+
* `heading`, `page`, offsets, hashes) and any consumer metadata, flattened
|
|
16
|
+
* into one record the retrieval formatter's provenance reader understands.
|
|
17
|
+
*/
|
|
18
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A corpus as a plain-JSON build artifact. Produced by `exportCorpus`
|
|
22
|
+
* (`agentfootprint/rag`), served by {@link staticVectorStore}, loadable into a
|
|
23
|
+
* writable store by `importCorpus`. Survives `JSON.stringify` → `JSON.parse`
|
|
24
|
+
* byte-for-byte, which is the whole point.
|
|
25
|
+
*/
|
|
26
|
+
export interface CorpusBundle {
|
|
27
|
+
readonly format: typeof CORPUS_BUNDLE_FORMAT;
|
|
28
|
+
/** The embedding space every vector in `entries` lives in. */
|
|
29
|
+
readonly embedder: {
|
|
30
|
+
/** The embedder id recorded at index time (`'default-embedder'` when the index never named one). */
|
|
31
|
+
readonly id: string;
|
|
32
|
+
/** Vector length. Every entry's vector has exactly this many numbers. */
|
|
33
|
+
readonly dimensions: number;
|
|
34
|
+
};
|
|
35
|
+
/** The namespace the corpus was exported from (`identityNamespace` form). */
|
|
36
|
+
readonly namespace: string;
|
|
37
|
+
/** Unix ms at export time. */
|
|
38
|
+
readonly exportedAt: number;
|
|
39
|
+
readonly entries: readonly CorpusBundleEntry[];
|
|
40
|
+
}
|
|
41
|
+
/** The embedder-shaped slice the load-time fingerprint check needs. */
|
|
42
|
+
export interface EmbedderFingerprint {
|
|
43
|
+
readonly id?: string;
|
|
44
|
+
readonly dimensions: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validate a value as a `CorpusBundle`, teachingly. Shared by
|
|
48
|
+
* `staticVectorStore` and `importCorpus`, so a truncated file or a
|
|
49
|
+
* hand-edited bundle fails the same way at every door.
|
|
50
|
+
*/
|
|
51
|
+
export declare function assertCorpusBundle(bundle: unknown, caller: string): asserts bundle is CorpusBundle;
|
|
52
|
+
/**
|
|
53
|
+
* The `MemoryEntry` a bundle entry seeds — in the exact shape the retrieval
|
|
54
|
+
* formatter reads: passage on `value.content`, provenance under
|
|
55
|
+
* `value.metadata`. Shared with `importCorpus` so a static corpus and an
|
|
56
|
+
* imported one render identically.
|
|
57
|
+
*/
|
|
58
|
+
export declare function bundleEntryToMemoryEntry(entry: CorpusBundleEntry, bundle: CorpusBundle): MemoryEntry<{
|
|
59
|
+
id: string;
|
|
60
|
+
content: string;
|
|
61
|
+
metadata?: Record<string, unknown>;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Serve an exported corpus bundle as a read-only, vector-capable
|
|
65
|
+
* `MemoryStore`.
|
|
66
|
+
*
|
|
67
|
+
* @param bundle a `CorpusBundle` from `exportCorpus` (usually
|
|
68
|
+
* `JSON.parse` of the shipped file).
|
|
69
|
+
* @param embedder optional — the embedder the RUNTIME will query with (or
|
|
70
|
+
* just `{ id, dimensions }`). When given, a fingerprint
|
|
71
|
+
* mismatch is refused HERE, at load, instead of surfacing as
|
|
72
|
+
* an empty retrieval at the first question. Recommended.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { staticVectorStore } from 'agentfootprint/memory';
|
|
77
|
+
* import corpus from './corpus.json';
|
|
78
|
+
*
|
|
79
|
+
* const store = staticVectorStore(corpus, embedder);
|
|
80
|
+
* const docs = defineRAG({ id: 'docs', store, embedder });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function staticVectorStore(bundle: CorpusBundle, embedder?: EmbedderFingerprint): MemoryStore;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { identityNamespace } from '../identity/index.js';
|
|
2
|
+
import { cosineSimilarity } from '../embedding/cosine.js';
|
|
3
|
+
/** The bundle format marker. Version the FORMAT, not the library. */
|
|
4
|
+
export const CORPUS_BUNDLE_FORMAT = 'agentfootprint-corpus-v1';
|
|
5
|
+
/**
|
|
6
|
+
* Validate a value as a `CorpusBundle`, teachingly. Shared by
|
|
7
|
+
* `staticVectorStore` and `importCorpus`, so a truncated file or a
|
|
8
|
+
* hand-edited bundle fails the same way at every door.
|
|
9
|
+
*/
|
|
10
|
+
export function assertCorpusBundle(bundle, caller) {
|
|
11
|
+
const b = bundle;
|
|
12
|
+
if (b === null || typeof b !== 'object') {
|
|
13
|
+
throw new Error(`${caller}: expected a corpus bundle object, received ${b === null ? 'null' : typeof b}. ` +
|
|
14
|
+
`A bundle comes from exportCorpus() — typically JSON.parse of the file it was saved to.`);
|
|
15
|
+
}
|
|
16
|
+
if (b.format !== CORPUS_BUNDLE_FORMAT) {
|
|
17
|
+
throw new Error(`${caller}: this is not a corpus bundle — \`format\` is ${JSON.stringify(b.format)}, expected '${CORPUS_BUNDLE_FORMAT}'. Bundles are produced by exportCorpus(); a raw ` +
|
|
18
|
+
`entries array or a different artifact cannot be served as one.`);
|
|
19
|
+
}
|
|
20
|
+
const dims = b.embedder?.dimensions;
|
|
21
|
+
if (typeof b.embedder?.id !== 'string' || typeof dims !== 'number' || dims < 1) {
|
|
22
|
+
throw new Error(`${caller}: the bundle does not name its embedding space — \`embedder\` must carry a ` +
|
|
23
|
+
`string \`id\` and a positive \`dimensions\`. Without them nothing can refuse a wrong ` +
|
|
24
|
+
`embedder at load, which is the silent failure this format exists to prevent.`);
|
|
25
|
+
}
|
|
26
|
+
if (typeof b.namespace !== 'string' || b.namespace.length === 0) {
|
|
27
|
+
throw new Error(`${caller}: the bundle carries no \`namespace\`. Re-export with exportCorpus().`);
|
|
28
|
+
}
|
|
29
|
+
if (!Array.isArray(b.entries)) {
|
|
30
|
+
throw new Error(`${caller}: \`entries\` must be an array. Re-export with exportCorpus().`);
|
|
31
|
+
}
|
|
32
|
+
b.entries.forEach((entry, i) => {
|
|
33
|
+
const where = `entries[${i}]${entry?.id ? ` ('${entry.id}')` : ''}`;
|
|
34
|
+
if (!entry || typeof entry.id !== 'string' || entry.id.length === 0) {
|
|
35
|
+
throw new Error(`${caller}: ${where} has no \`id\`.`);
|
|
36
|
+
}
|
|
37
|
+
if (typeof entry.text !== 'string' || entry.text.trim().length === 0) {
|
|
38
|
+
throw new Error(`${caller}: ${where} has no passage on \`text\`. A citable id with nothing to cite is ` +
|
|
39
|
+
`the blank-citation bug; a bundle never carries one.`);
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(entry.vector) || entry.vector.length !== dims) {
|
|
42
|
+
throw new Error(`${caller}: ${where} carries a vector of length ` +
|
|
43
|
+
`${Array.isArray(entry.vector) ? entry.vector.length : 'none'}, but the bundle's ` +
|
|
44
|
+
`embedder declares ${dims} dimensions. The bundle is corrupt or hand-edited — ` +
|
|
45
|
+
`re-export it.`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The `MemoryEntry` a bundle entry seeds — in the exact shape the retrieval
|
|
51
|
+
* formatter reads: passage on `value.content`, provenance under
|
|
52
|
+
* `value.metadata`. Shared with `importCorpus` so a static corpus and an
|
|
53
|
+
* imported one render identically.
|
|
54
|
+
*/
|
|
55
|
+
export function bundleEntryToMemoryEntry(entry, bundle) {
|
|
56
|
+
return {
|
|
57
|
+
id: entry.id,
|
|
58
|
+
value: {
|
|
59
|
+
id: entry.id,
|
|
60
|
+
content: entry.text,
|
|
61
|
+
...(entry.metadata !== undefined && { metadata: { ...entry.metadata } }),
|
|
62
|
+
},
|
|
63
|
+
version: 1,
|
|
64
|
+
createdAt: bundle.exportedAt,
|
|
65
|
+
updatedAt: bundle.exportedAt,
|
|
66
|
+
lastAccessedAt: bundle.exportedAt,
|
|
67
|
+
accessCount: 0,
|
|
68
|
+
embedding: [...entry.vector],
|
|
69
|
+
embeddingModel: bundle.embedder.id,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const READ_ONLY_FIX = `A static corpus is a build artifact: change it by re-indexing at build time and ` +
|
|
73
|
+
`re-exporting (exportCorpus), or load the bundle into a writable store with ` +
|
|
74
|
+
`importCorpus(store, bundle). For conversation memory alongside a static corpus, ` +
|
|
75
|
+
`register a SEPARATE defineMemory with its own writable store.`;
|
|
76
|
+
function refuseWrite(method) {
|
|
77
|
+
throw new Error(`staticVectorStore.${method}: this store is read-only — accepting the write and losing ` +
|
|
78
|
+
`it with the process would be the quiet version of data loss. ${READ_ONLY_FIX}`);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Serve an exported corpus bundle as a read-only, vector-capable
|
|
82
|
+
* `MemoryStore`.
|
|
83
|
+
*
|
|
84
|
+
* @param bundle a `CorpusBundle` from `exportCorpus` (usually
|
|
85
|
+
* `JSON.parse` of the shipped file).
|
|
86
|
+
* @param embedder optional — the embedder the RUNTIME will query with (or
|
|
87
|
+
* just `{ id, dimensions }`). When given, a fingerprint
|
|
88
|
+
* mismatch is refused HERE, at load, instead of surfacing as
|
|
89
|
+
* an empty retrieval at the first question. Recommended.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { staticVectorStore } from 'agentfootprint/memory';
|
|
94
|
+
* import corpus from './corpus.json';
|
|
95
|
+
*
|
|
96
|
+
* const store = staticVectorStore(corpus, embedder);
|
|
97
|
+
* const docs = defineRAG({ id: 'docs', store, embedder });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export function staticVectorStore(bundle, embedder) {
|
|
101
|
+
assertCorpusBundle(bundle, 'staticVectorStore');
|
|
102
|
+
if (embedder !== undefined) {
|
|
103
|
+
// The sqliteVectorStore rule, applied at load: dimensions ALWAYS decide;
|
|
104
|
+
// ids decide only when both sides named themselves.
|
|
105
|
+
if (embedder.dimensions !== bundle.embedder.dimensions) {
|
|
106
|
+
throw new Error(`staticVectorStore: this bundle was built in '${bundle.embedder.id}@` +
|
|
107
|
+
`${bundle.embedder.dimensions}' and the configured embedder produces ` +
|
|
108
|
+
`${embedder.dimensions}-dimensional vectors. Vectors of different lengths cannot ` +
|
|
109
|
+
`be compared at all. Re-export the corpus with the runtime's embedder, or ` +
|
|
110
|
+
`configure the embedder the corpus was built with.`);
|
|
111
|
+
}
|
|
112
|
+
if (embedder.id !== undefined && embedder.id !== bundle.embedder.id) {
|
|
113
|
+
throw new Error(`staticVectorStore: this bundle was built in '${bundle.embedder.id}@` +
|
|
114
|
+
`${bundle.embedder.dimensions}' and the configured embedder is '${embedder.id}'. ` +
|
|
115
|
+
`Cosine similarity between two embedding spaces is not a weak signal — it is not ` +
|
|
116
|
+
`a signal, and it comes back as a confident number in the same range as a real ` +
|
|
117
|
+
`one. Re-export the corpus with '${embedder.id}', or configure ` +
|
|
118
|
+
`'${bundle.embedder.id}'.`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const entries = new Map();
|
|
122
|
+
for (const entry of bundle.entries) {
|
|
123
|
+
entries.set(entry.id, bundleEntryToMemoryEntry(entry, bundle));
|
|
124
|
+
}
|
|
125
|
+
const namespace = bundle.namespace;
|
|
126
|
+
const inNamespace = (identity) => identityNamespace(identity) === namespace;
|
|
127
|
+
return {
|
|
128
|
+
// Vectors in, ranked vectors out — the cosine scan below ranks the
|
|
129
|
+
// embeddings the bundle carries. Declared, so corpus builders can tell
|
|
130
|
+
// this apart from a server-side store (and refuse to INDEX into it —
|
|
131
|
+
// which they will anyway, at the first write).
|
|
132
|
+
supportsVectorSearch: true,
|
|
133
|
+
async get(identity, id) {
|
|
134
|
+
if (!inNamespace(identity))
|
|
135
|
+
return null;
|
|
136
|
+
// No access-count bump: the store is read-only, decay signals frozen
|
|
137
|
+
// at export.
|
|
138
|
+
return entries.get(id) ?? null;
|
|
139
|
+
},
|
|
140
|
+
async put() {
|
|
141
|
+
refuseWrite('put');
|
|
142
|
+
},
|
|
143
|
+
async putMany() {
|
|
144
|
+
refuseWrite('putMany');
|
|
145
|
+
},
|
|
146
|
+
async putIfVersion() {
|
|
147
|
+
refuseWrite('putIfVersion');
|
|
148
|
+
},
|
|
149
|
+
async delete() {
|
|
150
|
+
refuseWrite('delete');
|
|
151
|
+
},
|
|
152
|
+
async forget() {
|
|
153
|
+
refuseWrite('forget');
|
|
154
|
+
},
|
|
155
|
+
async recordSignature() {
|
|
156
|
+
refuseWrite('recordSignature');
|
|
157
|
+
},
|
|
158
|
+
async feedback() {
|
|
159
|
+
refuseWrite('feedback');
|
|
160
|
+
},
|
|
161
|
+
async list(identity, options) {
|
|
162
|
+
if (!inNamespace(identity))
|
|
163
|
+
return { entries: [] };
|
|
164
|
+
const limit = Math.max(1, Math.min(options?.limit ?? 100, 1000));
|
|
165
|
+
const all = [...entries.values()];
|
|
166
|
+
const offset = options?.cursor ? parseInt(options.cursor, 10) : 0;
|
|
167
|
+
const safeOffset = Number.isFinite(offset) && offset >= 0 ? offset : 0;
|
|
168
|
+
const page = all.slice(safeOffset, safeOffset + limit);
|
|
169
|
+
const next = safeOffset + page.length;
|
|
170
|
+
return {
|
|
171
|
+
entries: page,
|
|
172
|
+
...(next < all.length && { cursor: String(next) }),
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
async seen() {
|
|
176
|
+
return false; // no signature set was exported; recognition is a write-side concern
|
|
177
|
+
},
|
|
178
|
+
async getFeedback() {
|
|
179
|
+
return null;
|
|
180
|
+
},
|
|
181
|
+
async search(identity, query, options) {
|
|
182
|
+
// A wrong-space query is refused BY NAME rather than ranked to an empty
|
|
183
|
+
// page — the loud version of the mismatch machinery, because on a
|
|
184
|
+
// static corpus "no results" reads as "the corpus has nothing to say".
|
|
185
|
+
if (query.length !== bundle.embedder.dimensions) {
|
|
186
|
+
throw new Error(`staticVectorStore.search: the query vector has ${query.length} dimensions, but ` +
|
|
187
|
+
`this bundle was built in '${bundle.embedder.id}@${bundle.embedder.dimensions}'. ` +
|
|
188
|
+
`The query was embedded with a different embedder than the corpus. Configure the ` +
|
|
189
|
+
`embedder the corpus was built with, or re-export the corpus.`);
|
|
190
|
+
}
|
|
191
|
+
if (options?.embedderId !== undefined && options.embedderId !== bundle.embedder.id) {
|
|
192
|
+
throw new Error(`staticVectorStore.search: the retriever declares embedderId '${options.embedderId}' ` +
|
|
193
|
+
`but this bundle was built in '${bundle.embedder.id}@` +
|
|
194
|
+
`${bundle.embedder.dimensions}'. Silently skipping every entry would look like an ` +
|
|
195
|
+
`empty corpus. Align the retriever's \`embedderId\` with the bundle, or re-export ` +
|
|
196
|
+
`the corpus with the new embedder.`);
|
|
197
|
+
}
|
|
198
|
+
if (!inNamespace(identity))
|
|
199
|
+
return [];
|
|
200
|
+
const k = options?.k ?? 10;
|
|
201
|
+
const tierFilter = options?.tiers ? new Set(options.tiers) : undefined;
|
|
202
|
+
const minScore = options?.minScore;
|
|
203
|
+
const scored = [];
|
|
204
|
+
for (const entry of entries.values()) {
|
|
205
|
+
if (tierFilter && (!entry.tier || !tierFilter.has(entry.tier)))
|
|
206
|
+
continue;
|
|
207
|
+
const emb = entry.embedding;
|
|
208
|
+
if (!emb || emb.length !== query.length)
|
|
209
|
+
continue;
|
|
210
|
+
const score = cosineSimilarity(emb, query);
|
|
211
|
+
if (minScore !== undefined && score < minScore)
|
|
212
|
+
continue;
|
|
213
|
+
scored.push({ entry: entry, score });
|
|
214
|
+
}
|
|
215
|
+
scored.sort((a, b) => {
|
|
216
|
+
if (b.score !== a.score)
|
|
217
|
+
return b.score - a.score;
|
|
218
|
+
return a.entry.id < b.entry.id ? -1 : a.entry.id > b.entry.id ? 1 : 0;
|
|
219
|
+
});
|
|
220
|
+
return scored.slice(0, k);
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=staticVectorStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staticVectorStore.js","sourceRoot":"","sources":["../../../../src/memory/store/staticVectorStore.ts"],"names":[],"mappings":"AA0CA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAU1D,qEAAqE;AACrE,MAAM,CAAC,MAAM,oBAAoB,GAAG,0BAAmC,CAAC;AA8CxE;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAe,EACf,MAAc;IAEd,MAAM,CAAC,GAAG,MAAkD,CAAC;IAC7D,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,+CAA+C,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,C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K,CAAC,SAAS,CAAC;gBAC5B,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;oBAAE,SAAS;gBAClD,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;gBAC3C,IAAI,QAAQ,KAAK,SAAS,IAAI,KAAK,GAAG,QAAQ;oBAAE,SAAS;gBACzD,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAuB,EAAE,KAAK,EAAE,CAAC,CAAC;YACzD,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;gBACnB,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK;oBAAE,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;gBAClD,OAAO,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxE,CAAC,CAAC,CAAC;YACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/esm/observe.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export { boundaryRecorder, BoundaryRecorder, type ActorArrow, type BoundaryAggre
|
|
|
39
39
|
export { buildRunSteps, RunStepRecorder, runStepRecorder, type BuildRunStepsOptions, type RunStep, type RunStepGraph, type RunStepKind, type RunStepMeta, type RunStepRecorderOptions, type RunStepTransition, } from './recorders/observability/RunStepRecorder.js';
|
|
40
40
|
export { attachFlowchart, buildStepGraph, buildStepGraphFromEvents, type StepGraph, type StepNode, type StepEdge, type SlotBoundary, type ContextInjection, type FlowchartOptions, type FlowchartHandle, } from './recorders/observability/FlowchartRecorder.js';
|
|
41
41
|
export { recordRun, type Recording, type RecordRunOptions, type RunRecorder, } from './recorders/observability/recordRun.js';
|
|
42
|
+
export { summarizeEmbeddings, summarizeVector, type EmbeddingSummary, } from './recorders/observability/embeddingSummary.js';
|
|
42
43
|
export { serializeTrace, redactContent, traceToStepGraph, type Trace, type TraceSummary, type TraceRedaction, type SerializeTraceOptions, } from './recorders/observability/trace.js';
|
|
43
44
|
export { attachLocalObservability, type LocalObservabilityHandle, type LocalObservabilityOptions, } from './recorders/observability/localObservability.js';
|
|
44
45
|
export { liveStateRecorder, LiveStateRecorder, LiveLLMTracker, LiveToolTracker, LiveAgentTurnTracker, type LLMLiveState, type ToolLiveState, type AgentTurnLiveState, type LiveStateRunnerLike, } from './recorders/observability/LiveStateRecorder.js';
|
package/dist/esm/observe.js
CHANGED
|
@@ -45,6 +45,11 @@ export { attachFlowchart, buildStepGraph, buildStepGraphFromEvents, } from './re
|
|
|
45
45
|
// which is the shape the UIs consume (lens's `observeRecording`) and the one
|
|
46
46
|
// every integration used to assemble by hand, each missing a different piece.
|
|
47
47
|
export { recordRun, } from './recorders/observability/recordRun.js';
|
|
48
|
+
// What a recording keeps of a vector: `{ dims, norm }`, not the bytes (8.20.0).
|
|
49
|
+
// Applied by BoundaryRecorder and recordRun unless `recordEmbeddings: true`;
|
|
50
|
+
// exported so consumers that render or post-process recordings can apply or
|
|
51
|
+
// recognise the same projection.
|
|
52
|
+
export { summarizeEmbeddings, summarizeVector, } from './recorders/observability/embeddingSummary.js';
|
|
48
53
|
// Offline replay: freeze a live run model into a UI-free, JSON-lossless Trace
|
|
49
54
|
// (redaction applied at the serialize boundary). agentfootprint-lens's <Replay>
|
|
50
55
|
// rehydrates it. See docs/design/local-observability-and-pii.md.
|
package/dist/esm/observe.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observe.js","sourceRoot":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,EAA8B,MAAM,oCAAoC,CAAC;AAChG,OAAO,EACL,iBAAiB,GAElB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,kBAAkB,GAEnB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,aAAa,EAA6B,MAAM,mCAAmC,CAAC;AAC7F,qEAAqE;AACrE,0EAA0E;AAC1E,wEAAwE;AACxE,oDAAoD;AACpD,OAAO,EACL,kBAAkB,GAEnB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,aAAa,EACb,cAAc,GAIf,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACL,YAAY,GAGb,MAAM,6CAA6C,CAAC;AACrD,4EAA4E;AAC5E,gFAAgF;AAChF,OAAO,EACL,mBAAmB,GAMpB,MAAM,kDAAkD,CAAC;AAC1D,gFAAgF;AAChF,gFAAgF;AAChF,OAAO,EACL,kBAAkB,GAQnB,MAAM,yDAAyD,CAAC;AAEjE,uDAAuD;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,kEAAkE;AAClE,uEAAuE;AACvE,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,wEAAwE;AACxE,cAAc,YAAY,CAAC;AAC3B,sEAAsE;AACtE,uEAAuE;AACvE,qEAAqE;AACrE,oEAAoE;AACpE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAOnB,MAAM,iDAAiD,CAAC;AAEzD,OAAO,EACL,aAAa,EACb,cAAc,GAOf,MAAM,4CAA4C,CAAC;AAEpD,sEAAsE;AACtE,4EAA4E;AAC5E,+CAA+C;AAC/C,OAAO,EACL,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,WAAW,GACZ,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* exportCorpus / importCorpus — a corpus as a build artifact.
|
|
3
|
+
*
|
|
4
|
+
* Pattern: projection (store → plain-JSON bundle) and its inverse.
|
|
5
|
+
* Role: rag/ layer — the build-time half of the story whose runtime half
|
|
6
|
+
* is `staticVectorStore` (`agentfootprint/memory`). Index where the
|
|
7
|
+
* credentials and the durable disk live; ship the bundle with the
|
|
8
|
+
* deploy; serve it read-only where the process runs.
|
|
9
|
+
* Emits: N/A — build-step helpers, not run-time stages.
|
|
10
|
+
*
|
|
11
|
+
* ── The deployment shape this exists for ────────────────────────────────────
|
|
12
|
+
* An immutable or serverless runtime loses its disk between invocations and
|
|
13
|
+
* often holds no embedding-API credentials — while the build machine has
|
|
14
|
+
* both. So the corpus becomes an artifact of the BUILD:
|
|
15
|
+
*
|
|
16
|
+
* // build step (cron, CI, deploy hook) — credentials live here
|
|
17
|
+
* const report = await indexFolder('./docs', { to: store, embedder });
|
|
18
|
+
* writeFileSync('corpus.json', JSON.stringify(await exportCorpus(store)));
|
|
19
|
+
*
|
|
20
|
+
* // runtime — no disk, no embedding writes, no drift
|
|
21
|
+
* const store = staticVectorStore(JSON.parse(readFileSync('corpus.json', 'utf8')), embedder);
|
|
22
|
+
* const docs = defineRAG({ id: 'docs', store, embedder });
|
|
23
|
+
*
|
|
24
|
+
* The bundle records the embedder id and dimensions it was built with, so the
|
|
25
|
+
* runtime can REFUSE a mismatched embedder at load instead of discovering it
|
|
26
|
+
* as an empty retrieval — the same fingerprint discipline the durable store
|
|
27
|
+
* enforces per write.
|
|
28
|
+
*
|
|
29
|
+
* `importCorpus` is the inverse for a WRITABLE store: load a bundle into
|
|
30
|
+
* InMemoryStore at boot, or into sqliteVectorStore to migrate a corpus
|
|
31
|
+
* between machines without re-embedding (and re-billing) anything.
|
|
32
|
+
*/
|
|
33
|
+
import type { MemoryStore } from '../memory/store/index.js';
|
|
34
|
+
import type { MemoryIdentity } from '../memory/identity/index.js';
|
|
35
|
+
import { type CorpusBundle } from '../memory/store/staticVectorStore.js';
|
|
36
|
+
/**
|
|
37
|
+
* Export every entry of a corpus namespace as a plain-JSON bundle.
|
|
38
|
+
*
|
|
39
|
+
* @param store the store the corpus was indexed into. Any `MemoryStore`
|
|
40
|
+
* that can `list` — the reference stores and the durable one
|
|
41
|
+
* all can.
|
|
42
|
+
* @param identity the namespace to export. Defaults to the same
|
|
43
|
+
* `{ conversationId: '_global' }` that `indexCorpus`,
|
|
44
|
+
* `indexFolder`, `indexDocuments` and `defineRAG` default to,
|
|
45
|
+
* so the plain path needs no argument anywhere.
|
|
46
|
+
*
|
|
47
|
+
* @throws when the namespace is empty (almost always an identity mismatch,
|
|
48
|
+
* named as such), when an entry carries no vector or no passage (a
|
|
49
|
+
* bundle never ships an unservable entry), or when the namespace
|
|
50
|
+
* mixes embedding spaces (two spaces in one bundle could never be
|
|
51
|
+
* served by one embedder).
|
|
52
|
+
*/
|
|
53
|
+
export declare function exportCorpus(store: MemoryStore, identity?: MemoryIdentity): Promise<CorpusBundle>;
|
|
54
|
+
/**
|
|
55
|
+
* Load a bundle into a WRITABLE vector-capable store — the inverse of
|
|
56
|
+
* `exportCorpus`. Use it to seed an `InMemoryStore` at boot from a shipped
|
|
57
|
+
* bundle, or to migrate a corpus between machines without re-embedding.
|
|
58
|
+
*
|
|
59
|
+
* Entries are written in the same formatter-ready shape `staticVectorStore`
|
|
60
|
+
* serves, so the two paths render identically.
|
|
61
|
+
*
|
|
62
|
+
* @returns the number of entries written.
|
|
63
|
+
*/
|
|
64
|
+
export declare function importCorpus(store: MemoryStore, bundle: CorpusBundle, identity?: MemoryIdentity): Promise<number>;
|