@mastra/mongodb 0.0.6-alpha.0 → 0.10.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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +50 -0
- package/dist/_tsup-dts-rollup.d.cts +12 -57
- package/dist/_tsup-dts-rollup.d.ts +12 -57
- package/dist/index.cjs +23 -67
- package/dist/index.d.cts +0 -3
- package/dist/index.d.ts +0 -3
- package/dist/index.js +23 -67
- package/package.json +7 -4
- package/src/vector/index.ts +23 -87
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/mongodb@0.0
|
|
2
|
+
> @mastra/mongodb@0.10.0-alpha.1 build /home/runner/work/mastra/mastra/stores/mongodb
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 5643ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 8219ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
21
|
-
[32mCJS[39m ⚡️ Build success in
|
|
22
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
23
|
-
[32mESM[39m ⚡️ Build success in
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m18.11 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 706ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m18.05 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 707ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @mastra/mongodb
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 83da932: Move @mastra/core to peerdeps
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
|
|
12
|
+
- a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
|
|
13
|
+
- Updated dependencies [b3a3d63]
|
|
14
|
+
- Updated dependencies [344f453]
|
|
15
|
+
- Updated dependencies [0a3ae6d]
|
|
16
|
+
- Updated dependencies [95911be]
|
|
17
|
+
- Updated dependencies [f53a6ac]
|
|
18
|
+
- Updated dependencies [5eb5a99]
|
|
19
|
+
- Updated dependencies [7e632c5]
|
|
20
|
+
- Updated dependencies [1e9fbfa]
|
|
21
|
+
- Updated dependencies [eabdcd9]
|
|
22
|
+
- Updated dependencies [90be034]
|
|
23
|
+
- Updated dependencies [99f050a]
|
|
24
|
+
- Updated dependencies [d0ee3c6]
|
|
25
|
+
- Updated dependencies [b2ae5aa]
|
|
26
|
+
- Updated dependencies [23f258c]
|
|
27
|
+
- Updated dependencies [a7292b0]
|
|
28
|
+
- Updated dependencies [0dcb9f0]
|
|
29
|
+
- Updated dependencies [2672a05]
|
|
30
|
+
- @mastra/core@0.10.0
|
|
31
|
+
|
|
32
|
+
## 0.1.0-alpha.1
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- 83da932: Move @mastra/core to peerdeps
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
|
|
41
|
+
- Updated dependencies [b3a3d63]
|
|
42
|
+
- Updated dependencies [344f453]
|
|
43
|
+
- Updated dependencies [0a3ae6d]
|
|
44
|
+
- Updated dependencies [95911be]
|
|
45
|
+
- Updated dependencies [5eb5a99]
|
|
46
|
+
- Updated dependencies [7e632c5]
|
|
47
|
+
- Updated dependencies [1e9fbfa]
|
|
48
|
+
- Updated dependencies [b2ae5aa]
|
|
49
|
+
- Updated dependencies [a7292b0]
|
|
50
|
+
- Updated dependencies [0dcb9f0]
|
|
51
|
+
- @mastra/core@0.10.0-alpha.1
|
|
52
|
+
|
|
3
53
|
## 0.0.6-alpha.0
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
|
@@ -7,12 +7,9 @@ import type { IndexStats } from '@mastra/core/vector';
|
|
|
7
7
|
import { MastraVector } from '@mastra/core/vector';
|
|
8
8
|
import type { MongoClientOptions } from 'mongodb';
|
|
9
9
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
10
|
-
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
11
10
|
import type { QueryResult } from '@mastra/core/vector';
|
|
12
|
-
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
13
11
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
14
12
|
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
15
|
-
import type { UpsertVectorArgs } from '@mastra/core/vector';
|
|
16
13
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
17
14
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
18
15
|
|
|
@@ -37,8 +34,6 @@ export declare class MongoDBFilterTranslator extends BaseFilterTranslator {
|
|
|
37
34
|
isEmpty(filter: any): boolean;
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
declare type MongoDBIndexReadyArgs = [string, number?, number?];
|
|
41
|
-
|
|
42
37
|
declare interface MongoDBIndexReadyParams {
|
|
43
38
|
indexName: string;
|
|
44
39
|
timeoutMs?: number;
|
|
@@ -47,24 +42,12 @@ declare interface MongoDBIndexReadyParams {
|
|
|
47
42
|
export { MongoDBIndexReadyParams }
|
|
48
43
|
export { MongoDBIndexReadyParams as MongoDBIndexReadyParams_alias_1 }
|
|
49
44
|
|
|
50
|
-
declare type MongoDBQueryArgs = [...QueryVectorArgs, string?];
|
|
51
|
-
export { MongoDBQueryArgs }
|
|
52
|
-
export { MongoDBQueryArgs as MongoDBQueryArgs_alias_1 }
|
|
53
|
-
|
|
54
45
|
declare interface MongoDBQueryVectorParams extends QueryVectorParams {
|
|
55
46
|
documentFilter?: VectorFilter;
|
|
56
47
|
}
|
|
57
48
|
export { MongoDBQueryVectorParams }
|
|
58
49
|
export { MongoDBQueryVectorParams as MongoDBQueryVectorParams_alias_1 }
|
|
59
50
|
|
|
60
|
-
declare type MongoDBUpsertArgs = [...UpsertVectorArgs, string[]?];
|
|
61
|
-
export { MongoDBUpsertArgs }
|
|
62
|
-
export { MongoDBUpsertArgs as MongoDBUpsertArgs_alias_1 }
|
|
63
|
-
|
|
64
|
-
declare type MongoDBUpsertParams = ParamsToArgs<MongoDBUpsertArgs>;
|
|
65
|
-
export { MongoDBUpsertParams }
|
|
66
|
-
export { MongoDBUpsertParams as MongoDBUpsertParams_alias_1 }
|
|
67
|
-
|
|
68
51
|
declare interface MongoDBUpsertVectorParams extends UpsertVectorParams {
|
|
69
52
|
documents?: string[];
|
|
70
53
|
}
|
|
@@ -87,32 +70,28 @@ declare class MongoDBVector extends MastraVector {
|
|
|
87
70
|
});
|
|
88
71
|
connect(): Promise<void>;
|
|
89
72
|
disconnect(): Promise<void>;
|
|
90
|
-
createIndex(
|
|
73
|
+
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
91
74
|
/**
|
|
92
75
|
* Waits for the index to be ready.
|
|
93
76
|
*
|
|
94
|
-
* @param
|
|
95
|
-
* @param
|
|
96
|
-
* @param
|
|
97
|
-
* @param params.checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
|
|
77
|
+
* @param {string} indexName - The name of the index to wait for
|
|
78
|
+
* @param {number} timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
|
|
79
|
+
* @param {number} checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
|
|
98
80
|
* @returns A promise that resolves when the index is ready
|
|
99
81
|
*/
|
|
100
|
-
waitForIndexReady(
|
|
101
|
-
upsert(
|
|
102
|
-
query(
|
|
82
|
+
waitForIndexReady({ indexName, timeoutMs, checkIntervalMs, }: MongoDBIndexReadyParams): Promise<void>;
|
|
83
|
+
upsert({ indexName, vectors, metadata, ids, documents }: MongoDBUpsertVectorParams): Promise<string[]>;
|
|
84
|
+
query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: MongoDBQueryVectorParams): Promise<QueryResult[]>;
|
|
103
85
|
listIndexes(): Promise<string[]>;
|
|
104
86
|
/**
|
|
105
87
|
* Retrieves statistics about a vector index.
|
|
106
88
|
*
|
|
107
|
-
* @param
|
|
108
|
-
* @param params.indexName - The name of the index to describe
|
|
89
|
+
* @param {string} indexName - The name of the index to describe
|
|
109
90
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
110
91
|
*/
|
|
111
|
-
describeIndex(
|
|
112
|
-
deleteIndex(
|
|
92
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
93
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
113
94
|
/**
|
|
114
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
115
|
-
*
|
|
116
95
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
117
96
|
* @param indexName - The name of the index containing the vector.
|
|
118
97
|
* @param id - The ID of the vector to update.
|
|
@@ -122,31 +101,7 @@ declare class MongoDBVector extends MastraVector {
|
|
|
122
101
|
* @returns A promise that resolves when the update is complete.
|
|
123
102
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
124
103
|
*/
|
|
125
|
-
|
|
126
|
-
vector?: number[];
|
|
127
|
-
metadata?: Record<string, any>;
|
|
128
|
-
}): Promise<void>;
|
|
129
|
-
/**
|
|
130
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
131
|
-
* @param indexName - The name of the index containing the vector.
|
|
132
|
-
* @param id - The ID of the vector to update.
|
|
133
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
134
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
135
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
136
|
-
* @returns A promise that resolves when the update is complete.
|
|
137
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
138
|
-
*/
|
|
139
|
-
updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
|
|
140
|
-
/**
|
|
141
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
142
|
-
*
|
|
143
|
-
* Deletes a vector by its ID.
|
|
144
|
-
* @param indexName - The name of the index containing the vector.
|
|
145
|
-
* @param id - The ID of the vector to delete.
|
|
146
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
147
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
148
|
-
*/
|
|
149
|
-
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
104
|
+
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
150
105
|
/**
|
|
151
106
|
* Deletes a vector by its ID.
|
|
152
107
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -154,7 +109,7 @@ declare class MongoDBVector extends MastraVector {
|
|
|
154
109
|
* @returns A promise that resolves when the deletion is complete.
|
|
155
110
|
* @throws Will throw an error if the deletion operation fails.
|
|
156
111
|
*/
|
|
157
|
-
deleteVector(
|
|
112
|
+
deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
|
|
158
113
|
private getCollection;
|
|
159
114
|
private validateVectorDimensions;
|
|
160
115
|
private setIndexDimension;
|
|
@@ -7,12 +7,9 @@ import type { IndexStats } from '@mastra/core/vector';
|
|
|
7
7
|
import { MastraVector } from '@mastra/core/vector';
|
|
8
8
|
import type { MongoClientOptions } from 'mongodb';
|
|
9
9
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
10
|
-
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
11
10
|
import type { QueryResult } from '@mastra/core/vector';
|
|
12
|
-
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
13
11
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
14
12
|
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
15
|
-
import type { UpsertVectorArgs } from '@mastra/core/vector';
|
|
16
13
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
17
14
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
18
15
|
|
|
@@ -37,8 +34,6 @@ export declare class MongoDBFilterTranslator extends BaseFilterTranslator {
|
|
|
37
34
|
isEmpty(filter: any): boolean;
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
declare type MongoDBIndexReadyArgs = [string, number?, number?];
|
|
41
|
-
|
|
42
37
|
declare interface MongoDBIndexReadyParams {
|
|
43
38
|
indexName: string;
|
|
44
39
|
timeoutMs?: number;
|
|
@@ -47,24 +42,12 @@ declare interface MongoDBIndexReadyParams {
|
|
|
47
42
|
export { MongoDBIndexReadyParams }
|
|
48
43
|
export { MongoDBIndexReadyParams as MongoDBIndexReadyParams_alias_1 }
|
|
49
44
|
|
|
50
|
-
declare type MongoDBQueryArgs = [...QueryVectorArgs, string?];
|
|
51
|
-
export { MongoDBQueryArgs }
|
|
52
|
-
export { MongoDBQueryArgs as MongoDBQueryArgs_alias_1 }
|
|
53
|
-
|
|
54
45
|
declare interface MongoDBQueryVectorParams extends QueryVectorParams {
|
|
55
46
|
documentFilter?: VectorFilter;
|
|
56
47
|
}
|
|
57
48
|
export { MongoDBQueryVectorParams }
|
|
58
49
|
export { MongoDBQueryVectorParams as MongoDBQueryVectorParams_alias_1 }
|
|
59
50
|
|
|
60
|
-
declare type MongoDBUpsertArgs = [...UpsertVectorArgs, string[]?];
|
|
61
|
-
export { MongoDBUpsertArgs }
|
|
62
|
-
export { MongoDBUpsertArgs as MongoDBUpsertArgs_alias_1 }
|
|
63
|
-
|
|
64
|
-
declare type MongoDBUpsertParams = ParamsToArgs<MongoDBUpsertArgs>;
|
|
65
|
-
export { MongoDBUpsertParams }
|
|
66
|
-
export { MongoDBUpsertParams as MongoDBUpsertParams_alias_1 }
|
|
67
|
-
|
|
68
51
|
declare interface MongoDBUpsertVectorParams extends UpsertVectorParams {
|
|
69
52
|
documents?: string[];
|
|
70
53
|
}
|
|
@@ -87,32 +70,28 @@ declare class MongoDBVector extends MastraVector {
|
|
|
87
70
|
});
|
|
88
71
|
connect(): Promise<void>;
|
|
89
72
|
disconnect(): Promise<void>;
|
|
90
|
-
createIndex(
|
|
73
|
+
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
91
74
|
/**
|
|
92
75
|
* Waits for the index to be ready.
|
|
93
76
|
*
|
|
94
|
-
* @param
|
|
95
|
-
* @param
|
|
96
|
-
* @param
|
|
97
|
-
* @param params.checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
|
|
77
|
+
* @param {string} indexName - The name of the index to wait for
|
|
78
|
+
* @param {number} timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
|
|
79
|
+
* @param {number} checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
|
|
98
80
|
* @returns A promise that resolves when the index is ready
|
|
99
81
|
*/
|
|
100
|
-
waitForIndexReady(
|
|
101
|
-
upsert(
|
|
102
|
-
query(
|
|
82
|
+
waitForIndexReady({ indexName, timeoutMs, checkIntervalMs, }: MongoDBIndexReadyParams): Promise<void>;
|
|
83
|
+
upsert({ indexName, vectors, metadata, ids, documents }: MongoDBUpsertVectorParams): Promise<string[]>;
|
|
84
|
+
query({ indexName, queryVector, topK, filter, includeVector, documentFilter, }: MongoDBQueryVectorParams): Promise<QueryResult[]>;
|
|
103
85
|
listIndexes(): Promise<string[]>;
|
|
104
86
|
/**
|
|
105
87
|
* Retrieves statistics about a vector index.
|
|
106
88
|
*
|
|
107
|
-
* @param
|
|
108
|
-
* @param params.indexName - The name of the index to describe
|
|
89
|
+
* @param {string} indexName - The name of the index to describe
|
|
109
90
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
110
91
|
*/
|
|
111
|
-
describeIndex(
|
|
112
|
-
deleteIndex(
|
|
92
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
93
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
113
94
|
/**
|
|
114
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
115
|
-
*
|
|
116
95
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
117
96
|
* @param indexName - The name of the index containing the vector.
|
|
118
97
|
* @param id - The ID of the vector to update.
|
|
@@ -122,31 +101,7 @@ declare class MongoDBVector extends MastraVector {
|
|
|
122
101
|
* @returns A promise that resolves when the update is complete.
|
|
123
102
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
124
103
|
*/
|
|
125
|
-
|
|
126
|
-
vector?: number[];
|
|
127
|
-
metadata?: Record<string, any>;
|
|
128
|
-
}): Promise<void>;
|
|
129
|
-
/**
|
|
130
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
131
|
-
* @param indexName - The name of the index containing the vector.
|
|
132
|
-
* @param id - The ID of the vector to update.
|
|
133
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
134
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
135
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
136
|
-
* @returns A promise that resolves when the update is complete.
|
|
137
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
138
|
-
*/
|
|
139
|
-
updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
|
|
140
|
-
/**
|
|
141
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
142
|
-
*
|
|
143
|
-
* Deletes a vector by its ID.
|
|
144
|
-
* @param indexName - The name of the index containing the vector.
|
|
145
|
-
* @param id - The ID of the vector to delete.
|
|
146
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
147
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
148
|
-
*/
|
|
149
|
-
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
104
|
+
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
150
105
|
/**
|
|
151
106
|
* Deletes a vector by its ID.
|
|
152
107
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -154,7 +109,7 @@ declare class MongoDBVector extends MastraVector {
|
|
|
154
109
|
* @returns A promise that resolves when the deletion is complete.
|
|
155
110
|
* @throws Will throw an error if the deletion operation fails.
|
|
156
111
|
*/
|
|
157
|
-
deleteVector(
|
|
112
|
+
deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
|
|
158
113
|
private getCollection;
|
|
159
114
|
private validateVectorDimensions;
|
|
160
115
|
private setIndexDimension;
|
package/dist/index.cjs
CHANGED
|
@@ -121,8 +121,7 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
121
121
|
async disconnect() {
|
|
122
122
|
await this.client.close();
|
|
123
123
|
}
|
|
124
|
-
async createIndex(
|
|
125
|
-
const { indexName, dimension, metric = "cosine" } = params;
|
|
124
|
+
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
126
125
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
127
126
|
throw new Error("Dimension must be a positive integer");
|
|
128
127
|
}
|
|
@@ -163,18 +162,16 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
163
162
|
/**
|
|
164
163
|
* Waits for the index to be ready.
|
|
165
164
|
*
|
|
166
|
-
* @param
|
|
167
|
-
* @param
|
|
168
|
-
* @param
|
|
169
|
-
* @param params.checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
|
|
165
|
+
* @param {string} indexName - The name of the index to wait for
|
|
166
|
+
* @param {number} timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
|
|
167
|
+
* @param {number} checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
|
|
170
168
|
* @returns A promise that resolves when the index is ready
|
|
171
169
|
*/
|
|
172
|
-
async waitForIndexReady(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const { indexName, timeoutMs = 6e4, checkIntervalMs = 2e3 } = params;
|
|
170
|
+
async waitForIndexReady({
|
|
171
|
+
indexName,
|
|
172
|
+
timeoutMs = 6e4,
|
|
173
|
+
checkIntervalMs = 2e3
|
|
174
|
+
}) {
|
|
178
175
|
const collection = await this.getCollection(indexName, true);
|
|
179
176
|
const indexNameInternal = `${indexName}_vector_index`;
|
|
180
177
|
const startTime = Date.now();
|
|
@@ -189,8 +186,7 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
189
186
|
}
|
|
190
187
|
throw new Error(`Index "${indexNameInternal}" did not become ready within timeout`);
|
|
191
188
|
}
|
|
192
|
-
async upsert(
|
|
193
|
-
const { indexName, vectors, metadata, ids, documents } = params;
|
|
189
|
+
async upsert({ indexName, vectors, metadata, ids, documents }) {
|
|
194
190
|
const collection = await this.getCollection(indexName);
|
|
195
191
|
this.collectionForValidation = collection;
|
|
196
192
|
const stats = await this.describeIndex({ indexName });
|
|
@@ -226,8 +222,14 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
226
222
|
await collection.bulkWrite(operations);
|
|
227
223
|
return generatedIds;
|
|
228
224
|
}
|
|
229
|
-
async query(
|
|
230
|
-
|
|
225
|
+
async query({
|
|
226
|
+
indexName,
|
|
227
|
+
queryVector,
|
|
228
|
+
topK = 10,
|
|
229
|
+
filter,
|
|
230
|
+
includeVector = false,
|
|
231
|
+
documentFilter
|
|
232
|
+
}) {
|
|
231
233
|
const collection = await this.getCollection(indexName, true);
|
|
232
234
|
const indexNameInternal = `${indexName}_vector_index`;
|
|
233
235
|
const mongoFilter = this.transformFilter(filter);
|
|
@@ -286,13 +288,10 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
286
288
|
/**
|
|
287
289
|
* Retrieves statistics about a vector index.
|
|
288
290
|
*
|
|
289
|
-
* @param
|
|
290
|
-
* @param params.indexName - The name of the index to describe
|
|
291
|
+
* @param {string} indexName - The name of the index to describe
|
|
291
292
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
292
293
|
*/
|
|
293
|
-
async describeIndex(
|
|
294
|
-
const params = this.normalizeArgs("describeIndex", args);
|
|
295
|
-
const { indexName } = params;
|
|
294
|
+
async describeIndex({ indexName }) {
|
|
296
295
|
const collection = await this.getCollection(indexName, true);
|
|
297
296
|
const count = await collection.countDocuments({ _id: { $ne: "__index_metadata__" } });
|
|
298
297
|
const metadataDoc = await collection.findOne({ _id: "__index_metadata__" });
|
|
@@ -304,9 +303,7 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
304
303
|
metric
|
|
305
304
|
};
|
|
306
305
|
}
|
|
307
|
-
async deleteIndex(
|
|
308
|
-
const params = this.normalizeArgs("deleteIndex", args);
|
|
309
|
-
const { indexName } = params;
|
|
306
|
+
async deleteIndex({ indexName }) {
|
|
310
307
|
const collection = await this.getCollection(indexName, false);
|
|
311
308
|
if (collection) {
|
|
312
309
|
await collection.drop();
|
|
@@ -316,8 +313,6 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
316
313
|
}
|
|
317
314
|
}
|
|
318
315
|
/**
|
|
319
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
320
|
-
*
|
|
321
316
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
322
317
|
* @param indexName - The name of the index containing the vector.
|
|
323
318
|
* @param id - The ID of the vector to update.
|
|
@@ -327,27 +322,7 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
327
322
|
* @returns A promise that resolves when the update is complete.
|
|
328
323
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
329
324
|
*/
|
|
330
|
-
async
|
|
331
|
-
this.logger.warn(
|
|
332
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
333
|
-
Please use updateVector() instead.
|
|
334
|
-
updateIndexById() will be removed on May 20th, 2025.`
|
|
335
|
-
);
|
|
336
|
-
await this.updateVector({ indexName, id, update });
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
340
|
-
* @param indexName - The name of the index containing the vector.
|
|
341
|
-
* @param id - The ID of the vector to update.
|
|
342
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
343
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
344
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
345
|
-
* @returns A promise that resolves when the update is complete.
|
|
346
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
347
|
-
*/
|
|
348
|
-
async updateVector(...args) {
|
|
349
|
-
const params = this.normalizeArgs("updateVector", args);
|
|
350
|
-
const { indexName, id, update } = params;
|
|
325
|
+
async updateVector({ indexName, id, update }) {
|
|
351
326
|
try {
|
|
352
327
|
if (!update.vector && !update.metadata) {
|
|
353
328
|
throw new Error("No updates provided");
|
|
@@ -374,23 +349,6 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
374
349
|
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
375
350
|
}
|
|
376
351
|
}
|
|
377
|
-
/**
|
|
378
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
379
|
-
*
|
|
380
|
-
* Deletes a vector by its ID.
|
|
381
|
-
* @param indexName - The name of the index containing the vector.
|
|
382
|
-
* @param id - The ID of the vector to delete.
|
|
383
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
384
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
385
|
-
*/
|
|
386
|
-
async deleteIndexById(indexName, id) {
|
|
387
|
-
this.logger.warn(
|
|
388
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
389
|
-
Please use deleteVector() instead.
|
|
390
|
-
deleteIndexById() will be removed on May 20th, 2025.`
|
|
391
|
-
);
|
|
392
|
-
await this.deleteVector({ indexName, id });
|
|
393
|
-
}
|
|
394
352
|
/**
|
|
395
353
|
* Deletes a vector by its ID.
|
|
396
354
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -398,9 +356,7 @@ var MongoDBVector = class extends vector.MastraVector {
|
|
|
398
356
|
* @returns A promise that resolves when the deletion is complete.
|
|
399
357
|
* @throws Will throw an error if the deletion operation fails.
|
|
400
358
|
*/
|
|
401
|
-
async deleteVector(
|
|
402
|
-
const params = this.normalizeArgs("deleteVector", args);
|
|
403
|
-
const { indexName, id } = params;
|
|
359
|
+
async deleteVector({ indexName, id }) {
|
|
404
360
|
try {
|
|
405
361
|
const collection = await this.getCollection(indexName, true);
|
|
406
362
|
await collection.deleteOne({ _id: id });
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export { MONGODB_PROMPT } from './_tsup-dts-rollup.cjs';
|
|
2
|
-
export { MongoDBUpsertArgs } from './_tsup-dts-rollup.cjs';
|
|
3
|
-
export { MongoDBQueryArgs } from './_tsup-dts-rollup.cjs';
|
|
4
|
-
export { MongoDBUpsertParams } from './_tsup-dts-rollup.cjs';
|
|
5
2
|
export { MongoDBUpsertVectorParams } from './_tsup-dts-rollup.cjs';
|
|
6
3
|
export { MongoDBQueryVectorParams } from './_tsup-dts-rollup.cjs';
|
|
7
4
|
export { MongoDBIndexReadyParams } from './_tsup-dts-rollup.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export { MONGODB_PROMPT } from './_tsup-dts-rollup.js';
|
|
2
|
-
export { MongoDBUpsertArgs } from './_tsup-dts-rollup.js';
|
|
3
|
-
export { MongoDBQueryArgs } from './_tsup-dts-rollup.js';
|
|
4
|
-
export { MongoDBUpsertParams } from './_tsup-dts-rollup.js';
|
|
5
2
|
export { MongoDBUpsertVectorParams } from './_tsup-dts-rollup.js';
|
|
6
3
|
export { MongoDBQueryVectorParams } from './_tsup-dts-rollup.js';
|
|
7
4
|
export { MongoDBIndexReadyParams } from './_tsup-dts-rollup.js';
|
package/dist/index.js
CHANGED
|
@@ -119,8 +119,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
119
119
|
async disconnect() {
|
|
120
120
|
await this.client.close();
|
|
121
121
|
}
|
|
122
|
-
async createIndex(
|
|
123
|
-
const { indexName, dimension, metric = "cosine" } = params;
|
|
122
|
+
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
124
123
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
125
124
|
throw new Error("Dimension must be a positive integer");
|
|
126
125
|
}
|
|
@@ -161,18 +160,16 @@ var MongoDBVector = class extends MastraVector {
|
|
|
161
160
|
/**
|
|
162
161
|
* Waits for the index to be ready.
|
|
163
162
|
*
|
|
164
|
-
* @param
|
|
165
|
-
* @param
|
|
166
|
-
* @param
|
|
167
|
-
* @param params.checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
|
|
163
|
+
* @param {string} indexName - The name of the index to wait for
|
|
164
|
+
* @param {number} timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
|
|
165
|
+
* @param {number} checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
|
|
168
166
|
* @returns A promise that resolves when the index is ready
|
|
169
167
|
*/
|
|
170
|
-
async waitForIndexReady(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const { indexName, timeoutMs = 6e4, checkIntervalMs = 2e3 } = params;
|
|
168
|
+
async waitForIndexReady({
|
|
169
|
+
indexName,
|
|
170
|
+
timeoutMs = 6e4,
|
|
171
|
+
checkIntervalMs = 2e3
|
|
172
|
+
}) {
|
|
176
173
|
const collection = await this.getCollection(indexName, true);
|
|
177
174
|
const indexNameInternal = `${indexName}_vector_index`;
|
|
178
175
|
const startTime = Date.now();
|
|
@@ -187,8 +184,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
187
184
|
}
|
|
188
185
|
throw new Error(`Index "${indexNameInternal}" did not become ready within timeout`);
|
|
189
186
|
}
|
|
190
|
-
async upsert(
|
|
191
|
-
const { indexName, vectors, metadata, ids, documents } = params;
|
|
187
|
+
async upsert({ indexName, vectors, metadata, ids, documents }) {
|
|
192
188
|
const collection = await this.getCollection(indexName);
|
|
193
189
|
this.collectionForValidation = collection;
|
|
194
190
|
const stats = await this.describeIndex({ indexName });
|
|
@@ -224,8 +220,14 @@ var MongoDBVector = class extends MastraVector {
|
|
|
224
220
|
await collection.bulkWrite(operations);
|
|
225
221
|
return generatedIds;
|
|
226
222
|
}
|
|
227
|
-
async query(
|
|
228
|
-
|
|
223
|
+
async query({
|
|
224
|
+
indexName,
|
|
225
|
+
queryVector,
|
|
226
|
+
topK = 10,
|
|
227
|
+
filter,
|
|
228
|
+
includeVector = false,
|
|
229
|
+
documentFilter
|
|
230
|
+
}) {
|
|
229
231
|
const collection = await this.getCollection(indexName, true);
|
|
230
232
|
const indexNameInternal = `${indexName}_vector_index`;
|
|
231
233
|
const mongoFilter = this.transformFilter(filter);
|
|
@@ -284,13 +286,10 @@ var MongoDBVector = class extends MastraVector {
|
|
|
284
286
|
/**
|
|
285
287
|
* Retrieves statistics about a vector index.
|
|
286
288
|
*
|
|
287
|
-
* @param
|
|
288
|
-
* @param params.indexName - The name of the index to describe
|
|
289
|
+
* @param {string} indexName - The name of the index to describe
|
|
289
290
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
290
291
|
*/
|
|
291
|
-
async describeIndex(
|
|
292
|
-
const params = this.normalizeArgs("describeIndex", args);
|
|
293
|
-
const { indexName } = params;
|
|
292
|
+
async describeIndex({ indexName }) {
|
|
294
293
|
const collection = await this.getCollection(indexName, true);
|
|
295
294
|
const count = await collection.countDocuments({ _id: { $ne: "__index_metadata__" } });
|
|
296
295
|
const metadataDoc = await collection.findOne({ _id: "__index_metadata__" });
|
|
@@ -302,9 +301,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
302
301
|
metric
|
|
303
302
|
};
|
|
304
303
|
}
|
|
305
|
-
async deleteIndex(
|
|
306
|
-
const params = this.normalizeArgs("deleteIndex", args);
|
|
307
|
-
const { indexName } = params;
|
|
304
|
+
async deleteIndex({ indexName }) {
|
|
308
305
|
const collection = await this.getCollection(indexName, false);
|
|
309
306
|
if (collection) {
|
|
310
307
|
await collection.drop();
|
|
@@ -314,8 +311,6 @@ var MongoDBVector = class extends MastraVector {
|
|
|
314
311
|
}
|
|
315
312
|
}
|
|
316
313
|
/**
|
|
317
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
318
|
-
*
|
|
319
314
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
320
315
|
* @param indexName - The name of the index containing the vector.
|
|
321
316
|
* @param id - The ID of the vector to update.
|
|
@@ -325,27 +320,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
325
320
|
* @returns A promise that resolves when the update is complete.
|
|
326
321
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
327
322
|
*/
|
|
328
|
-
async
|
|
329
|
-
this.logger.warn(
|
|
330
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
331
|
-
Please use updateVector() instead.
|
|
332
|
-
updateIndexById() will be removed on May 20th, 2025.`
|
|
333
|
-
);
|
|
334
|
-
await this.updateVector({ indexName, id, update });
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
338
|
-
* @param indexName - The name of the index containing the vector.
|
|
339
|
-
* @param id - The ID of the vector to update.
|
|
340
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
341
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
342
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
343
|
-
* @returns A promise that resolves when the update is complete.
|
|
344
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
345
|
-
*/
|
|
346
|
-
async updateVector(...args) {
|
|
347
|
-
const params = this.normalizeArgs("updateVector", args);
|
|
348
|
-
const { indexName, id, update } = params;
|
|
323
|
+
async updateVector({ indexName, id, update }) {
|
|
349
324
|
try {
|
|
350
325
|
if (!update.vector && !update.metadata) {
|
|
351
326
|
throw new Error("No updates provided");
|
|
@@ -372,23 +347,6 @@ var MongoDBVector = class extends MastraVector {
|
|
|
372
347
|
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
373
348
|
}
|
|
374
349
|
}
|
|
375
|
-
/**
|
|
376
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
377
|
-
*
|
|
378
|
-
* Deletes a vector by its ID.
|
|
379
|
-
* @param indexName - The name of the index containing the vector.
|
|
380
|
-
* @param id - The ID of the vector to delete.
|
|
381
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
382
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
383
|
-
*/
|
|
384
|
-
async deleteIndexById(indexName, id) {
|
|
385
|
-
this.logger.warn(
|
|
386
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
387
|
-
Please use deleteVector() instead.
|
|
388
|
-
deleteIndexById() will be removed on May 20th, 2025.`
|
|
389
|
-
);
|
|
390
|
-
await this.deleteVector({ indexName, id });
|
|
391
|
-
}
|
|
392
350
|
/**
|
|
393
351
|
* Deletes a vector by its ID.
|
|
394
352
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -396,9 +354,7 @@ var MongoDBVector = class extends MastraVector {
|
|
|
396
354
|
* @returns A promise that resolves when the deletion is complete.
|
|
397
355
|
* @throws Will throw an error if the deletion operation fails.
|
|
398
356
|
*/
|
|
399
|
-
async deleteVector(
|
|
400
|
-
const params = this.normalizeArgs("deleteVector", args);
|
|
401
|
-
const { indexName, id } = params;
|
|
357
|
+
async deleteVector({ indexName, id }) {
|
|
402
358
|
try {
|
|
403
359
|
const collection = await this.getCollection(indexName, true);
|
|
404
360
|
await collection.deleteOne({ _id: id });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mongodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "MongoDB provider for Mastra - includes vector store capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
"@types/mongodb": "^4.0.7",
|
|
23
23
|
"cloudflare": "^4.1.0",
|
|
24
24
|
"mongodb": "^6.15.0",
|
|
25
|
-
"uuid": "^11.1.0"
|
|
26
|
-
"@mastra/core": "^0.9.5-alpha.0"
|
|
25
|
+
"uuid": "^11.1.0"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
28
|
"@microsoft/api-extractor": "^7.52.5",
|
|
@@ -32,7 +31,11 @@
|
|
|
32
31
|
"tsup": "^8.4.0",
|
|
33
32
|
"typescript": "^5.8.2",
|
|
34
33
|
"vitest": "^3.1.2",
|
|
35
|
-
"@internal/lint": "0.0.
|
|
34
|
+
"@internal/lint": "0.0.6",
|
|
35
|
+
"@mastra/core": "0.10.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@mastra/core": "^0.10.0"
|
|
36
39
|
},
|
|
37
40
|
"scripts": {
|
|
38
41
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
package/src/vector/index.ts
CHANGED
|
@@ -5,9 +5,6 @@ import type {
|
|
|
5
5
|
CreateIndexParams,
|
|
6
6
|
UpsertVectorParams,
|
|
7
7
|
QueryVectorParams,
|
|
8
|
-
ParamsToArgs,
|
|
9
|
-
QueryVectorArgs,
|
|
10
|
-
UpsertVectorArgs,
|
|
11
8
|
DescribeIndexParams,
|
|
12
9
|
DeleteIndexParams,
|
|
13
10
|
DeleteVectorParams,
|
|
@@ -21,10 +18,6 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
21
18
|
import { MongoDBFilterTranslator } from './filter';
|
|
22
19
|
|
|
23
20
|
// Define necessary types and interfaces
|
|
24
|
-
export type MongoDBUpsertArgs = [...UpsertVectorArgs, string[]?];
|
|
25
|
-
export type MongoDBQueryArgs = [...QueryVectorArgs, string?];
|
|
26
|
-
export type MongoDBUpsertParams = ParamsToArgs<MongoDBUpsertArgs>;
|
|
27
|
-
|
|
28
21
|
export interface MongoDBUpsertVectorParams extends UpsertVectorParams {
|
|
29
22
|
documents?: string[];
|
|
30
23
|
}
|
|
@@ -39,8 +32,6 @@ export interface MongoDBIndexReadyParams {
|
|
|
39
32
|
checkIntervalMs?: number;
|
|
40
33
|
}
|
|
41
34
|
|
|
42
|
-
type MongoDBIndexReadyArgs = [string, number?, number?];
|
|
43
|
-
|
|
44
35
|
// Define the document interface
|
|
45
36
|
interface MongoDBDocument extends Document {
|
|
46
37
|
_id: string; // Explicitly declare '_id' as string
|
|
@@ -80,9 +71,7 @@ export class MongoDBVector extends MastraVector {
|
|
|
80
71
|
await this.client.close();
|
|
81
72
|
}
|
|
82
73
|
|
|
83
|
-
async createIndex(
|
|
84
|
-
const { indexName, dimension, metric = 'cosine' } = params;
|
|
85
|
-
|
|
74
|
+
async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {
|
|
86
75
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
87
76
|
throw new Error('Dimension must be a positive integer');
|
|
88
77
|
}
|
|
@@ -133,18 +122,16 @@ export class MongoDBVector extends MastraVector {
|
|
|
133
122
|
/**
|
|
134
123
|
* Waits for the index to be ready.
|
|
135
124
|
*
|
|
136
|
-
* @param
|
|
137
|
-
* @param
|
|
138
|
-
* @param
|
|
139
|
-
* @param params.checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
|
|
125
|
+
* @param {string} indexName - The name of the index to wait for
|
|
126
|
+
* @param {number} timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
|
|
127
|
+
* @param {number} checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
|
|
140
128
|
* @returns A promise that resolves when the index is ready
|
|
141
129
|
*/
|
|
142
|
-
async waitForIndexReady(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const { indexName, timeoutMs = 60000, checkIntervalMs = 2000 } = params;
|
|
130
|
+
async waitForIndexReady({
|
|
131
|
+
indexName,
|
|
132
|
+
timeoutMs = 60000,
|
|
133
|
+
checkIntervalMs = 2000,
|
|
134
|
+
}: MongoDBIndexReadyParams): Promise<void> {
|
|
148
135
|
const collection = await this.getCollection(indexName, true);
|
|
149
136
|
const indexNameInternal = `${indexName}_vector_index`;
|
|
150
137
|
|
|
@@ -161,9 +148,7 @@ export class MongoDBVector extends MastraVector {
|
|
|
161
148
|
throw new Error(`Index "${indexNameInternal}" did not become ready within timeout`);
|
|
162
149
|
}
|
|
163
150
|
|
|
164
|
-
async upsert(
|
|
165
|
-
const { indexName, vectors, metadata, ids, documents } = params;
|
|
166
|
-
|
|
151
|
+
async upsert({ indexName, vectors, metadata, ids, documents }: MongoDBUpsertVectorParams): Promise<string[]> {
|
|
167
152
|
const collection = await this.getCollection(indexName);
|
|
168
153
|
|
|
169
154
|
this.collectionForValidation = collection;
|
|
@@ -213,9 +198,14 @@ export class MongoDBVector extends MastraVector {
|
|
|
213
198
|
return generatedIds;
|
|
214
199
|
}
|
|
215
200
|
|
|
216
|
-
async query(
|
|
217
|
-
|
|
218
|
-
|
|
201
|
+
async query({
|
|
202
|
+
indexName,
|
|
203
|
+
queryVector,
|
|
204
|
+
topK = 10,
|
|
205
|
+
filter,
|
|
206
|
+
includeVector = false,
|
|
207
|
+
documentFilter,
|
|
208
|
+
}: MongoDBQueryVectorParams): Promise<QueryResult[]> {
|
|
219
209
|
const collection = await this.getCollection(indexName, true);
|
|
220
210
|
const indexNameInternal = `${indexName}_vector_index`;
|
|
221
211
|
|
|
@@ -284,14 +274,10 @@ export class MongoDBVector extends MastraVector {
|
|
|
284
274
|
/**
|
|
285
275
|
* Retrieves statistics about a vector index.
|
|
286
276
|
*
|
|
287
|
-
* @param
|
|
288
|
-
* @param params.indexName - The name of the index to describe
|
|
277
|
+
* @param {string} indexName - The name of the index to describe
|
|
289
278
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
290
279
|
*/
|
|
291
|
-
async describeIndex(
|
|
292
|
-
const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
|
|
293
|
-
|
|
294
|
-
const { indexName } = params;
|
|
280
|
+
async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {
|
|
295
281
|
const collection = await this.getCollection(indexName, true);
|
|
296
282
|
|
|
297
283
|
// Get the count of documents, excluding the metadata document
|
|
@@ -309,10 +295,7 @@ export class MongoDBVector extends MastraVector {
|
|
|
309
295
|
};
|
|
310
296
|
}
|
|
311
297
|
|
|
312
|
-
async deleteIndex(
|
|
313
|
-
const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
|
|
314
|
-
|
|
315
|
-
const { indexName } = params;
|
|
298
|
+
async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {
|
|
316
299
|
const collection = await this.getCollection(indexName, false); // Do not throw error if collection doesn't exist
|
|
317
300
|
if (collection) {
|
|
318
301
|
await collection.drop();
|
|
@@ -324,8 +307,6 @@ export class MongoDBVector extends MastraVector {
|
|
|
324
307
|
}
|
|
325
308
|
|
|
326
309
|
/**
|
|
327
|
-
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
328
|
-
*
|
|
329
310
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
330
311
|
* @param indexName - The name of the index containing the vector.
|
|
331
312
|
* @param id - The ID of the vector to update.
|
|
@@ -335,32 +316,7 @@ export class MongoDBVector extends MastraVector {
|
|
|
335
316
|
* @returns A promise that resolves when the update is complete.
|
|
336
317
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
337
318
|
*/
|
|
338
|
-
async
|
|
339
|
-
indexName: string,
|
|
340
|
-
id: string,
|
|
341
|
-
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
342
|
-
): Promise<void> {
|
|
343
|
-
this.logger.warn(
|
|
344
|
-
`Deprecation Warning: updateIndexById() is deprecated.
|
|
345
|
-
Please use updateVector() instead.
|
|
346
|
-
updateIndexById() will be removed on May 20th, 2025.`,
|
|
347
|
-
);
|
|
348
|
-
await this.updateVector({ indexName, id, update });
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
353
|
-
* @param indexName - The name of the index containing the vector.
|
|
354
|
-
* @param id - The ID of the vector to update.
|
|
355
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
356
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
357
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
358
|
-
* @returns A promise that resolves when the update is complete.
|
|
359
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
360
|
-
*/
|
|
361
|
-
async updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void> {
|
|
362
|
-
const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
|
|
363
|
-
const { indexName, id, update } = params;
|
|
319
|
+
async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {
|
|
364
320
|
try {
|
|
365
321
|
if (!update.vector && !update.metadata) {
|
|
366
322
|
throw new Error('No updates provided');
|
|
@@ -395,24 +351,6 @@ export class MongoDBVector extends MastraVector {
|
|
|
395
351
|
}
|
|
396
352
|
}
|
|
397
353
|
|
|
398
|
-
/**
|
|
399
|
-
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
400
|
-
*
|
|
401
|
-
* Deletes a vector by its ID.
|
|
402
|
-
* @param indexName - The name of the index containing the vector.
|
|
403
|
-
* @param id - The ID of the vector to delete.
|
|
404
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
405
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
406
|
-
*/
|
|
407
|
-
async deleteIndexById(indexName: string, id: string): Promise<void> {
|
|
408
|
-
this.logger.warn(
|
|
409
|
-
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
410
|
-
Please use deleteVector() instead.
|
|
411
|
-
deleteIndexById() will be removed on May 20th, 2025.`,
|
|
412
|
-
);
|
|
413
|
-
await this.deleteVector({ indexName, id });
|
|
414
|
-
}
|
|
415
|
-
|
|
416
354
|
/**
|
|
417
355
|
* Deletes a vector by its ID.
|
|
418
356
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -420,9 +358,7 @@ export class MongoDBVector extends MastraVector {
|
|
|
420
358
|
* @returns A promise that resolves when the deletion is complete.
|
|
421
359
|
* @throws Will throw an error if the deletion operation fails.
|
|
422
360
|
*/
|
|
423
|
-
async deleteVector(
|
|
424
|
-
const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
|
|
425
|
-
const { indexName, id } = params;
|
|
361
|
+
async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {
|
|
426
362
|
try {
|
|
427
363
|
const collection = await this.getCollection(indexName, true);
|
|
428
364
|
await collection.deleteOne({ _id: id });
|