@mastra/elasticsearch 0.0.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 ADDED
@@ -0,0 +1,11 @@
1
+ # @mastra/elasticsearch
2
+
3
+ ## 1.0.0-beta.1
4
+
5
+ ### Major Changes
6
+
7
+ - Initial release of `@mastra/elasticsearch` package
8
+ - ElasticSearch 8.x+ vector store implementation for Mastra
9
+ - Full support for vector similarity search using `dense_vector` field type
10
+ - Filter translator supporting MongoDB-style query operators
11
+ - Support for cosine, euclidean, and dot_product similarity metrics
package/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # @mastra/elasticsearch
2
+
3
+ ElasticSearch vector store implementation for Mastra, providing vector similarity search and index management using ElasticSearch 8.x+.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/elasticsearch
9
+ ```
10
+
11
+ ## Prerequisites
12
+
13
+ - ElasticSearch 8.x+ instance
14
+ - Dense vector support enabled (included by default in ES 8.x)
15
+
16
+ ## Usage
17
+
18
+ ### Vector Store
19
+
20
+ ```typescript
21
+ import { ElasticSearchVector } from '@mastra/elasticsearch';
22
+
23
+ const vectorDB = new ElasticSearchVector({
24
+ url: 'http://localhost:9200',
25
+ id: 'my-vector-store',
26
+ });
27
+
28
+ // Create a new vector index
29
+ await vectorDB.createIndex({
30
+ indexName: 'my_vectors',
31
+ dimension: 1536,
32
+ metric: 'cosine', // or 'euclidean', 'dotproduct'
33
+ });
34
+
35
+ // Upsert vectors
36
+ const ids = await vectorDB.upsert({
37
+ indexName: 'my_vectors',
38
+ vectors: [[0.1, 0.2, ...], [0.3, 0.4, ...]],
39
+ metadata: [{ text: 'doc1' }, { text: 'doc2' }],
40
+ });
41
+
42
+ // Query vectors
43
+ const results = await vectorDB.query({
44
+ indexName: 'my_vectors',
45
+ queryVector: [0.1, 0.2, ...],
46
+ topK: 10,
47
+ filter: { text: 'doc1' },
48
+ includeVector: false,
49
+ });
50
+
51
+ // Update vectors
52
+ await vectorDB.updateVector({
53
+ indexName: 'my_vectors',
54
+ id: 'vector-id',
55
+ update: {
56
+ vector: [0.5, 0.6, ...],
57
+ metadata: { text: 'updated' },
58
+ },
59
+ });
60
+
61
+ // Delete vectors
62
+ await vectorDB.deleteVector({
63
+ indexName: 'my_vectors',
64
+ id: 'vector-id',
65
+ });
66
+
67
+ // Bulk delete by filter
68
+ await vectorDB.deleteVectors({
69
+ indexName: 'my_vectors',
70
+ filter: { source: 'old-document.pdf' },
71
+ });
72
+ ```
73
+
74
+ ## Configuration
75
+
76
+ The ElasticSearchVector store can be initialized with:
77
+
78
+ - `url`: The ElasticSearch node URL (required)
79
+ - `id`: A unique identifier for the vector store instance (required)
80
+
81
+ ## Features
82
+
83
+ ### Vector Store Features
84
+
85
+ - **Create Index**: Create vector indexes with specified dimensions and similarity metrics
86
+ - **Upsert**: Insert or update vectors with optional metadata
87
+ - **Query**: Search for similar vectors with optional filtering
88
+ - **Update**: Update vector embeddings and/or metadata by ID or filter
89
+ - **Delete**: Remove vectors by ID or filter
90
+ - **List Indexes**: List all vector indexes
91
+ - **Describe Index**: Get index statistics (dimension, count, metric)
92
+
93
+ ### Supported Similarity Metrics
94
+
95
+ - `cosine`: Cosine similarity (default)
96
+ - `euclidean`: L2 (Euclidean) distance
97
+ - `dotproduct`: Dot product similarity
98
+
99
+ ### Filter Operators
100
+
101
+ The following filter operators are supported:
102
+
103
+ - **Comparison**: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`
104
+ - **Array**: `$in`, `$nin`, `$all`
105
+ - **Logical**: `$and`, `$or`, `$not`
106
+ - **Element**: `$exists`
107
+ - **Regex**: `$regex`
108
+
109
+ ## Development
110
+
111
+ ### Running Tests
112
+
113
+ ```bash
114
+ # Start ElasticSearch container
115
+ docker compose up -d
116
+
117
+ # Run tests
118
+ pnpm test
119
+
120
+ # Stop container
121
+ docker compose down -v
122
+ ```
123
+
124
+ ## License
125
+
126
+ MIT