@mastra/elasticsearch 1.1.2 → 1.2.0
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 +60 -0
- package/README.md +20 -4
- package/dist/docs/SKILL.md +3 -3
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-rag-vector-databases.md +13 -13
- package/dist/docs/references/reference-vectors-elasticsearch.md +14 -14
- package/dist/index.cjs +23 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -10
- package/dist/index.d.ts +17 -10
- package/dist/index.js +23 -11
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# @mastra/elasticsearch
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added support for constructing `ElasticSearchVector` with a pre-configured Elasticsearch client. You can now pass either a `client` instance or connection parameters (`url` and optional `auth`), giving you full control over client configuration when needed. ([#12802](https://github.com/mastra-ai/mastra/pull/12802))
|
|
8
|
+
|
|
9
|
+
**Using connection parameters:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
const vectorDB = new ElasticSearchVector({
|
|
13
|
+
id: 'my-store',
|
|
14
|
+
url: 'http://localhost:9200',
|
|
15
|
+
auth: { apiKey: 'my-key' },
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Using a pre-configured client:**
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Client } from '@elastic/elasticsearch';
|
|
23
|
+
|
|
24
|
+
const client = new Client({ node: 'http://localhost:9200' });
|
|
25
|
+
const vectorDB = new ElasticSearchVector({ id: 'my-store', client });
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [[`51970b3`](https://github.com/mastra-ai/mastra/commit/51970b3828494d59a8dd4df143b194d37d31e3f5), [`4444280`](https://github.com/mastra-ai/mastra/commit/444428094253e916ec077e66284e685fde67021e), [`085e371`](https://github.com/mastra-ai/mastra/commit/085e3718a7d0fe9a210fe7dd1c867b9bdfe8d16b), [`b77aa19`](https://github.com/mastra-ai/mastra/commit/b77aa1981361c021f2c881bee8f0c703687f00da), [`dbb879a`](https://github.com/mastra-ai/mastra/commit/dbb879af0b809c668e9b3a9d8bac97d806caa267), [`8b4ce84`](https://github.com/mastra-ai/mastra/commit/8b4ce84aed0808b9805cc4fd7147c1f8a2ef7a36), [`8d4cfe6`](https://github.com/mastra-ai/mastra/commit/8d4cfe6b9a7157d3876206227ec9f04cde6dbc4a), [`dd6ca1c`](https://github.com/mastra-ai/mastra/commit/dd6ca1cdea3b8b6182f4cf61df41070ba0cc0deb), [`ce26fe2`](https://github.com/mastra-ai/mastra/commit/ce26fe2166dd90254f8bee5776e55977143e97de), [`68a019d`](https://github.com/mastra-ai/mastra/commit/68a019d30d22251ddd628a2947d60215c03c350a), [`4cb4edf`](https://github.com/mastra-ai/mastra/commit/4cb4edf3c909d197ec356c1790d13270514ffef6), [`8de3555`](https://github.com/mastra-ai/mastra/commit/8de355572c6fd838f863a3e7e6fe24d0947b774f), [`b26307f`](https://github.com/mastra-ai/mastra/commit/b26307f050df39629511b0e831b8fc26973ce8b1), [`68a019d`](https://github.com/mastra-ai/mastra/commit/68a019d30d22251ddd628a2947d60215c03c350a)]:
|
|
31
|
+
- @mastra/core@1.14.0
|
|
32
|
+
|
|
33
|
+
## 1.2.0-alpha.0
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- Added support for constructing `ElasticSearchVector` with a pre-configured Elasticsearch client. You can now pass either a `client` instance or connection parameters (`url` and optional `auth`), giving you full control over client configuration when needed. ([#12802](https://github.com/mastra-ai/mastra/pull/12802))
|
|
38
|
+
|
|
39
|
+
**Using connection parameters:**
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const vectorDB = new ElasticSearchVector({
|
|
43
|
+
id: 'my-store',
|
|
44
|
+
url: 'http://localhost:9200',
|
|
45
|
+
auth: { apiKey: 'my-key' },
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Using a pre-configured client:**
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { Client } from '@elastic/elasticsearch';
|
|
53
|
+
|
|
54
|
+
const client = new Client({ node: 'http://localhost:9200' });
|
|
55
|
+
const vectorDB = new ElasticSearchVector({ id: 'my-store', client });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- Updated dependencies [[`51970b3`](https://github.com/mastra-ai/mastra/commit/51970b3828494d59a8dd4df143b194d37d31e3f5), [`085e371`](https://github.com/mastra-ai/mastra/commit/085e3718a7d0fe9a210fe7dd1c867b9bdfe8d16b), [`ce26fe2`](https://github.com/mastra-ai/mastra/commit/ce26fe2166dd90254f8bee5776e55977143e97de), [`b26307f`](https://github.com/mastra-ai/mastra/commit/b26307f050df39629511b0e831b8fc26973ce8b1)]:
|
|
61
|
+
- @mastra/core@1.13.3-alpha.0
|
|
62
|
+
|
|
3
63
|
## 1.1.2
|
|
4
64
|
|
|
5
65
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -74,13 +74,29 @@ await vectorDB.deleteVectors({
|
|
|
74
74
|
|
|
75
75
|
## Configuration
|
|
76
76
|
|
|
77
|
-
The ElasticSearchVector store
|
|
77
|
+
The ElasticSearchVector store accepts either connection parameters or a pre-configured client:
|
|
78
78
|
|
|
79
|
+
### Using connection parameters
|
|
80
|
+
|
|
81
|
+
- `id`: A unique identifier for the vector store instance (required)
|
|
79
82
|
- `url`: The ElasticSearch node URL (required)
|
|
83
|
+
- `auth`: The authentication mechanism (optional)
|
|
84
|
+
- HTTP basic: `{ auth: { username: 'insert-username', password: 'insert-password' } }`
|
|
85
|
+
- API key: `{ auth: { apiKey: 'insert-api-key' } }`
|
|
86
|
+
- Bearer token: `{ auth: { bearer: 'insert-token' } }`
|
|
87
|
+
|
|
88
|
+
### Using a pre-configured client
|
|
89
|
+
|
|
80
90
|
- `id`: A unique identifier for the vector store instance (required)
|
|
81
|
-
- `
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
- `client`: An existing `@elastic/elasticsearch` `Client` instance (required)
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { Client } from '@elastic/elasticsearch';
|
|
95
|
+
import { ElasticSearchVector } from '@mastra/elasticsearch';
|
|
96
|
+
|
|
97
|
+
const client = new Client({ node: 'http://localhost:9200' });
|
|
98
|
+
const vectorDB = new ElasticSearchVector({ id: 'my-vector-store', client });
|
|
99
|
+
```
|
|
84
100
|
|
|
85
101
|
## Features
|
|
86
102
|
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-elasticsearch
|
|
|
3
3
|
description: Documentation for @mastra/elasticsearch. Use when working with @mastra/elasticsearch APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/elasticsearch"
|
|
6
|
-
version: "1.
|
|
6
|
+
version: "1.2.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -16,11 +16,11 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
16
16
|
|
|
17
17
|
### Docs
|
|
18
18
|
|
|
19
|
-
- [Storing
|
|
19
|
+
- [Storing embeddings in a vector database](references/docs-rag-vector-databases.md) - Guide on vector storage options in Mastra, including embedded and dedicated vector databases for similarity search.
|
|
20
20
|
|
|
21
21
|
### Reference
|
|
22
22
|
|
|
23
|
-
- [Reference:
|
|
23
|
+
- [Reference: Elasticsearch vector store](references/reference-vectors-elasticsearch.md) - Documentation for the ElasticSearchVector class in Mastra, which provides vector search using Elasticsearch.
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# Storing
|
|
1
|
+
# Storing embeddings in a vector database
|
|
2
2
|
|
|
3
3
|
After generating embeddings, you need to store them in a database that supports vector similarity search. Mastra provides a consistent interface for storing and querying embeddings across various vector databases.
|
|
4
4
|
|
|
5
|
-
## Supported
|
|
5
|
+
## Supported databases
|
|
6
6
|
|
|
7
7
|
**MongoDB**:
|
|
8
8
|
|
|
@@ -234,7 +234,7 @@ await store.upsert({
|
|
|
234
234
|
})
|
|
235
235
|
```
|
|
236
236
|
|
|
237
|
-
**
|
|
237
|
+
**Elasticsearch**:
|
|
238
238
|
|
|
239
239
|
```ts
|
|
240
240
|
import { ElasticSearchVector } from '@mastra/elasticsearch'
|
|
@@ -337,7 +337,7 @@ await store.upsert({
|
|
|
337
337
|
})
|
|
338
338
|
```
|
|
339
339
|
|
|
340
|
-
## Using
|
|
340
|
+
## Using vector storage
|
|
341
341
|
|
|
342
342
|
Once initialized, all vector stores share the same interface for creating indexes, upserting embeddings, and querying.
|
|
343
343
|
|
|
@@ -355,11 +355,11 @@ await store.createIndex({
|
|
|
355
355
|
|
|
356
356
|
The dimension size must match the output dimension of your chosen embedding model. Common dimension sizes are:
|
|
357
357
|
|
|
358
|
-
- OpenAI text-embedding-3-small
|
|
359
|
-
- Cohere embed-multilingual-v3
|
|
360
|
-
- Google gemini-embedding-001
|
|
358
|
+
- `OpenAI text-embedding-3-small`: 1536 dimensions (or custom, e.g., 256)
|
|
359
|
+
- `Cohere embed-multilingual-v3`: 1024 dimensions
|
|
360
|
+
- `Google gemini-embedding-001`: 768 dimensions (or custom)
|
|
361
361
|
|
|
362
|
-
> **Warning:** Index dimensions
|
|
362
|
+
> **Warning:** Index dimensions can't be changed after creation. To use a different model, delete and recreate the index with the new dimension size.
|
|
363
363
|
|
|
364
364
|
### Naming Rules for Databases
|
|
365
365
|
|
|
@@ -490,7 +490,7 @@ Index names must:
|
|
|
490
490
|
- Example: `My_Index` is not valid (contains uppercase letters)
|
|
491
491
|
- Example: `_myindex` is not valid (begins with underscore)
|
|
492
492
|
|
|
493
|
-
**
|
|
493
|
+
**Elasticsearch**:
|
|
494
494
|
|
|
495
495
|
Index names must:
|
|
496
496
|
|
|
@@ -543,7 +543,7 @@ The upsert operation:
|
|
|
543
543
|
- Creates new vectors if they don't exist
|
|
544
544
|
- Automatically handles batching for large datasets
|
|
545
545
|
|
|
546
|
-
## Adding
|
|
546
|
+
## Adding metadata
|
|
547
547
|
|
|
548
548
|
Vector stores support rich metadata (any JSON-serializable fields) for filtering and organization. Since metadata is stored with no fixed schema, use consistent field naming to avoid unexpected query results.
|
|
549
549
|
|
|
@@ -581,9 +581,9 @@ Key metadata considerations:
|
|
|
581
581
|
- Only include fields you plan to filter or sort by - extra fields add overhead
|
|
582
582
|
- Add timestamps (e.g., 'createdAt', 'lastUpdated') to track content freshness
|
|
583
583
|
|
|
584
|
-
## Deleting
|
|
584
|
+
## Deleting vectors
|
|
585
585
|
|
|
586
|
-
When building RAG applications, you often need to clean up stale vectors when documents are deleted or updated. Mastra provides the `deleteVectors` method that supports deleting vectors by metadata filters, making it
|
|
586
|
+
When building RAG applications, you often need to clean up stale vectors when documents are deleted or updated. Mastra provides the `deleteVectors` method that supports deleting vectors by metadata filters, making it straightforward to remove all embeddings associated with a specific document.
|
|
587
587
|
|
|
588
588
|
### Delete by Metadata Filter
|
|
589
589
|
|
|
@@ -637,7 +637,7 @@ await store.deleteVectors({
|
|
|
637
637
|
})
|
|
638
638
|
```
|
|
639
639
|
|
|
640
|
-
## Best
|
|
640
|
+
## Best practices
|
|
641
641
|
|
|
642
642
|
- Create indexes before bulk insertions
|
|
643
643
|
- Use batch operations for large insertions (the upsert method handles batching automatically)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Elasticsearch vector store
|
|
2
2
|
|
|
3
|
-
The ElasticSearchVector class provides vector search using [
|
|
3
|
+
The `ElasticSearchVector` class provides vector search using [Elasticsearch](https://www.elastic.co/elasticsearch/) with its `dense_vector` field type and k-NN search capabilities. It's part of the `@mastra/elasticsearch` package.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -65,15 +65,15 @@ const results = await store.query({
|
|
|
65
65
|
});
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
## Constructor
|
|
68
|
+
## Constructor options
|
|
69
69
|
|
|
70
70
|
**id** (`string`): Unique identifier for this vector store instance
|
|
71
71
|
|
|
72
|
-
**url** (`string`):
|
|
72
|
+
**url** (`string`): Elasticsearch connection URL (e.g., 'http\://localhost:9200')
|
|
73
73
|
|
|
74
74
|
## Methods
|
|
75
75
|
|
|
76
|
-
### createIndex()
|
|
76
|
+
### `createIndex()`
|
|
77
77
|
|
|
78
78
|
Creates a new index with the specified configuration.
|
|
79
79
|
|
|
@@ -83,7 +83,7 @@ Creates a new index with the specified configuration.
|
|
|
83
83
|
|
|
84
84
|
**metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
|
|
85
85
|
|
|
86
|
-
### upsert()
|
|
86
|
+
### `upsert()`
|
|
87
87
|
|
|
88
88
|
Adds or updates vectors and their metadata in the index.
|
|
89
89
|
|
|
@@ -95,7 +95,7 @@ Adds or updates vectors and their metadata in the index.
|
|
|
95
95
|
|
|
96
96
|
**ids** (`string[]`): Optional vector IDs (auto-generated if not provided)
|
|
97
97
|
|
|
98
|
-
### query()
|
|
98
|
+
### `query()`
|
|
99
99
|
|
|
100
100
|
Searches for similar vectors with optional metadata filtering.
|
|
101
101
|
|
|
@@ -109,7 +109,7 @@ Searches for similar vectors with optional metadata filtering.
|
|
|
109
109
|
|
|
110
110
|
**includeVector** (`boolean`): Whether to include vector data in results (Default: `false`)
|
|
111
111
|
|
|
112
|
-
### describeIndex()
|
|
112
|
+
### `describeIndex()`
|
|
113
113
|
|
|
114
114
|
Gets information about an index.
|
|
115
115
|
|
|
@@ -125,19 +125,19 @@ interface IndexStats {
|
|
|
125
125
|
}
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
### deleteIndex()
|
|
128
|
+
### `deleteIndex()`
|
|
129
129
|
|
|
130
130
|
Deletes an index and all its data.
|
|
131
131
|
|
|
132
132
|
**indexName** (`string`): Name of the index to delete
|
|
133
133
|
|
|
134
|
-
### listIndexes()
|
|
134
|
+
### `listIndexes()`
|
|
135
135
|
|
|
136
136
|
Lists all vector indexes.
|
|
137
137
|
|
|
138
138
|
Returns: `Promise<string[]>`
|
|
139
139
|
|
|
140
|
-
### updateVector()
|
|
140
|
+
### `updateVector()`
|
|
141
141
|
|
|
142
142
|
Update a single vector by ID or by metadata filter. Either `id` or `filter` must be provided, but not both.
|
|
143
143
|
|
|
@@ -153,7 +153,7 @@ Update a single vector by ID or by metadata filter. Either `id` or `filter` must
|
|
|
153
153
|
|
|
154
154
|
**update.metadata** (`Record<string, any>`): New metadata
|
|
155
155
|
|
|
156
|
-
### deleteVector()
|
|
156
|
+
### `deleteVector()`
|
|
157
157
|
|
|
158
158
|
Deletes a single vector by its ID.
|
|
159
159
|
|
|
@@ -161,7 +161,7 @@ Deletes a single vector by its ID.
|
|
|
161
161
|
|
|
162
162
|
**id** (`string`): ID of the vector to delete
|
|
163
163
|
|
|
164
|
-
### deleteVectors()
|
|
164
|
+
### `deleteVectors()`
|
|
165
165
|
|
|
166
166
|
Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both.
|
|
167
167
|
|
|
@@ -171,7 +171,7 @@ Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` m
|
|
|
171
171
|
|
|
172
172
|
**filter** (`Record<string, any>`): Metadata filter to identify vectors to delete (mutually exclusive with ids)
|
|
173
173
|
|
|
174
|
-
## Response
|
|
174
|
+
## Response types
|
|
175
175
|
|
|
176
176
|
Query results are returned in this format:
|
|
177
177
|
|
package/dist/index.cjs
CHANGED
|
@@ -10,7 +10,7 @@ var filter = require('@mastra/core/vector/filter');
|
|
|
10
10
|
|
|
11
11
|
// package.json
|
|
12
12
|
var package_default = {
|
|
13
|
-
version: "1.
|
|
13
|
+
version: "1.2.0"};
|
|
14
14
|
var ElasticSearchFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
15
15
|
getSupportedOperators() {
|
|
16
16
|
return {
|
|
@@ -390,17 +390,29 @@ var ElasticSearchVector = class extends vector.MastraVector {
|
|
|
390
390
|
/**
|
|
391
391
|
* Creates a new ElasticSearchVector client.
|
|
392
392
|
*
|
|
393
|
-
*
|
|
394
|
-
*
|
|
393
|
+
* Accepts either a pre-configured ElasticSearch client or connection parameters:
|
|
394
|
+
* - `{ id, client }` - Use an existing ElasticSearch client
|
|
395
|
+
* - `{ id, url, auth? }` - Create a new client from connection parameters
|
|
395
396
|
*/
|
|
396
|
-
constructor(
|
|
397
|
-
super({ id });
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
397
|
+
constructor(config) {
|
|
398
|
+
super({ id: config.id });
|
|
399
|
+
if ("client" in config && config.client) {
|
|
400
|
+
this.client = config.client;
|
|
401
|
+
} else if ("url" in config && config.url) {
|
|
402
|
+
this.client = new elasticsearch.Client({
|
|
403
|
+
node: config.url,
|
|
404
|
+
...config.auth && { auth: config.auth },
|
|
405
|
+
name: "mastra-elasticsearch",
|
|
406
|
+
headers: { "user-agent": `mastra-es/${package_default.version}` }
|
|
407
|
+
});
|
|
408
|
+
} else {
|
|
409
|
+
throw new error.MastraError({
|
|
410
|
+
id: "ELASTIC_SEARCH_CONSTRUCTOR_ERROR",
|
|
411
|
+
domain: error.ErrorDomain.STORAGE,
|
|
412
|
+
category: error.ErrorCategory.SYSTEM,
|
|
413
|
+
text: "Invalid config: provide either { client } or { url }."
|
|
414
|
+
});
|
|
415
|
+
}
|
|
404
416
|
}
|
|
405
417
|
/**
|
|
406
418
|
* Creates a new collection with the specified configuration.
|