@mastra/opensearch 0.0.0-vector-sources-20250516175436 → 0.0.0-vector-extension-schema-20250922130418

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.
@@ -0,0 +1,101 @@
1
+ import type { CreateIndexParams, DeleteIndexParams, DeleteVectorParams, DescribeIndexParams, IndexStats, QueryResult, QueryVectorParams, UpdateVectorParams, UpsertVectorParams } from '@mastra/core/vector';
2
+ import { MastraVector } from '@mastra/core/vector';
3
+ import type { OpenSearchVectorFilter } from './filter.js';
4
+ type OpenSearchVectorParams = QueryVectorParams<OpenSearchVectorFilter>;
5
+ export declare class OpenSearchVector extends MastraVector<OpenSearchVectorFilter> {
6
+ private client;
7
+ /**
8
+ * Creates a new OpenSearchVector client.
9
+ *
10
+ * @param {string} url - The url of the OpenSearch node.
11
+ */
12
+ constructor({ url }: {
13
+ url: string;
14
+ });
15
+ /**
16
+ * Creates a new collection with the specified configuration.
17
+ *
18
+ * @param {string} indexName - The name of the collection to create.
19
+ * @param {number} dimension - The dimension of the vectors to be stored in the collection.
20
+ * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
21
+ * @returns {Promise<void>} A promise that resolves when the collection is created.
22
+ */
23
+ createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
24
+ /**
25
+ * Lists all indexes.
26
+ *
27
+ * @returns {Promise<string[]>} A promise that resolves to an array of indexes.
28
+ */
29
+ listIndexes(): Promise<string[]>;
30
+ /**
31
+ * Retrieves statistics about a vector index.
32
+ *
33
+ * @param {string} indexName - The name of the index to describe
34
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
35
+ */
36
+ describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
37
+ /**
38
+ * Deletes the specified index.
39
+ *
40
+ * @param {string} indexName - The name of the index to delete.
41
+ * @returns {Promise<void>} A promise that resolves when the index is deleted.
42
+ */
43
+ deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
44
+ /**
45
+ * Inserts or updates vectors in the specified collection.
46
+ *
47
+ * @param {string} indexName - The name of the collection to upsert into.
48
+ * @param {number[][]} vectors - An array of vectors to upsert.
49
+ * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
50
+ * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
51
+ * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
52
+ */
53
+ upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
54
+ /**
55
+ * Queries the specified collection using a vector and optional filter.
56
+ *
57
+ * @param {string} indexName - The name of the collection to query.
58
+ * @param {number[]} queryVector - The vector to query with.
59
+ * @param {number} [topK] - The maximum number of results to return.
60
+ * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in OpenSearch, see the filtering reference: https://opensearch.org/docs/latest/query-dsl/
61
+ * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
62
+ * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
63
+ */
64
+ query({ indexName, queryVector, filter, topK, includeVector, }: OpenSearchVectorParams): Promise<QueryResult[]>;
65
+ /**
66
+ * Validates the dimensions of the vectors.
67
+ *
68
+ * @param {number[][]} vectors - The vectors to validate.
69
+ * @param {number} dimension - The dimension of the vectors.
70
+ * @returns {void}
71
+ */
72
+ private validateVectorDimensions;
73
+ /**
74
+ * Transforms the filter to the OpenSearch DSL.
75
+ *
76
+ * @param {OpenSearchVectorFilter} filter - The filter to transform.
77
+ * @returns {Record<string, any>} The transformed filter.
78
+ */
79
+ private transformFilter;
80
+ /**
81
+ * Updates a vector by its ID with the provided vector and/or metadata.
82
+ * @param indexName - The name of the index containing the vector.
83
+ * @param id - The ID of the vector to update.
84
+ * @param update - An object containing the vector and/or metadata to update.
85
+ * @param update.vector - An optional array of numbers representing the new vector.
86
+ * @param update.metadata - An optional record containing the new metadata.
87
+ * @returns A promise that resolves when the update is complete.
88
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
89
+ */
90
+ updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
91
+ /**
92
+ * Deletes a vector by its ID.
93
+ * @param indexName - The name of the index containing the vector.
94
+ * @param id - The ID of the vector to delete.
95
+ * @returns A promise that resolves when the deletion is complete.
96
+ * @throws Will throw an error if the deletion operation fails.
97
+ */
98
+ deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
99
+ }
100
+ export {};
101
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAcvD,KAAK,sBAAsB,GAAG,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;AAExE,qBAAa,gBAAiB,SAAQ,YAAY,CAAC,sBAAsB,CAAC;IACxE,OAAO,CAAC,MAAM,CAAmB;IAEjC;;;;OAIG;gBACS,EAAE,GAAG,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE;IAKpC;;;;;;;OAOG;IACG,WAAW,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,MAAiB,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAqDhG;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAoBtC;;;;;OAKG;IACG,aAAa,CAAC,EAAE,SAAS,EAAE,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IAe5E;;;;;OAKG;IACG,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBlE;;;;;;;;OAQG;IACG,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,QAAa,EAAE,GAAG,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA+C/F;;;;;;;;;OASG;IACG,KAAK,CAAC,EACV,SAAS,EACT,WAAW,EACX,MAAM,EACN,IAAS,EACT,aAAqB,GACtB,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAyClD;;;;;;OAMG;IACH,OAAO,CAAC,wBAAwB;IAMhC;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAKvB;;;;;;;;;OASG;IACG,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgFhF;;;;;;OAMG;IACG,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAuBzE"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Vector store prompt for OpenSearch. This prompt details supported filter operators, syntax, and usage examples.
3
+ * Use this as a guide for constructing valid filters for OpenSearch vector queries in Mastra.
4
+ */
5
+ 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}";
6
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/vector/prompt.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,m0GA6E5B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/opensearch",
3
- "version": "0.0.0-vector-sources-20250516175436",
3
+ "version": "0.0.0-vector-extension-schema-20250922130418",
4
4
  "description": "OpenSearch vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,28 +12,45 @@
