@mastra/vectorize 0.2.9-alpha.0 → 0.2.9-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/dist/_tsup-dts-rollup.d.cts +1 -1
- package/dist/_tsup-dts-rollup.d.ts +1 -1
- package/dist/index.cjs +16 -33
- package/dist/index.js +16 -33
- package/package.json +2 -2
|
@@ -16,9 +16,9 @@ declare class CloudflareVector extends MastraVector {
|
|
|
16
16
|
accountId: string;
|
|
17
17
|
apiToken: string;
|
|
18
18
|
});
|
|
19
|
+
get indexSeparator(): string;
|
|
19
20
|
upsert(...args: ParamsToArgs<UpsertVectorParams>): Promise<string[]>;
|
|
20
21
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
21
|
-
private verifyIndexExists;
|
|
22
22
|
createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void>;
|
|
23
23
|
query(...args: ParamsToArgs<QueryVectorParams>): Promise<QueryResult[]>;
|
|
24
24
|
listIndexes(): Promise<string[]>;
|
|
@@ -16,9 +16,9 @@ declare class CloudflareVector extends MastraVector {
|
|
|
16
16
|
accountId: string;
|
|
17
17
|
apiToken: string;
|
|
18
18
|
});
|
|
19
|
+
get indexSeparator(): string;
|
|
19
20
|
upsert(...args: ParamsToArgs<UpsertVectorParams>): Promise<string[]>;
|
|
20
21
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
21
|
-
private verifyIndexExists;
|
|
22
22
|
createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void>;
|
|
23
23
|
query(...args: ParamsToArgs<QueryVectorParams>): Promise<QueryResult[]>;
|
|
24
24
|
listIndexes(): Promise<string[]>;
|
package/dist/index.cjs
CHANGED
|
@@ -74,6 +74,9 @@ var CloudflareVector = class extends vector.MastraVector {
|
|
|
74
74
|
apiToken
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
+
get indexSeparator() {
|
|
78
|
+
return "-";
|
|
79
|
+
}
|
|
77
80
|
async upsert(...args) {
|
|
78
81
|
const params = this.normalizeArgs("upsert", args);
|
|
79
82
|
const { indexName, vectors, metadata, ids } = params;
|
|
@@ -101,47 +104,27 @@ var CloudflareVector = class extends vector.MastraVector {
|
|
|
101
104
|
const translator = new VectorizeFilterTranslator();
|
|
102
105
|
return translator.translate(filter);
|
|
103
106
|
}
|
|
104
|
-
async
|
|
107
|
+
async createIndex(...args) {
|
|
108
|
+
const params = this.normalizeArgs("createIndex", args);
|
|
109
|
+
const { indexName, dimension, metric = "cosine" } = params;
|
|
105
110
|
try {
|
|
106
|
-
|
|
107
|
-
account_id: this.accountId
|
|
111
|
+
await this.client.vectorize.indexes.create({
|
|
112
|
+
account_id: this.accountId,
|
|
113
|
+
config: {
|
|
114
|
+
dimensions: dimension,
|
|
115
|
+
metric: metric === "dotproduct" ? "dot-product" : metric
|
|
116
|
+
},
|
|
117
|
+
name: indexName
|
|
108
118
|
});
|
|
109
|
-
if (!info) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
if (info.dimensions !== dimension) {
|
|
113
|
-
throw new Error(
|
|
114
|
-
`Index "${indexName}" already exists with ${info.dimensions} dimensions, but ${dimension} dimensions were requested`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
return true;
|
|
118
119
|
} catch (error) {
|
|
119
120
|
const message = error?.errors?.[0]?.message || error?.message;
|
|
120
|
-
if (error.status ===
|
|
121
|
-
|
|
121
|
+
if (error.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
|
|
122
|
+
await this.validateExistingIndex(indexName, dimension, metric);
|
|
123
|
+
return;
|
|
122
124
|
}
|
|
123
125
|
throw error;
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
|
-
async createIndex(...args) {
|
|
127
|
-
const params = this.normalizeArgs("createIndex", args);
|
|
128
|
-
const { indexName, dimension, metric = "cosine" } = params;
|
|
129
|
-
const exists = await this.verifyIndexExists(indexName, dimension);
|
|
130
|
-
if (exists) {
|
|
131
|
-
this.logger.info(
|
|
132
|
-
`Index "${indexName}" already exists with ${dimension} dimensions and metric ${metric}, skipping creation.`
|
|
133
|
-
);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
await this.client.vectorize.indexes.create({
|
|
137
|
-
account_id: this.accountId,
|
|
138
|
-
config: {
|
|
139
|
-
dimensions: dimension,
|
|
140
|
-
metric: metric === "dotproduct" ? "dot-product" : metric
|
|
141
|
-
},
|
|
142
|
-
name: indexName
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
128
|
async query(...args) {
|
|
146
129
|
const params = this.normalizeArgs("query", args);
|
|
147
130
|
const { indexName, queryVector, topK = 10, filter, includeVector = false } = params;
|
package/dist/index.js
CHANGED
|
@@ -68,6 +68,9 @@ var CloudflareVector = class extends MastraVector {
|
|
|
68
68
|
apiToken
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
+
get indexSeparator() {
|
|
72
|
+
return "-";
|
|
73
|
+
}
|
|
71
74
|
async upsert(...args) {
|
|
72
75
|
const params = this.normalizeArgs("upsert", args);
|
|
73
76
|
const { indexName, vectors, metadata, ids } = params;
|
|
@@ -95,47 +98,27 @@ var CloudflareVector = class extends MastraVector {
|
|
|
95
98
|
const translator = new VectorizeFilterTranslator();
|
|
96
99
|
return translator.translate(filter);
|
|
97
100
|
}
|
|
98
|
-
async
|
|
101
|
+
async createIndex(...args) {
|
|
102
|
+
const params = this.normalizeArgs("createIndex", args);
|
|
103
|
+
const { indexName, dimension, metric = "cosine" } = params;
|
|
99
104
|
try {
|
|
100
|
-
|
|
101
|
-
account_id: this.accountId
|
|
105
|
+
await this.client.vectorize.indexes.create({
|
|
106
|
+
account_id: this.accountId,
|
|
107
|
+
config: {
|
|
108
|
+
dimensions: dimension,
|
|
109
|
+
metric: metric === "dotproduct" ? "dot-product" : metric
|
|
110
|
+
},
|
|
111
|
+
name: indexName
|
|
102
112
|
});
|
|
103
|
-
if (!info) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
if (info.dimensions !== dimension) {
|
|
107
|
-
throw new Error(
|
|
108
|
-
`Index "${indexName}" already exists with ${info.dimensions} dimensions, but ${dimension} dimensions were requested`
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
return true;
|
|
112
113
|
} catch (error) {
|
|
113
114
|
const message = error?.errors?.[0]?.message || error?.message;
|
|
114
|
-
if (error.status ===
|
|
115
|
-
|
|
115
|
+
if (error.status === 409 || typeof message === "string" && (message.toLowerCase().includes("already exists") || message.toLowerCase().includes("duplicate"))) {
|
|
116
|
+
await this.validateExistingIndex(indexName, dimension, metric);
|
|
117
|
+
return;
|
|
116
118
|
}
|
|
117
119
|
throw error;
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
|
-
async createIndex(...args) {
|
|
121
|
-
const params = this.normalizeArgs("createIndex", args);
|
|
122
|
-
const { indexName, dimension, metric = "cosine" } = params;
|
|
123
|
-
const exists = await this.verifyIndexExists(indexName, dimension);
|
|
124
|
-
if (exists) {
|
|
125
|
-
this.logger.info(
|
|
126
|
-
`Index "${indexName}" already exists with ${dimension} dimensions and metric ${metric}, skipping creation.`
|
|
127
|
-
);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
await this.client.vectorize.indexes.create({
|
|
131
|
-
account_id: this.accountId,
|
|
132
|
-
config: {
|
|
133
|
-
dimensions: dimension,
|
|
134
|
-
metric: metric === "dotproduct" ? "dot-product" : metric
|
|
135
|
-
},
|
|
136
|
-
name: indexName
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
122
|
async query(...args) {
|
|
140
123
|
const params = this.normalizeArgs("query", args);
|
|
141
124
|
const { indexName, queryVector, topK = 10, filter, includeVector = false } = params;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/vectorize",
|
|
3
|
-
"version": "0.2.9-alpha.
|
|
3
|
+
"version": "0.2.9-alpha.1",
|
|
4
4
|
"description": "Cloudflare Vectorize store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"cloudflare": "^4.1.0",
|
|
27
|
-
"@mastra/core": "^0.9.3-alpha.
|
|
27
|
+
"@mastra/core": "^0.9.3-alpha.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@microsoft/api-extractor": "^7.52.5",
|