@mastra/s3vectors 0.0.0-issue-7498-20250905233741

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/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ # Apache License 2.0
2
+
3
+ Copyright (c) 2025 Kepler Software, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # @mastra/s3vectors
2
+
3
+ > ⚠️ Amazon S3 Vectors is a Preview service.
4
+ > Preview features may change or be removed without notice and are not covered by AWS SLAs.
5
+ > Behavior, limits, and regional availability can change at any time.
6
+ > This library may introduce breaking changes to stay aligned with AWS.
7
+
8
+ Vector store implementation for **Amazon S3 Vectors** (Preview) tailored for Mastra. It stores vectors in **vector buckets** and performs similarity queries in **vector indexes** with sub-second performance.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @mastra/s3vectors
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```typescript
19
+ import { S3Vectors } from '@mastra/s3vectors';
20
+
21
+ const vectorStore = new S3Vectors({
22
+ // required
23
+ vectorBucketName: process.env.S3VECTORS_BUCKET!, // e.g., 'my-vector-bucket'
24
+ // AWS SDK v3 client config (put region/credentials here)
25
+ clientConfig: {
26
+ region: process.env.AWS_REGION!, // e.g., 'us-east-1'
27
+ // credentials can rely on the default AWS provider chain
28
+ },
29
+ // optional: non-filterable metadata keys applied at index creation
30
+ nonFilterableMetadataKeys: ['content'],
31
+ });
32
+
33
+ // Create a new index
34
+ await vectorStore.createIndex({
35
+ indexName: 'my-index', // '_' will be replaced with '-' and letters lowercased
36
+ dimension: 1536,
37
+ metric: 'cosine', // 'euclidean' is also supported ('dotproduct' is not)
38
+ });
39
+
40
+ // Add vectors
41
+ const vectors = [
42
+ [0.1, 0.2 /* ... */],
43
+ [0.3, 0.4 /* ... */],
44
+ ];
45
+ const metadata = [
46
+ { text: 'doc1', genre: 'documentary', year: 2023, createdAt: new Date('2024-01-01') },
47
+ { text: 'doc2', genre: 'comedy', year: 2021 },
48
+ ];
49
+
50
+ // If ids are omitted, UUIDs will be generated
51
+ const ids = await vectorStore.upsert({
52
+ indexName: 'my-index',
53
+ vectors,
54
+ metadata,
55
+ });
56
+
57
+ // Query vectors
58
+ const results = await vectorStore.query({
59
+ indexName: 'my-index',
60
+ queryVector: [0.1, 0.2 /* ... */],
61
+ topK: 10, // (S3 Vectors limit is 30)
62
+ // S3 Vectors JSON-based filter syntax ($eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists, $and, $or)
63
+ filter: {
64
+ $and: [{ genre: { $in: ['documentary', 'comedy'] } }, { year: { $gte: 2020 } }],
65
+ },
66
+ includeVector: false, // set true to include raw vectors in the response
67
+ });
68
+
69
+ // Results example
70
+ for (const r of results) {
71
+ console.log(r.id, r.score, r.metadata /*, r.vector (when includeVector: true)*/);
72
+ }
73
+
74
+ // (optional) close the underlying HTTP handler
75
+ await vectorStore.disconnect();
76
+ ```
77
+
78
+ ### More operations
79
+
80
+ ```typescript
81
+ // Update a single vector (merge metadata or replace vector)
82
+ await vectorStore.updateVector({
83
+ indexName: 'my-index',
84
+ id: ids[0],
85
+ update: {
86
+ // vector: [/* new embedding of length 1536 */],
87
+ metadata: { tags: ['updated'] },
88
+ },
89
+ });
90
+
91
+ // Delete a single vector
92
+ await vectorStore.deleteVector({
93
+ indexName: 'my-index',
94
+ id: ids[1],
95
+ });
96
+
97
+ // Describe index (dimension/metric/count)
98
+ const stats = await vectorStore.describeIndex({ indexName: 'my-index' });
99
+
100
+ // List indexes in the bucket
101
+ const indexNames = await vectorStore.listIndexes();
102
+
103
+ // Delete index
104
+ await vectorStore.deleteIndex({ indexName: 'my-index' });
105
+ ```
106
+
107
+ ## Configuration
108
+
109
+ The S3 Vectors store reads configuration from the constructor and standard AWS SDK sources:
110
+
111
+ - `vectorBucketName` (required): The **vector bucket** name dedicated to S3 Vectors.
112
+ - `clientConfig` (optional): AWS SDK v3 `S3VectorsClientConfig` (e.g., `region`, `credentials`).
113
+ - `nonFilterableMetadataKeys` (optional): Keys that are **stored** but **not filterable** at query time.
114
+ _These are applied when an index is created._
115
+
116
+ > **Tip**
117
+ > Index names are normalized by the library: underscores are replaced with hyphens and names are lower-cased.
118
+
119
+ ## Features
120
+
121
+ - Purpose-built vector storage with S3-grade durability and elasticity
122
+ - Sub-second similarity search (`cosine` / `euclidean`)
123
+ - Rich **metadata filtering** with JSON operators (`$and`, `$or`, `$in`, …)
124
+ - IAM/SCP-based access control in the `s3vectors` namespace
125
+ - Automatic optimization for writes/updates/deletes as data scales
126
+
127
+ ## Methods
128
+
129
+ - `connect(): Promise<void>` / `disconnect(): Promise<void>` — No-ops for interface parity (disconnect closes the underlying HTTP handler)
130
+ - `createIndex({ indexName, dimension, metric? })` → `Promise<void>`
131
+ _After creation, index name/dimension/metric/non-filterable keys cannot be changed._
132
+ - `upsert({ indexName, vectors, metadata?, ids? })` → `Promise<string[]>`
133
+ _Dimensions are validated against the index; Dates in metadata are serialized to epoch millis._
134
+ - `query({ indexName, queryVector, topK?, filter?, includeVector? })` → `Promise<QueryResult[]>`
135
+ _`score` is derived from distance so that “higher is better”._
136
+ - `updateVector({ indexName, id, update: { vector?, metadata? } })` → `Promise<void>`
137
+ _Performs Get→merge→Put (Put is full replace)._
138
+ - `deleteVector({ indexName, id })` → `Promise<void>`
139
+ - `listIndexes()` → `Promise<string[]>`
140
+ - `describeIndex({ indexName })` → `Promise<IndexStats>`
141
+ _Returns `{ dimension, metric, count }`._
142
+ - `deleteIndex({ indexName })` → `Promise<void>`
143
+
144
+ ## Related Links
145
+
146
+ - Amazon S3 Vectors – Working with vector buckets & indexes:
147
+ https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-vectors.html
148
+ - Limitations and restrictions:
149
+ https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-vectors-limitations.html
150
+ - Vector indexes:
151
+ https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-vectors-indexes.html
152
+ - Metadata filtering:
153
+ https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-vectors-metadata-filtering.html
154
+ - Vector bucket naming rules:
155
+ https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-vectors-buckets-naming.html
156
+ - Managing vector bucket policies:
157
+ https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-vectors-bucket-policy.html
158
+ - Actions, resources, and condition keys for Amazon S3 Vectors:
159
+ https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3vectors.html