@mastra/mongodb 1.17.0-alpha.0 → 1.17.0-alpha.2

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 CHANGED
@@ -1,5 +1,33 @@
1
1
  # @mastra/mongodb
2
2
 
3
+ ## 1.17.0-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed generated thread titles being clobbered during a turn ([#21041](https://github.com/mastra-ai/mastra/pull/21041))
8
+
9
+ `updateThread` required both `title` and `metadata`, so callers that only needed to
10
+ change metadata (message persistence, working memory, observational memory, channel
11
+ subscriptions) had to read the thread and pass its title back. When title generation
12
+ finished between that read and the write, the freshly generated title was overwritten
13
+ with the stale one.
14
+
15
+ `title` and `metadata` are now independently optional: omitting one leaves that column
16
+ untouched. Callers that only change metadata no longer send a title, and message
17
+ persistence no longer rewrites a thread row it just read.
18
+
19
+ - Updated dependencies [[`1c75e32`](https://github.com/mastra-ai/mastra/commit/1c75e32f7fc0b9fb6f548b4407feaec8a1440212), [`c47165c`](https://github.com/mastra-ai/mastra/commit/c47165c983c87594c6952f1fd2fa51a90205034c), [`e08e789`](https://github.com/mastra-ai/mastra/commit/e08e789c1bf4cd2fe46363f7a4728536ceccc9bd), [`35cc901`](https://github.com/mastra-ai/mastra/commit/35cc90102cf834a84827acaf9eee0b6d6d1e2a3b), [`a8b4cf0`](https://github.com/mastra-ai/mastra/commit/a8b4cf02823cffebc4751a53337dfacf097c1ae1), [`f33264f`](https://github.com/mastra-ai/mastra/commit/f33264f517ae603279afd5c4251e2b40f6dd3618), [`689f2c4`](https://github.com/mastra-ai/mastra/commit/689f2c4b6c0835fe455702b01d21daa8abcd9331), [`eeae63e`](https://github.com/mastra-ai/mastra/commit/eeae63e7fbe8e1f237adc69bca6e2ac13c5ca907), [`4c186a0`](https://github.com/mastra-ai/mastra/commit/4c186a017275f45e6ed4c09de0f89550e2d09e8c), [`b0fa077`](https://github.com/mastra-ai/mastra/commit/b0fa077bcbc9b08551846fe372a0d3d15b71ed72)]:
20
+ - @mastra/core@1.58.0-alpha.8
21
+
22
+ ## 1.17.0-alpha.1
23
+
24
+ ### Patch Changes
25
+
26
+ - Fixed resource-scoped message includes across storage adapters so included context cannot cross resource boundaries. ([#20984](https://github.com/mastra-ai/mastra/pull/20984))
27
+
28
+ - Updated dependencies [[`6445eba`](https://github.com/mastra-ai/mastra/commit/6445eba6020abac681aba1cc9289f446cb400cbe), [`df31eb0`](https://github.com/mastra-ai/mastra/commit/df31eb0c7087d782a0d9346e467f9a4af4b0eef6), [`fcd0667`](https://github.com/mastra-ai/mastra/commit/fcd0667a4e378be35c9a1b1eb19cce78fbfd7282), [`bab06b1`](https://github.com/mastra-ai/mastra/commit/bab06b18923873a584bdfc71a6b4ec7fb4727fb7)]:
29
+ - @mastra/core@1.58.0-alpha.5
30
+
3
31
  ## 1.17.0-alpha.0
4
32
 
5
33
  ### Minor Changes
@@ -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.17.0-alpha.0"
6
+ version: "1.17.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.17.0-alpha.0",
2
+ "version": "1.17.0-alpha.2",
3
3
  "package": "@mastra/mongodb",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -148,6 +148,7 @@ Each vector store page below includes installation instructions, configuration p
148
148
  - [libSQL](https://mastra.ai/reference/vectors/libsql)
149
149
  - [MongoDB](https://mastra.ai/reference/vectors/mongodb)
150
150
  - [OpenSearch](https://mastra.ai/reference/vectors/opensearch)
151
+ - [OracleDB](https://mastra.ai/reference/vectors/oracledb)
151
152
  - [Pinecone](https://mastra.ai/reference/vectors/pinecone)
152
153
  - [PostgreSQL](https://mastra.ai/reference/vectors/pg)
153
154
  - [Qdrant](https://mastra.ai/reference/vectors/qdrant)
@@ -180,7 +181,7 @@ const agent = new Agent({
180
181
  })
181
182
  ```
182
183
 
183
- > **Note:** `scope: 'resource'` is supported by the LibSQL, PostgreSQL, MongoDB, and Upstash storage adapters.
184
+ > **Note:** `scope: 'resource'` is supported by the LibSQL, OracleDB, PostgreSQL, MongoDB, and Upstash storage adapters.
184
185
 
185
186
  ### Metadata filtering
186
187
 
@@ -129,6 +129,7 @@ Resource-scoped working memory requires specific storage adapters that support t
129
129
 
130
130
  - **libSQL** (`@mastra/libsql`)
131
131
  - **PostgreSQL** (`@mastra/pg`)
132
+ - **OracleDB** (`@mastra/oracledb`)
132
133
  - **Upstash** (`@mastra/upstash`)
133
134
  - **MongoDB** (`@mastra/mongodb`)
134
135
 
@@ -193,6 +193,7 @@ Each provider page includes installation instructions, configuration parameters,
193
193
  - [libSQL](https://mastra.ai/reference/storage/libsql)
194
194
  - [PostgreSQL](https://mastra.ai/reference/storage/postgresql)
195
195
  - [MongoDB](https://mastra.ai/reference/storage/mongodb)
196
+ - [OracleDB](https://mastra.ai/reference/storage/oracledb)
196
197
  - [Upstash](https://mastra.ai/reference/storage/upstash)
197
198
  - [Redis](https://mastra.ai/reference/storage/redis)
198
199
  - [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1)
@@ -436,6 +436,23 @@ export const ragAgent = new Agent({
436
436
  })
437
437
  ```
438
438
 
439
+ **OracleDB**:
440
+
441
+ ```ts
442
+ import { ORACLEDB_PROMPT } from '@mastra/oracledb'
443
+
444
+ export const ragAgent = new Agent({
445
+ id: 'rag-agent',
446
+ name: 'RAG Agent',
447
+ model: 'openai/gpt-5.6-sol',
448
+ instructions: `
449
+ Process queries using the provided context. Structure responses to be concise and relevant.
450
+ ${ORACLEDB_PROMPT}
451
+ `,
452
+ tools: { vectorQueryTool },
453
+ })
454
+ ```
455
+
439
456
  **S3Vectors**:
440
457
 
441
458
  ```ts
@@ -78,6 +78,35 @@ await store.upsert({
78
78
 
79
79
  PostgreSQL with the pgvector extension is a good solution for teams already using PostgreSQL who want to minimize infrastructure complexity. For detailed setup instructions and best practices, see the [official pgvector repository](https://github.com/pgvector/pgvector).
80
80
 
81
+ **OracleDB**:
82
+
83
+ ```ts
84
+ import { OracleVector } from '@mastra/oracledb'
85
+
86
+ const store = new OracleVector({
87
+ id: 'oracle-vector',
88
+ user: process.env.ORACLE_DATABASE_USER,
89
+ password: process.env.ORACLE_DATABASE_PASSWORD,
90
+ connectString: process.env.ORACLE_DATABASE_CONNECT_STRING,
91
+ })
92
+
93
+ await store.createIndex({
94
+ indexName: 'myCollection',
95
+ dimension: 1536,
96
+ indexConfig: { type: 'none' },
97
+ })
98
+
99
+ await store.upsert({
100
+ indexName: 'myCollection',
101
+ vectors: embeddings,
102
+ metadata: chunks.map(chunk => ({ text: chunk.text })),
103
+ })
104
+ ```
105
+
106
+ ### Using Oracle Database Vector Search
107
+
108
+ OracleDB stores embeddings in native `VECTOR` columns and metadata in Oracle JSON. Exact search is the default; HNSW and IVF indexes can be configured for tuned deployments.
109
+
81
110
  **Pinecone**:
82
111
 
83
112
  ```ts
@@ -410,6 +439,18 @@ Index names must:
410
439
  - Example: `my_index_123` is valid
411
440
  - Example: `my-index` is not valid (contains hyphen)
412
441
 
442
+ **OracleDB**:
443
+
444
+ Index names are logical Mastra names. OracleDB maps each logical index to a physical Oracle table internally.
445
+
446
+ Logical index names must:
447
+
448
+ - Be non-empty
449
+ - Be 512 characters or fewer
450
+ - Be stable for the lifetime of the vector index
451
+ - Example: `my_collection_123` is valid
452
+ - Example: `customer-support/docs:v1` is valid and is mapped to a safe Oracle table name
453
+
413
454
  **Pinecone**:
414
455
 
415
456
  Index names must:
@@ -251,6 +251,64 @@ const memoryStore = await storage.getStore('memory')
251
251
  const thread = await memoryStore?.getThreadById({ threadId: '...' })
252
252
  ```
253
253
 
254
+ ## Closing connections
255
+
256
+ `close()` releases the connections of the stores a composite was built from: the `default` and `editor` stores, plus any domain that owns its own client. Each store is closed once, even when it backs several domains. When passed to the Mastra class, `close()` is called by `shutdown()`:
257
+
258
+ ```typescript
259
+ import { MastraCompositeStore } from '@mastra/core/storage'
260
+ import { PostgresStore } from '@mastra/pg'
261
+ import { Mastra } from '@mastra/core'
262
+
263
+ const pgStore = new PostgresStore({
264
+ id: 'pg-storage',
265
+ connectionString: process.env.DATABASE_URL,
266
+ })
267
+
268
+ export const mastra = new Mastra({
269
+ storage: new MastraCompositeStore({ id: 'composite', default: pgStore }),
270
+ })
271
+
272
+ process.on('SIGTERM', async () => {
273
+ // Releases the Postgres pool, so the process can exit
274
+ await mastra.shutdown()
275
+ })
276
+ ```
277
+
278
+ A store you construct only to supply a domain isn't reachable through the composite. Keep a reference to it and close it yourself:
279
+
280
+ ```typescript
281
+ import { MastraCompositeStore } from '@mastra/core/storage'
282
+ import { ClickhouseStore } from '@mastra/clickhouse'
283
+ import { PostgresStore } from '@mastra/pg'
284
+ import { Mastra } from '@mastra/core'
285
+
286
+ const pgStore = new PostgresStore({
287
+ id: 'pg-storage',
288
+ connectionString: process.env.DATABASE_URL,
289
+ })
290
+
291
+ const clickhouseStore = new ClickhouseStore({
292
+ id: 'clickhouse-storage',
293
+ url: process.env.CLICKHOUSE_URL,
294
+ username: process.env.CLICKHOUSE_USERNAME,
295
+ password: process.env.CLICKHOUSE_PASSWORD,
296
+ })
297
+
298
+ export const mastra = new Mastra({
299
+ storage: new MastraCompositeStore({
300
+ id: 'composite',
301
+ default: pgStore,
302
+ domains: { observability: clickhouseStore.stores?.observability },
303
+ }),
304
+ })
305
+
306
+ process.on('SIGTERM', async () => {
307
+ await mastra.shutdown()
308
+ await clickhouseStore.close()
309
+ })
310
+ ```
311
+
254
312
  ## Use cases
255
313
 
256
314
  ### Separate databases for different workloads
package/dist/index.cjs CHANGED
@@ -10,7 +10,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
10
10
  let _mastra_core_evals = require("@mastra/core/evals");
11
11
  let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
12
12
  //#region package.json
13
- var version = "1.17.0-alpha.0";
13
+ var version = "1.17.0-alpha.2";
14
14
  //#endregion
15
15
  //#region src/vector/filter.ts
16
16
  /**
@@ -5405,12 +5405,23 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
5405
5405
  return direction === "ASC" ? String(aValue).localeCompare(String(bValue)) : String(bValue).localeCompare(String(aValue));
5406
5406
  });
5407
5407
  }
5408
- async _getIncludedMessages({ include }) {
5408
+ /**
5409
+ * Fetches the messages named by `include` together with their surrounding context.
5410
+ *
5411
+ * @param include - Message ids to pin, each with an optional before/after window.
5412
+ * @param resourceId - When set, restricts both the pinned messages and their context
5413
+ * to that resource so an id from another resource returns nothing.
5414
+ */
5415
+ async _getIncludedMessages({ include, resourceId }) {
5409
5416
  if (!include || include.length === 0) return null;
5410
5417
  const collection = await this.getCollection(_mastra_core_storage.TABLE_MESSAGES);
5418
+ const resourceFilter = resourceId ? { resourceId } : {};
5411
5419
  const targetIds = include.map((inc) => inc.id).filter(Boolean);
5412
5420
  if (targetIds.length === 0) return null;
5413
- const targetDocs = await collection.find({ id: { $in: targetIds } }, { projection: {
5421
+ const targetDocs = await collection.find({
5422
+ id: { $in: targetIds },
5423
+ ...resourceFilter
5424
+ }, { projection: {
5414
5425
  id: 1,
5415
5426
  thread_id: 1,
5416
5427
  createdAt: 1
@@ -5427,7 +5438,8 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
5427
5438
  if (!target) continue;
5428
5439
  const prevMessages = await collection.find({
5429
5440
  thread_id: target.threadId,
5430
- createdAt: { $lte: target.createdAt }
5441
+ createdAt: { $lte: target.createdAt },
5442
+ ...resourceFilter
5431
5443
  }).sort({
5432
5444
  createdAt: -1,
5433
5445
  id: -1
@@ -5436,7 +5448,8 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
5436
5448
  if (withNextMessages > 0) {
5437
5449
  const nextMessages = await collection.find({
5438
5450
  thread_id: target.threadId,
5439
- createdAt: { $gt: target.createdAt }
5451
+ createdAt: { $gt: target.createdAt },
5452
+ ...resourceFilter
5440
5453
  }).sort({
5441
5454
  createdAt: 1,
5442
5455
  id: 1
@@ -5511,7 +5524,10 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
5511
5524
  hasMore: false
5512
5525
  };
5513
5526
  if (perPage === 0 && include && include.length > 0) {
5514
- const includeMessages = await this._getIncludedMessages({ include });
5527
+ const includeMessages = await this._getIncludedMessages({
5528
+ include,
5529
+ resourceId
5530
+ });
5515
5531
  const list = new _mastra_core_agent.MessageList().add(includeMessages ?? [], "memory");
5516
5532
  return {
5517
5533
  messages: this._sortMessages(list.get.all.db(), field, direction),
@@ -5547,7 +5563,10 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
5547
5563
  };
5548
5564
  const messageIds = new Set(messages.map((m) => m.id));
5549
5565
  if (include && include.length > 0) {
5550
- const includeMessages = await this._getIncludedMessages({ include });
5566
+ const includeMessages = await this._getIncludedMessages({
5567
+ include,
5568
+ resourceId
5569
+ });
5551
5570
  if (includeMessages) {
5552
5571
  for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
5553
5572
  messages.push(includeMsg);
@@ -5628,7 +5647,10 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
5628
5647
  hasMore: false
5629
5648
  };
5630
5649
  if (perPage === 0 && include && include.length > 0) {
5631
- const includeMessages = await this._getIncludedMessages({ include });
5650
+ const includeMessages = await this._getIncludedMessages({
5651
+ include,
5652
+ resourceId
5653
+ });
5632
5654
  if (!includeMessages || includeMessages.length === 0) return {
5633
5655
  messages: [],
5634
5656
  total: 0,
@@ -5671,7 +5693,10 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
5671
5693
  };
5672
5694
  const messageIds = new Set(messages.map((m) => m.id));
5673
5695
  if (include && include.length > 0) {
5674
- const includeMessages = await this._getIncludedMessages({ include });
5696
+ const includeMessages = await this._getIncludedMessages({
5697
+ include,
5698
+ resourceId
5699
+ });
5675
5700
  if (includeMessages) {
5676
5701
  for (const includeMsg of includeMessages) if (!messageIds.has(includeMsg.id)) {
5677
5702
  messages.push(includeMsg);
@@ -5979,7 +6004,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
5979
6004
  const now = /* @__PURE__ */ new Date();
5980
6005
  const updatedThread = {
5981
6006
  ...thread,
5982
- title,
6007
+ title: title ?? thread.title,
5983
6008
  metadata: {
5984
6009
  ...thread.metadata,
5985
6010
  ...metadata
@@ -5988,7 +6013,7 @@ var MemoryStorageMongoDB = class MemoryStorageMongoDB extends _mastra_core_stora
5988
6013
  };
5989
6014
  try {
5990
6015
  await (await this.getCollection(_mastra_core_storage.TABLE_THREADS)).updateOne({ id }, { $set: {
5991
- title,
6016
+ title: updatedThread.title,
5992
6017
  metadata: updatedThread.metadata,
5993
6018
  updatedAt: now
5994
6019
  } });