@mastra/mongodb 1.24.1-alpha.1 → 1.25.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/README.md +1 -1
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-memory-semantic-recall.md +24 -22
- package/dist/docs/references/integrations-databases-mongodb.md +1 -1
- package/dist/docs/references/{reference-vectors-mongodb.md → integrations-vectors-mongodb.md} +7 -5
- package/dist/docs/references/reference-rag-vector-databases.md +3 -3
- package/dist/index.cjs +17 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +1 -0
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
- package/dist/vector/filter.d.ts.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ await vectorDB.disconnect();
|
|
|
57
57
|
## Documentation
|
|
58
58
|
|
|
59
59
|
- [MongoDB integration guide](https://mastra.ai/integrations/databases/mongodb)
|
|
60
|
-
- [MongoDB vector reference](https://mastra.ai/
|
|
60
|
+
- [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb)
|
|
61
61
|
|
|
62
62
|
## Changelog
|
|
63
63
|
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -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.
|
|
6
|
+
version: "1.25.0-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -23,6 +23,7 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
23
23
|
### Integrations
|
|
24
24
|
|
|
25
25
|
- [MongoDB](references/integrations-databases-mongodb.md) - Store Mastra application data and vectors in MongoDB, configure connections and collections, initialize schemas, and add persistent agent memory.
|
|
26
|
+
- [MongoDB](references/integrations-vectors-mongodb.md) - Run MongoDB Vector Search from Mastra with automatic or manual embedding, metadata filtering, hybrid search, and indexing of existing collections.
|
|
26
27
|
|
|
27
28
|
### Reference
|
|
28
29
|
|
|
@@ -30,7 +31,6 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
30
31
|
- [Storing embeddings in a vector database](references/reference-rag-vector-databases.md) - After generating embeddings, you need to store them in a database that supports vector similarity search.
|
|
31
32
|
- [Reference: Composite storage](references/reference-storage-composite.md) - MastraCompositeStore can compose storage domains from different providers. Use it when you need different databases for different purposes.
|
|
32
33
|
- [Reference: Storage retention (prune)](references/reference-storage-retention.md) - prune() deletes rows. It caps growth and is safe to run against large tables (batched, bounded, resumable, cancellable).
|
|
33
|
-
- [Reference: MongoDB vector store](references/reference-vectors-mongodb.md) - The MongoDBVector class provides vector search using MongoDB Vector Search. It enables efficient similarity search and metadata filtering within your MongoDB collections.
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
|
|
@@ -141,24 +141,24 @@ const agent = new Agent({
|
|
|
141
141
|
|
|
142
142
|
Each vector store page below includes installation instructions, configuration parameters, and usage examples:
|
|
143
143
|
|
|
144
|
-
- [Astra](https://mastra.ai/
|
|
145
|
-
- [Chroma](https://mastra.ai/
|
|
146
|
-
- [Cloudflare Vectorize](https://mastra.ai/
|
|
147
|
-
- [Convex](https://mastra.ai/
|
|
148
|
-
- [Couchbase](https://mastra.ai/
|
|
149
|
-
- [DuckDB](https://mastra.ai/
|
|
150
|
-
- [Elasticsearch](https://mastra.ai/
|
|
151
|
-
- [LanceDB](https://mastra.ai/
|
|
152
|
-
- [libSQL](https://mastra.ai/
|
|
153
|
-
- [MongoDB](https://mastra.ai/
|
|
154
|
-
- [OpenSearch](https://mastra.ai/
|
|
155
|
-
- [OracleDB](https://mastra.ai/
|
|
156
|
-
- [Pinecone](https://mastra.ai/
|
|
157
|
-
- [PostgreSQL](https://mastra.ai/
|
|
158
|
-
- [Qdrant](https://mastra.ai/
|
|
159
|
-
- [S3 Vectors](https://mastra.ai/
|
|
160
|
-
- [Turbopuffer](https://mastra.ai/
|
|
161
|
-
- [Upstash](https://mastra.ai/
|
|
144
|
+
- [Astra](https://mastra.ai/integrations/vectors/astra)
|
|
145
|
+
- [Chroma](https://mastra.ai/integrations/vectors/chroma)
|
|
146
|
+
- [Cloudflare Vectorize](https://mastra.ai/integrations/vectors/vectorize)
|
|
147
|
+
- [Convex](https://mastra.ai/integrations/vectors/convex)
|
|
148
|
+
- [Couchbase](https://mastra.ai/integrations/vectors/couchbase)
|
|
149
|
+
- [DuckDB](https://mastra.ai/integrations/vectors/duckdb)
|
|
150
|
+
- [Elasticsearch](https://mastra.ai/integrations/vectors/elasticsearch)
|
|
151
|
+
- [LanceDB](https://mastra.ai/integrations/vectors/lance)
|
|
152
|
+
- [libSQL](https://mastra.ai/integrations/vectors/libsql)
|
|
153
|
+
- [MongoDB](https://mastra.ai/integrations/vectors/mongodb)
|
|
154
|
+
- [OpenSearch](https://mastra.ai/integrations/vectors/opensearch)
|
|
155
|
+
- [OracleDB](https://mastra.ai/integrations/vectors/oracledb)
|
|
156
|
+
- [Pinecone](https://mastra.ai/integrations/vectors/pinecone)
|
|
157
|
+
- [PostgreSQL](https://mastra.ai/integrations/vectors/pg)
|
|
158
|
+
- [Qdrant](https://mastra.ai/integrations/vectors/qdrant)
|
|
159
|
+
- [S3 Vectors](https://mastra.ai/integrations/vectors/s3vectors)
|
|
160
|
+
- [Turbopuffer](https://mastra.ai/integrations/vectors/turbopuffer)
|
|
161
|
+
- [Upstash](https://mastra.ai/integrations/vectors/upstash)
|
|
162
162
|
|
|
163
163
|
## Recall configuration
|
|
164
164
|
|
|
@@ -250,7 +250,7 @@ const options = {
|
|
|
250
250
|
|
|
251
251
|
Some vector stores generate the embeddings themselves. With one of those, semantic recall runs without an `embedder`: the database embeds each message on write and the search string on arrival. The embedding provider stays out of your application entirely.
|
|
252
252
|
|
|
253
|
-
MongoDB does this through [Automated Embedding](https://mastra.ai/
|
|
253
|
+
MongoDB does this through [Automated Embedding](https://mastra.ai/integrations/vectors/mongodb): name a Voyage AI model on the vector store and leave the `embedder` out.
|
|
254
254
|
|
|
255
255
|
```typescript
|
|
256
256
|
import { Memory } from '@mastra/memory'
|
|
@@ -456,8 +456,10 @@ const agent = new Agent({
|
|
|
456
456
|
indexConfig: {
|
|
457
457
|
type: 'hnsw', // Use HNSW for better performance
|
|
458
458
|
metric: 'dotproduct', // Best for OpenAI embeddings
|
|
459
|
-
|
|
460
|
-
|
|
459
|
+
hnsw: {
|
|
460
|
+
m: 16, // Number of bi-directional links (default: 16)
|
|
461
|
+
efConstruction: 64, // Size of candidate list during construction (default: 64)
|
|
462
|
+
},
|
|
461
463
|
},
|
|
462
464
|
},
|
|
463
465
|
},
|
|
@@ -465,7 +467,7 @@ const agent = new Agent({
|
|
|
465
467
|
})
|
|
466
468
|
```
|
|
467
469
|
|
|
468
|
-
For detailed information about index configuration options and performance tuning, see the [PgVector configuration guide](https://mastra.ai/
|
|
470
|
+
For detailed information about index configuration options and performance tuning, see the [PgVector configuration guide](https://mastra.ai/integrations/vectors/pg).
|
|
469
471
|
|
|
470
472
|
## Disable semantic recall
|
|
471
473
|
|
|
@@ -194,7 +194,7 @@ await storage.close()
|
|
|
194
194
|
|
|
195
195
|
## Vector search capabilities
|
|
196
196
|
|
|
197
|
-
MongoDB storage includes built-in vector search capabilities for AI applications. For detailed vector operations including index creation, upserting embeddings, similarity search, and metadata filtering, see the [MongoDB vector reference](https://mastra.ai/
|
|
197
|
+
MongoDB storage includes built-in vector search capabilities for AI applications. For detailed vector operations including index creation, upserting embeddings, similarity search, and metadata filtering, see the [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb).
|
|
198
198
|
|
|
199
199
|
## Usage example
|
|
200
200
|
|
package/dist/docs/references/{reference-vectors-mongodb.md → integrations-vectors-mongodb.md}
RENAMED
|
@@ -71,6 +71,8 @@ const store = new MongoDBVector({
|
|
|
71
71
|
|
|
72
72
|
**embeddingFieldPath** (`string`): Path to the field that stores vector embeddings. Supports nested paths using dot notation (e.g., 'text.contentEmbedding'). (Default: `embedding`)
|
|
73
73
|
|
|
74
|
+
**autoEmbed** (`MongoDBAutoEmbedConfig`): Automated Embedding defaults for indexes this store creates, such as { model: 'voyage-4' }. An index created without its own autoEmbed or dimension uses these settings, which makes the store embed text server-side instead of receiving vectors.
|
|
75
|
+
|
|
74
76
|
## Methods
|
|
75
77
|
|
|
76
78
|
### `connect()`
|
|
@@ -178,7 +180,7 @@ await store.createSearchIndex({
|
|
|
178
180
|
})
|
|
179
181
|
```
|
|
180
182
|
|
|
181
|
-
The field-mapped index name includes the logical `indexName`, so two logical indexes on the same collection get distinct text indexes.
|
|
183
|
+
The field-mapped index name includes the logical `indexName`, so two logical indexes on the same collection get distinct text indexes. Calling `createSearchIndex()` again for the _same_ logical index with different `fields` updates the existing text index definition in place. You don't need to drop it first.
|
|
182
184
|
|
|
183
185
|
### `waitForSearchIndexReady()`
|
|
184
186
|
|
|
@@ -279,18 +281,18 @@ Returns:
|
|
|
279
281
|
interface IndexStats {
|
|
280
282
|
dimension: number
|
|
281
283
|
count: number
|
|
282
|
-
metric
|
|
284
|
+
metric?: 'cosine' | 'euclidean' | 'dotproduct'
|
|
283
285
|
}
|
|
284
286
|
```
|
|
285
287
|
|
|
286
|
-
On an `autoEmbed` index, `dimension` is read from the index definition and reports MongoDB's default of `1024` when the index doesn't pin one. `count` counts documents that carry the embedded text field, since the generated vectors aren't stored on your documents.
|
|
288
|
+
On an `autoEmbed` index, `dimension` is read from the index definition and reports MongoDB's default of `1024` when the index doesn't pin one. `metric` is omitted when the `autoEmbed` index doesn't specify a similarity. `count` counts documents that carry the embedded text field, since the generated vectors aren't stored on your documents.
|
|
287
289
|
|
|
288
290
|
### `deleteIndex()`
|
|
289
291
|
|
|
290
292
|
Deletes a vector index. Behavior depends on how the index was created:
|
|
291
293
|
|
|
292
294
|
- **Managed index** (created without `collectionName`): drops the entire collection and all its data.
|
|
293
|
-
- **Bring-your-own index** (created with `collectionName`): drops the MongoDB vectorSearch index. If `createSearchIndex()` provisioned a companion full-text search index, it drops that index too. The caller's operational collection and its documents are preserved. This store never drops a collection it didn't create.
|
|
295
|
+
- **Bring-your-own index** (created with `collectionName`): drops the MongoDB vectorSearch index. If `createSearchIndex()` provisioned a companion full-text search index, it drops that index too. A vectorSearch or full-text index that another logical index on the same collection still references is kept for that index. The caller's operational collection and its documents are preserved. This store never drops a collection it didn't create.
|
|
294
296
|
|
|
295
297
|
The BYO classification is recorded durably when the index is created, so it's applied correctly even by a different process (e.g. an index created by a setup job and later deleted by a long-lived service). Always pass the **logical index name** (the `indexName` used at `createIndex`), not the physical collection name.
|
|
296
298
|
|
|
@@ -350,7 +352,7 @@ Query results are returned in this format:
|
|
|
350
352
|
interface QueryResult {
|
|
351
353
|
id: string
|
|
352
354
|
score: number
|
|
353
|
-
metadata
|
|
355
|
+
metadata?: Record<string, any>
|
|
354
356
|
vector?: number[] // Only included if includeVector is true
|
|
355
357
|
document?: string // Source text stored with the vector, when available
|
|
356
358
|
}
|
|
@@ -35,7 +35,7 @@ MongoDB Vector Search is a good solution for teams who want to consolidate vecto
|
|
|
35
35
|
|
|
36
36
|
### Using VoyageAI with MongoDB
|
|
37
37
|
|
|
38
|
-
MongoDB works directly with VoyageAI's embedding models, which are optimized for retrieval tasks. For complete examples and specialized models, see the [VoyageAI embeddings documentation](https://mastra.ai/models/embeddings) and [MongoDB vector reference](https://mastra.ai/
|
|
38
|
+
MongoDB works directly with VoyageAI's embedding models, which are optimized for retrieval tasks. For complete examples and specialized models, see the [VoyageAI embeddings documentation](https://mastra.ai/models/embeddings) and [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb).
|
|
39
39
|
|
|
40
40
|
### Hybrid Search (Vector + Full-Text)
|
|
41
41
|
|
|
@@ -52,7 +52,7 @@ const results = await store.hybridQuery({
|
|
|
52
52
|
})
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
See the [MongoDB vector reference](https://mastra.ai/
|
|
55
|
+
See the [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb) for details on `createSearchIndex()`, `textQuery()`, and `hybridQuery()`.
|
|
56
56
|
|
|
57
57
|
### Automated Embedding
|
|
58
58
|
|
|
@@ -75,7 +75,7 @@ const results = await store.query({
|
|
|
75
75
|
})
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
Automated Embedding is a MongoDB Preview feature and needs a deployment where it's available. See the [MongoDB vector reference](https://mastra.ai/
|
|
78
|
+
Automated Embedding is a MongoDB Preview feature and needs a deployment where it's available. See the [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb) for the supported options and requirements.
|
|
79
79
|
|
|
80
80
|
**PgVector**:
|
|
81
81
|
|
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
|
// package.json
|
|
13
|
-
var version = "1.
|
|
13
|
+
var version = "1.25.0-alpha.0";
|
|
14
14
|
// src/vector/filter.ts
|
|
15
15
|
/**
|
|
16
16
|
* Translator for MongoDB filter queries.
|
|
@@ -46,10 +46,9 @@ var MongoDBFilterTranslator = class extends _mastra_core_vector_filter.BaseFilte
|
|
|
46
46
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("$not operator requires an object");
|
|
47
47
|
if (this.isEmpty(value)) throw new Error("$not operator cannot be empty");
|
|
48
48
|
return this.translateNode(value);
|
|
49
|
-
} else {
|
|
50
|
-
if (!Array.isArray(value)) throw new Error(`Value for logical operator ${operator} must be an array`);
|
|
51
|
-
return value.map((item) => this.translateNode(item));
|
|
52
49
|
}
|
|
50
|
+
if (!Array.isArray(value)) throw new Error(`Value for logical operator ${operator} must be an array`);
|
|
51
|
+
return value.map((item) => this.translateNode(item));
|
|
53
52
|
}
|
|
54
53
|
if (this.isBasicOperator(operator) || this.isNumericOperator(operator)) {
|
|
55
54
|
if (value instanceof Date) return value.toISOString();
|
|
@@ -2441,7 +2440,9 @@ function toDoc(task) {
|
|
|
2441
2440
|
suspendedAt: task.suspendedAt?.toISOString() ?? null,
|
|
2442
2441
|
completedAt: task.completedAt?.toISOString() ?? null,
|
|
2443
2442
|
ownerId: task.ownerId ?? null,
|
|
2444
|
-
leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null
|
|
2443
|
+
leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null,
|
|
2444
|
+
expiresAt: task.expiresAt?.toISOString() ?? null,
|
|
2445
|
+
metadata: task.metadata ?? null
|
|
2445
2446
|
};
|
|
2446
2447
|
}
|
|
2447
2448
|
function fromDoc(doc) {
|
|
@@ -2466,10 +2467,13 @@ function fromDoc(doc) {
|
|
|
2466
2467
|
suspendedAt: doc.suspendedAt ? new Date(doc.suspendedAt) : void 0,
|
|
2467
2468
|
completedAt: doc.completedAt ? new Date(doc.completedAt) : void 0,
|
|
2468
2469
|
ownerId: doc.ownerId ?? void 0,
|
|
2469
|
-
leaseExpiresAt: doc.leaseExpiresAt ? new Date(doc.leaseExpiresAt) : void 0
|
|
2470
|
+
leaseExpiresAt: doc.leaseExpiresAt ? new Date(doc.leaseExpiresAt) : void 0,
|
|
2471
|
+
expiresAt: doc.expiresAt ? new Date(doc.expiresAt) : void 0,
|
|
2472
|
+
metadata: doc.metadata ?? void 0
|
|
2470
2473
|
};
|
|
2471
2474
|
}
|
|
2472
2475
|
var BackgroundTasksStorageMongoDB = class BackgroundTasksStorageMongoDB extends _mastra_core_storage.BackgroundTasksStorage {
|
|
2476
|
+
supportsTaskExpiry = true;
|
|
2473
2477
|
#connector;
|
|
2474
2478
|
#skipDefaultIndexes;
|
|
2475
2479
|
#indexes;
|
|
@@ -2585,11 +2589,14 @@ var BackgroundTasksStorageMongoDB = class BackgroundTasksStorageMongoDB extends
|
|
|
2585
2589
|
if ("completedAt" in update) $set.completedAt = update.completedAt?.toISOString() ?? null;
|
|
2586
2590
|
if ("ownerId" in update) $set.ownerId = update.ownerId ?? null;
|
|
2587
2591
|
if ("leaseExpiresAt" in update) $set.leaseExpiresAt = update.leaseExpiresAt?.toISOString() ?? null;
|
|
2592
|
+
if ("expiresAt" in update) $set.expiresAt = update.expiresAt?.toISOString() ?? null;
|
|
2593
|
+
if ("metadata" in update) $set.metadata = update.metadata ?? null;
|
|
2588
2594
|
if (Object.keys($set).length === 0) return false;
|
|
2589
2595
|
const filter = { id: taskId };
|
|
2590
2596
|
if (options?.expectedStatus) filter.status = options.expectedStatus;
|
|
2591
2597
|
if (options?.expectedOwnerId !== void 0) filter.ownerId = options.expectedOwnerId;
|
|
2592
2598
|
if (options?.expectedLeaseExpiresAt !== void 0) filter.leaseExpiresAt = options.expectedLeaseExpiresAt?.toISOString() ?? null;
|
|
2599
|
+
if (options?.expectedSuspendedAt !== void 0) filter.suspendedAt = options.expectedSuspendedAt?.toISOString() ?? null;
|
|
2593
2600
|
return (await (await this.getCollection()).updateOne(filter, { $set })).matchedCount > 0;
|
|
2594
2601
|
}
|
|
2595
2602
|
async getTask(taskId) {
|
|
@@ -2608,7 +2615,8 @@ var BackgroundTasksStorageMongoDB = class BackgroundTasksStorageMongoDB extends
|
|
|
2608
2615
|
if (filter.runId) query.run_id = filter.runId;
|
|
2609
2616
|
if (filter.toolName) query.tool_name = filter.toolName;
|
|
2610
2617
|
if (filter.toolCallId) query.tool_call_id = filter.toolCallId;
|
|
2611
|
-
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
2618
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : filter.dateFilterBy === "expiresAt" ? "expiresAt" : "createdAt";
|
|
2619
|
+
if (filter.hasExpiresAt !== void 0) query.expiresAt = filter.hasExpiresAt ? { $ne: null } : { $eq: null };
|
|
2612
2620
|
if (filter.fromDate) query[dateCol] = {
|
|
2613
2621
|
...query[dateCol] || {},
|
|
2614
2622
|
$gte: filter.fromDate.toISOString()
|
|
@@ -2640,7 +2648,8 @@ var BackgroundTasksStorageMongoDB = class BackgroundTasksStorageMongoDB extends
|
|
|
2640
2648
|
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
2641
2649
|
query.status = statuses.length === 1 ? statuses[0] : { $in: statuses };
|
|
2642
2650
|
}
|
|
2643
|
-
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : "createdAt";
|
|
2651
|
+
const dateCol = filter.dateFilterBy === "startedAt" ? "startedAt" : filter.dateFilterBy === "suspendedAt" ? "suspendedAt" : filter.dateFilterBy === "completedAt" ? "completedAt" : filter.dateFilterBy === "expiresAt" ? "expiresAt" : "createdAt";
|
|
2652
|
+
if (filter.hasExpiresAt !== void 0) query.expiresAt = filter.hasExpiresAt ? { $ne: null } : { $eq: null };
|
|
2644
2653
|
if (filter.fromDate) query[dateCol] = {
|
|
2645
2654
|
...query[dateCol] || {},
|
|
2646
2655
|
$gte: filter.fromDate.toISOString()
|