@mastra/opensearch 0.10.3 → 0.10.4-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 +24 -0
- package/dist/_tsup-dts-rollup.d.cts +18 -5
- package/dist/_tsup-dts-rollup.d.ts +18 -5
- package/dist/index.cjs +128 -53
- package/dist/index.js +120 -45
- package/package.json +4 -4
- package/src/vector/filter.test.ts +55 -54
- package/src/vector/filter.ts +23 -5
- package/src/vector/index.test.ts +4 -5
- package/src/vector/index.ts +134 -55
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/opensearch@0.10.
|
|
2
|
+
> @mastra/opensearch@0.10.4-alpha.1 build /home/runner/work/mastra/mastra/stores/opensearch
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
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.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 11957ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/opensearch/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/opensearch/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 11764ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m23.79 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 807ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m23.58 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 814ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @mastra/opensearch
|
|
2
2
|
|
|
3
|
+
## 0.10.4-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 144eb0b: [MASTRA-3669] Metadata Filter Types
|
|
8
|
+
- Updated dependencies [15e9d26]
|
|
9
|
+
- Updated dependencies [07d6d88]
|
|
10
|
+
- Updated dependencies [5d74aab]
|
|
11
|
+
- Updated dependencies [144eb0b]
|
|
12
|
+
- @mastra/core@0.10.7-alpha.2
|
|
13
|
+
|
|
14
|
+
## 0.10.4-alpha.0
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 0e17048: Throw mastra errors in storage packages
|
|
19
|
+
- Updated dependencies [d1baedb]
|
|
20
|
+
- Updated dependencies [4d21bf2]
|
|
21
|
+
- Updated dependencies [2097952]
|
|
22
|
+
- Updated dependencies [4fb0cc2]
|
|
23
|
+
- Updated dependencies [d2a7a31]
|
|
24
|
+
- Updated dependencies [0e17048]
|
|
25
|
+
- @mastra/core@0.10.7-alpha.1
|
|
26
|
+
|
|
3
27
|
## 0.10.3
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
|
+
import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
|
|
2
3
|
import type { CreateIndexParams } from '@mastra/core';
|
|
3
4
|
import type { DeleteIndexParams } from '@mastra/core';
|
|
4
5
|
import type { DeleteVectorParams } from '@mastra/core';
|
|
5
6
|
import type { DescribeIndexParams } from '@mastra/core';
|
|
6
7
|
import type { IndexStats } from '@mastra/core';
|
|
8
|
+
import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
|
|
7
9
|
import { MastraVector } from '@mastra/core/vector';
|
|
8
10
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
11
|
+
import type { OperatorValueMap } from '@mastra/core/vector/filter';
|
|
9
12
|
import type { QueryResult } from '@mastra/core';
|
|
10
13
|
import type { QueryVectorParams } from '@mastra/core';
|
|
11
14
|
import type { UpdateVectorParams } from '@mastra/core';
|
|
@@ -18,14 +21,16 @@ import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
|
18
21
|
*/
|
|
19
22
|
export declare const OPENSEARCH_PROMPT = "When querying OpenSearch, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Do not explain how to construct the filter\u2014use the specified operators and fields to search the content and return relevant results.\nIf a user tries to use an unsupported operator, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default for field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n\nLogical Operators:\n- $and: Logical AND (implicit when using multiple conditions)\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nRegex Operator:\n- $regex: Match using a regular expression (ECMAScript syntax)\n Example: { \"name\": { \"$regex\": \"^Sam.*son$\" } }\n Note: Regex queries are supported for string fields only. Use valid ECMAScript patterns; invalid patterns will throw an error.\n\nRestrictions:\n- Nested fields are supported using dot notation (e.g., \"address.city\").\n- Multiple conditions on the same field are supported (e.g., { \"price\": { \"$gte\": 100, \"$lte\": 1000 } }).\n- Only logical operators ($and, $or, $not) can be used at the top level.\n- All other operators must be used within a field condition.\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators.\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Array operators work on array fields only.\n- Empty arrays in conditions are handled gracefully.\n- Regex queries are case-sensitive by default; use patterns accordingly.\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]},\n { \"name\": { \"$regex\": \"^Sam.*son$\" } }\n ]\n}";
|
|
20
23
|
|
|
24
|
+
declare type OpenSearchBlacklisted = BlacklistedRootOperators | '$nor';
|
|
25
|
+
|
|
21
26
|
/**
|
|
22
27
|
* Translator for OpenSearch filter queries.
|
|
23
28
|
* Maintains OpenSearch-compatible syntax while ensuring proper validation
|
|
24
29
|
* and normalization of values.
|
|
25
30
|
*/
|
|
26
|
-
export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
|
|
31
|
+
export declare class OpenSearchFilterTranslator extends BaseFilterTranslator<OpenSearchVectorFilter> {
|
|
27
32
|
protected getSupportedOperators(): OperatorSupport;
|
|
28
|
-
translate(filter?:
|
|
33
|
+
translate(filter?: OpenSearchVectorFilter): OpenSearchVectorFilter;
|
|
29
34
|
private translateNode;
|
|
30
35
|
/**
|
|
31
36
|
* Handles translation of nested objects with dot notation fields
|
|
@@ -58,7 +63,11 @@ export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
|
|
|
58
63
|
private createRangeQuery;
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
declare
|
|
66
|
+
declare type OpenSearchLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;
|
|
67
|
+
|
|
68
|
+
declare type OpenSearchOperatorValueMap = Omit<OperatorValueMap, '$options' | '$nor' | '$elemMatch'>;
|
|
69
|
+
|
|
70
|
+
declare class OpenSearchVector extends MastraVector<OpenSearchVectorFilter> {
|
|
62
71
|
private client;
|
|
63
72
|
/**
|
|
64
73
|
* Creates a new OpenSearchVector client.
|
|
@@ -117,7 +126,7 @@ declare class OpenSearchVector extends MastraVector {
|
|
|
117
126
|
* @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
|
|
118
127
|
* @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
|
|
119
128
|
*/
|
|
120
|
-
query({ indexName, queryVector, filter, topK, includeVector, }:
|
|
129
|
+
query({ indexName, queryVector, filter, topK, includeVector, }: OpenSearchVectorParams): Promise<QueryResult[]>;
|
|
121
130
|
/**
|
|
122
131
|
* Validates the dimensions of the vectors.
|
|
123
132
|
*
|
|
@@ -129,7 +138,7 @@ declare class OpenSearchVector extends MastraVector {
|
|
|
129
138
|
/**
|
|
130
139
|
* Transforms the filter to the OpenSearch DSL.
|
|
131
140
|
*
|
|
132
|
-
* @param {
|
|
141
|
+
* @param {OpenSearchVectorFilter} filter - The filter to transform.
|
|
133
142
|
* @returns {Record<string, any>} The transformed filter.
|
|
134
143
|
*/
|
|
135
144
|
private transformFilter;
|
|
@@ -156,4 +165,8 @@ declare class OpenSearchVector extends MastraVector {
|
|
|
156
165
|
export { OpenSearchVector }
|
|
157
166
|
export { OpenSearchVector as OpenSearchVector_alias_1 }
|
|
158
167
|
|
|
168
|
+
export declare type OpenSearchVectorFilter = VectorFilter<keyof OpenSearchOperatorValueMap, OpenSearchOperatorValueMap, OpenSearchLogicalOperatorValueMap, OpenSearchBlacklisted>;
|
|
169
|
+
|
|
170
|
+
declare type OpenSearchVectorParams = QueryVectorParams<OpenSearchVectorFilter>;
|
|
171
|
+
|
|
159
172
|
export { }
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
|
+
import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
|
|
2
3
|
import type { CreateIndexParams } from '@mastra/core';
|
|
3
4
|
import type { DeleteIndexParams } from '@mastra/core';
|
|
4
5
|
import type { DeleteVectorParams } from '@mastra/core';
|
|
5
6
|
import type { DescribeIndexParams } from '@mastra/core';
|
|
6
7
|
import type { IndexStats } from '@mastra/core';
|
|
8
|
+
import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
|
|
7
9
|
import { MastraVector } from '@mastra/core/vector';
|
|
8
10
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
11
|
+
import type { OperatorValueMap } from '@mastra/core/vector/filter';
|
|
9
12
|
import type { QueryResult } from '@mastra/core';
|
|
10
13
|
import type { QueryVectorParams } from '@mastra/core';
|
|
11
14
|
import type { UpdateVectorParams } from '@mastra/core';
|
|
@@ -18,14 +21,16 @@ import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
|
18
21
|
*/
|
|
19
22
|
export declare const OPENSEARCH_PROMPT = "When querying OpenSearch, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Do not explain how to construct the filter\u2014use the specified operators and fields to search the content and return relevant results.\nIf a user tries to use an unsupported operator, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default for field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n\nLogical Operators:\n- $and: Logical AND (implicit when using multiple conditions)\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nRegex Operator:\n- $regex: Match using a regular expression (ECMAScript syntax)\n Example: { \"name\": { \"$regex\": \"^Sam.*son$\" } }\n Note: Regex queries are supported for string fields only. Use valid ECMAScript patterns; invalid patterns will throw an error.\n\nRestrictions:\n- Nested fields are supported using dot notation (e.g., \"address.city\").\n- Multiple conditions on the same field are supported (e.g., { \"price\": { \"$gte\": 100, \"$lte\": 1000 } }).\n- Only logical operators ($and, $or, $not) can be used at the top level.\n- All other operators must be used within a field condition.\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n- Logical operators must contain field conditions, not direct operators.\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Array operators work on array fields only.\n- Empty arrays in conditions are handled gracefully.\n- Regex queries are case-sensitive by default; use patterns accordingly.\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]},\n { \"name\": { \"$regex\": \"^Sam.*son$\" } }\n ]\n}";
|
|
20
23
|
|
|
24
|
+
declare type OpenSearchBlacklisted = BlacklistedRootOperators | '$nor';
|
|
25
|
+
|
|
21
26
|
/**
|
|
22
27
|
* Translator for OpenSearch filter queries.
|
|
23
28
|
* Maintains OpenSearch-compatible syntax while ensuring proper validation
|
|
24
29
|
* and normalization of values.
|
|
25
30
|
*/
|
|
26
|
-
export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
|
|
31
|
+
export declare class OpenSearchFilterTranslator extends BaseFilterTranslator<OpenSearchVectorFilter> {
|
|
27
32
|
protected getSupportedOperators(): OperatorSupport;
|
|
28
|
-
translate(filter?:
|
|
33
|
+
translate(filter?: OpenSearchVectorFilter): OpenSearchVectorFilter;
|
|
29
34
|
private translateNode;
|
|
30
35
|
/**
|
|
31
36
|
* Handles translation of nested objects with dot notation fields
|
|
@@ -58,7 +63,11 @@ export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
|
|
|
58
63
|
private createRangeQuery;
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
declare
|
|
66
|
+
declare type OpenSearchLogicalOperatorValueMap = Omit<LogicalOperatorValueMap, '$nor'>;
|
|
67
|
+
|
|
68
|
+
declare type OpenSearchOperatorValueMap = Omit<OperatorValueMap, '$options' | '$nor' | '$elemMatch'>;
|
|
69
|
+
|
|
70
|
+
declare class OpenSearchVector extends MastraVector<OpenSearchVectorFilter> {
|
|
62
71
|
private client;
|
|
63
72
|
/**
|
|
64
73
|
* Creates a new OpenSearchVector client.
|
|
@@ -117,7 +126,7 @@ declare class OpenSearchVector extends MastraVector {
|
|
|
117
126
|
* @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
|
|
118
127
|
* @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
|
|
119
128
|
*/
|
|
120
|
-
query({ indexName, queryVector, filter, topK, includeVector, }:
|
|
129
|
+
query({ indexName, queryVector, filter, topK, includeVector, }: OpenSearchVectorParams): Promise<QueryResult[]>;
|
|
121
130
|
/**
|
|
122
131
|
* Validates the dimensions of the vectors.
|
|
123
132
|
*
|
|
@@ -129,7 +138,7 @@ declare class OpenSearchVector extends MastraVector {
|
|
|
129
138
|
/**
|
|
130
139
|
* Transforms the filter to the OpenSearch DSL.
|
|
131
140
|
*
|
|
132
|
-
* @param {
|
|
141
|
+
* @param {OpenSearchVectorFilter} filter - The filter to transform.
|
|
133
142
|
* @returns {Record<string, any>} The transformed filter.
|
|
134
143
|
*/
|
|
135
144
|
private transformFilter;
|
|
@@ -156,4 +165,8 @@ declare class OpenSearchVector extends MastraVector {
|
|
|
156
165
|
export { OpenSearchVector }
|
|
157
166
|
export { OpenSearchVector as OpenSearchVector_alias_1 }
|
|
158
167
|
|
|
168
|
+
export declare type OpenSearchVectorFilter = VectorFilter<keyof OpenSearchOperatorValueMap, OpenSearchOperatorValueMap, OpenSearchLogicalOperatorValueMap, OpenSearchBlacklisted>;
|
|
169
|
+
|
|
170
|
+
declare type OpenSearchVectorParams = QueryVectorParams<OpenSearchVectorFilter>;
|
|
171
|
+
|
|
159
172
|
export { }
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var error = require('@mastra/core/error');
|
|
3
4
|
var vector = require('@mastra/core/vector');
|
|
4
5
|
var opensearch = require('@opensearch-project/opensearch');
|
|
5
6
|
var filter = require('@mastra/core/vector/filter');
|
|
@@ -11,7 +12,6 @@ var OpenSearchFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
|
11
12
|
...filter.BaseFilterTranslator.DEFAULT_OPERATORS,
|
|
12
13
|
logical: ["$and", "$or", "$not"],
|
|
13
14
|
array: ["$in", "$nin", "$all"],
|
|
14
|
-
element: ["$exists"],
|
|
15
15
|
regex: ["$regex"],
|
|
16
16
|
custom: []
|
|
17
17
|
};
|
|
@@ -383,7 +383,13 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
383
383
|
*/
|
|
384
384
|
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
385
385
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
386
|
-
throw new
|
|
386
|
+
throw new error.MastraError({
|
|
387
|
+
id: "STORAGE_OPENSEARCH_VECTOR_CREATE_INDEX_INVALID_ARGS",
|
|
388
|
+
domain: error.ErrorDomain.STORAGE,
|
|
389
|
+
category: error.ErrorCategory.USER,
|
|
390
|
+
text: "Dimension must be a positive integer",
|
|
391
|
+
details: { indexName, dimension }
|
|
392
|
+
});
|
|
387
393
|
}
|
|
388
394
|
try {
|
|
389
395
|
await this.client.indices.create({
|
|
@@ -408,14 +414,21 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
408
414
|
}
|
|
409
415
|
}
|
|
410
416
|
});
|
|
411
|
-
} catch (error) {
|
|
412
|
-
const message = error?.message || error?.toString();
|
|
417
|
+
} catch (error$1) {
|
|
418
|
+
const message = error$1?.message || error$1?.toString();
|
|
413
419
|
if (message && message.toLowerCase().includes("already exists")) {
|
|
414
420
|
await this.validateExistingIndex(indexName, dimension, metric);
|
|
415
421
|
return;
|
|
416
422
|
}
|
|
417
|
-
|
|
418
|
-
|
|
423
|
+
throw new error.MastraError(
|
|
424
|
+
{
|
|
425
|
+
id: "STORAGE_OPENSEARCH_VECTOR_CREATE_INDEX_FAILED",
|
|
426
|
+
domain: error.ErrorDomain.STORAGE,
|
|
427
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
428
|
+
details: { indexName, dimension, metric }
|
|
429
|
+
},
|
|
430
|
+
error$1
|
|
431
|
+
);
|
|
419
432
|
}
|
|
420
433
|
}
|
|
421
434
|
/**
|
|
@@ -428,9 +441,15 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
428
441
|
const response = await this.client.cat.indices({ format: "json" });
|
|
429
442
|
const indexes = response.body.map((record) => record.index).filter((index) => index !== void 0);
|
|
430
443
|
return indexes;
|
|
431
|
-
} catch (error) {
|
|
432
|
-
|
|
433
|
-
|
|
444
|
+
} catch (error$1) {
|
|
445
|
+
throw new error.MastraError(
|
|
446
|
+
{
|
|
447
|
+
id: "STORAGE_OPENSEARCH_VECTOR_LIST_INDEXES_FAILED",
|
|
448
|
+
domain: error.ErrorDomain.STORAGE,
|
|
449
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
450
|
+
},
|
|
451
|
+
error$1
|
|
452
|
+
);
|
|
434
453
|
}
|
|
435
454
|
}
|
|
436
455
|
/**
|
|
@@ -460,8 +479,18 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
460
479
|
async deleteIndex({ indexName }) {
|
|
461
480
|
try {
|
|
462
481
|
await this.client.indices.delete({ index: indexName });
|
|
463
|
-
} catch (error) {
|
|
464
|
-
|
|
482
|
+
} catch (error$1) {
|
|
483
|
+
const mastraError = new error.MastraError(
|
|
484
|
+
{
|
|
485
|
+
id: "STORAGE_OPENSEARCH_VECTOR_DELETE_INDEX_FAILED",
|
|
486
|
+
domain: error.ErrorDomain.STORAGE,
|
|
487
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
488
|
+
details: { indexName }
|
|
489
|
+
},
|
|
490
|
+
error$1
|
|
491
|
+
);
|
|
492
|
+
this.logger?.error(mastraError.toString());
|
|
493
|
+
this.logger?.trackException(mastraError);
|
|
465
494
|
}
|
|
466
495
|
}
|
|
467
496
|
/**
|
|
@@ -476,31 +505,38 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
476
505
|
async upsert({ indexName, vectors, metadata = [], ids }) {
|
|
477
506
|
const vectorIds = ids || vectors.map(() => crypto.randomUUID());
|
|
478
507
|
const operations = [];
|
|
479
|
-
const indexInfo = await this.describeIndex({ indexName });
|
|
480
|
-
this.validateVectorDimensions(vectors, indexInfo.dimension);
|
|
481
|
-
for (let i = 0; i < vectors.length; i++) {
|
|
482
|
-
const operation = {
|
|
483
|
-
index: {
|
|
484
|
-
_index: indexName,
|
|
485
|
-
_id: vectorIds[i]
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
const document = {
|
|
489
|
-
id: vectorIds[i],
|
|
490
|
-
embedding: vectors[i],
|
|
491
|
-
metadata: metadata[i] || {}
|
|
492
|
-
};
|
|
493
|
-
operations.push(operation);
|
|
494
|
-
operations.push(document);
|
|
495
|
-
}
|
|
496
508
|
try {
|
|
509
|
+
const indexInfo = await this.describeIndex({ indexName });
|
|
510
|
+
this.validateVectorDimensions(vectors, indexInfo.dimension);
|
|
511
|
+
for (let i = 0; i < vectors.length; i++) {
|
|
512
|
+
const operation = {
|
|
513
|
+
index: {
|
|
514
|
+
_index: indexName,
|
|
515
|
+
_id: vectorIds[i]
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
const document = {
|
|
519
|
+
id: vectorIds[i],
|
|
520
|
+
embedding: vectors[i],
|
|
521
|
+
metadata: metadata[i] || {}
|
|
522
|
+
};
|
|
523
|
+
operations.push(operation);
|
|
524
|
+
operations.push(document);
|
|
525
|
+
}
|
|
497
526
|
if (operations.length > 0) {
|
|
498
527
|
await this.client.bulk({ body: operations, refresh: true });
|
|
499
528
|
}
|
|
500
529
|
return vectorIds;
|
|
501
|
-
} catch (error) {
|
|
502
|
-
|
|
503
|
-
|
|
530
|
+
} catch (error$1) {
|
|
531
|
+
throw new error.MastraError(
|
|
532
|
+
{
|
|
533
|
+
id: "STORAGE_OPENSEARCH_VECTOR_UPSERT_FAILED",
|
|
534
|
+
domain: error.ErrorDomain.STORAGE,
|
|
535
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
536
|
+
details: { indexName, vectorCount: vectors?.length || 0 }
|
|
537
|
+
},
|
|
538
|
+
error$1
|
|
539
|
+
);
|
|
504
540
|
}
|
|
505
541
|
}
|
|
506
542
|
/**
|
|
@@ -544,9 +580,16 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
544
580
|
};
|
|
545
581
|
});
|
|
546
582
|
return results;
|
|
547
|
-
} catch (error) {
|
|
548
|
-
|
|
549
|
-
|
|
583
|
+
} catch (error$1) {
|
|
584
|
+
throw new error.MastraError(
|
|
585
|
+
{
|
|
586
|
+
id: "STORAGE_OPENSEARCH_VECTOR_QUERY_FAILED",
|
|
587
|
+
domain: error.ErrorDomain.STORAGE,
|
|
588
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
589
|
+
details: { indexName, topK }
|
|
590
|
+
},
|
|
591
|
+
error$1
|
|
592
|
+
);
|
|
550
593
|
}
|
|
551
594
|
}
|
|
552
595
|
/**
|
|
@@ -564,7 +607,7 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
564
607
|
/**
|
|
565
608
|
* Transforms the filter to the OpenSearch DSL.
|
|
566
609
|
*
|
|
567
|
-
* @param {
|
|
610
|
+
* @param {OpenSearchVectorFilter} filter - The filter to transform.
|
|
568
611
|
* @returns {Record<string, any>} The transformed filter.
|
|
569
612
|
*/
|
|
570
613
|
transformFilter(filter) {
|
|
@@ -582,44 +625,68 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
582
625
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
583
626
|
*/
|
|
584
627
|
async updateVector({ indexName, id, update }) {
|
|
585
|
-
|
|
586
|
-
throw new Error("No updates provided");
|
|
587
|
-
}
|
|
628
|
+
let existingDoc;
|
|
588
629
|
try {
|
|
589
|
-
|
|
630
|
+
if (!update.vector && !update.metadata) {
|
|
631
|
+
throw new Error("No updates provided");
|
|
632
|
+
}
|
|
633
|
+
const { body } = await this.client.get({
|
|
590
634
|
index: indexName,
|
|
591
635
|
id
|
|
592
636
|
}).catch(() => {
|
|
593
637
|
throw new Error(`Document with ID ${id} not found in index ${indexName}`);
|
|
594
638
|
});
|
|
595
|
-
if (!
|
|
639
|
+
if (!body || !body._source) {
|
|
596
640
|
throw new Error(`Document with ID ${id} has no source data in index ${indexName}`);
|
|
597
641
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
642
|
+
existingDoc = body;
|
|
643
|
+
} catch (error$1) {
|
|
644
|
+
throw new error.MastraError(
|
|
645
|
+
{
|
|
646
|
+
id: "STORAGE_OPENSEARCH_VECTOR_UPDATE_VECTOR_FAILED",
|
|
647
|
+
domain: error.ErrorDomain.STORAGE,
|
|
648
|
+
category: error.ErrorCategory.USER,
|
|
649
|
+
details: { indexName, id }
|
|
650
|
+
},
|
|
651
|
+
error$1
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
const source = existingDoc._source;
|
|
655
|
+
const updatedDoc = {
|
|
656
|
+
id: source?.id || id
|
|
657
|
+
};
|
|
658
|
+
try {
|
|
602
659
|
if (update.vector) {
|
|
660
|
+
console.log(`1`);
|
|
603
661
|
const indexInfo = await this.describeIndex({ indexName });
|
|
662
|
+
console.log(`2`);
|
|
604
663
|
this.validateVectorDimensions([update.vector], indexInfo.dimension);
|
|
605
664
|
updatedDoc.embedding = update.vector;
|
|
606
|
-
} else if (source
|
|
665
|
+
} else if (source?.embedding) {
|
|
607
666
|
updatedDoc.embedding = source.embedding;
|
|
608
667
|
}
|
|
609
668
|
if (update.metadata) {
|
|
610
669
|
updatedDoc.metadata = update.metadata;
|
|
611
670
|
} else {
|
|
612
|
-
updatedDoc.metadata = source
|
|
671
|
+
updatedDoc.metadata = source?.metadata || {};
|
|
613
672
|
}
|
|
673
|
+
console.log(`3`);
|
|
614
674
|
await this.client.index({
|
|
615
675
|
index: indexName,
|
|
616
676
|
id,
|
|
617
677
|
body: updatedDoc,
|
|
618
678
|
refresh: true
|
|
619
679
|
});
|
|
620
|
-
} catch (error) {
|
|
621
|
-
|
|
622
|
-
|
|
680
|
+
} catch (error$1) {
|
|
681
|
+
throw new error.MastraError(
|
|
682
|
+
{
|
|
683
|
+
id: "STORAGE_OPENSEARCH_VECTOR_UPDATE_VECTOR_FAILED",
|
|
684
|
+
domain: error.ErrorDomain.STORAGE,
|
|
685
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
686
|
+
details: { indexName, id }
|
|
687
|
+
},
|
|
688
|
+
error$1
|
|
689
|
+
);
|
|
623
690
|
}
|
|
624
691
|
}
|
|
625
692
|
/**
|
|
@@ -636,11 +703,19 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
636
703
|
id,
|
|
637
704
|
refresh: true
|
|
638
705
|
});
|
|
639
|
-
} catch (error) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
throw error;
|
|
706
|
+
} catch (error$1) {
|
|
707
|
+
if (error$1 && typeof error$1 === "object" && "statusCode" in error$1 && error$1.statusCode === 404) {
|
|
708
|
+
return;
|
|
643
709
|
}
|
|
710
|
+
throw new error.MastraError(
|
|
711
|
+
{
|
|
712
|
+
id: "STORAGE_OPENSEARCH_VECTOR_DELETE_VECTOR_FAILED",
|
|
713
|
+
domain: error.ErrorDomain.STORAGE,
|
|
714
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
715
|
+
details: { indexName, id }
|
|
716
|
+
},
|
|
717
|
+
error$1
|
|
718
|
+
);
|
|
644
719
|
}
|
|
645
720
|
}
|
|
646
721
|
};
|