@mastra/mongodb 1.22.0 → 1.22.1-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.
@@ -3,7 +3,7 @@ name: mastra-mongodb
3
3
  description: Documentation for @mastra/mongodb. Use when working with @mastra/mongodb APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mongodb"
6
- version: "1.22.0"
6
+ version: "1.22.1-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.22.0",
2
+ "version": "1.22.1-alpha.0",
3
3
  "package": "@mastra/mongodb",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -411,11 +411,11 @@ PostgreSQL supports both IVFFlat and HNSW indexes. By default, Mastra creates an
411
411
 
412
412
  ```typescript
413
413
  import { Memory } from '@mastra/memory'
414
- import { PgStore, PgVector } from '@mastra/pg'
414
+ import { PostgresStore, PgVector } from '@mastra/pg'
415
415
 
416
416
  const agent = new Agent({
417
417
  memory: new Memory({
418
- storage: new PgStore({
418
+ storage: new PostgresStore({
419
419
  id: 'agent-storage',
420
420
  connectionString: process.env.DATABASE_URL,
421
421
  }),
@@ -272,6 +272,22 @@ Schema-based working memory uses **merge semantics**, meaning the agent only nee
272
272
  - **Set a field to `null` to delete it:** This explicitly removes the field from memory
273
273
  - **Arrays are replaced entirely:** When an array field is provided, it replaces the existing array (arrays aren't merged element-by-element)
274
274
 
275
+ ### Concurrent updates
276
+
277
+ With `scope: 'resource'` and a storage adapter that supports atomic merges (currently `@mastra/pg`), each merge runs inside a row-locked database transaction. Concurrent updates to different fields from separate processes are all kept. Other adapters merge in the application, which only serializes writers inside a single process.
278
+
279
+ To merge a partial update from your own code, call `memory.mergeWorkingMemory()`:
280
+
281
+ ```typescript
282
+ await memory.mergeWorkingMemory({
283
+ threadId: 'thread-1',
284
+ resourceId: 'user-123',
285
+ workingMemory: { preferences: { tone: 'formal' } },
286
+ })
287
+ ```
288
+
289
+ It throws if working memory isn't schema-based and resource-scoped, or if the storage adapter doesn't support atomic merges. Check `await memory.supportsAtomicWorkingMemoryMerge()` first if you need to fall back.
290
+
275
291
  ## Choosing between template and schema
276
292
 
277
293
  - Use a **template** (Markdown) if you want the agent to maintain memory as a free-form text block, such as a user profile or scratchpad. Templates use **replace semantics**: the agent must provide the complete memory content on each update.
@@ -50,23 +50,25 @@ console.log(results)
50
50
 
51
51
  The `topK` parameter specifies the maximum number of most similar results to return from the vector search.
52
52
 
53
- Results include both the text content and a similarity score:
53
+ Each result includes an `id`, a similarity `score`, and the stored `metadata`. When you store chunk text in metadata, it's available as `metadata.text`:
54
54
 
55
55
  ```ts
56
56
  [
57
57
  {
58
- text: 'Climate change poses significant challenges...',
58
+ id: 'chunk-1',
59
59
  score: 0.89,
60
- metadata: { source: 'article1.txt' },
60
+ metadata: { text: 'Climate change poses significant challenges...', source: 'article1.txt' },
61
61
  },
62
62
  {
63
- text: 'Rising temperatures affect crop yields...',
63
+ id: 'chunk-2',
64
64
  score: 0.82,
65
- metadata: { source: 'article1.txt' },
65
+ metadata: { text: 'Rising temperatures affect crop yields...', source: 'article1.txt' },
66
66
  },
67
67
  ]
68
68
  ```
69
69
 
70
+ Results can also include `vector` when you set `includeVector: true`, and `document` when the store returns the original document (Chroma only).
71
+
70
72
  ## Advanced retrieval options
71
73
 
72
74
  ### Metadata Filtering
@@ -230,7 +230,7 @@ await store.upsert({
230
230
  **libSQL**:
231
231
 
232
232
  ```ts
233
- import { LibSQLVector } from '@mastra/core/vector/libsql'
233
+ import { LibSQLVector } from '@mastra/libsql'
234
234
 
235
235
  const store = new LibSQLVector({
236
236
  id: 'libsql-vector',
package/dist/index.cjs CHANGED
@@ -9,7 +9,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
9
9
  let _mastra_core_evals = require("@mastra/core/evals");
10
10
  let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
11
11
  //#region package.json
12
- var version = "1.22.0";
12
+ var version = "1.22.1-alpha.0";
13
13
  //#endregion
14
14
  //#region src/vector/filter.ts
15
15
  /**
@@ -11592,10 +11592,12 @@ var WorkflowsStorageMongoDB = class WorkflowsStorageMongoDB extends _mastra_core
11592
11592
  async dangerouslyClearAll() {
11593
11593
  await (await this.getCollection(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT)).deleteMany({});
11594
11594
  }
11595
- async updateWorkflowResults({ workflowName, runId, stepId, result, requestContext }) {
11595
+ async updateWorkflowResults({ workflowName, runId, stepId, result, requestContext, state }) {
11596
11596
  try {
11597
11597
  const collection = await this.getCollection(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT);
11598
11598
  const now = /* @__PURE__ */ new Date();
11599
+ const contextUpdate = { [stepId]: result };
11600
+ if (state !== void 0) contextUpdate.__state = state;
11599
11601
  const defaultSnapshot = {
11600
11602
  context: {},
11601
11603
  activePaths: [],
@@ -11618,7 +11620,7 @@ var WorkflowsStorageMongoDB = class WorkflowsStorageMongoDB extends _mastra_core
11618
11620
  run_id: runId,
11619
11621
  snapshot: { $mergeObjects: [
11620
11622
  { $ifNull: ["$snapshot", defaultSnapshot] },
11621
- { context: { $mergeObjects: [{ $ifNull: [{ $ifNull: ["$snapshot.context", {}] }, {}] }, { [stepId]: result }] } },
11623
+ { context: { $mergeObjects: [{ $ifNull: [{ $ifNull: ["$snapshot.context", {}] }, {}] }, contextUpdate] } },
11622
11624
  { requestContext: { $mergeObjects: [{ $ifNull: [{ $ifNull: ["$snapshot.requestContext", {}] }, {}] }, requestContext] } }
11623
11625
  ] },
11624
11626
  updatedAt: now,