@mastra/opensearch 0.0.0-vector-sources-20250516175436 → 0.0.0-vector-query-tool-provider-options-20250828222356
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 +377 -2
- package/LICENSE.md +11 -42
- package/dist/index.cjs +150 -124
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +142 -116
- package/dist/index.js.map +1 -0
- package/dist/vector/filter.d.ts +47 -0
- package/dist/vector/filter.d.ts.map +1 -0
- package/dist/vector/index.d.ts +101 -0
- package/dist/vector/index.d.ts.map +1 -0
- package/dist/vector/prompt.d.ts +6 -0
- package/dist/vector/prompt.d.ts.map +1 -0
- package/package.json +17 -13
- 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 +150 -146
- package/src/vector/prompt.ts +82 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +17 -0
- package/dist/_tsup-dts-rollup.d.cts +0 -186
- package/dist/_tsup-dts-rollup.d.ts +0 -186
- package/dist/index.d.cts +0 -1
|
@@ -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';
|