@mastra/mongodb 1.2.0-alpha.0 → 1.3.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 +176 -0
- package/dist/docs/SKILL.md +17 -23
- package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +1 -1
- package/dist/docs/{memory/01-working-memory.md → references/docs-memory-working-memory.md} +16 -27
- package/dist/docs/{rag/02-retrieval.md → references/docs-rag-retrieval.md} +26 -53
- package/dist/docs/{rag/01-vector-databases.md → references/docs-rag-vector-databases.md} +198 -202
- package/dist/docs/{storage/01-reference.md → references/reference-storage-mongodb.md} +34 -15
- package/dist/docs/{vectors/01-reference.md → references/reference-vectors-mongodb.md} +108 -14
- package/dist/index.cjs +1700 -230
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1700 -232
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/agents/index.d.ts +7 -12
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +7 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/prompt-blocks/index.d.ts +35 -0
- package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts +35 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +3 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -6
- package/dist/docs/README.md +0 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,181 @@
|
|
|
1
1
|
# @mastra/mongodb
|
|
2
2
|
|
|
3
|
+
## 1.3.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- **Updated storage adapters for generic storage domain API** ([#12846](https://github.com/mastra-ai/mastra/pull/12846))
|
|
8
|
+
|
|
9
|
+
All storage adapters now implement the unified `VersionedStorageDomain` method names. Entity-specific methods (`createAgent`, `getAgentById`, `deleteAgent`, etc.) have been replaced with generic equivalents (`create`, `getById`, `delete`, etc.) across agents, prompt blocks, and scorer definitions domains.
|
|
10
|
+
|
|
11
|
+
Added `scorer-definitions` domain support to all adapters.
|
|
12
|
+
|
|
13
|
+
**Before:**
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const store = storage.getStore('agents');
|
|
17
|
+
await store.createAgent({ agent: input });
|
|
18
|
+
await store.getAgentById({ id: 'abc' });
|
|
19
|
+
await store.deleteAgent({ id: 'abc' });
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**After:**
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const store = storage.getStore('agents');
|
|
26
|
+
await store.create({ agent: input });
|
|
27
|
+
await store.getById('abc');
|
|
28
|
+
await store.delete('abc');
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Fixed issues with stored agents ([#12790](https://github.com/mastra-ai/mastra/pull/12790))
|
|
34
|
+
|
|
35
|
+
- **Async buffering for observational memory is now enabled by default.** Observations are pre-computed in the background as conversations grow — when the context window fills up, buffered observations activate instantly with no blocking LLM call. This keeps agents responsive during long conversations. ([#12891](https://github.com/mastra-ai/mastra/pull/12891))
|
|
36
|
+
|
|
37
|
+
**Default settings:**
|
|
38
|
+
- `observation.bufferTokens: 0.2` — buffer every 20% of `messageTokens` (~6k tokens with the default 30k threshold)
|
|
39
|
+
- `observation.bufferActivation: 0.8` — on activation, retain 20% of the message window
|
|
40
|
+
- `reflection.bufferActivation: 0.5` — start background reflection at 50% of the observation threshold
|
|
41
|
+
|
|
42
|
+
**Disabling async buffering:**
|
|
43
|
+
|
|
44
|
+
Set `observation.bufferTokens: false` to disable async buffering for both observations and reflections:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const memory = new Memory({
|
|
48
|
+
options: {
|
|
49
|
+
observationalMemory: {
|
|
50
|
+
model: 'google/gemini-2.5-flash',
|
|
51
|
+
observation: {
|
|
52
|
+
bufferTokens: false,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Model is now required** when passing an observational memory config object. Use `observationalMemory: true` for the default (google/gemini-2.5-flash), or set a model explicitly:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
// Uses default model (google/gemini-2.5-flash)
|
|
63
|
+
observationalMemory: true
|
|
64
|
+
|
|
65
|
+
// Explicit model
|
|
66
|
+
observationalMemory: {
|
|
67
|
+
model: "google/gemini-2.5-flash",
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**`shareTokenBudget` requires `bufferTokens: false`** (temporary limitation). If you use `shareTokenBudget: true`, you must explicitly disable async buffering:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
observationalMemory: {
|
|
75
|
+
model: "google/gemini-2.5-flash",
|
|
76
|
+
shareTokenBudget: true,
|
|
77
|
+
observation: { bufferTokens: false },
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**New streaming event:** `data-om-status` replaces `data-om-progress` with a structured status object containing active window usage, buffered observation/reflection state, and projected activation impact.
|
|
82
|
+
|
|
83
|
+
**Buffering markers:** New `data-om-buffering-start`, `data-om-buffering-end`, and `data-om-buffering-failed` streaming events for UI feedback during background operations.
|
|
84
|
+
|
|
85
|
+
- Added prompt block storage implementations. Each store supports full CRUD for prompt blocks and their versions, including JSON serialization for rules and metadata. Also updated agent instructions serialization to support the new `AgentInstructionBlock` array format alongside plain strings. ([#12776](https://github.com/mastra-ai/mastra/pull/12776))
|
|
86
|
+
|
|
87
|
+
- Updated dependencies [[`717ffab`](https://github.com/mastra-ai/mastra/commit/717ffab42cfd58ff723b5c19ada4939997773004), [`e4b6dab`](https://github.com/mastra-ai/mastra/commit/e4b6dab171c5960e340b3ea3ea6da8d64d2b8672), [`5719fa8`](https://github.com/mastra-ai/mastra/commit/5719fa8880e86e8affe698ec4b3807c7e0e0a06f), [`83cda45`](https://github.com/mastra-ai/mastra/commit/83cda4523e588558466892bff8f80f631a36945a), [`11804ad`](https://github.com/mastra-ai/mastra/commit/11804adf1d6be46ebe216be40a43b39bb8b397d7), [`aa95f95`](https://github.com/mastra-ai/mastra/commit/aa95f958b186ae5c9f4219c88e268f5565c277a2), [`f5501ae`](https://github.com/mastra-ai/mastra/commit/f5501aedb0a11106c7db7e480d6eaf3971b7bda8), [`44573af`](https://github.com/mastra-ai/mastra/commit/44573afad0a4bc86f627d6cbc0207961cdcb3bc3), [`00e3861`](https://github.com/mastra-ai/mastra/commit/00e3861863fbfee78faeb1ebbdc7c0223aae13ff), [`7bfbc52`](https://github.com/mastra-ai/mastra/commit/7bfbc52a8604feb0fff2c0a082c13c0c2a3df1a2), [`1445994`](https://github.com/mastra-ai/mastra/commit/1445994aee19c9334a6a101cf7bd80ca7ed4d186), [`61f44a2`](https://github.com/mastra-ai/mastra/commit/61f44a26861c89e364f367ff40825bdb7f19df55), [`37145d2`](https://github.com/mastra-ai/mastra/commit/37145d25f99dc31f1a9105576e5452609843ce32), [`fdad759`](https://github.com/mastra-ai/mastra/commit/fdad75939ff008b27625f5ec0ce9c6915d99d9ec), [`e4569c5`](https://github.com/mastra-ai/mastra/commit/e4569c589e00c4061a686c9eb85afe1b7050b0a8), [`7309a85`](https://github.com/mastra-ai/mastra/commit/7309a85427281a8be23f4fb80ca52e18eaffd596), [`99424f6`](https://github.com/mastra-ai/mastra/commit/99424f6862ffb679c4ec6765501486034754a4c2), [`44eb452`](https://github.com/mastra-ai/mastra/commit/44eb4529b10603c279688318bebf3048543a1d61), [`6c40593`](https://github.com/mastra-ai/mastra/commit/6c40593d6d2b1b68b0c45d1a3a4c6ac5ecac3937), [`8c1135d`](https://github.com/mastra-ai/mastra/commit/8c1135dfb91b057283eae7ee11f9ec28753cc64f), [`dd39e54`](https://github.com/mastra-ai/mastra/commit/dd39e54ea34532c995b33bee6e0e808bf41a7341), [`b6fad9a`](https://github.com/mastra-ai/mastra/commit/b6fad9a602182b1cc0df47cd8c55004fa829ad61), [`4129c07`](https://github.com/mastra-ai/mastra/commit/4129c073349b5a66643fd8136ebfe9d7097cf793), [`5b930ab`](https://github.com/mastra-ai/mastra/commit/5b930aba1834d9898e8460a49d15106f31ac7c8d), [`4be93d0`](https://github.com/mastra-ai/mastra/commit/4be93d09d68e20aaf0ea3f210749422719618b5f), [`047635c`](https://github.com/mastra-ai/mastra/commit/047635ccd7861d726c62d135560c0022a5490aec), [`8c90ff4`](https://github.com/mastra-ai/mastra/commit/8c90ff4d3414e7f2a2d216ea91274644f7b29133), [`ed232d1`](https://github.com/mastra-ai/mastra/commit/ed232d1583f403925dc5ae45f7bee948cf2a182b), [`3891795`](https://github.com/mastra-ai/mastra/commit/38917953518eb4154a984ee36e6ededdcfe80f72), [`4f955b2`](https://github.com/mastra-ai/mastra/commit/4f955b20c7f66ed282ee1fd8709696fa64c4f19d), [`55a4c90`](https://github.com/mastra-ai/mastra/commit/55a4c9044ac7454349b9f6aeba0bbab5ee65d10f)]:
|
|
88
|
+
- @mastra/core@1.3.0-alpha.1
|
|
89
|
+
|
|
90
|
+
## 1.2.0
|
|
91
|
+
|
|
92
|
+
### Minor Changes
|
|
93
|
+
|
|
94
|
+
- Added Observational Memory — a new memory system that keeps your agent's context window small while preserving long-term memory across conversations. ([#12599](https://github.com/mastra-ai/mastra/pull/12599))
|
|
95
|
+
|
|
96
|
+
**Why:** Long conversations cause context rot and waste tokens. Observational Memory compresses conversation history into observations (5–40x compression) and periodically condenses those into reflections. Your agent stays fast and focused, even after thousands of messages.
|
|
97
|
+
|
|
98
|
+
**Usage:**
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { Memory } from '@mastra/memory';
|
|
102
|
+
import { PostgresStore } from '@mastra/pg';
|
|
103
|
+
|
|
104
|
+
const memory = new Memory({
|
|
105
|
+
storage: new PostgresStore({ connectionString: process.env.DATABASE_URL }),
|
|
106
|
+
options: {
|
|
107
|
+
observationalMemory: true,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const agent = new Agent({
|
|
112
|
+
name: 'my-agent',
|
|
113
|
+
model: openai('gpt-4o'),
|
|
114
|
+
memory,
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**What's new:**
|
|
119
|
+
- `observationalMemory: true` enables the three-tier memory system (recent messages → observations → reflections)
|
|
120
|
+
- Thread-scoped (per-conversation) and resource-scoped (shared across all threads for a user) modes
|
|
121
|
+
- Manual `observe()` API for triggering observation outside the normal agent loop
|
|
122
|
+
- New OM storage methods for pg, libsql, and mongodb adapters (conditionally enabled)
|
|
123
|
+
- `Agent.findProcessor()` method for looking up processors by ID
|
|
124
|
+
- `processorStates` for persisting processor state across loop iterations
|
|
125
|
+
- Abort signal propagation to processors
|
|
126
|
+
- `ProcessorStreamWriter` for custom stream events from processors
|
|
127
|
+
|
|
128
|
+
### Patch Changes
|
|
129
|
+
|
|
130
|
+
- Created @mastra/editor package for managing and resolving stored agent configurations ([#12631](https://github.com/mastra-ai/mastra/pull/12631))
|
|
131
|
+
|
|
132
|
+
This major addition introduces the editor package, which provides a complete solution for storing, versioning, and instantiating agent configurations from a database. The editor seamlessly integrates with Mastra's storage layer to enable dynamic agent management.
|
|
133
|
+
|
|
134
|
+
**Key Features:**
|
|
135
|
+
- **Agent Storage & Retrieval**: Store complete agent configurations including instructions, model settings, tools, workflows, nested agents, scorers, processors, and memory configuration
|
|
136
|
+
- **Version Management**: Create and manage multiple versions of agents, with support for activating specific versions
|
|
137
|
+
- **Dependency Resolution**: Automatically resolves and instantiates all agent dependencies (tools, workflows, sub-agents, etc.) from the Mastra registry
|
|
138
|
+
- **Caching**: Built-in caching for improved performance when repeatedly accessing stored agents
|
|
139
|
+
- **Type Safety**: Full TypeScript support with proper typing for stored configurations
|
|
140
|
+
|
|
141
|
+
**Usage Example:**
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import { MastraEditor } from '@mastra/editor';
|
|
145
|
+
import { Mastra } from '@mastra/core';
|
|
146
|
+
|
|
147
|
+
// Initialize editor with Mastra
|
|
148
|
+
const mastra = new Mastra({
|
|
149
|
+
/* config */
|
|
150
|
+
editor: new MastraEditor(),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Store an agent configuration
|
|
154
|
+
const agentId = await mastra.storage.stores?.agents?.createAgent({
|
|
155
|
+
name: 'customer-support',
|
|
156
|
+
instructions: 'Help customers with inquiries',
|
|
157
|
+
model: { provider: 'openai', name: 'gpt-4' },
|
|
158
|
+
tools: ['search-kb', 'create-ticket'],
|
|
159
|
+
workflows: ['escalation-flow'],
|
|
160
|
+
memory: { vector: 'pinecone-db' },
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Retrieve and use the stored agent
|
|
164
|
+
const agent = await mastra.getEditor()?.getStoredAgentById(agentId);
|
|
165
|
+
const response = await agent?.generate('How do I reset my password?');
|
|
166
|
+
|
|
167
|
+
// List all stored agents
|
|
168
|
+
const agents = await mastra.getEditor()?.listStoredAgents({ pageSize: 10 });
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Storage Improvements:**
|
|
172
|
+
- Fixed JSONB handling in LibSQL, PostgreSQL, and MongoDB adapters
|
|
173
|
+
- Improved agent resolution queries to properly merge version data
|
|
174
|
+
- Enhanced type safety for serialized configurations
|
|
175
|
+
|
|
176
|
+
- Updated dependencies [[`e6fc281`](https://github.com/mastra-ai/mastra/commit/e6fc281896a3584e9e06465b356a44fe7faade65), [`97be6c8`](https://github.com/mastra-ai/mastra/commit/97be6c8963130fca8a664fcf99d7b3a38e463595), [`2770921`](https://github.com/mastra-ai/mastra/commit/2770921eec4d55a36b278d15c3a83f694e462ee5), [`b1695db`](https://github.com/mastra-ai/mastra/commit/b1695db2d7be0c329d499619c7881899649188d0), [`5fe1fe0`](https://github.com/mastra-ai/mastra/commit/5fe1fe0109faf2c87db34b725d8a4571a594f80e), [`4133d48`](https://github.com/mastra-ai/mastra/commit/4133d48eaa354cdb45920dc6265732ffbc96788d), [`5dd01cc`](https://github.com/mastra-ai/mastra/commit/5dd01cce68d61874aa3ecbd91ee17884cfd5aca2), [`13e0a2a`](https://github.com/mastra-ai/mastra/commit/13e0a2a2bcec01ff4d701274b3727d5e907a6a01), [`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), [`c987384`](https://github.com/mastra-ai/mastra/commit/c987384d6c8ca844a9701d7778f09f5a88da7f9f), [`cb8cc12`](https://github.com/mastra-ai/mastra/commit/cb8cc12bfadd526aa95a01125076f1da44e4afa7), [`aa37c84`](https://github.com/mastra-ai/mastra/commit/aa37c84d29b7db68c72517337932ef486c316275), [`62f5d50`](https://github.com/mastra-ai/mastra/commit/62f5d5043debbba497dacb7ab008fe86b38b8de3), [`47eba72`](https://github.com/mastra-ai/mastra/commit/47eba72f0397d0d14fbe324b97940c3d55e5a525)]:
|
|
177
|
+
- @mastra/core@1.2.0
|
|
178
|
+
|
|
3
179
|
## 1.2.0-alpha.0
|
|
4
180
|
|
|
5
181
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
---
|
|
2
|
-
name: mastra-mongodb
|
|
3
|
-
description: Documentation for @mastra/mongodb.
|
|
2
|
+
name: mastra-mongodb
|
|
3
|
+
description: Documentation for @mastra/mongodb. Use when working with @mastra/mongodb APIs, configuration, or implementation.
|
|
4
|
+
metadata:
|
|
5
|
+
package: "@mastra/mongodb"
|
|
6
|
+
version: "1.3.0-alpha.0"
|
|
4
7
|
---
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
## When to use
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
> **Package**: @mastra/mongodb
|
|
11
|
+
Use this skill whenever you are working with @mastra/mongodb to obtain the domain-specific knowledge.
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## How to use
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
Read the individual reference documents for detailed explanations and code examples.
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
cat docs/SOURCE_MAP.json
|
|
17
|
-
```
|
|
17
|
+
### Docs
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
- **docs**: Conceptual documentation in `docs/`
|
|
19
|
+
- [Working Memory](references/docs-memory-working-memory.md) - Learn how to configure working memory in Mastra to store persistent user data, preferences.
|
|
20
|
+
- [Retrieval, Semantic Search, Reranking](references/docs-rag-retrieval.md) - Guide on retrieval processes in Mastra's RAG systems, including semantic search, filtering, and re-ranking.
|
|
21
|
+
- [Storing Embeddings in A Vector Database](references/docs-rag-vector-databases.md) - Guide on vector storage options in Mastra, including embedded and dedicated vector databases for similarity search.
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
### Reference
|
|
25
24
|
|
|
25
|
+
- [Reference: MongoDB Storage](references/reference-storage-mongodb.md) - Documentation for the MongoDB storage implementation in Mastra.
|
|
26
|
+
- [Reference: MongoDB Vector Store](references/reference-vectors-mongodb.md) - Documentation for the MongoDBVector class in Mastra, which provides vector search using MongoDB Atlas and Atlas Vector Search.
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## Available Topics
|
|
31
|
-
|
|
32
|
-
- [Memory](memory/) - 1 file(s)
|
|
33
|
-
- [Rag](rag/) - 2 file(s)
|
|
34
|
-
- [Storage](storage/) - 1 file(s)
|
|
35
|
-
- [Vectors](vectors/) - 1 file(s)
|
|
29
|
+
Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
> Learn how to configure working memory in Mastra to store persistent user data, preferences.
|
|
2
|
-
|
|
3
1
|
# Working Memory
|
|
4
2
|
|
|
5
|
-
While [message history](https://mastra.ai/docs/memory/message-history) and [semantic recall](
|
|
3
|
+
While [message history](https://mastra.ai/docs/memory/message-history) and [semantic recall](https://mastra.ai/docs/memory/semantic-recall) help agents remember conversations, working memory allows them to maintain persistent information about users across interactions.
|
|
6
4
|
|
|
7
5
|
Think of it as the agent's active thoughts or scratchpad – the key information they keep available about the user or task. It's similar to how a person would naturally remember someone's name, preferences, or important details during a conversation.
|
|
8
6
|
|
|
@@ -19,7 +17,7 @@ Working memory can persist at two different scopes:
|
|
|
19
17
|
|
|
20
18
|
Here's a minimal example of setting up an agent with working memory:
|
|
21
19
|
|
|
22
|
-
```typescript
|
|
20
|
+
```typescript
|
|
23
21
|
import { Agent } from "@mastra/core/agent";
|
|
24
22
|
import { Memory } from "@mastra/memory";
|
|
25
23
|
|
|
@@ -43,7 +41,7 @@ const agent = new Agent({
|
|
|
43
41
|
|
|
44
42
|
Working memory is a block of Markdown text that the agent is able to update over time to store continuously relevant information:
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
[YouTube video player](https://www.youtube-nocookie.com/embed/UMy_JHLf1n8)
|
|
47
45
|
|
|
48
46
|
## Memory Persistence Scopes
|
|
49
47
|
|
|
@@ -136,7 +134,7 @@ Templates guide the agent on what information to track and update in working mem
|
|
|
136
134
|
|
|
137
135
|
Here's an example of a custom template. In this example the agent will store the users name, location, timezone, etc as soon as the user sends a message containing any of the info:
|
|
138
136
|
|
|
139
|
-
```typescript
|
|
137
|
+
```typescript
|
|
140
138
|
const memory = new Memory({
|
|
141
139
|
options: {
|
|
142
140
|
workingMemory: {
|
|
@@ -172,19 +170,13 @@ const memory = new Memory({
|
|
|
172
170
|
|
|
173
171
|
## Designing Effective Templates
|
|
174
172
|
|
|
175
|
-
A well-structured template keeps the information easy for the agent to parse and update. Treat the
|
|
176
|
-
template as a short form that you want the assistant to keep up to date.
|
|
173
|
+
A well-structured template keeps the information easy for the agent to parse and update. Treat the template as a short form that you want the assistant to keep up to date.
|
|
177
174
|
|
|
178
|
-
- **Short, focused labels.** Avoid paragraphs or very long headings. Keep labels brief (for example
|
|
179
|
-
|
|
180
|
-
- **
|
|
181
|
-
|
|
182
|
-
- **
|
|
183
|
-
fill in the correct spots.
|
|
184
|
-
- **Abbreviate very long values.** If you only need a short form, include guidance like
|
|
185
|
-
`- Name: [First name or nickname]` or `- Address (short):` rather than the full legal text.
|
|
186
|
-
- **Mention update rules in `instructions`.** You can instruct how and when to fill or clear parts of
|
|
187
|
-
the template directly in the agent's `instructions` field.
|
|
175
|
+
- **Short, focused labels.** Avoid paragraphs or very long headings. Keep labels brief (for example `## Personal Info` or `- Name:`) so updates are easy to read and less likely to be truncated.
|
|
176
|
+
- **Use consistent casing.** Inconsistent capitalization (`Timezone:` vs `timezone:`) can cause messy updates. Stick to Title Case or lower case for headings and bullet labels.
|
|
177
|
+
- **Keep placeholder text simple.** Use hints such as `[e.g., Formal]` or `[Date]` to help the LLM fill in the correct spots.
|
|
178
|
+
- **Abbreviate very long values.** If you only need a short form, include guidance like `- Name: [First name or nickname]` or `- Address (short):` rather than the full legal text.
|
|
179
|
+
- **Mention update rules in `instructions`.** You can instruct how and when to fill or clear parts of the template directly in the agent's `instructions` field.
|
|
188
180
|
|
|
189
181
|
### Alternative Template Styles
|
|
190
182
|
|
|
@@ -281,8 +273,7 @@ Schema-based working memory uses **merge semantics**, meaning the agent only nee
|
|
|
281
273
|
|
|
282
274
|
## Example: Multi-step Retention
|
|
283
275
|
|
|
284
|
-
Below is a simplified view of how the `User Profile` template updates across a short user
|
|
285
|
-
conversation:
|
|
276
|
+
Below is a simplified view of how the `User Profile` template updates across a short user conversation:
|
|
286
277
|
|
|
287
278
|
```nohighlight
|
|
288
279
|
# User Profile
|
|
@@ -308,11 +299,9 @@ conversation:
|
|
|
308
299
|
- Timezone: CET
|
|
309
300
|
```
|
|
310
301
|
|
|
311
|
-
The agent can now refer to `Sam` or `Berlin` in later responses without requesting the information
|
|
312
|
-
again because it has been stored in working memory.
|
|
302
|
+
The agent can now refer to `Sam` or `Berlin` in later responses without requesting the information again because it has been stored in working memory.
|
|
313
303
|
|
|
314
|
-
If your agent is not properly updating working memory when you expect it to, you can add system
|
|
315
|
-
instructions on _how_ and _when_ to use this template in your agent's `instructions` setting.
|
|
304
|
+
If your agent is not properly updating working memory when you expect it to, you can add system instructions on _how_ and _when_ to use this template in your agent's `instructions` setting.
|
|
316
305
|
|
|
317
306
|
## Setting Initial Working Memory
|
|
318
307
|
|
|
@@ -322,7 +311,7 @@ While agents typically update working memory through the `updateWorkingMemory` t
|
|
|
322
311
|
|
|
323
312
|
When creating a thread, you can provide initial working memory through the metadata's `workingMemory` key:
|
|
324
313
|
|
|
325
|
-
```typescript
|
|
314
|
+
```typescript
|
|
326
315
|
// Create a thread with initial working memory
|
|
327
316
|
const thread = await memory.createThread({
|
|
328
317
|
threadId: "thread-123",
|
|
@@ -353,7 +342,7 @@ await agent.generate("What's my blood type?", {
|
|
|
353
342
|
|
|
354
343
|
You can also update an existing thread's working memory:
|
|
355
344
|
|
|
356
|
-
```typescript
|
|
345
|
+
```typescript
|
|
357
346
|
// Update thread metadata to add/modify working memory
|
|
358
347
|
await memory.updateThread({
|
|
359
348
|
id: "thread-123",
|
|
@@ -375,7 +364,7 @@ await memory.updateThread({
|
|
|
375
364
|
|
|
376
365
|
Alternatively, use the `updateWorkingMemory` method directly:
|
|
377
366
|
|
|
378
|
-
```typescript
|
|
367
|
+
```typescript
|
|
379
368
|
await memory.updateWorkingMemory({
|
|
380
369
|
threadId: "thread-123",
|
|
381
370
|
resourceId: "user-456", // Required for resource-scoped memory
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
> Guide on retrieval processes in Mastra
|
|
2
|
-
|
|
3
1
|
# Retrieval in RAG Systems
|
|
4
2
|
|
|
5
3
|
After storing embeddings, you need to retrieve relevant chunks to answer user queries.
|
|
@@ -168,10 +166,9 @@ This is particularly useful when:
|
|
|
168
166
|
|
|
169
167
|
The Vector Query Tool supports database-specific configurations that enable you to leverage unique features and optimizations of different vector stores.
|
|
170
168
|
|
|
171
|
-
> **Note:**
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
Connection credentials (URLs, auth tokens) are configured when you instantiate the vector store class (e.g., `new LibSQLVector({ url: '...' })`).
|
|
169
|
+
> **Note:** These configurations are for **query-time options** like namespaces, performance tuning, and filtering—not for database connection setup.
|
|
170
|
+
>
|
|
171
|
+
> Connection credentials (URLs, auth tokens) are configured when you instantiate the vector store class (e.g., `new LibSQLVector({ url: '...' })`).
|
|
175
172
|
|
|
176
173
|
```ts
|
|
177
174
|
import { createVectorQueryTool } from "@mastra/rag";
|
|
@@ -268,10 +265,9 @@ For detailed configuration options and advanced usage, see the [Vector Query Too
|
|
|
268
265
|
|
|
269
266
|
### Vector Store Prompts
|
|
270
267
|
|
|
271
|
-
Vector store prompts define query patterns and filtering capabilities for each vector database implementation.
|
|
272
|
-
When implementing filtering, these prompts are required in the agent's instructions to specify valid operators and syntax for each vector store implementation.
|
|
268
|
+
Vector store prompts define query patterns and filtering capabilities for each vector database implementation. When implementing filtering, these prompts are required in the agent's instructions to specify valid operators and syntax for each vector store implementation.
|
|
273
269
|
|
|
274
|
-
|
|
270
|
+
**pgVector**:
|
|
275
271
|
|
|
276
272
|
```ts
|
|
277
273
|
import { PGVECTOR_PROMPT } from "@mastra/pg";
|
|
@@ -288,11 +284,9 @@ export const ragAgent = new Agent({
|
|
|
288
284
|
});
|
|
289
285
|
```
|
|
290
286
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
**pinecone:**
|
|
287
|
+
**Pinecone**:
|
|
294
288
|
|
|
295
|
-
```ts
|
|
289
|
+
```ts
|
|
296
290
|
import { PINECONE_PROMPT } from "@mastra/pinecone";
|
|
297
291
|
|
|
298
292
|
export const ragAgent = new Agent({
|
|
@@ -307,11 +301,9 @@ export const ragAgent = new Agent({
|
|
|
307
301
|
});
|
|
308
302
|
```
|
|
309
303
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
**qdrant:**
|
|
304
|
+
**Qdrant**:
|
|
313
305
|
|
|
314
|
-
```ts
|
|
306
|
+
```ts
|
|
315
307
|
import { QDRANT_PROMPT } from "@mastra/qdrant";
|
|
316
308
|
|
|
317
309
|
export const ragAgent = new Agent({
|
|
@@ -326,11 +318,9 @@ export const ragAgent = new Agent({
|
|
|
326
318
|
});
|
|
327
319
|
```
|
|
328
320
|
|
|
329
|
-
|
|
321
|
+
**Chroma**:
|
|
330
322
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
```ts title="vector-store.ts"
|
|
323
|
+
```ts
|
|
334
324
|
import { CHROMA_PROMPT } from "@mastra/chroma";
|
|
335
325
|
|
|
336
326
|
export const ragAgent = new Agent({
|
|
@@ -345,11 +335,9 @@ export const ragAgent = new Agent({
|
|
|
345
335
|
});
|
|
346
336
|
```
|
|
347
337
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
**astra:**
|
|
338
|
+
**Astra**:
|
|
351
339
|
|
|
352
|
-
```ts
|
|
340
|
+
```ts
|
|
353
341
|
import { ASTRA_PROMPT } from "@mastra/astra";
|
|
354
342
|
|
|
355
343
|
export const ragAgent = new Agent({
|
|
@@ -364,11 +352,9 @@ export const ragAgent = new Agent({
|
|
|
364
352
|
});
|
|
365
353
|
```
|
|
366
354
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
**libsql:**
|
|
355
|
+
**libSQL**:
|
|
370
356
|
|
|
371
|
-
```ts
|
|
357
|
+
```ts
|
|
372
358
|
import { LIBSQL_PROMPT } from "@mastra/libsql";
|
|
373
359
|
|
|
374
360
|
export const ragAgent = new Agent({
|
|
@@ -383,11 +369,9 @@ export const ragAgent = new Agent({
|
|
|
383
369
|
});
|
|
384
370
|
```
|
|
385
371
|
|
|
386
|
-
|
|
372
|
+
**Upstash**:
|
|
387
373
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
```ts title="vector-store.ts"
|
|
374
|
+
```ts
|
|
391
375
|
import { UPSTASH_PROMPT } from "@mastra/upstash";
|
|
392
376
|
|
|
393
377
|
export const ragAgent = new Agent({
|
|
@@ -402,11 +386,9 @@ export const ragAgent = new Agent({
|
|
|
402
386
|
});
|
|
403
387
|
```
|
|
404
388
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
**vectorize:**
|
|
389
|
+
**Vectorize**:
|
|
408
390
|
|
|
409
|
-
```ts
|
|
391
|
+
```ts
|
|
410
392
|
import { VECTORIZE_PROMPT } from "@mastra/vectorize";
|
|
411
393
|
|
|
412
394
|
export const ragAgent = new Agent({
|
|
@@ -421,11 +403,9 @@ export const ragAgent = new Agent({
|
|
|
421
403
|
});
|
|
422
404
|
```
|
|
423
405
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
**mongodb:**
|
|
406
|
+
**MongoDB**:
|
|
427
407
|
|
|
428
|
-
```ts
|
|
408
|
+
```ts
|
|
429
409
|
import { MONGODB_PROMPT } from "@mastra/mongodb";
|
|
430
410
|
|
|
431
411
|
export const ragAgent = new Agent({
|
|
@@ -440,11 +420,9 @@ export const ragAgent = new Agent({
|
|
|
440
420
|
});
|
|
441
421
|
```
|
|
442
422
|
|
|
443
|
-
|
|
423
|
+
**OpenSearch**:
|
|
444
424
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
```ts title="vector-store.ts"
|
|
425
|
+
```ts
|
|
448
426
|
import { OPENSEARCH_PROMPT } from "@mastra/opensearch";
|
|
449
427
|
|
|
450
428
|
export const ragAgent = new Agent({
|
|
@@ -459,11 +437,9 @@ export const ragAgent = new Agent({
|
|
|
459
437
|
});
|
|
460
438
|
```
|
|
461
439
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
**s3vectors:**
|
|
440
|
+
**S3Vectors**:
|
|
465
441
|
|
|
466
|
-
```ts
|
|
442
|
+
```ts
|
|
467
443
|
import { S3VECTORS_PROMPT } from "@mastra/s3vectors";
|
|
468
444
|
|
|
469
445
|
export const ragAgent = new Agent({
|
|
@@ -478,8 +454,6 @@ export const ragAgent = new Agent({
|
|
|
478
454
|
});
|
|
479
455
|
```
|
|
480
456
|
|
|
481
|
-
|
|
482
|
-
|
|
483
457
|
### Re-ranking
|
|
484
458
|
|
|
485
459
|
Initial vector similarity search can sometimes miss nuanced relevance. Re-ranking is a more computationally expensive process, but more accurate algorithm that improves results by:
|
|
@@ -528,8 +502,7 @@ The weights control how different factors influence the final ranking:
|
|
|
528
502
|
- `vector`: Higher values favor the original vector similarity scores
|
|
529
503
|
- `position`: Higher values help maintain the original ordering of results
|
|
530
504
|
|
|
531
|
-
> **Note:**
|
|
532
|
-
For semantic scoring to work properly during re-ranking, each result must include the text content in its `metadata.text` field.
|
|
505
|
+
> **Note:** For semantic scoring to work properly during re-ranking, each result must include the text content in its `metadata.text` field.
|
|
533
506
|
|
|
534
507
|
You can also use other relevance score providers like Cohere or ZeroEntropy:
|
|
535
508
|
|