@framers/agentos 0.1.247 → 0.1.249
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/memory/CognitiveMemoryManager.d.ts +47 -0
- package/dist/memory/CognitiveMemoryManager.d.ts.map +1 -1
- package/dist/memory/CognitiveMemoryManager.js +54 -0
- package/dist/memory/CognitiveMemoryManager.js.map +1 -1
- package/dist/memory/core/types.d.ts +31 -0
- package/dist/memory/core/types.d.ts.map +1 -1
- package/dist/memory/index.d.ts +13 -1
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +24 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/ingest/SessionSummarizer.d.ts +155 -0
- package/dist/memory/ingest/SessionSummarizer.d.ts.map +1 -0
- package/dist/memory/ingest/SessionSummarizer.js +178 -0
- package/dist/memory/ingest/SessionSummarizer.js.map +1 -0
- package/dist/memory/retrieval/fact-supersession/FactSupersession.d.ts +82 -0
- package/dist/memory/retrieval/fact-supersession/FactSupersession.d.ts.map +1 -0
- package/dist/memory/retrieval/fact-supersession/FactSupersession.js +159 -0
- package/dist/memory/retrieval/fact-supersession/FactSupersession.js.map +1 -0
- package/dist/memory/retrieval/fact-supersession/index.d.ts +10 -0
- package/dist/memory/retrieval/fact-supersession/index.d.ts.map +1 -0
- package/dist/memory/retrieval/fact-supersession/index.js +9 -0
- package/dist/memory/retrieval/fact-supersession/index.js.map +1 -0
- package/dist/memory/retrieval/hybrid/HybridRetriever.d.ts +151 -0
- package/dist/memory/retrieval/hybrid/HybridRetriever.d.ts.map +1 -0
- package/dist/memory/retrieval/hybrid/HybridRetriever.js +287 -0
- package/dist/memory/retrieval/hybrid/HybridRetriever.js.map +1 -0
- package/dist/memory/retrieval/hybrid/index.d.ts +12 -0
- package/dist/memory/retrieval/hybrid/index.d.ts.map +1 -0
- package/dist/memory/retrieval/hybrid/index.js +10 -0
- package/dist/memory/retrieval/hybrid/index.js.map +1 -0
- package/dist/memory/retrieval/hybrid/reciprocalRankFusion.d.ts +87 -0
- package/dist/memory/retrieval/hybrid/reciprocalRankFusion.d.ts.map +1 -0
- package/dist/memory/retrieval/hybrid/reciprocalRankFusion.js +88 -0
- package/dist/memory/retrieval/hybrid/reciprocalRankFusion.js.map +1 -0
- package/dist/memory/retrieval/session/SessionRetriever.d.ts +123 -0
- package/dist/memory/retrieval/session/SessionRetriever.d.ts.map +1 -0
- package/dist/memory/retrieval/session/SessionRetriever.js +220 -0
- package/dist/memory/retrieval/session/SessionRetriever.js.map +1 -0
- package/dist/memory/retrieval/session/SessionSummaryStore.d.ts +122 -0
- package/dist/memory/retrieval/session/SessionSummaryStore.d.ts.map +1 -0
- package/dist/memory/retrieval/session/SessionSummaryStore.js +142 -0
- package/dist/memory/retrieval/session/SessionSummaryStore.js.map +1 -0
- package/dist/memory/retrieval/session/index.d.ts +12 -0
- package/dist/memory/retrieval/session/index.d.ts.map +1 -0
- package/dist/memory/retrieval/session/index.js +10 -0
- package/dist/memory/retrieval/session/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file SessionSummaryStore.ts
|
|
3
|
+
* @description Vector store for session-level summaries, used by
|
|
4
|
+
* {@link SessionRetriever} to select top-K relevant sessions at
|
|
5
|
+
* retrieval time before drilling into chunk-level results.
|
|
6
|
+
*
|
|
7
|
+
* ## What this does
|
|
8
|
+
*
|
|
9
|
+
* Maintains a per-scope vector collection
|
|
10
|
+
* `<collectionPrefix>_<scope>_<scopeId>` (default prefix
|
|
11
|
+
* `cogmem_sessions`) with one vector per unique session. Each vector
|
|
12
|
+
* is the embedding of that session's {@link SessionSummarizer}
|
|
13
|
+
* output: a 50-100 token dense fact-laden summary.
|
|
14
|
+
*
|
|
15
|
+
* ## Why a dedicated collection
|
|
16
|
+
*
|
|
17
|
+
* Session summaries are a structurally different retrieval target
|
|
18
|
+
* than individual memory traces: there's one per conversation thread,
|
|
19
|
+
* they live longer, and they want to be searched in their own metric
|
|
20
|
+
* space without dilution from per-chunk vectors. A dedicated
|
|
21
|
+
* collection also lets {@link SessionRetriever} do Stage 1 session
|
|
22
|
+
* selection with a single cheap vector search, independent of the
|
|
23
|
+
* chunk-level trace store.
|
|
24
|
+
*
|
|
25
|
+
* ## Relation to Anthropic contextual retrieval
|
|
26
|
+
*
|
|
27
|
+
* `SessionSummarizer` implements the Anthropic Sep-2024
|
|
28
|
+
* contextual-retrieval pattern at session granularity: it prepends
|
|
29
|
+
* a summary to every chunk before embedding. This store is the
|
|
30
|
+
* retrieval-time counterpart. It lets callers search the summaries
|
|
31
|
+
* directly rather than relying on the prepended-summary chunks to
|
|
32
|
+
* surface via their own query embeddings. Together they form the
|
|
33
|
+
* `SessionRetriever` two-stage flow documented in the Step 2 design
|
|
34
|
+
* spec.
|
|
35
|
+
*
|
|
36
|
+
* @module agentos/memory/retrieval/session/SessionSummaryStore
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Dedicated vector store wrapper for session-level summaries.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const store = new SessionSummaryStore({ vectorStore, embeddingManager });
|
|
44
|
+
* await store.indexSession({
|
|
45
|
+
* scope: 'user', scopeId: 'u42', sessionId: 's-7',
|
|
46
|
+
* summary: 'User discussed adopting a rescue dog from Portland shelter...',
|
|
47
|
+
* });
|
|
48
|
+
* const hits = await store.querySessions('rescue dog adoption', {
|
|
49
|
+
* scope: 'user', scopeId: 'u42', topK: 5,
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export class SessionSummaryStore {
|
|
54
|
+
constructor(opts) {
|
|
55
|
+
this.vectorStore = opts.vectorStore;
|
|
56
|
+
this.embeddingManager = opts.embeddingManager;
|
|
57
|
+
this.collectionPrefix = opts.collectionPrefix ?? 'cogmem_sessions';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Embed the summary and upsert into the scope-specific collection.
|
|
61
|
+
* Upsert is idempotent: re-indexing the same `sessionId` replaces
|
|
62
|
+
* the prior vector rather than appending a duplicate.
|
|
63
|
+
*/
|
|
64
|
+
async indexSession(input) {
|
|
65
|
+
if (!input.summary || input.summary.trim().length === 0)
|
|
66
|
+
return;
|
|
67
|
+
const collection = this.collectionName(input.scope, input.scopeId);
|
|
68
|
+
const { embeddings } = await this.embeddingManager.generateEmbeddings({
|
|
69
|
+
texts: input.summary,
|
|
70
|
+
});
|
|
71
|
+
const embedding = embeddings[0];
|
|
72
|
+
await this.ensureCollection(collection, embedding.length);
|
|
73
|
+
const doc = {
|
|
74
|
+
id: input.sessionId,
|
|
75
|
+
textContent: input.summary,
|
|
76
|
+
embedding,
|
|
77
|
+
metadata: {
|
|
78
|
+
sessionId: input.sessionId,
|
|
79
|
+
scopeId: input.scopeId,
|
|
80
|
+
createdAt: Date.now(),
|
|
81
|
+
...(input.sessionDate ? { sessionDate: input.sessionDate } : {}),
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
await this.vectorStore.upsert(collection, [doc]);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Embed the query and return the top-K sessions for the given
|
|
88
|
+
* scope, ordered by descending similarity. Returns `[]` when the
|
|
89
|
+
* collection does not yet exist (cold scope).
|
|
90
|
+
*/
|
|
91
|
+
async querySessions(query, options) {
|
|
92
|
+
const collection = this.collectionName(options.scope, options.scopeId);
|
|
93
|
+
const exists = this.vectorStore.collectionExists
|
|
94
|
+
? await this.vectorStore.collectionExists(collection)
|
|
95
|
+
: true;
|
|
96
|
+
if (!exists)
|
|
97
|
+
return [];
|
|
98
|
+
const { embeddings } = await this.embeddingManager.generateEmbeddings({ texts: query });
|
|
99
|
+
const queryEmbedding = embeddings[0];
|
|
100
|
+
try {
|
|
101
|
+
const results = await this.vectorStore.query(collection, queryEmbedding, {
|
|
102
|
+
topK: options.topK,
|
|
103
|
+
includeMetadata: true,
|
|
104
|
+
});
|
|
105
|
+
return results.documents.map((d) => ({
|
|
106
|
+
sessionId: d.metadata?.sessionId ?? d.id,
|
|
107
|
+
similarityScore: d.similarityScore ?? 0,
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Collection may have been dropped between the existence check
|
|
112
|
+
// and the query. Degrade to empty rather than throwing.
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** Compose the per-scope collection name. */
|
|
117
|
+
collectionName(scope, scopeId) {
|
|
118
|
+
return `${this.collectionPrefix}_${scope}_${scopeId}`;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Lazily create the collection with the embedding dimension from
|
|
122
|
+
* the first indexed vector. Idempotent on the `InMemoryVectorStore`
|
|
123
|
+
* implementation; other providers' `createCollection` variants
|
|
124
|
+
* honour `overwriteIfExists: false`.
|
|
125
|
+
*/
|
|
126
|
+
async ensureCollection(collection, dim) {
|
|
127
|
+
try {
|
|
128
|
+
const exists = this.vectorStore.collectionExists
|
|
129
|
+
? await this.vectorStore.collectionExists(collection)
|
|
130
|
+
: true;
|
|
131
|
+
if (!exists) {
|
|
132
|
+
await this.vectorStore.createCollection?.(collection, dim, {
|
|
133
|
+
overwriteIfExists: false,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Some providers auto-create on first upsert — swallow here.
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=SessionSummaryStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SessionSummaryStore.js","sourceRoot":"","sources":["../../../../src/memory/retrieval/session/SessionSummaryStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AA+CH;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,mBAAmB;IAK9B,YAAY,IAAgC;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IACK,KAAK,CAAC,gBAAgB,CAAC,UAAkB,EAAE,GAAW;QAC5D,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,gBAAgB;gBAC9C,CAAC,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,CAAC;gBACrD,CAAC,CAAC,IAAI,CAAC;YACT,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;oBACzD,iBAAiB,EAAE,KAAK;iBACzB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,6DAA6D;QAC/D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Barrel exports for session-level hierarchical
|
|
4
|
+
* retrieval (Step 2 of the RAG stack sequenced rollout).
|
|
5
|
+
*
|
|
6
|
+
* @module agentos/memory/retrieval/session
|
|
7
|
+
*/
|
|
8
|
+
export { SessionSummaryStore } from './SessionSummaryStore.js';
|
|
9
|
+
export type { SessionSummaryStoreOptions, IndexSessionInput, QueriedSession, } from './SessionSummaryStore.js';
|
|
10
|
+
export { SessionRetriever } from './SessionRetriever.js';
|
|
11
|
+
export type { SessionRetrieverOptions, SessionRetrieveOptions, } from './SessionRetriever.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/memory/retrieval/session/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EACV,0BAA0B,EAC1B,iBAAiB,EACjB,cAAc,GACf,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EACV,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Barrel exports for session-level hierarchical
|
|
4
|
+
* retrieval (Step 2 of the RAG stack sequenced rollout).
|
|
5
|
+
*
|
|
6
|
+
* @module agentos/memory/retrieval/session
|
|
7
|
+
*/
|
|
8
|
+
export { SessionSummaryStore } from './SessionSummaryStore.js';
|
|
9
|
+
export { SessionRetriever } from './SessionRetriever.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/memory/retrieval/session/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAO/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|