@mastra/memory 0.1.0-alpha.71 → 0.1.0-alpha.73
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/CHANGELOG.md +24 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +21 -10
- package/package.json +4 -3
- package/src/index.ts +30 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.73
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d7d465a: Breaking change for Memory: embeddings: {} has been replaced with embedder: new OpenAIEmbedder() (or whichever embedder you want - check the docs)
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [d7d465a]
|
|
12
|
+
- Updated dependencies [d7d465a]
|
|
13
|
+
- Updated dependencies [2017553]
|
|
14
|
+
- Updated dependencies [a10b7a3]
|
|
15
|
+
- Updated dependencies [16e5b04]
|
|
16
|
+
- @mastra/core@0.2.0-alpha.91
|
|
17
|
+
|
|
18
|
+
## 0.1.0-alpha.72
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [8151f44]
|
|
23
|
+
- Updated dependencies [e897f1c]
|
|
24
|
+
- Updated dependencies [3700be1]
|
|
25
|
+
- @mastra/core@0.2.0-alpha.90
|
|
26
|
+
|
|
3
27
|
## 0.1.0-alpha.71
|
|
4
28
|
|
|
5
29
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ import { Message } from 'ai';
|
|
|
8
8
|
* and message injection.
|
|
9
9
|
*/
|
|
10
10
|
declare class Memory extends MastraMemory {
|
|
11
|
-
constructor(config: SharedMemoryConfig
|
|
11
|
+
constructor(config: SharedMemoryConfig & {
|
|
12
|
+
embeddings?: any;
|
|
13
|
+
});
|
|
12
14
|
query({ threadId, selectBy, threadConfig, }: StorageGetMessagesArg): Promise<{
|
|
13
15
|
messages: CoreMessage[];
|
|
14
16
|
uiMessages: Message[];
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,11 @@ import { MastraMemory } from '@mastra/core/memory';
|
|
|
4
4
|
// src/index.ts
|
|
5
5
|
var Memory = class extends MastraMemory {
|
|
6
6
|
constructor(config) {
|
|
7
|
+
if (config.embeddings) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
'The `embeddings` option is deprecated. Please use `embedder` instead. Example: new Memory({ embedder: new OpenAIEmbedder({ model: "text-embedding-3-small" }) })'
|
|
10
|
+
);
|
|
11
|
+
}
|
|
7
12
|
super({ name: "Memory", ...config });
|
|
8
13
|
this.defaultWorkingMemoryTemplate = `
|
|
9
14
|
<user>
|
|
@@ -46,9 +51,10 @@ var Memory = class extends MastraMemory {
|
|
|
46
51
|
messageRange: config?.semanticRecall?.messageRange || { before: 2, after: 2 }
|
|
47
52
|
};
|
|
48
53
|
if (selectBy?.vectorSearchString && this.vector) {
|
|
49
|
-
const
|
|
54
|
+
const embedder = this.getEmbedder();
|
|
55
|
+
const { embedding } = await embedder.embed(selectBy.vectorSearchString);
|
|
50
56
|
await this.vector.createIndex("memory_messages", 1536);
|
|
51
|
-
vectorResults = await this.vector.query("memory_messages",
|
|
57
|
+
vectorResults = await this.vector.query("memory_messages", embedding, vectorConfig.topK, {
|
|
52
58
|
thread_id: threadId
|
|
53
59
|
});
|
|
54
60
|
}
|
|
@@ -136,14 +142,19 @@ var Memory = class extends MastraMemory {
|
|
|
136
142
|
await this.vector.createIndex("memory_messages", 1536);
|
|
137
143
|
for (const message of messages) {
|
|
138
144
|
if (typeof message.content !== `string`) continue;
|
|
139
|
-
const
|
|
140
|
-
await
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
const embedder = this.getEmbedder();
|
|
146
|
+
const { embedding } = await embedder.embed(message.content);
|
|
147
|
+
await this.vector.upsert(
|
|
148
|
+
"memory_messages",
|
|
149
|
+
[embedding],
|
|
150
|
+
[
|
|
151
|
+
{
|
|
152
|
+
text: message.content,
|
|
153
|
+
message_id: message.id,
|
|
154
|
+
thread_id: message.threadId
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
);
|
|
147
158
|
}
|
|
148
159
|
}
|
|
149
160
|
return this.storage.__saveMessages({ messages });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/memory",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.73",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"pg-pool": "^3.7.0",
|
|
37
37
|
"postgres": "^3.4.5",
|
|
38
38
|
"redis": "^4.7.0",
|
|
39
|
-
"@mastra/core": "^0.2.0-alpha.
|
|
39
|
+
"@mastra/core": "^0.2.0-alpha.91"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@babel/preset-env": "^7.26.0",
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
"vitest": "^3.0.4"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
|
-
"
|
|
51
|
+
"check": "tsc --noEmit",
|
|
52
|
+
"build": "pnpm run check && tsup src/index.ts --format esm --dts --clean --treeshake",
|
|
52
53
|
"dev": "tsup src/index.ts --format esm --dts --clean --watch",
|
|
53
54
|
"test:integration": "cd integration-tests && pnpm run test",
|
|
54
55
|
"test": "pnpm test:integration"
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,19 @@ import { Message as AiMessage } from 'ai';
|
|
|
8
8
|
* and message injection.
|
|
9
9
|
*/
|
|
10
10
|
export class Memory extends MastraMemory {
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(
|
|
12
|
+
config: SharedMemoryConfig & {
|
|
13
|
+
/* @deprecated use embedder instead */
|
|
14
|
+
embeddings?: any;
|
|
15
|
+
},
|
|
16
|
+
) {
|
|
17
|
+
// Check for deprecated embeddings object
|
|
18
|
+
if (config.embeddings) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'The `embeddings` option is deprecated. Please use `embedder` instead. Example: new Memory({ embedder: new OpenAIEmbedder({ model: "text-embedding-3-small" }) })',
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
12
24
|
super({ name: 'Memory', ...config });
|
|
13
25
|
|
|
14
26
|
const mergedConfig = this.getMergedThreadConfig({
|
|
@@ -54,10 +66,11 @@ export class Memory extends MastraMemory {
|
|
|
54
66
|
};
|
|
55
67
|
|
|
56
68
|
if (selectBy?.vectorSearchString && this.vector) {
|
|
57
|
-
const
|
|
69
|
+
const embedder = this.getEmbedder();
|
|
70
|
+
const { embedding } = await embedder.embed(selectBy.vectorSearchString);
|
|
58
71
|
|
|
59
72
|
await this.vector.createIndex('memory_messages', 1536);
|
|
60
|
-
vectorResults = await this.vector.query('memory_messages',
|
|
73
|
+
vectorResults = await this.vector.query('memory_messages', embedding, vectorConfig.topK, {
|
|
61
74
|
thread_id: threadId,
|
|
62
75
|
});
|
|
63
76
|
}
|
|
@@ -183,7 +196,7 @@ export class Memory extends MastraMemory {
|
|
|
183
196
|
async saveMessages({ messages }: { messages: MessageType[] }): Promise<MessageType[]> {
|
|
184
197
|
// First save working memory from any messages
|
|
185
198
|
await this.saveWorkingMemory(messages);
|
|
186
|
-
|
|
199
|
+
|
|
187
200
|
// Then strip working memory tags from all messages
|
|
188
201
|
this.mutateMessagesToHideWorkingMemory(messages);
|
|
189
202
|
|
|
@@ -191,14 +204,19 @@ export class Memory extends MastraMemory {
|
|
|
191
204
|
await this.vector.createIndex('memory_messages', 1536);
|
|
192
205
|
for (const message of messages) {
|
|
193
206
|
if (typeof message.content !== `string`) continue;
|
|
194
|
-
const
|
|
195
|
-
await
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
207
|
+
const embedder = this.getEmbedder();
|
|
208
|
+
const { embedding } = await embedder.embed(message.content);
|
|
209
|
+
await this.vector.upsert(
|
|
210
|
+
'memory_messages',
|
|
211
|
+
[embedding],
|
|
212
|
+
[
|
|
213
|
+
{
|
|
214
|
+
text: message.content,
|
|
215
|
+
message_id: message.id,
|
|
216
|
+
thread_id: message.threadId,
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
);
|
|
202
220
|
}
|
|
203
221
|
}
|
|
204
222
|
|