@mastra/opensearch 0.0.0-tsconfig-compile-20250703214351 → 0.0.0-unified-sidebar-20251010130811
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 +329 -4
- package/LICENSE.md +11 -42
- package/dist/index.cjs +2 -3
- 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 +2 -3
- 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 +22 -8
- package/dist/_tsup-dts-rollup.d.cts +0 -172
- package/dist/_tsup-dts-rollup.d.ts +0 -172
- package/dist/index.d.cts +0 -1
- package/docker-compose.yaml +0 -23
- package/eslint.config.js +0 -6
- package/src/index.ts +0 -1
- package/src/vector/filter.test.ts +0 -661
- package/src/vector/filter.ts +0 -479
- package/src/vector/index.test.ts +0 -1558
- package/src/vector/index.ts +0 -436
- package/src/vector/prompt.ts +0 -82
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -11
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
2
|
-
import type { BlacklistedRootOperators } from '@mastra/core/vector/filter';
|
|
3
|
-
import type { CreateIndexParams } from '@mastra/core';
|
|
4
|
-
import type { DeleteIndexParams } from '@mastra/core';
|
|
5
|
-
import type { DeleteVectorParams } from '@mastra/core';
|
|
6
|
-
import type { DescribeIndexParams } from '@mastra/core';
|
|
7
|
-
import type { IndexStats } from '@mastra/core';
|
|
8
|
-
import type { LogicalOperatorValueMap } from '@mastra/core/vector/filter';
|
|
9
|
-
import { MastraVector } from '@mastra/core/vector';
|
|
10
|
-
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
11
|
-
import type { OperatorValueMap } from '@mastra/core/vector/filter';
|
|
12
|
-
import type { QueryResult } from '@mastra/core';
|
|
13
|
-
import type { QueryVectorParams } from '@mastra/core';
|
|
14
|
-
import type { UpdateVectorParams } from '@mastra/core';
|
|
15
|
-
import type { UpsertVectorParams } from '@mastra/core';
|
|
16
|
-
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Vector store prompt for OpenSearch. This prompt details supported filter operators, syntax, and usage examples.
|
|
20
|
-
* Use this as a guide for constructing valid filters for OpenSearch vector queries in Mastra.
|
|
21
|
-
*/
|
|
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}";
|
|
23
|
-
|
|
24
|
-
declare type OpenSearchBlacklisted = BlacklistedRootOperators | '$nor';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Translator for OpenSearch filter queries.
|
|
28
|
-
* Maintains OpenSearch-compatible syntax while ensuring proper validation
|
|
29
|
-
* and normalization of values.
|
|
30
|
-
*/
|
|
31
|
-
export declare class OpenSearchFilterTranslator extends BaseFilterTranslator<OpenSearchVectorFilter> {
|
|
32
|
-
protected getSupportedOperators(): OperatorSupport;
|
|
33
|
-
translate(filter?: OpenSearchVectorFilter): OpenSearchVectorFilter;
|
|
34
|
-
private translateNode;
|
|
35
|
-
/**
|
|
36
|
-
* Handles translation of nested objects with dot notation fields
|
|
37
|
-
*/
|
|
38
|
-
private translateNestedObject;
|
|
39
|
-
private translateLogicalOperator;
|
|
40
|
-
private translateFieldOperator;
|
|
41
|
-
/**
|
|
42
|
-
* Translates regex patterns to OpenSearch query syntax
|
|
43
|
-
*/
|
|
44
|
-
private translateRegexOperator;
|
|
45
|
-
private addKeywordIfNeeded;
|
|
46
|
-
/**
|
|
47
|
-
* Helper method to handle special cases for the $not operator
|
|
48
|
-
*/
|
|
49
|
-
private handleNotOperatorSpecialCases;
|
|
50
|
-
private translateOperator;
|
|
51
|
-
/**
|
|
52
|
-
* Translates field conditions to OpenSearch query syntax
|
|
53
|
-
* Handles special cases like range queries and multiple operators
|
|
54
|
-
*/
|
|
55
|
-
private translateFieldConditions;
|
|
56
|
-
/**
|
|
57
|
-
* Checks if conditions can be optimized to a range query
|
|
58
|
-
*/
|
|
59
|
-
private canOptimizeToRangeQuery;
|
|
60
|
-
/**
|
|
61
|
-
* Creates a range query from numeric operators
|
|
62
|
-
*/
|
|
63
|
-
private createRangeQuery;
|
|
64
|
-
}
|
|
65
|
-
|
|
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> {
|
|
71
|
-
private client;
|
|
72
|
-
/**
|
|
73
|
-
* Creates a new OpenSearchVector client.
|
|
74
|
-
*
|
|
75
|
-
* @param {string} url - The url of the OpenSearch node.
|
|
76
|
-
*/
|
|
77
|
-
constructor({ url }: {
|
|
78
|
-
url: string;
|
|
79
|
-
});
|
|
80
|
-
/**
|
|
81
|
-
* Creates a new collection with the specified configuration.
|
|
82
|
-
*
|
|
83
|
-
* @param {string} indexName - The name of the collection to create.
|
|
84
|
-
* @param {number} dimension - The dimension of the vectors to be stored in the collection.
|
|
85
|
-
* @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
|
|
86
|
-
* @returns {Promise<void>} A promise that resolves when the collection is created.
|
|
87
|
-
*/
|
|
88
|
-
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* Lists all indexes.
|
|
91
|
-
*
|
|
92
|
-
* @returns {Promise<string[]>} A promise that resolves to an array of indexes.
|
|
93
|
-
*/
|
|
94
|
-
listIndexes(): Promise<string[]>;
|
|
95
|
-
/**
|
|
96
|
-
* Retrieves statistics about a vector index.
|
|
97
|
-
*
|
|
98
|
-
* @param {string} indexName - The name of the index to describe
|
|
99
|
-
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
100
|
-
*/
|
|
101
|
-
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
102
|
-
/**
|
|
103
|
-
* Deletes the specified index.
|
|
104
|
-
*
|
|
105
|
-
* @param {string} indexName - The name of the index to delete.
|
|
106
|
-
* @returns {Promise<void>} A promise that resolves when the index is deleted.
|
|
107
|
-
*/
|
|
108
|
-
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
109
|
-
/**
|
|
110
|
-
* Inserts or updates vectors in the specified collection.
|
|
111
|
-
*
|
|
112
|
-
* @param {string} indexName - The name of the collection to upsert into.
|
|
113
|
-
* @param {number[][]} vectors - An array of vectors to upsert.
|
|
114
|
-
* @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
|
|
115
|
-
* @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
|
|
116
|
-
* @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
|
|
117
|
-
*/
|
|
118
|
-
upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
|
|
119
|
-
/**
|
|
120
|
-
* Queries the specified collection using a vector and optional filter.
|
|
121
|
-
*
|
|
122
|
-
* @param {string} indexName - The name of the collection to query.
|
|
123
|
-
* @param {number[]} queryVector - The vector to query with.
|
|
124
|
-
* @param {number} [topK] - The maximum number of results to return.
|
|
125
|
-
* @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/
|
|
126
|
-
* @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
|
|
127
|
-
* @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
|
|
128
|
-
*/
|
|
129
|
-
query({ indexName, queryVector, filter, topK, includeVector, }: OpenSearchVectorParams): Promise<QueryResult[]>;
|
|
130
|
-
/**
|
|
131
|
-
* Validates the dimensions of the vectors.
|
|
132
|
-
*
|
|
133
|
-
* @param {number[][]} vectors - The vectors to validate.
|
|
134
|
-
* @param {number} dimension - The dimension of the vectors.
|
|
135
|
-
* @returns {void}
|
|
136
|
-
*/
|
|
137
|
-
private validateVectorDimensions;
|
|
138
|
-
/**
|
|
139
|
-
* Transforms the filter to the OpenSearch DSL.
|
|
140
|
-
*
|
|
141
|
-
* @param {OpenSearchVectorFilter} filter - The filter to transform.
|
|
142
|
-
* @returns {Record<string, any>} The transformed filter.
|
|
143
|
-
*/
|
|
144
|
-
private transformFilter;
|
|
145
|
-
/**
|
|
146
|
-
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
147
|
-
* @param indexName - The name of the index containing the vector.
|
|
148
|
-
* @param id - The ID of the vector to update.
|
|
149
|
-
* @param update - An object containing the vector and/or metadata to update.
|
|
150
|
-
* @param update.vector - An optional array of numbers representing the new vector.
|
|
151
|
-
* @param update.metadata - An optional record containing the new metadata.
|
|
152
|
-
* @returns A promise that resolves when the update is complete.
|
|
153
|
-
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
154
|
-
*/
|
|
155
|
-
updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
|
|
156
|
-
/**
|
|
157
|
-
* Deletes a vector by its ID.
|
|
158
|
-
* @param indexName - The name of the index containing the vector.
|
|
159
|
-
* @param id - The ID of the vector to delete.
|
|
160
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
161
|
-
* @throws Will throw an error if the deletion operation fails.
|
|
162
|
-
*/
|
|
163
|
-
deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
|
|
164
|
-
}
|
|
165
|
-
export { OpenSearchVector }
|
|
166
|
-
export { OpenSearchVector as OpenSearchVector_alias_1 }
|
|
167
|
-
|
|
168
|
-
export declare type OpenSearchVectorFilter = VectorFilter<keyof OpenSearchOperatorValueMap, OpenSearchOperatorValueMap, OpenSearchLogicalOperatorValueMap, OpenSearchBlacklisted>;
|
|
169
|
-
|
|
170
|
-
declare type OpenSearchVectorParams = QueryVectorParams<OpenSearchVectorFilter>;
|
|
171
|
-
|
|
172
|
-
export { }
|
package/dist/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { OpenSearchVector } from './_tsup-dts-rollup.cjs';
|
package/docker-compose.yaml
DELETED
|
@@ -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
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './vector';
|