@mastra/mongodb 1.2.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.
@@ -1,20 +1,31 @@
1
- # Vectors API Reference
1
+ # MongoDB Vector Store
2
2
 
3
- > API reference for vectors - 1 entries
3
+ The `MongoDBVector` class provides vector search using [MongoDB Atlas Vector Search](https://www.mongodb.com/docs/atlas/atlas-vector-search/). It enables efficient similarity search and metadata filtering within your MongoDB collections.
4
4
 
5
+ ## Installation
5
6
 
6
- ---
7
+ **npm**:
7
8
 
8
- ## Reference: MongoDB Vector Store
9
+ ```bash
10
+ npm install @mastra/mongodb@latest
11
+ ```
9
12
 
10
- > Documentation for the MongoDBVector class in Mastra, which provides vector search using MongoDB Atlas and Atlas Vector Search.
13
+ **pnpm**:
11
14
 
12
- The `MongoDBVector` class provides vector search using [MongoDB Atlas Vector Search](https://www.mongodb.com/docs/atlas/atlas-vector-search/). It enables efficient similarity search and metadata filtering within your MongoDB collections.
15
+ ```bash
16
+ pnpm add @mastra/mongodb@latest
17
+ ```
13
18
 
14
- ## Installation
19
+ **Yarn**:
15
20
 
16
- ```bash npm2yarn
17
- npm install @mastra/mongodb@latest
21
+ ```bash
22
+ yarn add @mastra/mongodb@latest
23
+ ```
24
+
25
+ **Bun**:
26
+
27
+ ```bash
28
+ bun add @mastra/mongodb@latest
18
29
  ```
19
30
 
20
31
  ## Usage Example
@@ -46,24 +57,64 @@ const store = new MongoDBVector({
46
57
 
47
58
  ## Constructor Options
48
59
 
60
+ **id:** (`string`): Unique identifier for this vector store instance
61
+
62
+ **uri:** (`string`): MongoDB connection string
63
+
64
+ **dbName:** (`string`): Name of the MongoDB database to use
65
+
66
+ **options?:** (`MongoClientOptions`): Optional MongoDB client options
67
+
68
+ **embeddingFieldPath?:** (`string`): Path to the field that stores vector embeddings. Supports nested paths using dot notation (e.g., 'text.contentEmbedding'). (Default: `embedding`)
69
+
49
70
  ## Methods
50
71
 
51
72
  ### createIndex()
52
73
 
53
74
  Creates a new vector index (collection) in MongoDB.
54
75
 
76
+ **indexName:** (`string`): Name of the collection to create
77
+
78
+ **dimension:** (`number`): Vector dimension (must match your embedding model)
79
+
80
+ **metric?:** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
81
+
55
82
  ### upsert()
56
83
 
57
84
  Adds or updates vectors and their metadata in the collection.
58
85
 
86
+ **indexName:** (`string`): Name of the collection to insert into
87
+
88
+ **vectors:** (`number[][]`): Array of embedding vectors
89
+
90
+ **metadata?:** (`Record<string, any>[]`): Metadata for each vector
91
+
92
+ **ids?:** (`string[]`): Optional vector IDs (auto-generated if not provided)
93
+
59
94
  ### query()
60
95
 
61
96
  Searches for similar vectors with optional metadata filtering.
62
97
 
98
+ **indexName:** (`string`): Name of the collection to search in
99
+
100
+ **queryVector:** (`number[]`): Query vector to find similar vectors for
101
+
102
+ **topK?:** (`number`): Number of results to return (Default: `10`)
103
+
104
+ **filter?:** (`Record<string, any>`): Metadata filters (applies to the \`metadata\` field)
105
+
106
+ **documentFilter?:** (`Record<string, any>`): Filters on original document fields (not just metadata)
107
+
108
+ **includeVector?:** (`boolean`): Whether to include vector data in results (Default: `false`)
109
+
110
+ **minScore?:** (`number`): Minimum similarity score threshold (Default: `0`)
111
+
63
112
  ### describeIndex()
64
113
 
65
114
  Returns information about the index (collection).
66
115
 
116
+ **indexName:** (`string`): Name of the collection to describe
117
+
67
118
  Returns:
68
119
 
69
120
  ```typescript
@@ -78,6 +129,8 @@ interface IndexStats {
78
129
 
79
130
  Deletes a collection and all its data.
80
131
 
132
+ **indexName:** (`string`): Name of the collection to delete
133
+
81
134
  ### listIndexes()
82
135
 
83
136
  Lists all vector collections in the MongoDB database.
@@ -88,14 +141,36 @@ Returns: `Promise<string[]>`
88
141
 
89
142
  Update a single vector by ID or by metadata filter. Either `id` or `filter` must be provided, but not both.
90
143
 
144
+ **indexName:** (`string`): Name of the collection containing the vector
145
+
146
+ **id?:** (`string`): ID of the vector entry to update (mutually exclusive with filter)
147
+
148
+ **filter?:** (`Record<string, any>`): Metadata filter to identify vector(s) to update (mutually exclusive with id)
149
+
150
+ **update:** (`object`): Update data containing vector and/or metadata
151
+
152
+ **update.vector?:** (`number[]`): New vector data to update
153
+
154
+ **update.metadata?:** (`Record<string, any>`): New metadata to update
155
+
91
156
  ### deleteVector()
92
157
 
93
158
  Deletes a specific vector entry from an index by its ID.
94
159
 
160
+ **indexName:** (`string`): Name of the collection containing the vector
161
+
162
+ **id:** (`string`): ID of the vector entry to delete
163
+
95
164
  ### deleteVectors()
96
165
 
97
166
  Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both.
98
167
 
168
+ **indexName:** (`string`): Name of the collection containing the vectors to delete
169
+
170
+ **ids?:** (`string[]`): Array of vector IDs to delete (mutually exclusive with filter)
171
+
172
+ **filter?:** (`Record<string, any>`): Metadata filter to identify vectors to delete (mutually exclusive with ids)
173
+
99
174
  ### disconnect()
100
175
 
101
176
  Closes the MongoDB client connection. Should be called when done using the store.
@@ -151,16 +226,35 @@ Embeddings are numeric vectors used by memory's `semanticRecall` to retrieve rel
151
226
 
152
227
  > Note: You must use a deployment hosted on MongoDB Atlas to successfully use the MongoDB Vector database.
153
228
 
154
- This setup uses FastEmbed, a local embedding model, to generate vector embeddings.
155
- To use this, install `@mastra/fastembed`:
229
+ This setup uses FastEmbed, a local embedding model, to generate vector embeddings. To use this, install `@mastra/fastembed`:
156
230
 
157
- ```bash npm2yarn
231
+ **npm**:
232
+
233
+ ```bash
158
234
  npm install @mastra/fastembed@latest
159
235
  ```
160
236
 
237
+ **pnpm**:
238
+
239
+ ```bash
240
+ pnpm add @mastra/fastembed@latest
241
+ ```
242
+
243
+ **Yarn**:
244
+
245
+ ```bash
246
+ yarn add @mastra/fastembed@latest
247
+ ```
248
+
249
+ **Bun**:
250
+
251
+ ```bash
252
+ bun add @mastra/fastembed@latest
253
+ ```
254
+
161
255
  Add the following to your agent:
162
256
 
163
- ```typescript title="src/mastra/agents/example-mongodb-agent.ts"
257
+ ```typescript
164
258
  import { Memory } from "@mastra/memory";
165
259
  import { Agent } from "@mastra/core/agent";
166
260
  import { MongoDBStore, MongoDBVector } from "@mastra/mongodb";
@@ -198,4 +292,4 @@ export const mongodbAgent = new Agent({
198
292
 
199
293
  ## Related
200
294
 
201
- - [Metadata Filters](../rag/metadata-filters)
295
+ - [Metadata Filters](https://mastra.ai/reference/rag/metadata-filters)