@mastra/vectorize 0.2.2-alpha.8 → 0.2.2-alpha.9
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 -0
- package/dist/_tsup-dts-rollup.d.ts +1 -0
- package/dist/index.cjs +29 -0
- package/dist/index.js +29 -0
- package/package.json +1 -1
|
@@ -18,6 +18,7 @@ declare class CloudflareVector extends MastraVector {
|
|
|
18
18
|
});
|
|
19
19
|
upsert(...args: ParamsToArgs<UpsertVectorParams>): Promise<string[]>;
|
|
20
20
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
21
|
+
private verifyIndexExists;
|
|
21
22
|
createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void>;
|
|
22
23
|
query(...args: ParamsToArgs<QueryVectorParams>): Promise<QueryResult[]>;
|
|
23
24
|
listIndexes(): Promise<string[]>;
|
|
@@ -18,6 +18,7 @@ declare class CloudflareVector extends MastraVector {
|
|
|
18
18
|
});
|
|
19
19
|
upsert(...args: ParamsToArgs<UpsertVectorParams>): Promise<string[]>;
|
|
20
20
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
21
|
+
private verifyIndexExists;
|
|
21
22
|
createIndex(...args: ParamsToArgs<CreateIndexParams>): Promise<void>;
|
|
22
23
|
query(...args: ParamsToArgs<QueryVectorParams>): Promise<QueryResult[]>;
|
|
23
24
|
listIndexes(): Promise<string[]>;
|
package/dist/index.cjs
CHANGED
|
@@ -101,9 +101,38 @@ var CloudflareVector = class extends vector.MastraVector {
|
|
|
101
101
|
const translator = new VectorizeFilterTranslator();
|
|
102
102
|
return translator.translate(filter);
|
|
103
103
|
}
|
|
104
|
+
async verifyIndexExists(indexName, dimension) {
|
|
105
|
+
try {
|
|
106
|
+
const info = await this.client.vectorize.indexes.info(indexName, {
|
|
107
|
+
account_id: this.accountId
|
|
108
|
+
});
|
|
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
|
+
} catch (error) {
|
|
119
|
+
const message = error?.errors?.[0]?.message || error?.message;
|
|
120
|
+
if (error.status === 404 || error.status === 410 || message?.toLowerCase().includes("not found") || message?.toLowerCase().includes("deleted")) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
104
126
|
async createIndex(...args) {
|
|
105
127
|
const params = this.normalizeArgs("createIndex", args);
|
|
106
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
|
+
}
|
|
107
136
|
await this.client.vectorize.indexes.create({
|
|
108
137
|
account_id: this.accountId,
|
|
109
138
|
config: {
|
package/dist/index.js
CHANGED
|
@@ -95,9 +95,38 @@ var CloudflareVector = class extends MastraVector {
|
|
|
95
95
|
const translator = new VectorizeFilterTranslator();
|
|
96
96
|
return translator.translate(filter);
|
|
97
97
|
}
|
|
98
|
+
async verifyIndexExists(indexName, dimension) {
|
|
99
|
+
try {
|
|
100
|
+
const info = await this.client.vectorize.indexes.info(indexName, {
|
|
101
|
+
account_id: this.accountId
|
|
102
|
+
});
|
|
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
|
+
} catch (error) {
|
|
113
|
+
const message = error?.errors?.[0]?.message || error?.message;
|
|
114
|
+
if (error.status === 404 || error.status === 410 || message?.toLowerCase().includes("not found") || message?.toLowerCase().includes("deleted")) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
98
120
|
async createIndex(...args) {
|
|
99
121
|
const params = this.normalizeArgs("createIndex", args);
|
|
100
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
|
+
}
|
|
101
130
|
await this.client.vectorize.indexes.create({
|
|
102
131
|
account_id: this.accountId,
|
|
103
132
|
config: {
|