12
12
  "default": "./dist/index.js"
13
13
  },
14
14
  "require": {
15
- "types": "./dist/index.d.cts",
15
+ "types": "./dist/index.d.ts",
16
16
  "default": "./dist/index.cjs"
17
17
  }
18
18
  },
19
19
  "./package.json": "./package.json"
20
20
  },
21
21
  "dependencies": {
22
- "@opensearch-project/opensearch": "^3.4.0",
23
- "@mastra/core": "0.0.0-vector-sources-20250516175436"
22
+ "@opensearch-project/opensearch": "^3.5.1"
24
23
  },
25
24
  "devDependencies": {
26
- "@microsoft/api-extractor": "^7.52.1",
27
- "@types/node": "^22.13.10",
28
- "eslint": "^9.22.0",
29
- "tsup": "^8.4.0",
30
- "typescript": "^5.8.2",
31
- "vitest": "^3.0.8",
32
- "@internal/lint": "0.0.0-vector-sources-20250516175436"
25
+ "@microsoft/api-extractor": "^7.52.8",
26
+ "@types/node": "^20.19.0",
27
+ "eslint": "^9.35.0",
28
+ "tsup": "^8.5.0",
29
+ "typescript": "^5.8.3",
30
+ "vitest": "^3.2.4",
31
+ "@internal/lint": "0.0.0-vector-extension-schema-20250922130418",
32
+ "@internal/types-builder": "0.0.0-vector-extension-schema-20250922130418",
33
+ "@mastra/core": "0.0.0-vector-extension-schema-20250922130418"
34
+ },
35
+ "peerDependencies": {
36
+ "@mastra/core": "0.0.0-vector-extension-schema-20250922130418"
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "CHANGELOG.md"
41
+ ],
42
+ "homepage": "https://mastra.ai",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/mastra-ai/mastra.git",
46
+ "directory": "stores/opensearch"
47
+ },
48
+ "bugs": {
49
+ "url": "https://github.com/mastra-ai/mastra/issues"
33
50
  },
