@mastra/libsql 1.6.4 → 1.7.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 +38 -0
- package/dist/docs/SKILL.md +18 -18
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-agent-approval.md +3 -3
- package/dist/docs/references/docs-agents-agent-memory.md +3 -3
- package/dist/docs/references/docs-agents-network-approval.md +5 -2
- package/dist/docs/references/docs-agents-networks.md +2 -2
- package/dist/docs/references/docs-memory-memory-processors.md +9 -9
- package/dist/docs/references/docs-memory-message-history.md +4 -4
- package/dist/docs/references/docs-memory-semantic-recall.md +9 -9
- package/dist/docs/references/docs-memory-storage.md +1 -1
- package/dist/docs/references/docs-memory-working-memory.md +20 -20
- package/dist/docs/references/docs-observability-overview.md +5 -5
- package/dist/docs/references/docs-observability-tracing-exporters-default.md +8 -8
- package/dist/docs/references/docs-rag-retrieval.md +4 -4
- package/dist/docs/references/docs-workflows-snapshots.md +1 -1
- package/dist/docs/references/reference-core-getMemory.md +1 -1
- package/dist/docs/references/reference-core-listMemory.md +1 -1
- package/dist/docs/references/reference-core-mastra-class.md +2 -2
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-storage-composite.md +1 -1
- package/dist/docs/references/reference-storage-dynamodb.md +7 -7
- package/dist/docs/references/reference-storage-libsql.md +1 -1
- package/dist/docs/references/reference-vectors-libsql.md +15 -15
- package/dist/index.cjs +195 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +196 -62
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +12 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +1 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# Retrieval in RAG
|
|
1
|
+
# Retrieval in RAG systems
|
|
2
2
|
|
|
3
3
|
After storing embeddings, you need to retrieve relevant chunks to answer user queries.
|
|
4
4
|
|
|
5
5
|
Mastra provides flexible retrieval options with support for semantic search, filtering, and re-ranking.
|
|
6
6
|
|
|
7
|
-
## How
|
|
7
|
+
## How retrieval works
|
|
8
8
|
|
|
9
9
|
1. The user's query is converted to an embedding using the same model used for document embeddings
|
|
10
10
|
2. This embedding is compared to stored embeddings using vector similarity
|
|
@@ -14,7 +14,7 @@ Mastra provides flexible retrieval options with support for semantic search, fil
|
|
|
14
14
|
- Re-ranked for better relevance
|
|
15
15
|
- Processed through a knowledge graph
|
|
16
16
|
|
|
17
|
-
## Basic
|
|
17
|
+
## Basic retrieval
|
|
18
18
|
|
|
19
19
|
The simplest approach is direct semantic search. This method uses vector similarity to find chunks that are semantically similar to the query:
|
|
20
20
|
|
|
@@ -63,7 +63,7 @@ Results include both the text content and a similarity score:
|
|
|
63
63
|
]
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
## Advanced
|
|
66
|
+
## Advanced retrieval options
|
|
67
67
|
|
|
68
68
|
### Metadata Filtering
|
|
69
69
|
|
|
@@ -150,7 +150,7 @@ export const mastra = new Mastra({
|
|
|
150
150
|
1. **Ensure Serializability**: Any data that needs to be included in the snapshot must be serializable (convertible to JSON).
|
|
151
151
|
2. **Minimize Snapshot Size**: Avoid storing large data objects directly in the workflow context. Instead, store references to them (like IDs) and retrieve the data when needed.
|
|
152
152
|
3. **Handle Resume Context Carefully**: When resuming a workflow, carefully consider what context to provide. This will be merged with the existing snapshot data.
|
|
153
|
-
4. **Set Up Proper Monitoring**: Implement monitoring for suspended workflows, especially long-running ones, to ensure they
|
|
153
|
+
4. **Set Up Proper Monitoring**: Implement monitoring for suspended workflows, especially long-running ones, to ensure they're properly resumed.
|
|
154
154
|
5. **Consider Storage Scaling**: For applications with many suspended workflows, ensure your storage solution is appropriately scaled.
|
|
155
155
|
|
|
156
156
|
## Custom snapshot metadata
|
|
@@ -22,7 +22,7 @@ const thread = await memory.createThread({
|
|
|
22
22
|
|
|
23
23
|
**memory** (`TMemory[TMemoryKey]`): The memory instance with the specified key. Throws an error if the memory is not found.
|
|
24
24
|
|
|
25
|
-
## Example: Registering and
|
|
25
|
+
## Example: Registering and retrieving memory
|
|
26
26
|
|
|
27
27
|
```typescript
|
|
28
28
|
import { Mastra } from '@mastra/core'
|
|
@@ -20,7 +20,7 @@ This method takes no parameters.
|
|
|
20
20
|
|
|
21
21
|
**memory** (`Record<string, MastraMemory>`): An object containing all registered memory instances, keyed by their registry keys.
|
|
22
22
|
|
|
23
|
-
## Example: Checking
|
|
23
|
+
## Example: Checking registered memory
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
26
|
import { Mastra } from '@mastra/core'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Mastra
|
|
1
|
+
# Mastra class
|
|
2
2
|
|
|
3
3
|
The `Mastra` class is the central orchestrator in any Mastra application, managing agents, workflows, storage, logging, observability, and more. Typically, you create a single instance of `Mastra` to coordinate your application.
|
|
4
4
|
|
|
@@ -41,7 +41,7 @@ Visit the [Configuration reference](https://mastra.ai/reference/configuration) f
|
|
|
41
41
|
|
|
42
42
|
**logger** (`Logger`): Logger instance created with new PinoLogger() (Default: `Console logger with INFO level`)
|
|
43
43
|
|
|
44
|
-
**idGenerator** (`() => string`): Custom ID generator function. Used by agents, workflows, memory, and other components to generate unique identifiers.
|
|
44
|
+
**idGenerator** (`(context?: IdGeneratorContext) => string`): Custom ID generator function. Used by agents, workflows, memory, and other components to generate unique identifiers. Receives optional context such as idType, source, entityId, and threadId to support context-aware ID formats.
|
|
45
45
|
|
|
46
46
|
**workflows** (`Record<string, Workflow>`): Workflows to register. Structured as a key-value pair, with keys being the workflow name and values being the workflow instance. (Default: `{}`)
|
|
47
47
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Memory
|
|
1
|
+
# Memory class
|
|
2
2
|
|
|
3
3
|
The `Memory` class provides a robust system for managing conversation history and thread-based message storage in Mastra. It enables persistent storage of conversations, semantic search capabilities, and efficient message retrieval. You must configure a storage provider for conversation history, and if you enable semantic recall you will also need to provide a vector store and embedder.
|
|
4
4
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# DynamoDB
|
|
1
|
+
# DynamoDB storage
|
|
2
2
|
|
|
3
3
|
The DynamoDB storage implementation provides a scalable and performant NoSQL database solution for Mastra, leveraging a single-table design pattern with [ElectroDB](https://electrodb.dev/).
|
|
4
4
|
|
|
5
|
-
> **Observability Not Supported:** DynamoDB storage **
|
|
5
|
+
> **Observability Not Supported:** DynamoDB storage **doesn't support the observability domain**. Traces from the `DefaultExporter` can't be persisted to DynamoDB, and Mastra Studio's observability features won't work with DynamoDB as your only storage provider. To enable observability, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to a supported provider like ClickHouse or PostgreSQL.
|
|
6
6
|
|
|
7
7
|
> **Item Size Limit:** DynamoDB enforces a **400 KB maximum item size**. This limit can be exceeded when storing messages with base64-encoded attachments such as images. See [Handling large attachments](https://mastra.ai/docs/memory/storage) for workarounds including uploading attachments to external storage.
|
|
8
8
|
|
|
@@ -120,7 +120,7 @@ For local development, you can use [DynamoDB Local](https://docs.aws.amazon.com/
|
|
|
120
120
|
|
|
121
121
|
**config.ttl** (`object`): TTL (Time To Live) configuration for automatic data expiration. Configure per entity type: thread, message, trace, eval, workflow\_snapshot, resource, score. Each entity config includes: enabled (boolean), attributeName (string, default: 'ttl'), defaultTtlSeconds (number).
|
|
122
122
|
|
|
123
|
-
## TTL (
|
|
123
|
+
## TTL (time to live) configuration
|
|
124
124
|
|
|
125
125
|
DynamoDB TTL allows you to automatically delete items after a specified time period. This is useful for:
|
|
126
126
|
|
|
@@ -211,12 +211,12 @@ aws dynamodb update-time-to-live \
|
|
|
211
211
|
1. Go to the DynamoDB console
|
|
212
212
|
2. Select your table
|
|
213
213
|
3. Go to "Additional settings" tab
|
|
214
|
-
4. Under "Time to Live (TTL)",
|
|
214
|
+
4. Under "Time to Live (TTL)", select "Manage TTL"
|
|
215
215
|
5. Enable TTL and specify the attribute name (default: `ttl`)
|
|
216
216
|
|
|
217
217
|
> **Note:** DynamoDB deletes expired items within 48 hours after expiration. Items remain queryable until actually deleted.
|
|
218
218
|
|
|
219
|
-
## AWS IAM
|
|
219
|
+
## AWS IAM permissions
|
|
220
220
|
|
|
221
221
|
The IAM role or user executing the code needs appropriate permissions to interact with the specified DynamoDB table and its indexes. Below is a sample policy. Replace `${YOUR_TABLE_NAME}` with your actual table name and `${YOUR_AWS_REGION}` and `${YOUR_AWS_ACCOUNT_ID}` with appropriate values.
|
|
222
222
|
|
|
@@ -246,7 +246,7 @@ The IAM role or user executing the code needs appropriate permissions to interac
|
|
|
246
246
|
}
|
|
247
247
|
```
|
|
248
248
|
|
|
249
|
-
## Key
|
|
249
|
+
## Key considerations
|
|
250
250
|
|
|
251
251
|
Before diving into the architectural details, keep these key points in mind when working with the DynamoDB storage adapter:
|
|
252
252
|
|
|
@@ -255,7 +255,7 @@ Before diving into the architectural details, keep these key points in mind when
|
|
|
255
255
|
- **Understanding GSIs:** Familiarity with how the GSIs are structured (as per `TABLE_SETUP.md`) is important for understanding data retrieval and potential query patterns.
|
|
256
256
|
- **ElectroDB:** The adapter uses ElectroDB to manage interactions with DynamoDB, providing a layer of abstraction and type safety over raw DynamoDB operations.
|
|
257
257
|
|
|
258
|
-
## Architectural
|
|
258
|
+
## Architectural approach
|
|
259
259
|
|
|
260
260
|
This storage adapter utilizes a **single-table design pattern** leveraging [ElectroDB](https://electrodb.dev/), a common and recommended approach for DynamoDB. This differs architecturally from relational database adapters (like `@mastra/pg` or `@mastra/libsql`) that typically use multiple tables, each dedicated to a specific entity (threads, messages, etc.).
|
|
261
261
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# libSQL
|
|
1
|
+
# libSQL vector store
|
|
2
2
|
|
|
3
3
|
The libSQL storage implementation provides a SQLite-compatible vector search [libSQL](https://github.com/tursodatabase/libsql), a fork of SQLite with vector extensions, and [Turso](https://turso.tech/) with vector extensions, offering a lightweight and efficient vector database solution. It's part of the `@mastra/libsql` package and offers efficient vector similarity search with metadata filtering.
|
|
4
4
|
|
|
@@ -69,7 +69,7 @@ const results = await store.query({
|
|
|
69
69
|
});
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
-
## Constructor
|
|
72
|
+
## Constructor options
|
|
73
73
|
|
|
74
74
|
**url** (`string`): libSQL database URL. Use ':memory:' for in-memory database, 'file:dbname.db' for local file, or a libSQL-compatible connection string like 'libsql://your-database.turso.io'.
|
|
75
75
|
|
|
@@ -81,7 +81,7 @@ const results = await store.query({
|
|
|
81
81
|
|
|
82
82
|
## Methods
|
|
83
83
|
|
|
84
|
-
### createIndex()
|
|
84
|
+
### `createIndex()`
|
|
85
85
|
|
|
86
86
|
Creates a new vector collection. The index name must start with a letter or underscore and can only contain letters, numbers, and underscores. The dimension must be a positive integer.
|
|
87
87
|
|
|
@@ -91,7 +91,7 @@ Creates a new vector collection. The index name must start with a letter or unde
|
|
|
91
91
|
|
|
92
92
|
**metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search. Note: Currently only cosine similarity is supported by libSQL. (Default: `cosine`)
|
|
93
93
|
|
|
94
|
-
### upsert()
|
|
94
|
+
### `upsert()`
|
|
95
95
|
|
|
96
96
|
Adds or updates vectors and their metadata in the index. Uses a transaction to ensure all vectors are inserted atomically - if any insert fails, the entire operation is rolled back.
|
|
97
97
|
|
|
@@ -103,7 +103,7 @@ Adds or updates vectors and their metadata in the index. Uses a transaction to e
|
|
|
103
103
|
|
|
104
104
|
**ids** (`string[]`): Optional vector IDs (auto-generated if not provided)
|
|
105
105
|
|
|
106
|
-
### query()
|
|
106
|
+
### `query()`
|
|
107
107
|
|
|
108
108
|
Searches for similar vectors with optional metadata filtering.
|
|
109
109
|
|
|
@@ -119,7 +119,7 @@ Searches for similar vectors with optional metadata filtering.
|
|
|
119
119
|
|
|
120
120
|
**minScore** (`number`): Minimum similarity score threshold (Default: `0`)
|
|
121
121
|
|
|
122
|
-
### describeIndex()
|
|
122
|
+
### `describeIndex()`
|
|
123
123
|
|
|
124
124
|
Gets information about an index.
|
|
125
125
|
|
|
@@ -135,25 +135,25 @@ interface IndexStats {
|
|
|
135
135
|
}
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
### deleteIndex()
|
|
138
|
+
### `deleteIndex()`
|
|
139
139
|
|
|
140
140
|
Deletes an index and all its data.
|
|
141
141
|
|
|
142
142
|
**indexName** (`string`): Name of the index to delete
|
|
143
143
|
|
|
144
|
-
### listIndexes()
|
|
144
|
+
### `listIndexes()`
|
|
145
145
|
|
|
146
146
|
Lists all vector indexes in the database.
|
|
147
147
|
|
|
148
148
|
Returns: `Promise<string[]>`
|
|
149
149
|
|
|
150
|
-
### truncateIndex()
|
|
150
|
+
### `truncateIndex()`
|
|
151
151
|
|
|
152
152
|
Removes all vectors from an index while keeping the index structure.
|
|
153
153
|
|
|
154
154
|
**indexName** (`string`): Name of the index to truncate
|
|
155
155
|
|
|
156
|
-
### updateVector()
|
|
156
|
+
### `updateVector()`
|
|
157
157
|
|
|
158
158
|
Update a single vector by ID or by metadata filter. Either `id` or `filter` must be provided, but not both.
|
|
159
159
|
|
|
@@ -169,7 +169,7 @@ Update a single vector by ID or by metadata filter. Either `id` or `filter` must
|
|
|
169
169
|
|
|
170
170
|
**update.metadata** (`Record<string, any>`): New metadata to update
|
|
171
171
|
|
|
172
|
-
### deleteVector()
|
|
172
|
+
### `deleteVector()`
|
|
173
173
|
|
|
174
174
|
Deletes a specific vector entry from an index by its ID.
|
|
175
175
|
|
|
@@ -177,7 +177,7 @@ Deletes a specific vector entry from an index by its ID.
|
|
|
177
177
|
|
|
178
178
|
**id** (`string`): ID of the vector entry to delete
|
|
179
179
|
|
|
180
|
-
### deleteVectors()
|
|
180
|
+
### `deleteVectors()`
|
|
181
181
|
|
|
182
182
|
Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both.
|
|
183
183
|
|
|
@@ -187,7 +187,7 @@ Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` m
|
|
|
187
187
|
|
|
188
188
|
**filter** (`Record<string, any>`): Metadata filter to identify vectors to delete (mutually exclusive with ids)
|
|
189
189
|
|
|
190
|
-
## Response
|
|
190
|
+
## Response types
|
|
191
191
|
|
|
192
192
|
Query results are returned in this format:
|
|
193
193
|
|
|
@@ -200,7 +200,7 @@ interface QueryResult {
|
|
|
200
200
|
}
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
-
## Error
|
|
203
|
+
## Error handling
|
|
204
204
|
|
|
205
205
|
The store throws specific errors for different failure cases:
|
|
206
206
|
|
|
@@ -232,7 +232,7 @@ Common error cases include:
|
|
|
232
232
|
- Database connection issues
|
|
233
233
|
- Transaction failures during upsert
|
|
234
234
|
|
|
235
|
-
## Usage
|
|
235
|
+
## Usage example
|
|
236
236
|
|
|
237
237
|
### Local embeddings with fastembed
|
|
238
238
|
|