@mastra/mongodb 0.12.4 → 0.13.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +14 -0
- package/dist/index.cjs +9 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/storage/domains/scores/index.ts +15 -11
- package/src/vector/index.test.ts +31 -0
|
@@ -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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mongodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0-alpha.0",
|
|
4
4
|
"description": "MongoDB provider for Mastra - includes vector store capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"tsup": "^8.5.0",
|
|
32
32
|
"typescript": "^5.8.3",
|
|
33
33
|
"vitest": "^3.2.4",
|
|
34
|
-
"@
|
|
35
|
-
"@internal/
|
|
36
|
-
"@
|
|
34
|
+
"@internal/lint": "0.0.26",
|
|
35
|
+
"@internal/storage-test-utils": "0.0.22",
|
|
36
|
+
"@mastra/core": "0.13.0-alpha.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@mastra/core": ">=0.10.7-0 <0.13.0-0"
|
|
@@ -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,
|
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
|
});
|