34
51
  "scripts": {
35
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
36
- "build:watch": "pnpm build --watch",
52
+ "build": "tsup --silent --config tsup.config.ts",
53
+ "build:watch": "tsup --watch --silent --config tsup.config.ts",
37
54
  "pretest": "docker compose up -d && (for i in $(seq 1 30); do curl -s http://localhost:9200/_cluster/health | grep -q '\"status\"' && break || (sleep 1; [ $i -eq 30 ] && exit 1); done)",
38
55
  "test": "vitest run",
39
56
  "posttest": "docker compose down -v",
@@ -1,186 +0,0 @@
1
- import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
- import type { CreateIndexParams } from '@mastra/core';
3
- import type { DeleteIndexParams } from '@mastra/core';
4
- import type { DeleteVectorParams } from '@mastra/core';
5
- import type { DescribeIndexParams } from '@mastra/core';
6
- import type { IndexStats } from '@mastra/core';
7
- import { MastraVector } from '@mastra/core/vector';
8
- import type { OperatorSupport } from '@mastra/core/vector/filter';
9
- import type { ParamsToArgs } from '@mastra/core';
10
- import type { QueryResult } from '@mastra/core';
11
- import type { QueryVectorParams } from '@mastra/core';
12
- import type { UpdateVectorParams } from '@mastra/core';
13
- import type { UpsertVectorParams } from '@mastra/core';
14
- import type { VectorFilter } from '@mastra/core/vector/filter';
15
-
16
- /**
17
- * Translator for OpenSearch filter queries.
18
- * Maintains OpenSearch-compatible syntax while ensuring proper validation
19
- * and normalization of values.
20
- */
21
- export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
22
- protected getSupportedOperators(): OperatorSupport;
23
- translate(filter?: VectorFilter): VectorFilter;
24
- private translateNode;
25
- /**
26
- * Handles translation of nested objects with dot notation fields
27
- */
28
- private translateNestedObject;
29
- private translateLogicalOperator;
30
- private translateFieldOperator;
31
- /**
32
- * Translates regex patterns to OpenSearch query syntax
33
- */
34
- private translateRegexOperator;
35
- private addKeywordIfNeeded;
36
- /**
37
- * Helper method to handle special cases for the $not operator
38
- */
39
- private handleNotOperatorSpecialCases;
40
- private translateOperator;
41
- /**
42
- * Translates field conditions to OpenSearch query syntax
43
- * Handles special cases like range queries and multiple operators
44
- */
45
- private translateFieldConditions;
46
- /**
47
- * Checks if conditions can be optimized to a range query
48
- */
49
- private canOptimizeToRangeQuery;
50
- /**
51
- * Creates a range query from numeric operators
52
- */
53
- private createRangeQuery;
54
- }
55
-
56
- declare class OpenSearchVector extends MastraVector {
57
- private client;
58
- /**
59
- * @deprecated Passing a string URL is deprecated. Use an object parameter: { url }.
60
- * @param url - The OpenSearch node URL (deprecated)
61
- */
62
- constructor(url: string);
63
- /**
64
- * Creates a new OpenSearchVector client.
65
- *
66
- * @param params - An object with a url property specifying the OpenSearch node.
67
- */
68
- constructor(params: {
69
- url: string;
70
- });
71
- /**
72
- * Creates a new collection with the specified configuration.
73
- *
74
- * @param {string} indexName - The name of the collection to create.
75
- * @param {number} dimension - The dimension of the vectors to be stored in the collection.
76
- * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
77
- * @returns {Promise<void>} A promise that resolves when the collection is created.
78
- */
79
- createIndex(params: CreateIndexParams): Promise<void>;
80
- /**
81
- * Lists all indexes.
82
- *
83
- * @returns {Promise<string[]>} A promise that resolves to an array of indexes.
84
- */
85
- listIndexes(): Promise<string[]>;
86
- /**
87
- * Retrieves statistics about a vector index.
88
- *
89
- * @param params - The parameters for describing an index
90
- * @param params.indexName - The name of the index to describe
91
- * @returns A promise that resolves to the index statistics including dimension, count and metric
92
- */
93
- describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
94
- /**
95
- * Deletes the specified index.
96
- *
97
- * @param {string} indexName - The name of the index to delete.
98
- * @returns {Promise<void>} A promise that resolves when the index is deleted.
99
- */
100
- deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
101
- /**
102
- * Inserts or updates vectors in the specified collection.
103
- *
104
- * @param {string} indexName - The name of the collection to upsert into.
105
- * @param {number[][]} vectors - An array of vectors to upsert.
106
- * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
107
- * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
108
- * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
109
- */
110
- upsert(params: UpsertVectorParams): Promise<string[]>;
111
- /**
112
- * Queries the specified collection using a vector and optional filter.
113
- *
114
- * @param {string} indexName - The name of the collection to query.
115
- * @param {number[]} queryVector - The vector to query with.
116
- * @param {number} [topK] - The maximum number of results to return.
117
- * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in OpenSearch, see the filtering reference: https://opensearch.org/docs/latest/query-dsl/
118
- * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
119
- * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
120
- */
121
- query(params: QueryVectorParams): Promise<QueryResult[]>;
122
- /**
123
- * Validates the dimensions of the vectors.
124
- *
125
- * @param {number[][]} vectors - The vectors to validate.
126
- * @param {number} dimension - The dimension of the vectors.
127
- * @returns {void}
128
- */
129
- private validateVectorDimensions;
130
- /**
131
- * Transforms the filter to the OpenSearch DSL.
132
- *
133
- * @param {VectorFilter} filter - The filter to transform.
134
- * @returns {Record<string, any>} The transformed filter.
135
- */
136
- private transformFilter;
137
- /**
138
- * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
139
- *
140
- * Updates a vector by its ID with the provided vector and/or metadata.
141
- * @param indexName - The name of the index containing the vector.
142
- * @param id - The ID of the vector to update.
143
- * @param update - An object containing the vector and/or metadata to update.
144
- * @param update.vector - An optional array of numbers representing the new vector.
145
- * @param update.metadata - An optional record containing the new metadata.
146
- * @returns A promise that resolves when the update is complete.
147
- * @throws Will throw an error if no updates are provided or if the update operation fails.
148
- */
149
- updateIndexById(indexName: string, id: string, update: {
150
- vector?: number[];
151
- metadata?: Record<string, any>;
152
- }): Promise<void>;
153
- /**
154
- * Updates a vector by its ID with the provided vector and/or metadata.
155
- * @param indexName - The name of the index containing the vector.
156
- * @param id - The ID of the vector to update.
157
- * @param update - An object containing the vector and/or metadata to update.
158
- * @param update.vector - An optional array of numbers representing the new vector.
159
- * @param update.metadata - An optional record containing the new metadata.
160
- * @returns A promise that resolves when the update is complete.
161
- * @throws Will throw an error if no updates are provided or if the update operation fails.
162
- */
163
- updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
164
- /**
165
- * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
166
- *
167
- * Deletes a vector by its ID.
168
- * @param indexName - The name of the index containing the vector.
169
- * @param id - The ID of the vector to delete.
170
- * @returns A promise that resolves when the deletion is complete.
171
- * @throws Will throw an error if the deletion operation fails.
172
- */
173
- deleteIndexById(indexName: string, id: string): Promise<void>;
174
- /**
175
- * Deletes a vector by its ID.
176
- * @param indexName - The name of the index containing the vector.
177
- * @param id - The ID of the vector to delete.
178
- * @returns A promise that resolves when the deletion is complete.
179
- * @throws Will throw an error if the deletion operation fails.
180
- */
181
- deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
182
- }
183
- export { OpenSearchVector }
184
- export { OpenSearchVector as OpenSearchVector_alias_1 }
185
-
186
- export { }
@@ -1,186 +0,0 @@
1
- import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
- import type { CreateIndexParams } from '@mastra/core';
3
- import type { DeleteIndexParams } from '@mastra/core';
4
- import type { DeleteVectorParams } from '@mastra/core';
5
- import type { DescribeIndexParams } from '@mastra/core';
6
- import type { IndexStats } from '@mastra/core';
7
- import { MastraVector } from '@mastra/core/vector';
8
- import type { OperatorSupport } from '@mastra/core/vector/filter';
9
- import type { ParamsToArgs } from '@mastra/core';
10
- import type { QueryResult } from '@mastra/core';
11
- import type { QueryVectorParams } from '@mastra/core';
12
- import type { UpdateVectorParams } from '@mastra/core';
13
- import type { UpsertVectorParams } from '@mastra/core';
14
- import type { VectorFilter } from '@mastra/core/vector/filter';
15
-
16
- /**
17
- * Translator for OpenSearch filter queries.
18
- * Maintains OpenSearch-compatible syntax while ensuring proper validation
19
- * and normalization of values.
20
- */
21
- export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
22
- protected getSupportedOperators(): OperatorSupport;
23
- translate(filter?: VectorFilter): VectorFilter;
24
- private translateNode;
25
- /**
26
- * Handles translation of nested objects with dot notation fields
27
- */
28
- private translateNestedObject;
29
- private translateLogicalOperator;
30
- private translateFieldOperator;
31
- /**
32
- * Translates regex patterns to OpenSearch query syntax
33
- */
34
- private translateRegexOperator;
35
- private addKeywordIfNeeded;
36
- /**
37
- * Helper method to handle special cases for the $not operator
38
- */
39
- private handleNotOperatorSpecialCases;
40
- private translateOperator;
41
- /**
42
- * Translates field conditions to OpenSearch query syntax
43
- * Handles special cases like range queries and multiple operators
44
- */
45
- private translateFieldConditions;
46
- /**
47
- * Checks if conditions can be optimized to a range query
48
- */
49
- private canOptimizeToRangeQuery;
50
- /**
51
- * Creates a range query from numeric operators
52
- */
53
- private createRangeQuery;
54
- }
55
-
56
- declare class OpenSearchVector extends MastraVector {
57
- private client;
58
- /**
59
- * @deprecated Passing a string URL is deprecated. Use an object parameter: { url }.
60
- * @param url - The OpenSearch node URL (deprecated)
61
- */
62
- constructor(url: string);
63
- /**
64
- * Creates a new OpenSearchVector client.
65
- *
66
- * @param params - An object with a url property specifying the OpenSearch node.
67
- */
68
- constructor(params: {
69
- url: string;
70
- });
71
- /**
72
- * Creates a new collection with the specified configuration.
73
- *
74
- * @param {string} indexName - The name of the collection to create.
75
- * @param {number} dimension - The dimension of the vectors to be stored in the collection.
76
- * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
77
- * @returns {Promise<void>} A promise that resolves when the collection is created.
78
- */
79
- createIndex(params: CreateIndexParams): Promise<void>;
80
- /**
81
- * Lists all indexes.
82
- *
83
- * @returns {Promise<string[]>} A promise that resolves to an array of indexes.
84
- */
85
- listIndexes(): Promise<string[]>;
86
- /**
87
- * Retrieves statistics about a vector index.
88
- *
89
- * @param params - The parameters for describing an index
90
- * @param params.indexName - The name of the index to describe
91
- * @returns A promise that resolves to the index statistics including dimension, count and metric
92
- */
93
- describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
94
- /**
95
- * Deletes the specified index.
96
- *
97
- * @param {string} indexName - The name of the index to delete.
98
- * @returns {Promise<void>} A promise that resolves when the index is deleted.
99
- */
100
- deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
101
- /**
102
- * Inserts or updates vectors in the specified collection.
103
- *
104
- * @param {string} indexName - The name of the collection to upsert into.
105
- * @param {number[][]} vectors - An array of vectors to upsert.
106
- * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
107
- * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
108
- * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
109
- */
110
- upsert(params: UpsertVectorParams): Promise<string[]>;
111
- /**
112
- * Queries the specified collection using a vector and optional filter.
113
- *
114
- * @param {string} indexName - The name of the collection to query.
115
- * @param {number[]} queryVector - The vector to query with.
116
- * @param {number} [topK] - The maximum number of results to return.
117
- * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in OpenSearch, see the filtering reference: https://opensearch.org/docs/latest/query-dsl/
118
- * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
119
- * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
120
- */
121
- query(params: QueryVectorParams): Promise<QueryResult[]>;
122
- /**
123
- * Validates the dimensions of the vectors.
124
- *
125
- * @param {number[][]} vectors - The vectors to validate.
126
- * @param {number} dimension - The dimension of the vectors.
127
- * @returns {void}
128
- */
129
- private validateVectorDimensions;
130
- /**
131
- * Transforms the filter to the OpenSearch DSL.
132
- *
133
- * @param {VectorFilter} filter - The filter to transform.
134
- * @returns {Record<string, any>} The transformed filter.
135
- */
136
- private transformFilter;
137
- /**
138
- * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
139
- *
140
- * Updates a vector by its ID with the provided vector and/or metadata.
141
- * @param indexName - The name of the index containing the vector.
142
- * @param id - The ID of the vector to update.
143
- * @param update - An object containing the vector and/or metadata to update.
144
- * @param update.vector - An optional array of numbers representing the new vector.
145
- * @param update.metadata - An optional record containing the new metadata.
146
- * @returns A promise that resolves when the update is complete.
147
- * @throws Will throw an error if no updates are provided or if the update operation fails.
148
- */
149
- updateIndexById(indexName: string, id: string, update: {
150
- vector?: number[];
151
- metadata?: Record<string, any>;
152
- }): Promise<void>;
153
- /**
154
- * Updates a vector by its ID with the provided vector and/or metadata.
155
- * @param indexName - The name of the index containing the vector.
156
- * @param id - The ID of the vector to update.
157
- * @param update - An object containing the vector and/or metadata to update.
158
- * @param update.vector - An optional array of numbers representing the new vector.
159
- * @param update.metadata - An optional record containing the new metadata.
160
- * @returns A promise that resolves when the update is complete.
161
- * @throws Will throw an error if no updates are provided or if the update operation fails.
162
- */
163
- updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
164
- /**
165
- * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
166
- *
167
- * Deletes a vector by its ID.
168
- * @param indexName - The name of the index containing the vector.
169
- * @param id - The ID of the vector to delete.
170
- * @returns A promise that resolves when the deletion is complete.
171
- * @throws Will throw an error if the deletion operation fails.
172
- */
173
- deleteIndexById(indexName: string, id: string): Promise<void>;
174
- /**
175
- * Deletes a vector by its ID.
176
- * @param indexName - The name of the index containing the vector.
177
- * @param id - The ID of the vector to delete.
178
- * @returns A promise that resolves when the deletion is complete.
179
- * @throws Will throw an error if the deletion operation fails.
180
- */
181
- deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
182
- }
183
- export { OpenSearchVector }
184
- export { OpenSearchVector as OpenSearchVector_alias_1 }
185
-
186
- export { }
package/dist/index.d.cts DELETED
@@ -1 +0,0 @@
1
- export { OpenSearchVector } from './_tsup-dts-rollup.cjs';
@@ -1,23 +0,0 @@
1
- version: '3.8'
2
-
3
- services:
4
- opensearch:
5
- image: opensearchproject/opensearch:latest
6
- ports:
7
- - '9200:9200'
8
- volumes:
9
- - opensearch_data:/usr/share/opensearch/data
10
- environment:
11
- - discovery.type=single-node
12
- - OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m
13
- - bootstrap.memory_lock=true
14
- - DISABLE_SECURITY_PLUGIN=true
15
- ulimits:
16
- memlock:
17
- soft: -1
18
- hard: -1
19
- restart: always
20
-
21
- volumes:
22
- opensearch_data:
23
- driver: local
package/eslint.config.js DELETED
@@ -1,6 +0,0 @@
1
- import { createConfig } from '@internal/lint/eslint';
2
-
3
- const config = await createConfig();
4
-
5
- /** @type {import("eslint").Linter.Config[]} */
6
- export default [...config];
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './vector';