@mastra/mongodb 0.12.4 → 0.13.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +34 -0
- package/dist/index.cjs +9 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/storage/MongoDBConnector.d.ts +2 -2
- package/dist/storage/connectors/MongoDBConnector.d.ts +2 -2
- package/dist/storage/domains/legacy-evals/index.d.ts +1 -1
- package/dist/storage/domains/memory/index.d.ts +1 -1
- package/dist/storage/domains/operations/index.d.ts +1 -1
- package/dist/storage/domains/scores/index.d.ts +1 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/traces/index.d.ts +1 -1
- package/dist/storage/domains/workflows/index.d.ts +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/types.d.ts +1 -1
- package/dist/vector/index.d.ts +1 -1
- package/package.json +7 -6
- package/src/storage/domains/scores/index.ts +15 -11
- package/src/storage/domains/traces/index.ts +5 -5
- package/src/vector/index.test.ts +31 -0
- package/tsup.config.ts +2 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MongoClient } from 'mongodb';
|
|
2
|
-
import type { ConnectorHandler } from './connectors/base';
|
|
3
|
-
import type { DatabaseConfig } from './types';
|
|
2
|
+
import type { ConnectorHandler } from './connectors/base.js';
|
|
3
|
+
import type { DatabaseConfig } from './types.js';
|
|
4
4
|
type MongoDBConnectorOptions = {
|
|
5
5
|
client: MongoClient;
|
|
6
6
|
dbName: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MongoClient } from 'mongodb';
|
|
2
|
-
import type { DatabaseConfig } from '../types';
|
|
3
|
-
import type { ConnectorHandler } from './base';
|
|
2
|
+
import type { DatabaseConfig } from '../types.js';
|
|
3
|
+
import type { ConnectorHandler } from './base.js';
|
|
4
4
|
type MongoDBConnectorOptions = {
|
|
5
5
|
client: MongoClient;
|
|
6
6
|
dbName: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LegacyEvalsStorage } from '@mastra/core/storage';
|
|
2
2
|
import type { PaginationArgs, PaginationInfo, EvalRow } from '@mastra/core/storage';
|
|
3
|
-
import type { StoreOperationsMongoDB } from '../operations';
|
|
3
|
+
import type { StoreOperationsMongoDB } from '../operations/index.js';
|
|
4
4
|
export declare class LegacyEvalsMongoDB extends LegacyEvalsStorage {
|
|
5
5
|
private operations;
|
|
6
6
|
constructor({ operations }: {
|
|
@@ -2,7 +2,7 @@ import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
|
2
2
|
import type { MastraMessageV1, MastraMessageV2, StorageThreadType } from '@mastra/core/memory';
|
|
3
3
|
import { MemoryStorage } from '@mastra/core/storage';
|
|
4
4
|
import type { PaginationInfo, StorageGetMessagesArg, StorageResourceType } from '@mastra/core/storage';
|
|
5
|
-
import type { StoreOperationsMongoDB } from '../operations';
|
|
5
|
+
import type { StoreOperationsMongoDB } from '../operations/index.js';
|
|
6
6
|
export declare class MemoryStorageMongoDB extends MemoryStorage {
|
|
7
7
|
private operations;
|
|
8
8
|
constructor({ operations }: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StoreOperations } from '@mastra/core/storage';
|
|
2
2
|
import type { StorageColumn, TABLE_NAMES } from '@mastra/core/storage';
|
|
3
|
-
import type { ConnectorHandler } from '../../connectors/base';
|
|
3
|
+
import type { ConnectorHandler } from '../../connectors/base.js';
|
|
4
4
|
export interface MongoDBOperationsConfig {
|
|
5
5
|
connector: ConnectorHandler;
|
|
6
6
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ScoreRowData } from '@mastra/core/scores';
|
|
2
2
|
import { ScoresStorage } from '@mastra/core/storage';
|
|
3
3
|
import type { PaginationInfo, StoragePagination } from '@mastra/core/storage';
|
|
4
|
-
import type { StoreOperationsMongoDB } from '../operations';
|
|
4
|
+
import type { StoreOperationsMongoDB } from '../operations/index.js';
|
|
5
5
|
export declare class ScoresStorageMongoDB extends ScoresStorage {
|
|
6
6
|
private operations;
|
|
7
7
|
constructor({ operations }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/scores/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAoC,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAkC,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/scores/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAoC,MAAM,qBAAqB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAkC,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAmG5D,qBAAa,oBAAqB,SAAQ,aAAa;IACrD,OAAO,CAAC,UAAU,CAAyB;gBAE/B,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,sBAAsB,CAAA;KAAE;IAK5D,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAuBlE,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC;IAiExG,mBAAmB,CAAC,EACxB,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,UAAU,GACX,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,iBAAiB,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IA4D7D,gBAAgB,CAAC,EACrB,KAAK,EACL,UAAU,GACX,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IAkD7D,mBAAmB,CAAC,EACxB,QAAQ,EACR,UAAU,EACV,UAAU,GACX,EAAE;QACD,UAAU,EAAE,iBAAiB,CAAC;QAC9B,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;CAiDpE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PaginationInfo, StorageGetTracesArg, StorageGetTracesPaginatedArg } from '@mastra/core/storage';
|
|
2
2
|
import { TracesStorage } from '@mastra/core/storage';
|
|
3
3
|
import type { Trace } from '@mastra/core/telemetry';
|
|
4
|
-
import type { StoreOperationsMongoDB } from '../operations';
|
|
4
|
+
import type { StoreOperationsMongoDB } from '../operations/index.js';
|
|
5
5
|
export declare class TracesStorageMongoDB extends TracesStorage {
|
|
6
6
|
private operations;
|
|
7
7
|
constructor({ operations }: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WorkflowsStorage } from '@mastra/core/storage';
|
|
2
2
|
import type { WorkflowRun, WorkflowRuns } from '@mastra/core/storage';
|
|
3
3
|
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
4
|
-
import type { StoreOperationsMongoDB } from '../operations';
|
|
4
|
+
import type { StoreOperationsMongoDB } from '../operations/index.js';
|
|
5
5
|
export declare class WorkflowsStorageMongoDB extends WorkflowsStorage {
|
|
6
6
|
private operations;
|
|
7
7
|
constructor({ operations }: {
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { EvalRow, PaginationArgs, PaginationInfo, StorageColumn, StorageDom
|
|
|
5
5
|
import { MastraStorage } from '@mastra/core/storage';
|
|
6
6
|
import type { Trace } from '@mastra/core/telemetry';
|
|
7
7
|
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
8
|
-
import type { MongoDBConfig } from './types';
|
|
8
|
+
import type { MongoDBConfig } from './types.js';
|
|
9
9
|
export declare class MongoDBStore extends MastraStorage {
|
|
10
10
|
#private;
|
|
11
11
|
stores: StorageDomains;
|
package/dist/storage/types.d.ts
CHANGED
package/dist/vector/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MastraVector } from '@mastra/core/vector';
|
|
2
2
|
import type { QueryResult, IndexStats, CreateIndexParams, UpsertVectorParams, QueryVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams } from '@mastra/core/vector';
|
|
3
3
|
import type { MongoClientOptions } from 'mongodb';
|
|
4
|
-
import type { MongoDBVectorFilter } from './filter';
|
|
4
|
+
import type { MongoDBVectorFilter } from './filter.js';
|
|
5
5
|
export interface MongoDBUpsertVectorParams extends UpsertVectorParams {
|
|
6
6
|
documents?: string[];
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mongodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0-alpha.2",
|
|
4
4
|
"description": "MongoDB provider for Mastra - includes vector store capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"require": {
|
|
15
|
-
"types": "./dist/index.d.
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
16
|
"default": "./dist/index.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
@@ -31,12 +31,13 @@
|
|
|
31
31
|
"tsup": "^8.5.0",
|
|
32
32
|
"typescript": "^5.8.3",
|
|
33
33
|
"vitest": "^3.2.4",
|
|
34
|
-
"@
|
|
35
|
-
"@internal/
|
|
36
|
-
"@internal/
|
|
34
|
+
"@internal/lint": "0.0.26",
|
|
35
|
+
"@internal/storage-test-utils": "0.0.22",
|
|
36
|
+
"@internal/types-builder": "0.0.1",
|
|
37
|
+
"@mastra/core": "0.13.0-alpha.2"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
|
-
"@mastra/core": ">=0.
|
|
40
|
+
"@mastra/core": ">=0.13.0-0 <0.14.0-0"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "tsup --silent --config tsup.config.ts",
|
|
@@ -14,13 +14,15 @@ function transformScoreRow(row: Record<string, any>): ScoreRowData {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
let
|
|
18
|
-
if (row.
|
|
17
|
+
let preprocessStepResultValue: any = null;
|
|
18
|
+
if (row.preprocessStepResult) {
|
|
19
19
|
try {
|
|
20
|
-
|
|
21
|
-
typeof row.
|
|
20
|
+
preprocessStepResultValue =
|
|
21
|
+
typeof row.preprocessStepResult === 'string'
|
|
22
|
+
? safelyParseJSON(row.preprocessStepResult)
|
|
23
|
+
: row.preprocessStepResult;
|
|
22
24
|
} catch (e) {
|
|
23
|
-
console.warn('Failed to parse
|
|
25
|
+
console.warn('Failed to parse preprocessStepResult:', e);
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -79,7 +81,7 @@ function transformScoreRow(row: Record<string, any>): ScoreRowData {
|
|
|
79
81
|
traceId: row.traceId as string,
|
|
80
82
|
runId: row.runId as string,
|
|
81
83
|
scorer: scorerValue,
|
|
82
|
-
|
|
84
|
+
preprocessStepResult: preprocessStepResultValue,
|
|
83
85
|
analyzeStepResult: analyzeStepResultValue,
|
|
84
86
|
score: row.score as number,
|
|
85
87
|
reason: row.reason as string,
|
|
@@ -143,17 +145,19 @@ export class ScoresStorageMongoDB extends ScoresStorage {
|
|
|
143
145
|
traceId: score.traceId || '',
|
|
144
146
|
runId: score.runId,
|
|
145
147
|
scorer: typeof score.scorer === 'string' ? safelyParseJSON(score.scorer) : score.scorer,
|
|
146
|
-
|
|
147
|
-
typeof score.
|
|
148
|
-
? safelyParseJSON(score.
|
|
149
|
-
: score.
|
|
148
|
+
preprocessStepResult:
|
|
149
|
+
typeof score.preprocessStepResult === 'string'
|
|
150
|
+
? safelyParseJSON(score.preprocessStepResult)
|
|
151
|
+
: score.preprocessStepResult,
|
|
150
152
|
analyzeStepResult:
|
|
151
153
|
typeof score.analyzeStepResult === 'string'
|
|
152
154
|
? safelyParseJSON(score.analyzeStepResult)
|
|
153
155
|
: score.analyzeStepResult,
|
|
154
156
|
score: score.score,
|
|
155
157
|
reason: score.reason,
|
|
156
|
-
|
|
158
|
+
preprocessPrompt: score.preprocessPrompt,
|
|
159
|
+
generateScorePrompt: score.generateScorePrompt,
|
|
160
|
+
generateReasonPrompt: score.generateReasonPrompt,
|
|
157
161
|
analyzePrompt: score.analyzePrompt,
|
|
158
162
|
reasonPrompt: score.reasonPrompt,
|
|
159
163
|
input: typeof score.input === 'string' ? safelyParseJSON(score.input) : score.input,
|
|
@@ -103,13 +103,13 @@ export class TracesStorageMongoDB extends TracesStorage {
|
|
|
103
103
|
name: row.name,
|
|
104
104
|
scope: row.scope,
|
|
105
105
|
kind: row.kind,
|
|
106
|
-
status: safelyParseJSON(row.status
|
|
107
|
-
events: safelyParseJSON(row.events
|
|
108
|
-
links: safelyParseJSON(row.links
|
|
109
|
-
attributes: safelyParseJSON(row.attributes
|
|
106
|
+
status: safelyParseJSON(row.status),
|
|
107
|
+
events: safelyParseJSON(row.events),
|
|
108
|
+
links: safelyParseJSON(row.links),
|
|
109
|
+
attributes: safelyParseJSON(row.attributes),
|
|
110
110
|
startTime: row.startTime,
|
|
111
111
|
endTime: row.endTime,
|
|
112
|
-
other: safelyParseJSON(row.other
|
|
112
|
+
other: safelyParseJSON(row.other),
|
|
113
113
|
createdAt: row.createdAt,
|
|
114
114
|
})) as Trace[];
|
|
115
115
|
|
package/src/vector/index.test.ts
CHANGED
|
@@ -93,6 +93,7 @@ describe('MongoDBVector Integration Tests', () => {
|
|
|
93
93
|
let vectorDB: MongoDBVector;
|
|
94
94
|
const testIndexName = 'my_vectors';
|
|
95
95
|
const testIndexName2 = 'my_vectors_2';
|
|
96
|
+
const emptyIndexName = 'empty-index';
|
|
96
97
|
|
|
97
98
|
beforeAll(async () => {
|
|
98
99
|
vectorDB = new MongoDBVector({ uri, dbName });
|
|
@@ -114,6 +115,7 @@ describe('MongoDBVector Integration Tests', () => {
|
|
|
114
115
|
|
|
115
116
|
await createIndexAndWait(vectorDB, testIndexName, 4, 'cosine');
|
|
116
117
|
await createIndexAndWait(vectorDB, testIndexName2, 4, 'cosine');
|
|
118
|
+
await createIndexAndWait(vectorDB, emptyIndexName, 4, 'cosine');
|
|
117
119
|
}, 500000);
|
|
118
120
|
|
|
119
121
|
afterAll(async () => {
|
|
@@ -127,6 +129,11 @@ describe('MongoDBVector Integration Tests', () => {
|
|
|
127
129
|
} catch (error) {
|
|
128
130
|
console.error('Failed to delete test collection:', error);
|
|
129
131
|
}
|
|
132
|
+
try {
|
|
133
|
+
await vectorDB.deleteIndex({ indexName: emptyIndexName });
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error('Failed to delete test collection:', error);
|
|
136
|
+
}
|
|
130
137
|
await vectorDB.disconnect();
|
|
131
138
|
});
|
|
132
139
|
|
|
@@ -482,5 +489,29 @@ describe('MongoDBVector Integration Tests', () => {
|
|
|
482
489
|
const invalidVector = [1, 2, 3]; // 3D vector for 4D index
|
|
483
490
|
await expect(vectorDB.upsert({ indexName: testIndexName, vectors: [invalidVector] })).rejects.toThrow();
|
|
484
491
|
});
|
|
492
|
+
it('should return empty results and not throw when semantic search filter matches zero documents', async () => {
|
|
493
|
+
// Use a valid embedding vector matching your test index dimension
|
|
494
|
+
const testEmbedding = [0.1, 0.2, 0.3, 0.4]; // Adjust dimension as needed
|
|
495
|
+
|
|
496
|
+
// Should not throw, should return an empty array
|
|
497
|
+
let error: unknown = null;
|
|
498
|
+
let results: any[] = [];
|
|
499
|
+
try {
|
|
500
|
+
results = await vectorDB.query({
|
|
501
|
+
indexName: emptyIndexName,
|
|
502
|
+
queryVector: testEmbedding,
|
|
503
|
+
topK: 2,
|
|
504
|
+
filter: {
|
|
505
|
+
'metadata.label': 'test_filter_validation',
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
} catch (e) {
|
|
509
|
+
error = e;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
expect(error).toBeNull();
|
|
513
|
+
expect(Array.isArray(results)).toBe(true);
|
|
514
|
+
expect(results.length).toBe(0);
|
|
515
|
+
});
|
|
485
516
|
});
|
|
486
517
|
});
|
package/tsup.config.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { promisify } from 'util';
|
|
1
|
+
import { generateTypes } from '@internal/types-builder';
|
|
3
2
|
import { defineConfig } from 'tsup';
|
|
4
3
|
|
|
5
|
-
const exec = promisify(spawn);
|
|
6
|
-
|
|
7
4
|
export default defineConfig({
|
|
8
5
|
entry: ['src/index.ts'],
|
|
9
6
|
format: ['esm', 'cjs'],
|
|
@@ -15,8 +12,6 @@ export default defineConfig({
|
|
|
15
12
|
},
|
|
16
13
|
sourcemap: true,
|
|
17
14
|
onSuccess: async () => {
|
|
18
|
-
await
|
|
19
|
-
stdio: 'inherit',
|
|
20
|
-
});
|
|
15
|
+
await generateTypes(process.cwd());
|
|
21
16
|
},
|
|
22
17
|
});
|