@mastra/vectorize 0.1.0-alpha.35 → 0.1.0-alpha.37

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @mastra/vectorize
2
2
 
3
+ ## 0.1.0-alpha.37
4
+
5
+ ### Patch Changes
6
+
7
+ - 4f1d1a1: Enforce types ann cleanup package.json
8
+ - Updated dependencies [66a03ec]
9
+ - Updated dependencies [4f1d1a1]
10
+ - @mastra/core@0.2.0-alpha.101
11
+
12
+ ## 0.1.0-alpha.36
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [9d1796d]
17
+ - @mastra/core@0.2.0-alpha.100
18
+
3
19
  ## 0.1.0-alpha.35
4
20
 
5
21
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/vectorize",
3
- "version": "0.1.0-alpha.35",
3
+ "version": "0.1.0-alpha.37",
4
4
  "description": "Cloudflare Vectorize store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,16 +16,16 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "cloudflare": "^4.0.0",
19
- "@mastra/core": "^0.2.0-alpha.99"
19
+ "@mastra/core": "^0.2.0-alpha.101"
20
20
  },
21
21
  "devDependencies": {
22
- "@tsconfig/recommended": "^1.0.7",
23
- "@types/node": "^22.9.0",
22
+ "@microsoft/api-extractor": "^7.49.2",
23
+ "@types/node": "^22.13.1",
24
24
  "tsup": "^8.0.1",
25
25
  "vitest": "^3.0.5"
26
26
  },
27
27
  "scripts": {
28
- "build": "tsup src/index.ts --format esm --dts --clean --treeshake",
28
+ "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
29
29
  "build:watch": "pnpm build --watch",
30
30
  "test": "vitest run"
31
31
  }
@@ -1,4 +1,4 @@
1
- import { BaseFilterTranslator, Filter, FieldCondition, OperatorSupport } from '@mastra/core/filter';
1
+ import { BaseFilterTranslator, type Filter, type FieldCondition, type OperatorSupport } from '@mastra/core/filter';
2
2
 
