@mastra/s3vectors 1.0.0-beta.2 → 1.0.0-beta.3
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 +18 -0
- package/dist/docs/README.md +32 -0
- package/dist/docs/SKILL.md +33 -0
- package/dist/docs/SOURCE_MAP.json +6 -0
- package/dist/docs/rag/01-vector-databases.md +638 -0
- package/dist/docs/rag/02-retrieval.md +549 -0
- package/dist/docs/vectors/01-reference.md +221 -0
- package/package.json +6 -6
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# Vectors API Reference
|
|
2
|
+
|
|
3
|
+
> API reference for vectors - 1 entries
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Reference: Amazon S3 Vectors Store
|
|
9
|
+
|
|
10
|
+
> Documentation for the S3Vectors class in Mastra, which provides vector search using Amazon S3 Vectors (Preview).
|
|
11
|
+
|
|
12
|
+
> ⚠️ Amazon S3 Vectors is a Preview service.
|
|
13
|
+
> Preview features may change or be removed without notice and are not covered by AWS SLAs.
|
|
14
|
+
> Behavior, limits, and regional availability can change at any time.
|
|
15
|
+
> This library may introduce breaking changes to stay aligned with AWS.
|
|
16
|
+
|
|
17
|
+
The `S3Vectors` class provides vector search using [Amazon S3 Vectors (Preview)](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-vectors.html). It stores vectors in **vector buckets** and performs similarity search in **vector indexes**, with JSON-based metadata filters.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @mastra/s3vectors@beta
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage Example
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { S3Vectors } from "@mastra/s3vectors";
|
|
29
|
+
|
|
30
|
+
const store = new S3Vectors({
|
|
31
|
+
vectorBucketName: process.env.S3_VECTORS_BUCKET_NAME!, // e.g. "my-vector-bucket"
|
|
32
|
+
clientConfig: {
|
|
33
|
+
region: process.env.AWS_REGION!, // credentials use the default AWS provider chain
|
|
34
|
+
},
|
|
35
|
+
// Optional: mark large/long-text fields as non-filterable at index creation time
|
|
36
|
+
nonFilterableMetadataKeys: ["content"],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Create an index (names are normalized: "_" → "-" and lowercased)
|
|
40
|
+
await store.createIndex({
|
|
41
|
+
indexName: "my_index",
|
|
42
|
+
dimension: 1536,
|
|
43
|
+
metric: "cosine", // "euclidean" also supported; "dotproduct" is NOT supported
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Upsert vectors (ids auto-generated if omitted). Date values in metadata are serialized to epoch ms.
|
|
47
|
+
const ids = await store.upsert({
|
|
48
|
+
indexName: "my_index",
|
|
49
|
+
vectors: [
|
|
50
|
+
[0.1, 0.2 /* … */],
|
|
51
|
+
[0.3, 0.4 /* … */],
|
|
52
|
+
],
|
|
53
|
+
metadata: [
|
|
54
|
+
{
|
|
55
|
+
text: "doc1",
|
|
56
|
+
genre: "documentary",
|
|
57
|
+
year: 2023,
|
|
58
|
+
createdAt: new Date("2024-01-01"),
|
|
59
|
+
},
|
|
60
|
+
{ text: "doc2", genre: "comedy", year: 2021 },
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Query with metadata filters (implicit AND is canonicalized)
|
|
65
|
+
const results = await store.query({
|
|
66
|
+
indexName: "my-index",
|
|
67
|
+
queryVector: [0.1, 0.2 /* … */],
|
|
68
|
+
topK: 10, // Service-side limits may apply (commonly 30)
|
|
69
|
+
filter: { genre: { $in: ["documentary", "comedy"] }, year: { $gte: 2020 } },
|
|
70
|
+
includeVector: false, // set true to include raw vectors (may trigger a secondary fetch)
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Clean up resources (closes the underlying HTTP handler)
|
|
74
|
+
await store.disconnect();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Constructor Options
|
|
78
|
+
|
|
79
|
+
## Methods
|
|
80
|
+
|
|
81
|
+
### createIndex()
|
|
82
|
+
|
|
83
|
+
Creates a new vector index in the configured vector bucket. If the index already exists, the call validates the schema and becomes a no-op (existing metric and dimension are preserved).
|
|
84
|
+
|
|
85
|
+
### upsert()
|
|
86
|
+
|
|
87
|
+
Adds or replaces vectors (full-record put). If `ids` are not provided, UUIDs are generated.
|
|
88
|
+
|
|
89
|
+
### query()
|
|
90
|
+
|
|
91
|
+
Searches for nearest neighbors with optional metadata filtering.
|
|
92
|
+
|
|
93
|
+
> **Scoring:** Results include `score = 1/(1 + distance)` so that higher is better while preserving the underlying distance ranking.
|
|
94
|
+
|
|
95
|
+
### describeIndex()
|
|
96
|
+
|
|
97
|
+
Returns information about the index.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
interface IndexStats {
|
|
103
|
+
dimension: number;
|
|
104
|
+
count: number; // computed via ListVectors pagination (O(n))
|
|
105
|
+
metric: "cosine" | "euclidean";
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### deleteIndex()
|
|
110
|
+
|
|
111
|
+
Deletes an index and its data.
|
|
112
|
+
|
|
113
|
+
### listIndexes()
|
|
114
|
+
|
|
115
|
+
Lists all indexes in the configured vector bucket.
|
|
116
|
+
|
|
117
|
+
Returns: `Promise<string[]>`
|
|
118
|
+
|
|
119
|
+
### updateVector()
|
|
120
|
+
|
|
121
|
+
Updates a vector or metadata for a specific ID within an index.
|
|
122
|
+
|
|
123
|
+
### deleteVector()
|
|
124
|
+
|
|
125
|
+
Deletes a specific vector by ID.
|
|
126
|
+
|
|
127
|
+
### disconnect()
|
|
128
|
+
|
|
129
|
+
Closes the underlying AWS SDK HTTP handler to free sockets.
|
|
130
|
+
|
|
131
|
+
## Response Types
|
|
132
|
+
|
|
133
|
+
Query results are returned in this format:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
interface QueryResult {
|
|
137
|
+
id: string;
|
|
138
|
+
score: number; // 1/(1 + distance)
|
|
139
|
+
metadata: Record<string, any>;
|
|
140
|
+
vector?: number[]; // Only included if includeVector is true
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Filter Syntax
|
|
145
|
+
|
|
146
|
+
S3 Vectors supports a strict subset of operators and value types. The Mastra filter translator:
|
|
147
|
+
|
|
148
|
+
- **Canonicalizes implicit AND**: `{a:1,b:2}` → `{ $and: [{a:1},{b:2}] }`.
|
|
149
|
+
- **Normalizes Date values** to epoch ms for numeric comparisons and array elements.
|
|
150
|
+
- **Disallows Date** in equality positions (`field: value` or `$eq/$ne`); equality values must be **string | number | boolean**.
|
|
151
|
+
- **Rejects** null/undefined for equality; **array equality** is not supported (use `$in`/`$nin`).
|
|
152
|
+
- Only **`$and` / `$or`** are allowed as top-level logical operators.
|
|
153
|
+
- Logical operators must contain **field conditions** (not direct operators).
|
|
154
|
+
|
|
155
|
+
**Supported operators:**
|
|
156
|
+
|
|
157
|
+
- **Logical:** `$and`, `$or` (non-empty arrays)
|
|
158
|
+
- **Basic:** `$eq`, `$ne` (string | number | boolean)
|
|
159
|
+
- **Numeric:** `$gt`, `$gte`, `$lt`, `$lte` (number or `Date` → epoch ms)
|
|
160
|
+
- **Array:** `$in`, `$nin` (non-empty arrays of string | number | boolean; `Date` → epoch ms)
|
|
161
|
+
- **Element:** `$exists` (boolean)
|
|
162
|
+
|
|
163
|
+
**Unsupported / disallowed (rejected):** `$not`, `$nor`, `$regex`, `$all`, `$elemMatch`, `$size`, `$text`, etc.
|
|
164
|
+
|
|
165
|
+
**Examples:**
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
// Implicit AND
|
|
169
|
+
{ genre: { $in: ["documentary", "comedy"] }, year: { $gte: 2020 } }
|
|
170
|
+
|
|
171
|
+
// Explicit logicals and ranges
|
|
172
|
+
{
|
|
173
|
+
$and: [
|
|
174
|
+
{ price: { $gte: 100, $lte: 1000 } },
|
|
175
|
+
{ $or: [{ stock: { $gt: 0 } }, { preorder: true }] }
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Dates in range (converted to epoch ms)
|
|
180
|
+
{ timestamp: { $gt: new Date("2024-01-01T00:00:00Z") } }
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
> **Non-filterable keys:** If you set `nonFilterableMetadataKeys` at index creation, those keys are stored but **cannot** be used in filters.
|
|
184
|
+
|
|
185
|
+
## Error Handling
|
|
186
|
+
|
|
187
|
+
The store throws typed errors that can be caught:
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
try {
|
|
191
|
+
await store.query({
|
|
192
|
+
indexName: "index-name",
|
|
193
|
+
queryVector: queryVector,
|
|
194
|
+
});
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error instanceof VectorStoreError) {
|
|
197
|
+
console.log(error.code); // 'connection_failed' | 'invalid_dimension' | etc
|
|
198
|
+
console.log(error.details); // Additional error context
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Environment Variables
|
|
204
|
+
|
|
205
|
+
Typical environment variables when wiring your app:
|
|
206
|
+
|
|
207
|
+
- `S3_VECTORS_BUCKET_NAME`: Your S3 **vector bucket** name (used to populate `vectorBucketName`).
|
|
208
|
+
- `AWS_REGION`: AWS region for the S3 Vectors bucket.
|
|
209
|
+
- **AWS credentials**: via the standard AWS SDK provider chain (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_PROFILE`, etc.).
|
|
210
|
+
|
|
211
|
+
## Best Practices
|
|
212
|
+
|
|
213
|
+
- Choose the metric (`cosine` or `euclidean`) to match your embedding model; `dotproduct` is not supported.
|
|
214
|
+
- Keep **filterable** metadata small and structured (string/number/boolean). Store large text (e.g., `content`) as **non-filterable**.
|
|
215
|
+
- Use **dotted paths** for nested metadata and explicit `$and`/`$or` for complex logic.
|
|
216
|
+
- Avoid calling `describeIndex()` on hot paths—`count` is computed with paginated `ListVectors` (**O(n)**).
|
|
217
|
+
- Use `includeVector: true` only when you need raw vectors.
|
|
218
|
+
|
|
219
|
+
## Related
|
|
220
|
+
|
|
221
|
+
- [Metadata Filters](../rag/metadata-filters)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/s3vectors",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"description": "Amazon S3 Vectors store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -28,19 +28,18 @@
|
|
|
28
28
|
"uuid": "^11.1.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@microsoft/api-extractor": "^7.52.8",
|
|
32
31
|
"@types/node": "22.13.17",
|
|
33
32
|
"@vitest/coverage-v8": "4.0.12",
|
|
34
33
|
"@vitest/ui": "4.0.12",
|
|
35
34
|
"dotenv": "^17.0.0",
|
|
36
35
|
"eslint": "^9.37.0",
|
|
37
36
|
"tsup": "^8.5.0",
|
|
38
|
-
"typescript": "^5.
|
|
39
|
-
"vitest": "4.0.
|
|
37
|
+
"typescript": "^5.9.3",
|
|
38
|
+
"vitest": "4.0.16",
|
|
40
39
|
"@internal/lint": "0.0.53",
|
|
41
40
|
"@internal/storage-test-utils": "0.0.49",
|
|
42
41
|
"@internal/types-builder": "0.0.28",
|
|
43
|
-
"@mastra/core": "1.0.0-beta.
|
|
42
|
+
"@mastra/core": "1.0.0-beta.20"
|
|
44
43
|
},
|
|
45
44
|
"peerDependencies": {
|
|
46
45
|
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|
|
@@ -58,7 +57,8 @@
|
|
|
58
57
|
"node": ">=22.13.0"
|
|
59
58
|
},
|
|
60
59
|
"scripts": {
|
|
61
|
-
"build": "tsup --silent --config tsup.config.ts",
|
|
60
|
+
"build:lib": "tsup --silent --config tsup.config.ts",
|
|
61
|
+
"build:docs": "pnpx tsx ../../scripts/generate-package-docs.ts stores/s3vectors",
|
|
62
62
|
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
|
63
63
|
"test": "vitest run",
|
|
64
64
|
"lint": "eslint ."
|