@mastra/memory 1.0.1 → 1.1.0-alpha.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/CHANGELOG.md +16 -0
- package/dist/docs/README.md +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +12 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.1.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Expose token usage from embedding operations ([#12556](https://github.com/mastra-ai/mastra/pull/12556))
|
|
8
|
+
- `saveMessages` now returns `usage: { tokens: number }` with aggregated token count from all embeddings
|
|
9
|
+
- `recall` now returns `usage: { tokens: number }` from the vector search query embedding
|
|
10
|
+
- Updated abstract method signatures in `MastraMemory` to include optional `usage` in return types
|
|
11
|
+
|
|
12
|
+
This allows users to track embedding token usage when using the Memory class.
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`e6fc281`](https://github.com/mastra-ai/mastra/commit/e6fc281896a3584e9e06465b356a44fe7faade65), [`97be6c8`](https://github.com/mastra-ai/mastra/commit/97be6c8963130fca8a664fcf99d7b3a38e463595), [`5fe1fe0`](https://github.com/mastra-ai/mastra/commit/5fe1fe0109faf2c87db34b725d8a4571a594f80e), [`f6673b8`](https://github.com/mastra-ai/mastra/commit/f6673b893b65b7d273ad25ead42e990704cc1e17), [`cd6be8a`](https://github.com/mastra-ai/mastra/commit/cd6be8ad32741cd41cabf508355bb31b71e8a5bd), [`9eb4e8e`](https://github.com/mastra-ai/mastra/commit/9eb4e8e39efbdcfff7a40ff2ce07ce2714c65fa8), [`aa37c84`](https://github.com/mastra-ai/mastra/commit/aa37c84d29b7db68c72517337932ef486c316275), [`47eba72`](https://github.com/mastra-ai/mastra/commit/47eba72f0397d0d14fbe324b97940c3d55e5a525)]:
|
|
17
|
+
- @mastra/core@1.2.0-alpha.0
|
|
18
|
+
|
|
3
19
|
## 1.0.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/docs/README.md
CHANGED
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -14671,8 +14671,11 @@ var Memory = class extends memory.MastraMemory {
|
|
|
14671
14671
|
`Memory error: Resource-scoped semantic recall is enabled but no resourceId was provided. Either provide a resourceId or explicitly set semanticRecall.scope to 'thread'.`
|
|
14672
14672
|
);
|
|
14673
14673
|
}
|
|
14674
|
+
let usage;
|
|
14674
14675
|
if (config?.semanticRecall && vectorSearchString && this.vector) {
|
|
14675
|
-
const
|
|
14676
|
+
const result = await this.embedMessageContent(vectorSearchString);
|
|
14677
|
+
usage = result.usage;
|
|
14678
|
+
const { embeddings, dimension } = result;
|
|
14676
14679
|
const { indexName } = await this.createEmbeddingIndex(dimension, config);
|
|
14677
14680
|
await Promise.all(
|
|
14678
14681
|
embeddings.map(async (embedding) => {
|
|
@@ -14716,7 +14719,7 @@ var Memory = class extends memory.MastraMemory {
|
|
|
14716
14719
|
const rawMessages = shouldGetNewestAndReverse ? paginatedResult.messages.reverse() : paginatedResult.messages;
|
|
14717
14720
|
const list = new agent.MessageList({ threadId, resourceId }).add(rawMessages, "memory");
|
|
14718
14721
|
const messages = list.get.all.db();
|
|
14719
|
-
return { messages };
|
|
14722
|
+
return { messages, usage };
|
|
14720
14723
|
}
|
|
14721
14724
|
async getThreadById({ threadId }) {
|
|
14722
14725
|
const memoryStore = await this.getMemoryStore();
|
|
@@ -14963,10 +14966,11 @@ ${workingMemory}`;
|
|
|
14963
14966
|
...this.embedderOptions || {}
|
|
14964
14967
|
});
|
|
14965
14968
|
if (isFastEmbed && !this.firstEmbed) this.firstEmbed = promise;
|
|
14966
|
-
const { embeddings } = await promise;
|
|
14969
|
+
const { embeddings, usage } = await promise;
|
|
14967
14970
|
const result = {
|
|
14968
14971
|
embeddings,
|
|
14969
14972
|
chunks,
|
|
14973
|
+
usage,
|
|
14970
14974
|
dimension: embeddings[0]?.length
|
|
14971
14975
|
};
|
|
14972
14976
|
this.embeddingCache.set(key, result);
|
|
@@ -14987,6 +14991,7 @@ ${workingMemory}`;
|
|
|
14987
14991
|
const result = await memoryStore.saveMessages({
|
|
14988
14992
|
messages: dbMessages
|
|
14989
14993
|
});
|
|
14994
|
+
let totalTokens = 0;
|
|
14990
14995
|
if (this.vector && config.semanticRecall) {
|
|
14991
14996
|
const embeddingData = [];
|
|
14992
14997
|
let dimension;
|
|
@@ -15002,6 +15007,9 @@ ${workingMemory}`;
|
|
|
15002
15007
|
if (!textForEmbedding) return;
|
|
15003
15008
|
const result2 = await this.embedMessageContent(textForEmbedding);
|
|
15004
15009
|
dimension = result2.dimension;
|
|
15010
|
+
if (result2.usage?.tokens) {
|
|
15011
|
+
totalTokens += result2.usage.tokens;
|
|
15012
|
+
}
|
|
15005
15013
|
embeddingData.push({
|
|
15006
15014
|
embeddings: result2.embeddings,
|
|
15007
15015
|
metadata: result2.chunks.map(() => ({
|
|
@@ -15030,7 +15038,7 @@ ${workingMemory}`;
|
|
|
15030
15038
|
});
|
|
15031
15039
|
}
|
|
15032
15040
|
}
|
|
15033
|
-
return result;
|
|
15041
|
+
return { ...result, usage: totalTokens > 0 ? { tokens: totalTokens } : void 0 };
|
|
15034
15042
|
}
|
|
15035
15043
|
updateMessageToHideWorkingMemoryV2(message) {
|
|
15036
15044
|
const newMessage = { ...message };
|