3
3
  export class VectorizeFilterTranslator extends BaseFilterTranslator {
4
4
  protected override getSupportedOperators(): OperatorSupport {
@@ -1,5 +1,5 @@
1
- import { Filter } from '@mastra/core/filter';
2
- import { MastraVector, QueryResult } from '@mastra/core/vector';
1
+ import { type Filter } from '@mastra/core/filter';
2
+ import { MastraVector, type QueryResult } from '@mastra/core/vector';
3
3
  import Cloudflare from 'cloudflare';
4
4
 
5
5
  import { VectorizeFilterTranslator } from './filter';
package/tsconfig.json CHANGED
@@ -1,10 +1,5 @@
1
1
  {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "moduleResolution": "bundler",
5
- "outDir": "./dist",
6
- "rootDir": "./src"
7
- },
2
+ "extends": "../../tsconfig.node.json",
8
3
  "include": ["src/**/*"],
9
4
  "exclude": ["node_modules", "**/*.test.ts"]
10
5
  }
package/dist/index.d.ts DELETED
@@ -1,28 +0,0 @@
1
- import { Filter } from '@mastra/core/filter';
2
- import { MastraVector, QueryResult } from '@mastra/core/vector';
3
- import Cloudflare from 'cloudflare';
4
-
5
- declare class CloudflareVector extends MastraVector {
6
- client: Cloudflare;
7
- accountId: string;
8
- constructor({ accountId, apiToken }: {
9
- accountId: string;
10
- apiToken: string;
11
- });
12
- upsert(indexName: string, vectors: number[][], metadata?: Record<string, any>[], ids?: string[]): Promise<string[]>;
13
- transformFilter(filter?: Filter): Filter | undefined;
14
- createIndex(indexName: string, dimension: number, metric?: 'cosine' | 'euclidean' | 'dotproduct'): Promise<void>;
15
- query(indexName: string, queryVector: number[], topK?: number, filter?: Filter, includeVector?: boolean): Promise<QueryResult[]>;
16
- listIndexes(): Promise<string[]>;
17
- describeIndex(indexName: string): Promise<{
18
- dimension: number;
19
- count: number;
20
- metric: "cosine" | "euclidean" | "dotproduct";
21
- }>;
22
- deleteIndex(indexName: string): Promise<void>;
23
- createMetadataIndex(indexName: string, propertyName: string, indexType: 'string' | 'number' | 'boolean'): Promise<void>;
24
- deleteMetadataIndex(indexName: string, propertyName: string): Promise<void>;
25
- listMetadataIndexes(indexName: string): Promise<Cloudflare.Vectorize.Indexes.MetadataIndex.MetadataIndexListResponse.MetadataIndex[]>;
26
- }
27
-
28
- export { CloudflareVector };
package/dist/index.js DELETED
@@ -1,163 +0,0 @@
1
- import { MastraVector } from '@mastra/core/vector';
2
- import Cloudflare from 'cloudflare';
3
- import { BaseFilterTranslator } from '@mastra/core/filter';
4
-
5
- // src/vector/index.ts
6
- var VectorizeFilterTranslator = class extends BaseFilterTranslator {
7
- getSupportedOperators() {
8
- return {
9
- ...BaseFilterTranslator.DEFAULT_OPERATORS,
10
- logical: [],
11
- array: ["$in", "$nin"],
12
- element: [],
13
- regex: [],
14
- custom: []
15
- };
16
- }
17
- translate(filter) {
18
- if (this.isEmpty(filter)) return filter;
19
- this.validateFilter(filter);
20
- return this.translateNode(filter);
21
- }
22
- translateNode(node, currentPath = "") {
23
- if (this.isRegex(node)) {
24
- throw new Error("Regex is not supported in Vectorize");
25
- }
26
- if (this.isPrimitive(node)) return { $eq: this.normalizeComparisonValue(node) };
27
- if (Array.isArray(node)) return { $in: this.normalizeArrayValues(node) };
28
- const entries = Object.entries(node);
29
- const firstEntry = entries[0];
30
- if (entries.length === 1 && firstEntry && this.isOperator(firstEntry[0])) {
31
- const [operator, value] = firstEntry;
32
- return { [operator]: this.normalizeComparisonValue(value) };
33
- }
34
- const result = {};
35
- for (const [key, value] of entries) {
36
- const newPath = currentPath ? `${currentPath}.${key}` : key;
37
- if (this.isOperator(key)) {
38
- result[key] = this.normalizeComparisonValue(value);
39
- continue;
40
- }
41
- if (typeof value === "object" && value !== null && !Array.isArray(value)) {
42
- if (Object.keys(value).length === 0) {
43
- result[newPath] = this.translateNode(value);
44
- continue;
45
- }
46
- const hasOperators = Object.keys(value).some((k) => this.isOperator(k));
47
- if (hasOperators) {
48
- result[newPath] = this.translateNode(value);
49
- } else {
50
- Object.assign(result, this.translateNode(value, newPath));
51
- }
52
- } else {
53
- result[newPath] = this.translateNode(value);
54
- }
55
- }
56
- return result;
57
- }
58
- };
59
-
60
- // src/vector/index.ts
61
- var CloudflareVector = class extends MastraVector {
62
- constructor({ accountId, apiToken }) {
63
- super();
64
- this.accountId = accountId;
65
- this.client = new Cloudflare({
66
- apiKey: apiToken
67
- });
68
- }
69
- async upsert(indexName, vectors, metadata, ids) {
70
- const generatedIds = ids || vectors.map(() => crypto.randomUUID());
71
- const ndjson = vectors.map((vector, index) => ({
72
- id: generatedIds[index],
73
- values: vector,
74
- metadata: metadata?.[index]
75
- })).map((record) => JSON.stringify(record)).join("\n");
76
- await this.client.vectorize.indexes.upsert(indexName, {
77
- account_id: this.accountId,
78
- body: ndjson
79
- });
80
- return generatedIds;
81
- }
82
- transformFilter(filter) {
83
- const translator = new VectorizeFilterTranslator();
84
- const translatedFilter = translator.translate(filter);
85
- return translatedFilter;
86
- }
87
- async createIndex(indexName, dimension, metric = "cosine") {
88
- await this.client.vectorize.indexes.create({
89
- account_id: this.accountId,
90
- config: {
91
- dimensions: dimension,
92
- metric: metric === "dotproduct" ? "dot-product" : metric
93
- },
94
- name: indexName
95
- });
96
- }
97
- async query(indexName, queryVector, topK = 10, filter, includeVector = false) {
98
- const translatedFilter = this.transformFilter(filter);
99
- const response = await this.client.vectorize.indexes.query(indexName, {
100
- account_id: this.accountId,
101
- vector: queryVector,
102
- returnValues: includeVector,
103
- returnMetadata: "all",
104
- topK,
105
- filter: translatedFilter
106
- });
107
- return response?.matches?.map((match) => {
108
- return {
109
- id: match.id,
110
- metadata: match.metadata,
111
- score: match.score,
112
- vector: match.values
113
- };
114
- }) || [];
115
- }
116
- async listIndexes() {
117
- const res = await this.client.vectorize.indexes.list({
118
- account_id: this.accountId
119
- });
120
- return res?.result?.map((index) => index.name) || [];
121
- }
122
- async describeIndex(indexName) {
123
- const index = await this.client.vectorize.indexes.get(indexName, {
124
- account_id: this.accountId
125
- });
126
- const described = await this.client.vectorize.indexes.info(indexName, {
127
- account_id: this.accountId
128
- });
129
- return {
130
- dimension: described?.dimensions,
131
- // Since vector_count is not available in the response,
132
- // we might need a separate API call to get the count if needed
133
- count: described?.vectorCount || 0,
134
- metric: index?.config?.metric
135
- };
136
- }
137
- async deleteIndex(indexName) {
138
- await this.client.vectorize.indexes.delete(indexName, {
139
- account_id: this.accountId
140
- });
141
- }
142
- async createMetadataIndex(indexName, propertyName, indexType) {
143
- await this.client.vectorize.indexes.metadataIndex.create(indexName, {
144
- account_id: this.accountId,
145
- propertyName,
146
- indexType
147
- });
148
- }
149
- async deleteMetadataIndex(indexName, propertyName) {
150
- await this.client.vectorize.indexes.metadataIndex.delete(indexName, {
151
- account_id: this.accountId,
152
- propertyName
153
- });
154
- }
155
- async listMetadataIndexes(indexName) {
156
- const res = await this.client.vectorize.indexes.metadataIndex.list(indexName, {
157
- account_id: this.accountId
158
- });
159
- return res?.metadataIndexes ?? [];
160
- }
161
- };
162
-
163
- export { CloudflareVector };