@mastra/libsql 1.2.0-alpha.0 → 1.3.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 +176 -0
- package/dist/docs/SKILL.md +36 -26
- package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +1 -1
- package/dist/docs/{agents/03-agent-approval.md → references/docs-agents-agent-approval.md} +19 -19
- package/dist/docs/references/docs-agents-agent-memory.md +212 -0
- package/dist/docs/{agents/04-network-approval.md → references/docs-agents-network-approval.md} +13 -12
- package/dist/docs/{agents/02-networks.md → references/docs-agents-networks.md} +10 -12
- package/dist/docs/{memory/06-memory-processors.md → references/docs-memory-memory-processors.md} +6 -8
- package/dist/docs/{memory/03-message-history.md → references/docs-memory-message-history.md} +31 -20
- package/dist/docs/{memory/01-overview.md → references/docs-memory-overview.md} +8 -8
- package/dist/docs/{memory/05-semantic-recall.md → references/docs-memory-semantic-recall.md} +33 -17
- package/dist/docs/{memory/02-storage.md → references/docs-memory-storage.md} +29 -39
- package/dist/docs/{memory/04-working-memory.md → references/docs-memory-working-memory.md} +16 -27
- package/dist/docs/{observability/01-overview.md → references/docs-observability-overview.md} +4 -7
- package/dist/docs/{observability/02-default.md → references/docs-observability-tracing-exporters-default.md} +11 -14
- package/dist/docs/{rag/01-retrieval.md → references/docs-rag-retrieval.md} +26 -53
- package/dist/docs/{workflows/01-snapshots.md → references/docs-workflows-snapshots.md} +3 -5
- package/dist/docs/{guides/01-ai-sdk.md → references/guides-agent-frameworks-ai-sdk.md} +25 -9
- package/dist/docs/references/reference-core-getMemory.md +50 -0
- package/dist/docs/references/reference-core-listMemory.md +56 -0
- package/dist/docs/references/reference-core-mastra-class.md +66 -0
- package/dist/docs/{memory/07-reference.md → references/reference-memory-memory-class.md} +28 -14
- package/dist/docs/references/reference-storage-composite.md +235 -0
- package/dist/docs/references/reference-storage-dynamodb.md +282 -0
- package/dist/docs/references/reference-storage-libsql.md +135 -0
- package/dist/docs/{vectors/01-reference.md → references/reference-vectors-libsql.md} +105 -13
- package/dist/index.cjs +1676 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1676 -196
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/agents/index.d.ts +9 -12
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +7 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/prompt-blocks/index.d.ts +25 -0
- package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts +26 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +3 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +5 -6
- package/dist/docs/README.md +0 -39
- package/dist/docs/agents/01-agent-memory.md +0 -166
- package/dist/docs/core/01-reference.md +0 -151
- package/dist/docs/storage/01-reference.md +0 -556
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# libSQL Storage
|
|
2
|
+
|
|
3
|
+
[libSQL](https://docs.turso.tech/libsql) is an open-source, SQLite-compatible database that supports both local and remote deployments. It can be used to store message history, workflow snapshots, traces, and eval scores.
|
|
4
|
+
|
|
5
|
+
For vectors like semantic recall or traditional RAG, use [libSQL Vector](https://mastra.ai/reference/vectors/libsql) which covers embeddings and vector search.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Storage providers must be installed as separate packages:
|
|
10
|
+
|
|
11
|
+
**npm**:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @mastra/libsql@latest
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**pnpm**:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @mastra/libsql@latest
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Yarn**:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
yarn add @mastra/libsql@latest
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Bun**:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bun add @mastra/libsql@latest
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
39
|
+
import { Mastra } from "@mastra/core";
|
|
40
|
+
|
|
41
|
+
const mastra = new Mastra({
|
|
42
|
+
storage: new LibSQLStore({
|
|
43
|
+
id: 'libsql-storage',
|
|
44
|
+
url: "file:./storage.db",
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Agent-level file storage:
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { Memory } from "@mastra/memory";
|
|
53
|
+
import { Agent } from "@mastra/core/agent";
|
|
54
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
55
|
+
|
|
56
|
+
export const agent = new Agent({
|
|
57
|
+
id: "example-agent",
|
|
58
|
+
memory: new Memory({
|
|
59
|
+
storage: new LibSQLStore({
|
|
60
|
+
id: 'libsql-storage',
|
|
61
|
+
url: "file:./agent.db",
|
|
62
|
+
}),
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
> **Warning:** File storage doesn't work with serverless platforms that have ephemeral file systems. For serverless deployments, use [Turso](https://turso.tech) or a different database engine.
|
|
68
|
+
|
|
69
|
+
Production with remote database:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
storage: new LibSQLStore({
|
|
73
|
+
id: 'libsql-storage',
|
|
74
|
+
url: "libsql://your-db-name.aws-ap-northeast-1.turso.io",
|
|
75
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
For local development and testing, you can store data in memory:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
storage: new LibSQLStore({
|
|
83
|
+
id: 'libsql-storage',
|
|
84
|
+
url: ":memory:",
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
> **Warning:** In-memory storage resets when the process changes. Only suitable for development.
|
|
89
|
+
|
|
90
|
+
## Options
|
|
91
|
+
|
|
92
|
+
**url:** (`string`): Database URL. Use \`:memory:\` for in-memory database, \`file:filename.db\` for a file database, or a libSQL connection string (e.g., \`libsql://your-database.turso.io\`) for remote storage.
|
|
93
|
+
|
|
94
|
+
**authToken?:** (`string`): Authentication token for remote libSQL databases.
|
|
95
|
+
|
|
96
|
+
## Initialization
|
|
97
|
+
|
|
98
|
+
When you pass storage to the Mastra class, `init()` is called automatically to create the [core schema](https://mastra.ai/reference/storage/overview):
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { Mastra } from "@mastra/core";
|
|
102
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
103
|
+
|
|
104
|
+
const storage = new LibSQLStore({
|
|
105
|
+
id: 'libsql-storage',
|
|
106
|
+
url: "file:./storage.db",
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const mastra = new Mastra({
|
|
110
|
+
storage, // init() called automatically
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
If using storage directly without Mastra, call `init()` explicitly:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
118
|
+
|
|
119
|
+
const storage = new LibSQLStore({
|
|
120
|
+
id: 'libsql-storage',
|
|
121
|
+
url: "file:./storage.db",
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
await storage.init();
|
|
125
|
+
|
|
126
|
+
// Access domain-specific stores via getStore()
|
|
127
|
+
const memoryStore = await storage.getStore('memory');
|
|
128
|
+
const thread = await memoryStore?.getThreadById({ threadId: "..." });
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Observability
|
|
132
|
+
|
|
133
|
+
libSQL supports observability and is ideal for local development. Use the `realtime` [tracing strategy](https://mastra.ai/docs/observability/tracing/exporters/default) for immediate visibility while debugging.
|
|
134
|
+
|
|
135
|
+
For production environments with higher trace volumes, consider using [PostgreSQL](https://mastra.ai/reference/storage/postgresql) or [ClickHouse via composite storage](https://mastra.ai/reference/storage/composite).
|
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
#
|
|
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
|
|
|
5
|
+
## Installation
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
**npm**:
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mastra/libsql@latest
|
|
11
|
+
```
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
**pnpm**:
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @mastra/libsql@latest
|
|
17
|
+
```
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
**Yarn**:
|
|
16
20
|
|
|
17
|
-
```bash
|
|
18
|
-
|
|
21
|
+
```bash
|
|
22
|
+
yarn add @mastra/libsql@latest
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Bun**:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
bun add @mastra/libsql@latest
|
|
19
29
|
```
|
|
20
30
|
|
|
21
31
|
## Usage
|
|
@@ -61,24 +71,60 @@ const results = await store.query({
|
|
|
61
71
|
|
|
62
72
|
## Constructor Options
|
|
63
73
|
|
|
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
|
+
|
|
76
|
+
**authToken?:** (`string`): Authentication token for Turso cloud databases
|
|
77
|
+
|
|
78
|
+
**syncUrl?:** (`string`): URL for database replication (Turso specific)
|
|
79
|
+
|
|
80
|
+
**syncInterval?:** (`number`): Interval in milliseconds for database sync (Turso specific)
|
|
81
|
+
|
|
64
82
|
## Methods
|
|
65
83
|
|
|
66
84
|
### createIndex()
|
|
67
85
|
|
|
68
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.
|
|
69
87
|
|
|
88
|
+
**indexName:** (`string`): Name of the index to create
|
|
89
|
+
|
|
90
|
+
**dimension:** (`number`): Vector dimension size (must match your embedding model)
|
|
91
|
+
|
|
92
|
+
**metric?:** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search. Note: Currently only cosine similarity is supported by libSQL. (Default: `cosine`)
|
|
93
|
+
|
|
70
94
|
### upsert()
|
|
71
95
|
|
|
72
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.
|
|
73
97
|
|
|
98
|
+
**indexName:** (`string`): Name of the index to insert into
|
|
99
|
+
|
|
100
|
+
**vectors:** (`number[][]`): Array of embedding vectors
|
|
101
|
+
|
|
102
|
+
**metadata?:** (`Record<string, any>[]`): Metadata for each vector
|
|
103
|
+
|
|
104
|
+
**ids?:** (`string[]`): Optional vector IDs (auto-generated if not provided)
|
|
105
|
+
|
|
74
106
|
### query()
|
|
75
107
|
|
|
76
108
|
Searches for similar vectors with optional metadata filtering.
|
|
77
109
|
|
|
110
|
+
**indexName:** (`string`): Name of the index to search in
|
|
111
|
+
|
|
112
|
+
**queryVector:** (`number[]`): Query vector to find similar vectors for
|
|
113
|
+
|
|
114
|
+
**topK?:** (`number`): Number of results to return (Default: `10`)
|
|
115
|
+
|
|
116
|
+
**filter?:** (`Filter`): Metadata filters
|
|
117
|
+
|
|
118
|
+
**includeVector?:** (`boolean`): Whether to include vector data in results (Default: `false`)
|
|
119
|
+
|
|
120
|
+
**minScore?:** (`number`): Minimum similarity score threshold (Default: `0`)
|
|
121
|
+
|
|
78
122
|
### describeIndex()
|
|
79
123
|
|
|
80
124
|
Gets information about an index.
|
|
81
125
|
|
|
126
|
+
**indexName:** (`string`): Name of the index to describe
|
|
127
|
+
|
|
82
128
|
Returns:
|
|
83
129
|
|
|
84
130
|
```typescript
|
|
@@ -93,6 +139,8 @@ interface IndexStats {
|
|
|
93
139
|
|
|
94
140
|
Deletes an index and all its data.
|
|
95
141
|
|
|
142
|
+
**indexName:** (`string`): Name of the index to delete
|
|
143
|
+
|
|
96
144
|
### listIndexes()
|
|
97
145
|
|
|
98
146
|
Lists all vector indexes in the database.
|
|
@@ -103,18 +151,42 @@ Returns: `Promise<string[]>`
|
|
|
103
151
|
|
|
104
152
|
Removes all vectors from an index while keeping the index structure.
|
|
105
153
|
|
|
154
|
+
**indexName:** (`string`): Name of the index to truncate
|
|
155
|
+
|
|
106
156
|
### updateVector()
|
|
107
157
|
|
|
108
158
|
Update a single vector by ID or by metadata filter. Either `id` or `filter` must be provided, but not both.
|
|
109
159
|
|
|
160
|
+
**indexName:** (`string`): Name of the index containing the vector
|
|
161
|
+
|
|
162
|
+
**id?:** (`string`): ID of the vector entry to update (mutually exclusive with filter)
|
|
163
|
+
|
|
164
|
+
**filter?:** (`Record<string, any>`): Metadata filter to identify vector(s) to update (mutually exclusive with id)
|
|
165
|
+
|
|
166
|
+
**update:** (`object`): Update data containing vector and/or metadata
|
|
167
|
+
|
|
168
|
+
**update.vector?:** (`number[]`): New vector data to update
|
|
169
|
+
|
|
170
|
+
**update.metadata?:** (`Record<string, any>`): New metadata to update
|
|
171
|
+
|
|
110
172
|
### deleteVector()
|
|
111
173
|
|
|
112
174
|
Deletes a specific vector entry from an index by its ID.
|
|
113
175
|
|
|
176
|
+
**indexName:** (`string`): Name of the index containing the vector
|
|
177
|
+
|
|
178
|
+
**id:** (`string`): ID of the vector entry to delete
|
|
179
|
+
|
|
114
180
|
### deleteVectors()
|
|
115
181
|
|
|
116
182
|
Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both.
|
|
117
183
|
|
|
184
|
+
**indexName:** (`string`): Name of the index containing the vectors to delete
|
|
185
|
+
|
|
186
|
+
**ids?:** (`string[]`): Array of vector IDs to delete (mutually exclusive with filter)
|
|
187
|
+
|
|
188
|
+
**filter?:** (`Record<string, any>`): Metadata filter to identify vectors to delete (mutually exclusive with ids)
|
|
189
|
+
|
|
118
190
|
## Response Types
|
|
119
191
|
|
|
120
192
|
Query results are returned in this format:
|
|
@@ -168,13 +240,33 @@ Embeddings are numeric vectors used by memory's `semanticRecall` to retrieve rel
|
|
|
168
240
|
|
|
169
241
|
Install `fastembed` to get started:
|
|
170
242
|
|
|
171
|
-
|
|
243
|
+
**npm**:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
172
246
|
npm install @mastra/fastembed@latest
|
|
173
247
|
```
|
|
174
248
|
|
|
249
|
+
**pnpm**:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
pnpm add @mastra/fastembed@latest
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**Yarn**:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
yarn add @mastra/fastembed@latest
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Bun**:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
bun add @mastra/fastembed@latest
|
|
265
|
+
```
|
|
266
|
+
|
|
175
267
|
Add the following to your agent:
|
|
176
268
|
|
|
177
|
-
```typescript
|
|
269
|
+
```typescript
|
|
178
270
|
import { Memory } from "@mastra/memory";
|
|
179
271
|
import { Agent } from "@mastra/core/agent";
|
|
180
272
|
import { LibSQLStore, LibSQLVector } from "@mastra/libsql";
|
|
@@ -210,4 +302,4 @@ export const libsqlAgent = new Agent({
|
|
|
210
302
|
|
|
211
303
|
## Related
|
|
212
304
|
|
|
213
|
-
- [Metadata Filters](
|
|
305
|
+
- [Metadata Filters](https://mastra.ai/reference/rag/metadata-filters)
|