@mastra/memory 0.1.0-alpha.74 → 0.1.0-alpha.76
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 +20 -0
- package/dist/index.js +26 -3
- package/package.json +2 -2
- package/src/index.ts +29 -4
- package/.turbo/turbo-build.log +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.76
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8b416d9: Breaking changes
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 9c10484: update all packages
|
|
12
|
+
- Updated dependencies [9c10484]
|
|
13
|
+
- Updated dependencies [8b416d9]
|
|
14
|
+
- @mastra/core@0.2.0-alpha.94
|
|
15
|
+
|
|
16
|
+
## 0.1.0-alpha.75
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [5285356]
|
|
21
|
+
- @mastra/core@0.2.0-alpha.93
|
|
22
|
+
|
|
3
23
|
## 0.1.0-alpha.74
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import { deepMerge } from '@mastra/core';
|
|
2
2
|
import { MastraMemory } from '@mastra/core/memory';
|
|
3
|
+
import { embed } from 'ai';
|
|
3
4
|
|
|
4
5
|
// src/index.ts
|
|
5
6
|
var Memory = class extends MastraMemory {
|
|
6
7
|
constructor(config) {
|
|
8
|
+
const embedderExample = `
|
|
9
|
+
Example:
|
|
10
|
+
|
|
11
|
+
import { openai } from '@ai-sdk/openai';
|
|
12
|
+
|
|
13
|
+
new Memory({
|
|
14
|
+
embedder: openai.embedding(\`text-embedding-3-small\`)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
`;
|
|
7
18
|
if (config.embeddings) {
|
|
8
19
|
throw new Error(
|
|
9
|
-
|
|
20
|
+
`The \`embeddings\` option is deprecated. Please use \`embedder\` instead.
|
|
21
|
+
${embedderExample}
|
|
22
|
+
`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
if (config.vector && !config.embedder) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`The \`embedder\` option is required when a vector DB is attached to new Memory({ vector })
|
|
28
|
+
|
|
29
|
+
${embedderExample}`
|
|
10
30
|
);
|
|
11
31
|
}
|
|
12
32
|
super({ name: "Memory", ...config });
|
|
@@ -52,7 +72,10 @@ var Memory = class extends MastraMemory {
|
|
|
52
72
|
};
|
|
53
73
|
if (selectBy?.vectorSearchString && this.vector) {
|
|
54
74
|
const embedder = this.getEmbedder();
|
|
55
|
-
const { embedding } = await
|
|
75
|
+
const { embedding } = await embed({
|
|
76
|
+
value: selectBy.vectorSearchString,
|
|
77
|
+
model: embedder
|
|
78
|
+
});
|
|
56
79
|
await this.vector.createIndex("memory_messages", 1536);
|
|
57
80
|
vectorResults = await this.vector.query("memory_messages", embedding, vectorConfig.topK, {
|
|
58
81
|
thread_id: threadId
|
|
@@ -143,7 +166,7 @@ var Memory = class extends MastraMemory {
|
|
|
143
166
|
for (const message of messages) {
|
|
144
167
|
if (typeof message.content !== `string`) continue;
|
|
145
168
|
const embedder = this.getEmbedder();
|
|
146
|
-
const { embedding } = await
|
|
169
|
+
const { embedding } = await embed({ value: message.content, model: embedder, maxRetries: 3 });
|
|
147
170
|
await this.vector.upsert(
|
|
148
171
|
"memory_messages",
|
|
149
172
|
[embedding],
|
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.76",
|
|
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.94"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@babel/preset-env": "^7.26.0",
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CoreMessage, deepMerge } from '@mastra/core';
|
|
2
2
|
import { MastraMemory, MessageType, MemoryConfig, SharedMemoryConfig, StorageThreadType } from '@mastra/core/memory';
|
|
3
3
|
import { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
4
|
-
import { Message as AiMessage } from 'ai';
|
|
4
|
+
import { embed, Message as AiMessage } from 'ai';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Concrete implementation of MastraMemory that adds support for thread configuration
|
|
@@ -14,10 +14,31 @@ export class Memory extends MastraMemory {
|
|
|
14
14
|
embeddings?: any;
|
|
15
15
|
},
|
|
16
16
|
) {
|
|
17
|
+
const embedderExample = `
|
|
18
|
+
Example:
|
|
19
|
+
|
|
20
|
+
import { openai } from '@ai-sdk/openai';
|
|
21
|
+
|
|
22
|
+
new Memory({
|
|
23
|
+
embedder: openai.embedding(\`text-embedding-3-small\`)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
`;
|
|
27
|
+
|
|
17
28
|
// Check for deprecated embeddings object
|
|
18
29
|
if (config.embeddings) {
|
|
19
30
|
throw new Error(
|
|
20
|
-
|
|
31
|
+
`The \`embeddings\` option is deprecated. Please use \`embedder\` instead.
|
|
32
|
+
${embedderExample}
|
|
33
|
+
`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (config.vector && !config.embedder) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`The \`embedder\` option is required when a vector DB is attached to new Memory({ vector })
|
|
40
|
+
|
|
41
|
+
${embedderExample}`,
|
|
21
42
|
);
|
|
22
43
|
}
|
|
23
44
|
|
|
@@ -67,7 +88,11 @@ export class Memory extends MastraMemory {
|
|
|
67
88
|
|
|
68
89
|
if (selectBy?.vectorSearchString && this.vector) {
|
|
69
90
|
const embedder = this.getEmbedder();
|
|
70
|
-
|
|
91
|
+
|
|
92
|
+
const { embedding } = await embed({
|
|
93
|
+
value: selectBy.vectorSearchString,
|
|
94
|
+
model: embedder,
|
|
95
|
+
});
|
|
71
96
|
|
|
72
97
|
await this.vector.createIndex('memory_messages', 1536);
|
|
73
98
|
vectorResults = await this.vector.query('memory_messages', embedding, vectorConfig.topK, {
|
|
@@ -205,7 +230,7 @@ export class Memory extends MastraMemory {
|
|
|
205
230
|
for (const message of messages) {
|
|
206
231
|
if (typeof message.content !== `string`) continue;
|
|
207
232
|
const embedder = this.getEmbedder();
|
|
208
|
-
const { embedding } = await
|
|
233
|
+
const { embedding } = await embed({ value: message.content, model: embedder, maxRetries: 3 });
|
|
209
234
|
await this.vector.upsert(
|
|
210
235
|
'memory_messages',
|
|
211
236
|
[embedding],
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @mastra/memory@0.0.2-alpha.43 build C:\Users\Ward\projects\mastra\mastra\packages\memory
|
|
3
|
-
> dts build
|
|
4
|
-
|
|
5
|
-
⠙ Creating entry file 99% 2.1s, estimated 1.5s
|
|
6
|
-
[2K[1A[2K[G⠙ Building modules 46% 2.1s, estimated 4.5s
|
|
7
|
-
[2K[1A[2K[G✓ Creating entry file 2.1 secs
|
|
8
|
-
⠹ Building modules 66% 3.0s, estimated 4.5s
|
|
9
|
-
[2K[1A[2K[G⠸ Building modules 96% 4.3s, estimated 4.5s
|
|
10
|
-
[2K[1A[2K[G⠼ Building modules 99% 6.4s, estimated 4.5s
|
|
11
|
-
[2K[1A[2K[G⠴ Building modules 99% 6.5s, estimated 4.5s
|
|
12
|
-
[2K[1A[2K[G⠦ Building modules 99% 6.5s, estimated 4.5s
|
|
13
|
-
[2K[1A[2K[G⠧ Building modules 99% 6.6s, estimated 4.5s
|
|
14
|
-
[2K[1A[2K[G✓ Building modules 6.7 secs
|