@mastra/vectorize 0.1.5 → 0.1.6-alpha.1
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 +20 -0
- package/dist/_tsup-dts-rollup.d.ts +3 -3
- package/dist/index.js +18 -10
- package/eslint.config.js +6 -0
- package/package.json +7 -4
- package/src/vector/filter.ts +2 -1
- package/src/vector/index.test.ts +5 -5
- package/src/vector/index.ts +21 -12
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/vectorize@0.1.
|
|
2
|
+
> @mastra/vectorize@0.1.6-alpha.1 build /home/runner/work/mastra/mastra/stores/vectorize
|
|
3
3
|
> tsup src/index.ts --format esm --experimental-dts --clean --treeshake
|
|
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.3.6
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 13586ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
|
-
[34mCLI[39m Cleaning output folder
|
|
13
|
-
[34mESM[39m Build start
|
|
14
12
|
Analysis will use the bundled TypeScript version 5.7.3
|
|
15
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/vectorize/dist/_tsup-dts-rollup.d.ts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[
|
|
18
|
-
[
|
|
14
|
+
[32mDTS[39m ⚡️ Build success in 10111ms
|
|
15
|
+
[34mCLI[39m Cleaning output folder
|
|
16
|
+
[34mESM[39m Build start
|
|
17
|
+
[32mESM[39m [1mdist/index.js [22m[32m5.26 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 497ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/vectorize
|
|
2
2
|
|
|
3
|
+
## 0.1.6-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [0d185b1]
|
|
8
|
+
- Updated dependencies [ed55f1d]
|
|
9
|
+
- Updated dependencies [8d13b14]
|
|
10
|
+
- Updated dependencies [3ee4831]
|
|
11
|
+
- Updated dependencies [108793c]
|
|
12
|
+
- Updated dependencies [5f28f44]
|
|
13
|
+
- @mastra/core@0.4.3-alpha.1
|
|
14
|
+
|
|
15
|
+
## 0.1.6-alpha.0
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 0f7bd01: Fixed upsert for vectorize by adding \_\_binaryRequest
|
|
20
|
+
- Updated dependencies [06aa827]
|
|
21
|
+
- @mastra/core@0.4.3-alpha.0
|
|
22
|
+
|
|
3
23
|
## 0.1.5
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/filter';
|
|
2
2
|
import Cloudflare from 'cloudflare';
|
|
3
|
-
import { Filter } from '@mastra/core/filter';
|
|
3
|
+
import type { Filter } from '@mastra/core/filter';
|
|
4
4
|
import { MastraVector } from '@mastra/core/vector';
|
|
5
|
-
import { OperatorSupport } from '@mastra/core/filter';
|
|
6
|
-
import { QueryResult } from '@mastra/core/vector';
|
|
5
|
+
import type { OperatorSupport } from '@mastra/core/filter';
|
|
6
|
+
import type { QueryResult } from '@mastra/core/vector';
|
|
7
7
|
|
|
8
8
|
declare class CloudflareVector extends MastraVector {
|
|
9
9
|
client: Cloudflare;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BaseFilterTranslator } from '@mastra/core/filter';
|
|
2
1
|
import { MastraVector } from '@mastra/core/vector';
|
|
3
2
|
import Cloudflare from 'cloudflare';
|
|
3
|
+
import { BaseFilterTranslator } from '@mastra/core/filter';
|
|
4
4
|
|
|
5
5
|
// src/vector/index.ts
|
|
6
6
|
var VectorizeFilterTranslator = class extends BaseFilterTranslator {
|
|
@@ -70,15 +70,23 @@ var CloudflareVector = class extends MastraVector {
|
|
|
70
70
|
}
|
|
71
71
|
async upsert(indexName, vectors, metadata, ids) {
|
|
72
72
|
const generatedIds = ids || vectors.map(() => crypto.randomUUID());
|
|
73
|
-
const ndjson = vectors.map(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
const ndjson = vectors.map(
|
|
74
|
+
(vector, index) => JSON.stringify({
|
|
75
|
+
id: generatedIds[index],
|
|
76
|
+
values: vector,
|
|
77
|
+
metadata: metadata?.[index]
|
|
78
|
+
})
|
|
79
|
+
).join("\n");
|
|
80
|
+
await this.client.vectorize.indexes.upsert(
|
|
81
|
+
indexName,
|
|
82
|
+
{
|
|
83
|
+
account_id: this.accountId,
|
|
84
|
+
body: ndjson
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
__binaryRequest: true
|
|
88
|
+
}
|
|
89
|
+
);
|
|
82
90
|
return generatedIds;
|
|
83
91
|
}
|
|
84
92
|
transformFilter(filter) {
|
package/eslint.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/vectorize",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6-alpha.1",
|
|
4
4
|
"description": "Cloudflare Vectorize store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,18 +16,21 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"cloudflare": "^4.0.0",
|
|
19
|
-
"@mastra/core": "^0.4.
|
|
19
|
+
"@mastra/core": "^0.4.3-alpha.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@microsoft/api-extractor": "^7.49.2",
|
|
23
23
|
"@types/node": "^22.13.1",
|
|
24
24
|
"tsup": "^8.0.1",
|
|
25
25
|
"typescript": "^5.7.3",
|
|
26
|
-
"vitest": "^3.0.5"
|
|
26
|
+
"vitest": "^3.0.5",
|
|
27
|
+
"eslint": "^9.20.1",
|
|
28
|
+
"@internal/lint": "0.0.0"
|
|
27
29
|
},
|
|
28
30
|
"scripts": {
|
|
29
31
|
"build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
|
|
30
32
|
"build:watch": "pnpm build --watch",
|
|
31
|
-
"test": "vitest run"
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"lint": "eslint ."
|
|
32
35
|
}
|
|
33
36
|
}
|
package/src/vector/filter.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BaseFilterTranslator
|
|
1
|
+
import { BaseFilterTranslator } from '@mastra/core/filter';
|
|
2
|
+
import type { Filter, FieldCondition, OperatorSupport } from '@mastra/core/filter';
|
|
2
3
|
|
|
3
4
|
export class VectorizeFilterTranslator extends BaseFilterTranslator {
|
|
4
5
|
protected override getSupportedOperators(): OperatorSupport {
|
package/src/vector/index.test.ts
CHANGED
|
@@ -167,7 +167,7 @@ describe('CloudflareVector', () => {
|
|
|
167
167
|
expect(result.vector).toHaveLength(VECTOR_DIMENSION);
|
|
168
168
|
}
|
|
169
169
|
});
|
|
170
|
-
},
|
|
170
|
+
}, 60000);
|
|
171
171
|
|
|
172
172
|
describe('Error Handling', () => {
|
|
173
173
|
it('should handle invalid dimension vectors', async () => {
|
|
@@ -480,7 +480,7 @@ describe('CloudflareVector', () => {
|
|
|
480
480
|
results.forEach(result => {
|
|
481
481
|
expect(result.metadata?.nested?.string).toBe('premium');
|
|
482
482
|
});
|
|
483
|
-
},
|
|
483
|
+
}, 10000);
|
|
484
484
|
|
|
485
485
|
it('combines nested numeric and boolean conditions', async () => {
|
|
486
486
|
const results = await vectorDB.query(testIndexName2, createVector(0, 1.0), 10, {
|
|
@@ -490,7 +490,7 @@ describe('CloudflareVector', () => {
|
|
|
490
490
|
expect(results.length).toBe(1);
|
|
491
491
|
expect(results[0]?.metadata?.nested?.number).toBeGreaterThan(100);
|
|
492
492
|
expect(results[0]?.metadata?.nested?.boolean).toBe(true);
|
|
493
|
-
},
|
|
493
|
+
}, 10000);
|
|
494
494
|
|
|
495
495
|
it('handles multiple nested field comparisons', async () => {
|
|
496
496
|
const results = await vectorDB.query(testIndexName2, createVector(0, 1.0), 10, {
|
|
@@ -503,7 +503,7 @@ describe('CloudflareVector', () => {
|
|
|
503
503
|
expect(result?.string).toBe('premium');
|
|
504
504
|
expect(result?.number).toBeLessThan(200);
|
|
505
505
|
expect(result?.boolean).toBe(true);
|
|
506
|
-
},
|
|
506
|
+
}, 10000);
|
|
507
507
|
|
|
508
508
|
it('handles $in with nested string values', async () => {
|
|
509
509
|
const results = await vectorDB.query(testIndexName2, createVector(0, 1.0), 10, {
|
|
@@ -513,7 +513,7 @@ describe('CloudflareVector', () => {
|
|
|
513
513
|
results.forEach(result => {
|
|
514
514
|
expect(['premium', 'basic']).toContain(result.metadata?.nested?.string);
|
|
515
515
|
});
|
|
516
|
-
},
|
|
516
|
+
}, 10000);
|
|
517
517
|
});
|
|
518
518
|
|
|
519
519
|
describe('String Operations', () => {
|
package/src/vector/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { MastraVector
|
|
1
|
+
import type { Filter } from '@mastra/core/filter';
|
|
2
|
+
import { MastraVector } from '@mastra/core/vector';
|
|
3
|
+
import type { QueryResult } from '@mastra/core/vector';
|
|
3
4
|
import Cloudflare from 'cloudflare';
|
|
4
5
|
|
|
5
6
|
import { VectorizeFilterTranslator } from './filter';
|
|
@@ -27,18 +28,26 @@ export class CloudflareVector extends MastraVector {
|
|
|
27
28
|
|
|
28
29
|
// Create NDJSON string - each line is a JSON object
|
|
29
30
|
const ndjson = vectors
|
|
30
|
-
.map((vector, index) =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
.map((vector, index) =>
|
|
32
|
+
JSON.stringify({
|
|
33
|
+
id: generatedIds[index]!,
|
|
34
|
+
values: vector,
|
|
35
|
+
metadata: metadata?.[index],
|
|
36
|
+
}),
|
|
37
|
+
)
|
|
36
38
|
.join('\n');
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
// Note: __binaryRequest is required for proper NDJSON handling
|
|
41
|
+
await this.client.vectorize.indexes.upsert(
|
|
42
|
+
indexName,
|
|
43
|
+
{
|
|
44
|
+
account_id: this.accountId,
|
|
45
|
+
body: ndjson,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
__binaryRequest: true,
|
|
49
|
+
},
|
|
50
|
+
);
|
|
42
51
|
|
|
43
52
|
return generatedIds;
|
|
44
53
|
}
|