@mastra/elasticsearch 1.1.2 → 1.2.0-alpha.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 CHANGED
@@ -1,5 +1,35 @@
1
1
  # @mastra/elasticsearch
2
2
 
3
+ ## 1.2.0-alpha.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), [`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)]:
31
+ - @mastra/core@1.13.3-alpha.0
32
+
3
33
  ## 1.1.2
4
34
 
5
35
  ### Patch Changes
package/README.md CHANGED
@@ -74,13 +74,29 @@ await vectorDB.deleteVectors({
74
74
 
75
75
  ## Configuration
76
76
 
77
- The ElasticSearchVector store can be initialized with:
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
- - `auth` : The authentication mechanism (HTTP basic or API key)
82
- - HTTP basic: { auth: { username : 'insert-username', password : 'insert-password' }}
83
- - API key: { auth: { apiKey: 'insert-api-key' }}
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
 
@@ -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.1.2"
6
+ version: "1.2.0-alpha.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 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.
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: ElasticSearch Vector Store](references/reference-vectors-elasticsearch.md) - Documentation for the ElasticSearchVector class in Mastra, which provides vector search using ElasticSearch.
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,5 +1,5 @@
1
1
  {
2
- "version": "1.1.2",
2
+ "version": "1.2.0-alpha.0",
3
3
  "package": "@mastra/elasticsearch",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -1,8 +1,8 @@
1
- # Storing Embeddings in A Vector Database
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 Databases
5
+ ## Supported databases
6
6
 
7
7
  **MongoDB**:
8
8
 
@@ -234,7 +234,7 @@ await store.upsert({
234
234
  })
235
235
  ```
236
236
 
237
- **ElasticSearch**:
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 Vector Storage
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: 1536 dimensions (or custom, e.g., 256)
359
- - Cohere embed-multilingual-v3: 1024 dimensions
360
- - Google gemini-embedding-001: 768 dimensions (or custom)
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 cannot be changed after creation. To use a different model, delete and recreate the index with the new dimension size.
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
- **ElasticSearch**:
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 Metadata
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 Vectors
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 easy to remove all embeddings associated with a specific document.
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 Practices
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
- # ElasticSearch Vector Store
1
+ # Elasticsearch vector store
2
2
 
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.
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 Options
68
+ ## Constructor options
69
69
 
70
70
  **id** (`string`): Unique identifier for this vector store instance
71
71
 
72
- **url** (`string`): ElasticSearch connection URL (e.g., 'http\://localhost:9200')
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 Types
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.1.2"};
13
+ version: "1.2.0-alpha.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
- * @param {string} url - The url of the ElasticSearch node.
394
- * @param {ElasticSearchAuth} [auth] - The authentication credentials for ElasticSearch.
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({ url, id, auth }) {
397
- super({ id });
398
- this.client = new elasticsearch.Client({
399
- node: url,
400
- ...auth && { auth },
401
- name: "mastra-elasticsearch",
402
- headers: { "user-agent": `mastra-es/${package_default.version}` }
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.