agentfootprint 9.2.0 → 9.3.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/dist/adapters/memory/pgVector.js +731 -0
- package/dist/adapters/memory/pgVector.js.map +1 -0
- package/dist/adapters/memory/s3Vectors.js +628 -0
- package/dist/adapters/memory/s3Vectors.js.map +1 -0
- package/dist/adapters/memory/sqliteVector.js +16 -79
- package/dist/adapters/memory/sqliteVector.js.map +1 -1
- package/dist/embedders/index.js +240 -76
- package/dist/embedders/index.js.map +1 -1
- package/dist/esm/adapters/memory/pgVector.d.ts +243 -0
- package/dist/esm/adapters/memory/pgVector.js +726 -0
- package/dist/esm/adapters/memory/pgVector.js.map +1 -0
- package/dist/esm/adapters/memory/s3Vectors.d.ts +208 -0
- package/dist/esm/adapters/memory/s3Vectors.js +624 -0
- package/dist/esm/adapters/memory/s3Vectors.js.map +1 -0
- package/dist/esm/adapters/memory/sqliteVector.d.ts +5 -27
- package/dist/esm/adapters/memory/sqliteVector.js +10 -73
- package/dist/esm/adapters/memory/sqliteVector.js.map +1 -1
- package/dist/esm/embedders/index.d.ts +99 -19
- package/dist/esm/embedders/index.js +240 -76
- package/dist/esm/embedders/index.js.map +1 -1
- package/dist/esm/lib/embedderMismatch.d.ts +67 -0
- package/dist/esm/lib/embedderMismatch.js +96 -0
- package/dist/esm/lib/embedderMismatch.js.map +1 -0
- package/dist/esm/lib/rag/defineRAG.d.ts +28 -6
- package/dist/esm/lib/rag/defineRAG.js +39 -5
- package/dist/esm/lib/rag/defineRAG.js.map +1 -1
- package/dist/esm/memory/define.js +31 -1
- package/dist/esm/memory/define.js.map +1 -1
- package/dist/esm/memory/define.types.d.ts +13 -2
- package/dist/esm/memory/define.types.js.map +1 -1
- package/dist/esm/memory/embedding/loadRelevant.d.ts +10 -2
- package/dist/esm/memory/embedding/loadRelevant.js +36 -18
- package/dist/esm/memory/embedding/loadRelevant.js.map +1 -1
- package/dist/esm/memory/pipeline/semantic.d.ts +13 -2
- package/dist/esm/memory/pipeline/semantic.js +11 -5
- package/dist/esm/memory/pipeline/semantic.js.map +1 -1
- package/dist/esm/memory/store/capability.d.ts +25 -6
- package/dist/esm/memory/store/capability.js +68 -3
- package/dist/esm/memory/store/capability.js.map +1 -1
- package/dist/esm/memory/store/index.d.ts +1 -0
- package/dist/esm/memory/store/index.js +4 -0
- package/dist/esm/memory/store/index.js.map +1 -1
- package/dist/esm/memory/store/types.d.ts +40 -0
- package/dist/esm/memory-providers.d.ts +7 -4
- package/dist/esm/memory-providers.js +18 -4
- package/dist/esm/memory-providers.js.map +1 -1
- package/dist/lib/embedderMismatch.js +103 -0
- package/dist/lib/embedderMismatch.js.map +1 -0
- package/dist/lib/rag/defineRAG.js +39 -5
- package/dist/lib/rag/defineRAG.js.map +1 -1
- package/dist/memory/define.js +31 -1
- package/dist/memory/define.js.map +1 -1
- package/dist/memory/define.types.js.map +1 -1
- package/dist/memory/embedding/loadRelevant.js +36 -18
- package/dist/memory/embedding/loadRelevant.js.map +1 -1
- package/dist/memory/pipeline/semantic.js +11 -5
- package/dist/memory/pipeline/semantic.js.map +1 -1
- package/dist/memory/store/capability.js +70 -4
- package/dist/memory/store/capability.js.map +1 -1
- package/dist/memory/store/index.js +7 -1
- package/dist/memory/store/index.js.map +1 -1
- package/dist/memory-providers.js +22 -5
- package/dist/memory-providers.js.map +1 -1
- package/dist/types/adapters/memory/pgVector.d.ts +244 -0
- package/dist/types/adapters/memory/pgVector.d.ts.map +1 -0
- package/dist/types/adapters/memory/s3Vectors.d.ts +209 -0
- package/dist/types/adapters/memory/s3Vectors.d.ts.map +1 -0
- package/dist/types/adapters/memory/sqliteVector.d.ts +5 -27
- package/dist/types/adapters/memory/sqliteVector.d.ts.map +1 -1
- package/dist/types/embedders/index.d.ts +99 -19
- package/dist/types/embedders/index.d.ts.map +1 -1
- package/dist/types/lib/embedderMismatch.d.ts +68 -0
- package/dist/types/lib/embedderMismatch.d.ts.map +1 -0
- package/dist/types/lib/rag/defineRAG.d.ts +28 -6
- package/dist/types/lib/rag/defineRAG.d.ts.map +1 -1
- package/dist/types/memory/define.d.ts.map +1 -1
- package/dist/types/memory/define.types.d.ts +13 -2
- package/dist/types/memory/define.types.d.ts.map +1 -1
- package/dist/types/memory/embedding/loadRelevant.d.ts +10 -2
- package/dist/types/memory/embedding/loadRelevant.d.ts.map +1 -1
- package/dist/types/memory/pipeline/semantic.d.ts +13 -2
- package/dist/types/memory/pipeline/semantic.d.ts.map +1 -1
- package/dist/types/memory/store/capability.d.ts +25 -6
- package/dist/types/memory/store/capability.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/types.d.ts +40 -0
- package/dist/types/memory/store/types.d.ts.map +1 -1
- package/dist/types/memory-providers.d.ts +7 -4
- package/dist/types/memory-providers.d.ts.map +1 -1
- package/package.json +9 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.__resetEmptyCorpusWarnings = exports.loadRelevant = void 0;
|
|
4
4
|
const index_js_1 = require("../identity/index.js");
|
|
5
|
+
const capability_js_1 = require("../store/capability.js");
|
|
5
6
|
const fnv1a_js_1 = require("../../lib/fnv1a.js");
|
|
6
7
|
const provenance_js_1 = require("../retrieval/provenance.js");
|
|
7
8
|
const topK_js_1 = require("../retrieval/topK.js");
|
|
@@ -37,7 +38,17 @@ function loadRelevant(config) {
|
|
|
37
38
|
const { store, embedder } = config;
|
|
38
39
|
if (!store.search) {
|
|
39
40
|
throw new Error('loadRelevant: the configured store does not implement search(). ' +
|
|
40
|
-
'Use a
|
|
41
|
+
'Use a store that can retrieve (InMemoryStore, sqliteVectorStore, pgVectorStore, ' +
|
|
42
|
+
's3VectorsStore, ...).');
|
|
43
|
+
}
|
|
44
|
+
// Fail-loud at STAGE BUILD time, as this stage has always done for a store
|
|
45
|
+
// with no `search()`: a retriever with no embedder over a store that ranks
|
|
46
|
+
// vectors is a config bug, not a runtime condition, and its symptom would be
|
|
47
|
+
// an empty answer.
|
|
48
|
+
if (!embedder && (0, capability_js_1.resolveRankingMode)(store, 'loadRelevant') !== 'server-text') {
|
|
49
|
+
throw new Error('loadRelevant: no `embedder` was configured, and this store does not declare ' +
|
|
50
|
+
"`ranksBy: 'server-text'`. Something has to turn the query into a vector before a " +
|
|
51
|
+
'vector-ranking store can answer it.');
|
|
41
52
|
}
|
|
42
53
|
const queryFrom = config.queryFrom ?? defaultQueryFrom;
|
|
43
54
|
// The shorthand and the strategy are two spellings of one rule; the
|
|
@@ -80,23 +91,30 @@ function loadRelevant(config) {
|
|
|
80
91
|
return;
|
|
81
92
|
}
|
|
82
93
|
const signal = scope.$getEnv?.()?.signal;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
// No embedder means a store that ranks the TEXT server-side: there is no
|
|
95
|
+
// vector to make, so none is made, none is billed, and no embedding event
|
|
96
|
+
// is emitted. `[]` is what the port's `query` argument honestly is here,
|
|
97
|
+
// and `options.text` below is the query such a store actually reads.
|
|
98
|
+
let queryVec = [];
|
|
99
|
+
if (embedder) {
|
|
100
|
+
const embedStartedAt = Date.now();
|
|
101
|
+
queryVec = (await embedder.embed({
|
|
102
|
+
text,
|
|
103
|
+
...(signal ? { signal } : {}),
|
|
104
|
+
}));
|
|
105
|
+
// The QUERY-time half of the two-phase cost model (8.9.0): one embedding
|
|
106
|
+
// per retrieval, scaling with traffic rather than with corpus size. Paired
|
|
107
|
+
// with the `'document'` side in `embedMessages`, this is what makes the
|
|
108
|
+
// cost of a corpus a number you can read rather than one you estimate.
|
|
109
|
+
(0, emitEmbedding_js_1.emitEmbedding)(scope, {
|
|
110
|
+
model: config.embedderId ?? embedder.id ?? 'unknown',
|
|
111
|
+
provider: 'custom',
|
|
112
|
+
inputKind: 'query',
|
|
113
|
+
dimension: queryVec.length,
|
|
114
|
+
count: 1,
|
|
115
|
+
durationMs: Date.now() - embedStartedAt,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
100
118
|
// store.search optional on MemoryStore but required when an embedder
|
|
101
119
|
// is configured (validated upstream by defineMemory).
|
|
102
120
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadRelevant.js","sourceRoot":"","sources":["../../../src/memory/embedding/loadRelevant.ts"],"names":[],"mappings":";;;AA8DA,mDAAyD;AACzD,iDAA2C;AAC3C,8DAAwE;AACxE,kDAA4C;AAQ5C,yDAAmD;
|
|
1
|
+
{"version":3,"file":"loadRelevant.js","sourceRoot":"","sources":["../../../src/memory/embedding/loadRelevant.ts"],"names":[],"mappings":";;;AA8DA,mDAAyD;AACzD,0DAA4D;AAC5D,iDAA2C;AAC3C,8DAAwE;AACxE,kDAA4C;AAQ5C,yDAAmD;AAyDnD;;;;;;;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,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM;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AC;AAC3B,CAAC;AAFD,gEAEC"}
|
|
@@ -55,7 +55,7 @@ function semanticPipeline(config) {
|
|
|
55
55
|
}
|
|
56
56
|
const loadConfig = {
|
|
57
57
|
store: config.store,
|
|
58
|
-
embedder: config.embedder,
|
|
58
|
+
...(config.embedder !== undefined && { embedder: config.embedder }),
|
|
59
59
|
...(config.embedderId !== undefined && { embedderId: config.embedderId }),
|
|
60
60
|
...(config.k !== undefined && { k: config.k }),
|
|
61
61
|
...(config.minScore !== undefined && { minScore: config.minScore }),
|
|
@@ -73,10 +73,6 @@ function semanticPipeline(config) {
|
|
|
73
73
|
...(config.formatFooter !== undefined && { footer: config.formatFooter }),
|
|
74
74
|
...(config.flavor !== undefined && { flavor: config.flavor }),
|
|
75
75
|
};
|
|
76
|
-
const embedConfig = {
|
|
77
|
-
embedder: config.embedder,
|
|
78
|
-
...(config.embedderId !== undefined && { embedderId: config.embedderId }),
|
|
79
|
-
};
|
|
80
76
|
const writeConfig = {
|
|
81
77
|
store: config.store,
|
|
82
78
|
...(config.writeTier && { tier: config.writeTier }),
|
|
@@ -89,6 +85,16 @@ function semanticPipeline(config) {
|
|
|
89
85
|
.addFunction('Format', (0, formatDefault_js_1.formatDefault)(formatConfig), 'format-default', 'Render selected entries as a system message')
|
|
90
86
|
.build();
|
|
91
87
|
// ── Write subflow: EmbedMessages → WriteMessages
|
|
88
|
+
//
|
|
89
|
+
// Built only when there is an embedder to build it around. Without one the
|
|
90
|
+
// pipeline is read-only by construction rather than by a flag — nothing to
|
|
91
|
+
// disable later by accident, and no stage in the chart that does nothing.
|
|
92
|
+
if (config.embedder === undefined)
|
|
93
|
+
return { read };
|
|
94
|
+
const embedConfig = {
|
|
95
|
+
embedder: config.embedder,
|
|
96
|
+
...(config.embedderId !== undefined && { embedderId: config.embedderId }),
|
|
97
|
+
};
|
|
92
98
|
const write = (0, footprintjs_1.flowChart)('EmbedMessages', (0, embedMessages_js_1.embedMessages)(embedConfig), 'embed-messages', { description: 'Embed newMessages into per-message vectors for vector search' })
|
|
93
99
|
.addFunction('WriteMessages', (0, writeMessages_js_1.writeMessages)(writeConfig), 'write-messages', 'Batch-persist messages with embeddings via store.putMany')
|
|
94
100
|
.build();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic.js","sourceRoot":"","sources":["../../../src/memory/pipeline/semantic.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,6CAAwC;AAExC,+DAAkF;AAClF,iEAIoC;AAEpC,iEAAqF;AAKrF,kEAAqF;AACrF,oEAIuC;
|
|
1
|
+
{"version":3,"file":"semantic.js","sourceRoot":"","sources":["../../../src/memory/pipeline/semantic.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,6CAAwC;AAExC,+DAAkF;AAClF,iEAIoC;AAEpC,iEAAqF;AAKrF,kEAAqF;AACrF,oEAIuC;AA0EvC;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,MAA8B;IAC7D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,sEAAsE;YACpE,yEAAyE,CAC5E,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAuB;QACrC,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,GAAG,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;QACnE,GAAG,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC;QACzE,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,SAAS,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;QAC9C,GAAG,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,E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3
|
-
exports.assertServesVectors = void 0;
|
|
3
|
+
exports.assertServesVectors = exports.resolveRankingMode = void 0;
|
|
4
4
|
/** The stores this library ships that DO rank the vectors they were given. */
|
|
5
|
-
const VECTOR_CAPABLE = 'InMemoryStore (dev/tests)
|
|
5
|
+
const VECTOR_CAPABLE = 'InMemoryStore (dev/tests), sqliteVectorStore (durable, one file), pgVectorStore ' +
|
|
6
|
+
'(Postgres + pgvector) or s3VectorsStore (Amazon S3 Vectors)';
|
|
7
|
+
/**
|
|
8
|
+
* The ranking mode a store DECLARES, with a contradiction refused by name.
|
|
9
|
+
*
|
|
10
|
+
* Two members answer two questions ({@link MemoryStore.supportsVectorSearch}
|
|
11
|
+
* "can you serve my vectors back?" and {@link MemoryStore.ranksBy} "what query
|
|
12
|
+
* form does your search take?"), and a store may state either, both, or
|
|
13
|
+
* neither. Both, disagreeing, is the one case that cannot be resolved: there is
|
|
14
|
+
* no reading of `{ supportsVectorSearch: true, ranksBy: 'server-text' }` that
|
|
15
|
+
* is not somebody's bug, and picking a winner would encode a guess about which
|
|
16
|
+
* line was the mistake. Refused — the same law that refuses `topK` beside
|
|
17
|
+
* `retrieval`.
|
|
18
|
+
*
|
|
19
|
+
* @returns `'vector'` | `'server-text'` | `undefined` (undeclared — the state
|
|
20
|
+
* every adapter written before 9.3.0 is in, and the one that must
|
|
21
|
+
* change nothing).
|
|
22
|
+
* @throws when the two declarations contradict each other.
|
|
23
|
+
*/
|
|
24
|
+
function resolveRankingMode(store, caller) {
|
|
25
|
+
const declared = store.ranksBy;
|
|
26
|
+
const servesVectors = store.supportsVectorSearch;
|
|
27
|
+
if (declared === undefined) {
|
|
28
|
+
// A bare `supportsVectorSearch: true` is a store saying it ranks the
|
|
29
|
+
// vectors it was given, which IS `'vector'` — read it as one, so a
|
|
30
|
+
// pre-9.3.0 adapter gets the new behaviour without a new line. A bare
|
|
31
|
+
// `false` says only that it cannot serve them back, not how it ranks, so
|
|
32
|
+
// it stays undeclared here.
|
|
33
|
+
return servesVectors === true ? 'vector' : undefined;
|
|
34
|
+
}
|
|
35
|
+
if (declared === 'vector' && servesVectors === false) {
|
|
36
|
+
throw new Error(contradiction(store, caller, 'vector', false));
|
|
37
|
+
}
|
|
38
|
+
if (declared === 'server-text' && servesVectors === true) {
|
|
39
|
+
throw new Error(contradiction(store, caller, 'server-text', true));
|
|
40
|
+
}
|
|
41
|
+
return declared;
|
|
42
|
+
}
|
|
43
|
+
exports.resolveRankingMode = resolveRankingMode;
|
|
44
|
+
function contradiction(store, caller, ranksBy, supportsVectorSearch) {
|
|
45
|
+
const name = storeName(store);
|
|
46
|
+
return (`${caller}: \`${name}\` declares \`ranksBy: '${ranksBy}'\` and ` +
|
|
47
|
+
`\`supportsVectorSearch: ${String(supportsVectorSearch)}\`, and those two cannot both be ` +
|
|
48
|
+
`true.\n` +
|
|
49
|
+
` \`ranksBy: 'vector'\` means search() ranks the embeddings you wrote, which is exactly ` +
|
|
50
|
+
`what \`supportsVectorSearch: true\` claims; \`'server-text'\` means the backend ranks ` +
|
|
51
|
+
`text on its own side, which is exactly what \`false\` admits.\n` +
|
|
52
|
+
` Fix: keep ONE of them. A local vector backend declares ` +
|
|
53
|
+
`\`ranksBy: 'vector'\` (or nothing but \`supportsVectorSearch: true\`); a managed ` +
|
|
54
|
+
`text-ranking backend declares \`ranksBy: 'server-text'\` and \`supportsVectorSearch: false\`.\n` +
|
|
55
|
+
` This refuses rather than picking a winner — either line could be the mistake, and ` +
|
|
56
|
+
`guessing which would silently decide whether your queries get embedded.`);
|
|
57
|
+
}
|
|
6
58
|
/**
|
|
7
59
|
* Refuse a store that has declared it cannot rank the vectors it is given.
|
|
8
60
|
*
|
|
9
61
|
* @param store the store the caller passed.
|
|
10
62
|
* @param caller the function name to put in the message — the call the
|
|
11
63
|
* reader actually wrote, not this helper.
|
|
12
|
-
* @throws when `store.supportsVectorSearch === false
|
|
13
|
-
*
|
|
64
|
+
* @throws when `store.supportsVectorSearch === false`, when it declares
|
|
65
|
+
* `ranksBy: 'server-text'`, or when the two declarations contradict.
|
|
66
|
+
* Never throws on a store that declares nothing.
|
|
14
67
|
*/
|
|
15
68
|
function assertServesVectors(store, caller) {
|
|
69
|
+
// A contradiction is refused here too — a corpus builder is usually the
|
|
70
|
+
// FIRST call a new store meets, and it is the cheapest place to find out.
|
|
71
|
+
const mode = resolveRankingMode(store, caller);
|
|
72
|
+
if (mode === 'server-text') {
|
|
73
|
+
throw new Error(`${caller}: \`${storeName(store)}\` declares \`ranksBy: 'server-text'\`, so indexing a ` +
|
|
74
|
+
`corpus into it would report success and retrieve nothing.\n` +
|
|
75
|
+
` It embeds and ranks on the BACKEND's side, over a population the backend derived ` +
|
|
76
|
+
`itself — the vectors written here would be stored and never read.\n` +
|
|
77
|
+
` Fix: index into a vector-ranking store — ${VECTOR_CAPABLE}.\n` +
|
|
78
|
+
` Or: let the backend do its own ingestion (its console, its API), and point ` +
|
|
79
|
+
`\`defineRAG\` at it with NO embedder — a server-text store takes the question as ` +
|
|
80
|
+
`words, so there is nothing for this library to embed.`);
|
|
81
|
+
}
|
|
16
82
|
if (store.supportsVectorSearch !== false)
|
|
17
83
|
return;
|
|
18
84
|
const name = storeName(store);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../../../src/memory/store/capability.ts"],"names":[],"mappings":";;;AA2BA,8EAA8E;AAC9E,MAAM,cAAc,GAAG,
|
|
1
|
+
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../../../src/memory/store/capability.ts"],"names":[],"mappings":";;;AA2BA,8EAA8E;AAC9E,MAAM,cAAc,GAClB,kFAAkF;IAClF,6DAA6D,CAAC;AAEhE;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,kBAAkB,CAChC,KAAkB,EAClB,MAAc;IAEd,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC;IAC/B,MAAM,aAAa,GAAG,KAAK,CAAC,oBAAoB,CAAC;IACjD,IAAI,QAAQ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undleEntryToMemoryEntry = exports.assertCorpusBundle = exports.staticVectorStore = exports.InMemoryStore = void 0;
|
|
3
|
+
exports.CORPUS_BUNDLE_FORMAT = exports.bundleEntryToMemoryEntry = exports.assertCorpusBundle = exports.staticVectorStore = exports.resolveRankingMode = exports.assertServesVectors = exports.InMemoryStore = void 0;
|
|
4
4
|
var InMemoryStore_js_1 = require("./InMemoryStore.js");
|
|
5
5
|
Object.defineProperty(exports, "InMemoryStore", { enumerable: true, get: function () { return InMemoryStore_js_1.InMemoryStore; } });
|
|
6
|
+
// The declared-capability readers (9.3.0). `resolveRankingMode` is exported so
|
|
7
|
+
// an adapter author can check their own two declarations agree without waiting
|
|
8
|
+
// for a corpus builder to tell them.
|
|
9
|
+
var capability_js_1 = require("./capability.js");
|
|
10
|
+
Object.defineProperty(exports, "assertServesVectors", { enumerable: true, get: function () { return capability_js_1.assertServesVectors; } });
|
|
11
|
+
Object.defineProperty(exports, "resolveRankingMode", { enumerable: true, get: function () { return capability_js_1.resolveRankingMode; } });
|
|
6
12
|
var staticVectorStore_js_1 = require("./staticVectorStore.js");
|
|
7
13
|
Object.defineProperty(exports, "staticVectorStore", { enumerable: true, get: function () { return staticVectorStore_js_1.staticVectorStore; } });
|
|
8
14
|
Object.defineProperty(exports, "assertCorpusBundle", { enumerable: true, get: function () { return staticVectorStore_js_1.assertCorpusBundle; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/memory/store/index.ts"],"names":[],"mappings":";;;AASA,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AACtB,+DAQgC;AAP9B,yHAAA,iBAAiB,OAAA;AACjB,0HAAA,kBAAkB,OAAA;AAClB,gIAAA,wBAAwB,OAAA;AACxB,4HAAA,oBAAoB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/memory/store/index.ts"],"names":[],"mappings":";;;AASA,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AACtB,+EAA+E;AAC/E,+EAA+E;AAC/E,qCAAqC;AACrC,iDAA0E;AAAjE,oHAAA,mBAAmB,OAAA;AAAE,mHAAA,kBAAkB,OAAA;AAChD,+DAQgC;AAP9B,yHAAA,iBAAiB,OAAA;AACjB,0HAAA,kBAAkB,OAAA;AAClB,gIAAA,wBAAwB,OAAA;AACxB,4HAAA,oBAAoB,OAAA"}
|
package/dist/memory-providers.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* memory-providers — memory store adapters.
|
|
4
4
|
*
|
|
5
|
-
* RedisStore, AgentCoreStore,
|
|
6
|
-
* Pinecone, …) all live here — a new store adds an
|
|
7
|
-
* import path.
|
|
5
|
+
* RedisStore, AgentCoreStore, sqliteVectorStore, pgVectorStore, s3VectorsStore
|
|
6
|
+
* and future stores (DynamoDB, Pinecone, …) all live here — a new store adds an
|
|
7
|
+
* export, never a new import path.
|
|
8
8
|
*
|
|
9
9
|
* Pattern: Adapter (GoF) — each store translates the `MemoryStore`
|
|
10
10
|
* interface onto a specific backend (Redis, DynamoDB-style
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* symbols, one door. Import from the door.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.BedrockAgentMemory = exports.
|
|
25
|
+
exports.BedrockAgentMemory = exports.s3VectorsStore = exports.PgVectorSchemaError = exports.pgVectorStore = exports.EmbedderMismatchError = exports.SqliteUnavailableError = exports.UnreadableIndexFileError = exports.sqliteVectorStore = exports.UnreadableMemoryEntryError = exports.AgentCoreStore = exports.RedisStore = void 0;
|
|
26
26
|
// Lazy-required peer-dep stores. Both adapters defer their vendor SDK
|
|
27
27
|
// `require()` to constructor time; importing this barrel doesn't load
|
|
28
28
|
// `ioredis` or `@aws-sdk/client-bedrock-agent-runtime`.
|
|
@@ -38,11 +38,28 @@ Object.defineProperty(exports, "UnreadableMemoryEntryError", { enumerable: true,
|
|
|
38
38
|
var sqliteVector_js_1 = require("./adapters/memory/sqliteVector.js");
|
|
39
39
|
Object.defineProperty(exports, "sqliteVectorStore", { enumerable: true, get: function () { return sqliteVector_js_1.sqliteVectorStore; } });
|
|
40
40
|
Object.defineProperty(exports, "UnreadableIndexFileError", { enumerable: true, get: function () { return sqliteVector_js_1.UnreadableIndexFileError; } });
|
|
41
|
-
Object.defineProperty(exports, "EmbedderMismatchError", { enumerable: true, get: function () { return sqliteVector_js_1.EmbedderMismatchError; } });
|
|
42
41
|
// The SAME refusal `sqliteSessions` raises for the same missing module — one
|
|
43
42
|
// class, so catching it does not require knowing which store was being built.
|
|
44
43
|
var sqliteUnavailable_js_1 = require("./lib/sqliteUnavailable.js");
|
|
45
44
|
Object.defineProperty(exports, "SqliteUnavailableError", { enumerable: true, get: function () { return sqliteUnavailable_js_1.SqliteUnavailableError; } });
|
|
45
|
+
// ONE refusal for every store that can tell a vector met an index built by a
|
|
46
|
+
// different embedder (9.3.0). It lived in sqliteVector.ts from 8.9.0; when
|
|
47
|
+
// pgVectorStore and s3VectorsStore learned the same check it moved to lib/, so
|
|
48
|
+
// `catch (e) { if (e instanceof EmbedderMismatchError) }` cannot depend on
|
|
49
|
+
// which store threw. The old import path still works.
|
|
50
|
+
var embedderMismatch_js_1 = require("./lib/embedderMismatch.js");
|
|
51
|
+
Object.defineProperty(exports, "EmbedderMismatchError", { enumerable: true, get: function () { return embedderMismatch_js_1.EmbedderMismatchError; } });
|
|
52
|
+
// Postgres + pgvector: the corpus beside the application's own data, inheriting
|
|
53
|
+
// its backups, failover and access control. `pg` is lazy-required at the first
|
|
54
|
+
// call — pass `client` to reuse the pool your app already has.
|
|
55
|
+
var pgVector_js_1 = require("./adapters/memory/pgVector.js");
|
|
56
|
+
Object.defineProperty(exports, "pgVectorStore", { enumerable: true, get: function () { return pgVector_js_1.pgVectorStore; } });
|
|
57
|
+
Object.defineProperty(exports, "PgVectorSchemaError", { enumerable: true, get: function () { return pgVector_js_1.PgVectorSchemaError; } });
|
|
58
|
+
// Amazon S3 Vectors: a durable corpus with nothing to run, that can be added to
|
|
59
|
+
// from a cron job rather than at the next deploy. Lazy-requires
|
|
60
|
+
// `@aws-sdk/client-s3vectors` at the first call.
|
|
61
|
+
var s3Vectors_js_1 = require("./adapters/memory/s3Vectors.js");
|
|
62
|
+
Object.defineProperty(exports, "s3VectorsStore", { enumerable: true, get: function () { return s3Vectors_js_1.s3VectorsStore; } });
|
|
46
63
|
// Read-only reader for the legacy Bedrock Agents auto session-summary memory.
|
|
47
64
|
// NOT a MemoryStore (Bedrock owns the writes) — see the class docstring.
|
|
48
65
|
var bedrockAgentMemory_js_1 = require("./adapters/memory/bedrockAgentMemory.js");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-providers.js","sourceRoot":"","sources":["../src/memory-providers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAEH,sEAAsE;AACtE,sEAAsE;AACtE,wDAAwD;AACxD,uDAKoC;AAJlC,sGAAA,UAAU,OAAA;AAMZ,+DAOwC;AANtC,8GAAA,cAAc,OAAA;AACd,0HAAA,0BAA0B,OAAA;AAO5B,gFAAgF;AAChF,gFAAgF;AAChF,8EAA8E;AAC9E,mDAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"memory-providers.js","sourceRoot":"","sources":["../src/memory-providers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAEH,sEAAsE;AACtE,sEAAsE;AACtE,wDAAwD;AACxD,uDAKoC;AAJlC,sGAAA,UAAU,OAAA;AAMZ,+DAOwC;AANtC,8GAAA,cAAc,OAAA;AACd,0HAAA,0BAA0B,OAAA;AAO5B,gFAAgF;AAChF,gFAAgF;AAChF,8EAA8E;AAC9E,mDAAmD;AACnD,qEAQ2C;AAPzC,oHAAA,iBAAiB,OAAA;AACjB,2HAAA,wBAAwB,OAAA;AAQ1B,6EAA6E;AAC7E,8EAA8E;AAC9E,mEAAoE;AAA3D,8HAAA,sBAAsB,OAAA;AAE/B,6EAA6E;AAC7E,2EAA2E;AAC3E,+EAA+E;AAC/E,2EAA2E;AAC3E,sDAAsD;AACtD,iEAAkE;AAAzD,4HAAA,qBAAqB,OAAA;AAE9B,gFAAgF;AAChF,+EAA+E;AAC/E,+DAA+D;AAC/D,6DASuC;AARrC,4GAAA,aAAa,OAAA;AACb,kHAAA,mBAAmB,OAAA;AASrB,gFAAgF;AAChF,gEAAgE;AAChE,iDAAiD;AACjD,+DAMwC;AALtC,8GAAA,cAAc,OAAA;AAOhB,8EAA8E;AAC9E,yEAAyE;AACzE,iFAKiD;AAJ/C,2HAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* adapters/memory/pgVector — the target our own port has named since 2.x.
|
|
3
|
+
*
|
|
4
|
+
* `MemoryStore`'s docstring has listed the backends it was designed for from
|
|
5
|
+
* the beginning — *"Every storage backend (InMemory, Redis, DynamoDB,
|
|
6
|
+
* **Postgres**, Bedrock AgentCore) implements this interface"* — and named the
|
|
7
|
+
* query, twice, in the places an implementer would look: *"**Postgres**:
|
|
8
|
+
* multi-row INSERT … ON CONFLICT DO UPDATE"* for `putMany`, *"**pgvector**:
|
|
9
|
+
* `ORDER BY embedding <=> query LIMIT k`"* for `search`. Every one of those
|
|
10
|
+
* sentences was true about the design and false about the shipped package.
|
|
11
|
+
* This is the adapter that makes them the same sentence.
|
|
12
|
+
*
|
|
13
|
+
* It matters more than one row in a table of backends. Postgres is the database
|
|
14
|
+
* most teams already run, `pgvector` is an extension away, and a corpus that
|
|
15
|
+
* lives beside the application's own data inherits its backups, its failover,
|
|
16
|
+
* its access control and its migrations. `sqliteVectorStore` is one machine;
|
|
17
|
+
* `s3VectorsStore` is serverless and eventually consistent; this is the one for
|
|
18
|
+
* a fleet that already has a database.
|
|
19
|
+
*
|
|
20
|
+
* ── The table, and why this does not create it ──────────────────────────────
|
|
21
|
+
* A `vector(N)` column fixes N at creation, and N is a fact about your
|
|
22
|
+
* embedder. Creating the table implicitly would pick that number — and the
|
|
23
|
+
* index type, and the operator class — on your behalf, in a migration you never
|
|
24
|
+
* reviewed, in a database whose DDL is usually somebody's job. So the schema is
|
|
25
|
+
* yours to run, and this store REFUSES a table that is missing rather than
|
|
26
|
+
* silently answering "no matches" against nothing:
|
|
27
|
+
*
|
|
28
|
+
* ```sql
|
|
29
|
+
* CREATE EXTENSION IF NOT EXISTS vector;
|
|
30
|
+
*
|
|
31
|
+
* -- 1024 = your embedder's dimensions. bedrockEmbedder() default: 1024.
|
|
32
|
+
* -- openaiEmbedder() default: 1536. staticEmbedder(): 256.
|
|
33
|
+
* CREATE TABLE af_vectors (
|
|
34
|
+
* namespace TEXT NOT NULL,
|
|
35
|
+
* id TEXT NOT NULL,
|
|
36
|
+
* value JSONB NOT NULL,
|
|
37
|
+
* metadata JSONB,
|
|
38
|
+
* embedding vector(1024),
|
|
39
|
+
* embedder_fp TEXT,
|
|
40
|
+
* version INTEGER NOT NULL,
|
|
41
|
+
* created_at BIGINT NOT NULL,
|
|
42
|
+
* updated_at BIGINT NOT NULL,
|
|
43
|
+
* last_accessed_at BIGINT NOT NULL,
|
|
44
|
+
* access_count INTEGER NOT NULL,
|
|
45
|
+
* ttl BIGINT,
|
|
46
|
+
* tier TEXT,
|
|
47
|
+
* source JSONB,
|
|
48
|
+
* embedding_model TEXT,
|
|
49
|
+
* PRIMARY KEY (namespace, id)
|
|
50
|
+
* );
|
|
51
|
+
*
|
|
52
|
+
* -- Cosine, because that is the score this port reports and every threshold
|
|
53
|
+
* -- in this library is calibrated on. Match the operator class to the metric.
|
|
54
|
+
* CREATE INDEX af_vectors_hnsw ON af_vectors
|
|
55
|
+
* USING hnsw (embedding vector_cosine_ops);
|
|
56
|
+
* CREATE INDEX af_vectors_ns ON af_vectors (namespace);
|
|
57
|
+
*
|
|
58
|
+
* -- Recognition (`seen`/`recordSignature`), usefulness feedback, and the
|
|
59
|
+
* -- per-namespace embedder fingerprint. Small, and each one is a port method
|
|
60
|
+
* -- that would otherwise have to be refused.
|
|
61
|
+
* CREATE TABLE af_signatures (
|
|
62
|
+
* namespace TEXT NOT NULL, signature TEXT NOT NULL,
|
|
63
|
+
* PRIMARY KEY (namespace, signature)
|
|
64
|
+
* );
|
|
65
|
+
* CREATE TABLE af_feedback (
|
|
66
|
+
* namespace TEXT NOT NULL, id TEXT NOT NULL,
|
|
67
|
+
* total DOUBLE PRECISION NOT NULL, count INTEGER NOT NULL,
|
|
68
|
+
* PRIMARY KEY (namespace, id)
|
|
69
|
+
* );
|
|
70
|
+
* CREATE TABLE af_index_meta (key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* Every table and column name above is an OPTION with that value as its
|
|
74
|
+
* default, so this drops into a schema that already has naming conventions —
|
|
75
|
+
* see {@link PgVectorStoreOptions}. Identifiers are validated and quoted; a
|
|
76
|
+
* name that is not a plain SQL identifier is refused rather than interpolated.
|
|
77
|
+
*
|
|
78
|
+
* ── Cosine, and only cosine ─────────────────────────────────────────────────
|
|
79
|
+
* `search` is `1 - (embedding <=> $query::vector)` — pgvector's cosine
|
|
80
|
+
* DISTANCE, converted to the cosine SIMILARITY the port reports and
|
|
81
|
+
* `defineRAG`'s 0.7 default is calibrated on. `<->` (L2) and `<#>` (inner
|
|
82
|
+
* product) are deliberately not options: their ranges are not that range, and a
|
|
83
|
+
* number that reads like a cosine and is not one is the failure mode the whole
|
|
84
|
+
* fingerprint machinery exists to prevent. Build the HNSW index with
|
|
85
|
+
* `vector_cosine_ops` so the operator and the index agree — with the wrong
|
|
86
|
+
* operator class the query still returns the right answer, slowly, by scanning.
|
|
87
|
+
*
|
|
88
|
+
* ── One statement at a time, on purpose ─────────────────────────────────────
|
|
89
|
+
* The client here is anything with `query()` — a `pg.Pool` is the expected one,
|
|
90
|
+
* and a Pool hands each `query()` its own connection. `BEGIN` on one and the
|
|
91
|
+
* next statement on another is a transaction that silently is not one, so this
|
|
92
|
+
* adapter never writes multi-statement transactions. Everything that must be
|
|
93
|
+
* atomic is ONE statement: `putMany` is one multi-row upsert, `putIfVersion` is
|
|
94
|
+
* one conditional upsert, `forget` is one statement with CTEs across all four
|
|
95
|
+
* tables. That is a constraint that made the code better.
|
|
96
|
+
*
|
|
97
|
+
* ── Lazy peer dependency ────────────────────────────────────────────────────
|
|
98
|
+
* `pg` is an OPTIONAL peer dependency, required at construction time. Importing
|
|
99
|
+
* `agentfootprint/memory` costs nothing for consumers who never build one of
|
|
100
|
+
* these. Pass `client` to reuse the pool your app already has — which is the
|
|
101
|
+
* recommended shape, because a second pool to the same database is a second set
|
|
102
|
+
* of connections nobody counted.
|
|
103
|
+
*/
|
|
104
|
+
import type { MemoryIdentity } from '../../memory/identity/index.js';
|
|
105
|
+
import type { MemoryStore } from '../../memory/store/types.js';
|
|
106
|
+
/** One result set, as this adapter reads it. */
|
|
107
|
+
export interface PgQueryResult {
|
|
108
|
+
readonly rows: readonly Record<string, unknown>[];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The slice of a `pg` client this adapter calls.
|
|
112
|
+
*
|
|
113
|
+
* Structural, so a `Pool`, a `Client`, a pgBouncer-fronted wrapper or a test
|
|
114
|
+
* double all satisfy it without this package taking a hard type dependency on
|
|
115
|
+
* the optional peer.
|
|
116
|
+
*/
|
|
117
|
+
export interface PgLikeClient {
|
|
118
|
+
query(text: string, params?: readonly unknown[]): Promise<PgQueryResult>;
|
|
119
|
+
/** Optional — awaited by {@link PgVectorStore.close} when this store built the pool. */
|
|
120
|
+
end?(): Promise<void>;
|
|
121
|
+
}
|
|
122
|
+
/** The one constructor this adapter needs out of `pg`. */
|
|
123
|
+
export interface PgSdkModule {
|
|
124
|
+
readonly Pool?: new (config: {
|
|
125
|
+
connectionString?: string;
|
|
126
|
+
}) => PgLikeClient;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Column names, so this store fits a schema that already has conventions.
|
|
130
|
+
* Every one defaults to the name in the `CREATE TABLE` above.
|
|
131
|
+
*/
|
|
132
|
+
export interface PgVectorColumns {
|
|
133
|
+
readonly namespace?: string;
|
|
134
|
+
readonly id?: string;
|
|
135
|
+
readonly value?: string;
|
|
136
|
+
readonly metadata?: string;
|
|
137
|
+
readonly embedding?: string;
|
|
138
|
+
readonly embedderFp?: string;
|
|
139
|
+
readonly version?: string;
|
|
140
|
+
readonly createdAt?: string;
|
|
141
|
+
readonly updatedAt?: string;
|
|
142
|
+
readonly lastAccessedAt?: string;
|
|
143
|
+
readonly accessCount?: string;
|
|
144
|
+
readonly ttl?: string;
|
|
145
|
+
readonly tier?: string;
|
|
146
|
+
readonly source?: string;
|
|
147
|
+
readonly embeddingModel?: string;
|
|
148
|
+
}
|
|
149
|
+
export interface PgVectorStoreOptions {
|
|
150
|
+
/**
|
|
151
|
+
* Postgres connection string, used only when this store builds its own pool.
|
|
152
|
+
* Prefer `client` — a second pool to one database is a second set of
|
|
153
|
+
* connections nobody counted.
|
|
154
|
+
*/
|
|
155
|
+
readonly connectionString?: string;
|
|
156
|
+
/** A pre-built `pg.Pool` (or anything with `query`). Recommended. */
|
|
157
|
+
readonly client?: PgLikeClient;
|
|
158
|
+
/** Schema the tables live in. Default `'public'`. */
|
|
159
|
+
readonly schema?: string;
|
|
160
|
+
/** The vectors table. Default `'af_vectors'`. */
|
|
161
|
+
readonly table?: string;
|
|
162
|
+
/** The recognition-set table (`seen`/`recordSignature`). Default `'af_signatures'`. */
|
|
163
|
+
readonly signaturesTable?: string;
|
|
164
|
+
/** The usefulness-aggregate table. Default `'af_feedback'`. */
|
|
165
|
+
readonly feedbackTable?: string;
|
|
166
|
+
/** The key/value table holding one embedder fingerprint per namespace. Default `'af_index_meta'`. */
|
|
167
|
+
readonly metaTable?: string;
|
|
168
|
+
/** Column names inside {@link table}. Each defaults to the documented one. */
|
|
169
|
+
readonly columns?: PgVectorColumns;
|
|
170
|
+
/**
|
|
171
|
+
* Rows per multi-row upsert. Default 500.
|
|
172
|
+
*
|
|
173
|
+
* Postgres caps a statement at 65,535 bound parameters and this store binds
|
|
174
|
+
* 15 per row, so 500 leaves an order of magnitude of headroom. Raising it
|
|
175
|
+
* trades round-trips for a statement that fails all-or-nothing on a bigger
|
|
176
|
+
* unit.
|
|
177
|
+
*/
|
|
178
|
+
readonly batchSize?: number;
|
|
179
|
+
/** @internal Test injection — skips the `pg` require entirely. */
|
|
180
|
+
readonly _client?: PgLikeClient;
|
|
181
|
+
/** @internal Test injection — the `pg` module (exercises the real shim with a mock module). */
|
|
182
|
+
readonly _pg?: PgSdkModule;
|
|
183
|
+
}
|
|
184
|
+
/** A Postgres-backed vector store, plus the two things it owns beyond the port. */
|
|
185
|
+
export interface PgVectorStore extends MemoryStore {
|
|
186
|
+
/**
|
|
187
|
+
* The embedder fingerprint (`'<id>@<dims>'`) a namespace was built with, or
|
|
188
|
+
* `undefined` when nothing with a vector has been written to it yet.
|
|
189
|
+
*
|
|
190
|
+
* Read this before an embedder swap: it is the fact `EmbedderMismatchError`
|
|
191
|
+
* refuses on, available up front instead of at the first failed write.
|
|
192
|
+
*/
|
|
193
|
+
fingerprintOf(identity: MemoryIdentity): Promise<string | undefined>;
|
|
194
|
+
/**
|
|
195
|
+
* Release the pool, if this store built one. Idempotent. A client you passed
|
|
196
|
+
* in is yours and is left alone.
|
|
197
|
+
*/
|
|
198
|
+
close(): Promise<void>;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Raised when the database is reachable but its schema is not this store's.
|
|
202
|
+
*
|
|
203
|
+
* The law `sqliteVectorStore` states for a file, one backend over: **an
|
|
204
|
+
* unreadable index and an empty one are different facts, and only one of them
|
|
205
|
+
* is safe to answer with "no matches".** A store that treated a missing table
|
|
206
|
+
* as an empty corpus would answer every question from the model's own weights
|
|
207
|
+
* and log nothing.
|
|
208
|
+
*/
|
|
209
|
+
export declare class PgVectorSchemaError extends Error {
|
|
210
|
+
readonly code: "ERR_PGVECTOR_SCHEMA";
|
|
211
|
+
/** The schema-qualified table that could not be used. */
|
|
212
|
+
readonly table: string;
|
|
213
|
+
/** Columns this store needs and did not find. Empty when the table is absent entirely. */
|
|
214
|
+
readonly missingColumns: readonly string[];
|
|
215
|
+
constructor(table: string, missingColumns: readonly string[], detail: string);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Open a `MemoryStore` over an existing Postgres + pgvector table.
|
|
219
|
+
*
|
|
220
|
+
* @throws when `pg` is absent and no `client` was passed.
|
|
221
|
+
* @throws PgVectorSchemaError on the first call, when the table or a column it
|
|
222
|
+
* needs is not there.
|
|
223
|
+
* @throws EmbedderMismatchError from `put`/`putMany`/`search` when a vector
|
|
224
|
+
* meets a namespace built by a different embedder.
|
|
225
|
+
*
|
|
226
|
+
* @example A corpus beside the application's own data
|
|
227
|
+
* ```ts
|
|
228
|
+
* import { Pool } from 'pg';
|
|
229
|
+
* import { defineRAG, indexDocuments } from 'agentfootprint';
|
|
230
|
+
* import { pgVectorStore } from 'agentfootprint/memory';
|
|
231
|
+
* import { openaiEmbedder } from 'agentfootprint/providers';
|
|
232
|
+
*
|
|
233
|
+
* const store = pgVectorStore({ client: new Pool({ connectionString: process.env.DATABASE_URL }) });
|
|
234
|
+
* const embedder = openaiEmbedder();
|
|
235
|
+
*
|
|
236
|
+
* await indexDocuments(store, embedder, docs, { embedderId: embedder.id });
|
|
237
|
+
*
|
|
238
|
+
* const agent = Agent.create({ provider })
|
|
239
|
+
* .rag(defineRAG({ id: 'docs', store, embedder, embedderId: embedder.id }))
|
|
240
|
+
* .build();
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
export declare function pgVectorStore(options?: PgVectorStoreOptions): PgVectorStore;
|
|
244
|
+
//# sourceMappingURL=pgVector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pgVector.d.ts","sourceRoot":"","sources":["../../../../src/adapters/memory/pgVector.ts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