@mastra/lance 1.3.2-alpha.0 → 1.3.2
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/README.md +17 -300
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,320 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mastra/lance
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@mastra/lance` provides Mastra storage and vector search backed by the embedded LanceDB database. Use it when you want local, file-based persistence and semantic search without operating a separate database service.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
8
|
+
npm install @mastra/lance
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Create a local LanceDB vector store, then create an index before writing embeddings.
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
|
-
import {
|
|
17
|
-
import { Mastra } from '@mastra/core/mastra';
|
|
16
|
+
import { LanceVectorStore } from '@mastra/lance';
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
const storage = await LanceStorage.create(
|
|
21
|
-
'myApp', // Name for your storage instance
|
|
22
|
-
'path/to/db', // Path to database directory
|
|
23
|
-
);
|
|
18
|
+
const vectorStore = await LanceVectorStore.create('./data/lancedb');
|
|
24
19
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
await vectorStore.createIndex({
|
|
21
|
+
indexName: 'documents',
|
|
22
|
+
dimension: 1536,
|
|
28
23
|
});
|
|
29
24
|
```
|
|
30
25
|
|
|
31
|
-
|
|
26
|
+
## Documentation
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
- [LanceDB integration guide](https://mastra.ai/integrations/databases/lancedb)
|
|
29
|
+
- [Lance vector reference](https://mastra.ai/reference/vectors/lance)
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
// Local database
|
|
37
|
-
const localStore = await LanceStorage.create('myApp', '/path/to/db');
|
|
38
|
-
|
|
39
|
-
// LanceDB Cloud
|
|
40
|
-
const cloudStore = await LanceStorage.create('myApp', 'db://host:port');
|
|
41
|
-
|
|
42
|
-
// S3 bucket
|
|
43
|
-
const s3Store = await LanceStorage.create('myApp', 's3://bucket/db', { storageOptions: { timeout: '60s' } });
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Basic Operations
|
|
47
|
-
|
|
48
|
-
### Creating Tables
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
import { TABLE_MESSAGES } from '@mastra/core/storage';
|
|
52
|
-
import type { StorageColumn } from '@mastra/core/storage';
|
|
53
|
-
|
|
54
|
-
// Define schema with appropriate types
|
|
55
|
-
const schema: Record<string, StorageColumn> = {
|
|
56
|
-
id: { type: 'uuid', nullable: false },
|
|
57
|
-
threadId: { type: 'uuid', nullable: false },
|
|
58
|
-
content: { type: 'text', nullable: true },
|
|
59
|
-
createdAt: { type: 'timestamp', nullable: false },
|
|
60
|
-
metadata: { type: 'jsonb', nullable: true },
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// Create table
|
|
64
|
-
await storage.createTable({
|
|
65
|
-
tableName: TABLE_MESSAGES,
|
|
66
|
-
schema,
|
|
67
|
-
});
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Inserting Records
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
// Insert a single record
|
|
74
|
-
await storage.insert({
|
|
75
|
-
tableName: TABLE_MESSAGES,
|
|
76
|
-
record: {
|
|
77
|
-
id: '123e4567-e89b-12d3-a456-426614174000',
|
|
78
|
-
threadId: '123e4567-e89b-12d3-a456-426614174001',
|
|
79
|
-
content: 'Hello, world!',
|
|
80
|
-
createdAt: new Date(),
|
|
81
|
-
metadata: { tags: ['important', 'greeting'] },
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// Batch insert multiple records
|
|
86
|
-
await storage.batchInsert({
|
|
87
|
-
tableName: TABLE_MESSAGES,
|
|
88
|
-
records: [
|
|
89
|
-
{
|
|
90
|
-
id: '123e4567-e89b-12d3-a456-426614174002',
|
|
91
|
-
threadId: '123e4567-e89b-12d3-a456-426614174001',
|
|
92
|
-
content: 'First message',
|
|
93
|
-
createdAt: new Date(),
|
|
94
|
-
metadata: { priority: 'high' },
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
id: '123e4567-e89b-12d3-a456-426614174003',
|
|
98
|
-
threadId: '123e4567-e89b-12d3-a456-426614174001',
|
|
99
|
-
content: 'Second message',
|
|
100
|
-
createdAt: new Date(),
|
|
101
|
-
metadata: { priority: 'low' },
|
|
102
|
-
},
|
|
103
|
-
],
|
|
104
|
-
});
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Querying Data
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
// Load a record by id
|
|
111
|
-
const message = await storage.load({
|
|
112
|
-
tableName: TABLE_MESSAGES,
|
|
113
|
-
keys: { id: '123e4567-e89b-12d3-a456-426614174000' },
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// Load messages from a thread
|
|
117
|
-
const messages = await storage.listMessages({
|
|
118
|
-
threadId: '123e4567-e89b-12d3-a456-426614174001',
|
|
119
|
-
});
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
## Working with Threads & Messages
|
|
123
|
-
|
|
124
|
-
### Creating Threads
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
import type { StorageThreadType } from '@mastra/core/storage';
|
|
128
|
-
|
|
129
|
-
// Create a new thread
|
|
130
|
-
const thread: StorageThreadType = {
|
|
131
|
-
id: '123e4567-e89b-12d3-a456-426614174010',
|
|
132
|
-
resourceId: 'resource-123',
|
|
133
|
-
title: 'New Discussion',
|
|
134
|
-
createdAt: new Date(),
|
|
135
|
-
metadata: { topic: 'technical-support' },
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// Save the thread
|
|
139
|
-
const savedThread = await storage.saveThread({ thread });
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Working with Messages
|
|
143
|
-
|
|
144
|
-
```typescript
|
|
145
|
-
import type { MessageType } from '@mastra/core/memory';
|
|
146
|
-
|
|
147
|
-
// Create messages
|
|
148
|
-
const messages: MessageType[] = [
|
|
149
|
-
{
|
|
150
|
-
id: 'msg-001',
|
|
151
|
-
threadId: '123e4567-e89b-12d3-a456-426614174010',
|
|
152
|
-
resourceId: 'resource-123',
|
|
153
|
-
role: 'user',
|
|
154
|
-
content: 'How can I use LanceDB with Mastra?',
|
|
155
|
-
createdAt: new Date(),
|
|
156
|
-
type: 'text',
|
|
157
|
-
toolCallIds: [],
|
|
158
|
-
toolCallArgs: [],
|
|
159
|
-
toolNames: [],
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
id: 'msg-002',
|
|
163
|
-
threadId: '123e4567-e89b-12d3-a456-426614174010',
|
|
164
|
-
resourceId: 'resource-123',
|
|
165
|
-
role: 'assistant',
|
|
166
|
-
content: 'You can use LanceDB with Mastra by installing @mastra/lance package.',
|
|
167
|
-
createdAt: new Date(),
|
|
168
|
-
type: 'text',
|
|
169
|
-
toolCallIds: [],
|
|
170
|
-
toolCallArgs: [],
|
|
171
|
-
toolNames: [],
|
|
172
|
-
},
|
|
173
|
-
];
|
|
174
|
-
|
|
175
|
-
// Save messages
|
|
176
|
-
await storage.saveMessages({ messages });
|
|
177
|
-
|
|
178
|
-
// Retrieve messages with pagination and context
|
|
179
|
-
const retrievedMessages = await storage.listMessages({
|
|
180
|
-
threadId: '123e4567-e89b-12d3-a456-426614174010',
|
|
181
|
-
perPage: 10,
|
|
182
|
-
page: 0,
|
|
183
|
-
include: [
|
|
184
|
-
{
|
|
185
|
-
id: 'msg-001',
|
|
186
|
-
withPreviousMessages: 5, // Include up to 5 messages before this one
|
|
187
|
-
withNextMessages: 5, // Include up to 5 messages after this one
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
});
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## Working with Workflows
|
|
194
|
-
|
|
195
|
-
Mastra's workflow system uses LanceDB to persist workflow state for continuity across runs:
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
import type { WorkflowRunState } from '@mastra/core/storage';
|
|
199
|
-
|
|
200
|
-
// Persist a workflow snapshot
|
|
201
|
-
await storage.persistWorkflowSnapshot({
|
|
202
|
-
workflowName: 'documentProcessing',
|
|
203
|
-
runId: 'run-123',
|
|
204
|
-
snapshot: {
|
|
205
|
-
context: {
|
|
206
|
-
steps: {
|
|
207
|
-
step1: { status: 'success', payload: { data: 'processed' } },
|
|
208
|
-
step2: { status: 'waiting' },
|
|
209
|
-
},
|
|
210
|
-
triggerData: { documentId: 'doc-123' },
|
|
211
|
-
attempts: { step1: 1, step2: 0 },
|
|
212
|
-
},
|
|
213
|
-
} as WorkflowRunState,
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
// Load a workflow snapshot
|
|
217
|
-
const workflowState = await storage.loadWorkflowSnapshot({
|
|
218
|
-
workflowName: 'documentProcessing',
|
|
219
|
-
runId: 'run-123',
|
|
220
|
-
});
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
## Using Lance for Vector Storage
|
|
224
|
-
|
|
225
|
-
The LanceDB integration in Mastra can be used for both traditional storage and vector search:
|
|
226
|
-
|
|
227
|
-
```typescript
|
|
228
|
-
// Create a schema with vector field
|
|
229
|
-
const vectorSchema: Record<string, StorageColumn> = {
|
|
230
|
-
id: { type: 'uuid', nullable: false },
|
|
231
|
-
content: { type: 'text', nullable: true },
|
|
232
|
-
embedding: { type: 'binary', nullable: false }, // Vector embedding
|
|
233
|
-
metadata: { type: 'jsonb', nullable: true },
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
// Create a vector table
|
|
237
|
-
await storage.createTable({
|
|
238
|
-
tableName: 'vector_store',
|
|
239
|
-
schema: vectorSchema,
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
// Insert a vector with content and metadata
|
|
243
|
-
await storage.insert({
|
|
244
|
-
tableName: 'vector_store',
|
|
245
|
-
record: {
|
|
246
|
-
id: 'vec-001',
|
|
247
|
-
content: 'This is a document about LanceDB and Mastra integration',
|
|
248
|
-
embedding: new Float32Array([0.1, 0.2, 0.3, 0.4]), // Your embedding vector
|
|
249
|
-
metadata: { source: 'documentation', category: 'integration' },
|
|
250
|
-
},
|
|
251
|
-
});
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
## Data Management
|
|
255
|
-
|
|
256
|
-
```typescript
|
|
257
|
-
// Drop a table
|
|
258
|
-
await storage.dropTable(TABLE_MESSAGES);
|
|
259
|
-
|
|
260
|
-
// Clear all records from a table
|
|
261
|
-
await storage.clearTable({ tableName: TABLE_MESSAGES });
|
|
262
|
-
|
|
263
|
-
// Get table schema
|
|
264
|
-
const schema = await storage.getTableSchema(TABLE_MESSAGES);
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
## Storage Methods
|
|
268
|
-
|
|
269
|
-
### Thread Operations
|
|
270
|
-
|
|
271
|
-
- `saveThread({ thread })`: Create or update a thread
|
|
272
|
-
- `getThreadById({ threadId })`: Get a thread by ID
|
|
273
|
-
- `listThreadsByResourceId({ resourceId, offset, limit, orderBy? })`: List paginated threads for a resource
|
|
274
|
-
- `updateThread({ id, title, metadata })`: Update thread title and/or metadata
|
|
275
|
-
- `deleteThread({ threadId })`: Delete a thread and its messages
|
|
276
|
-
|
|
277
|
-
### Message Operations
|
|
278
|
-
|
|
279
|
-
- `saveMessages({ messages })`: Save multiple messages in a transaction
|
|
280
|
-
- `listMessages({ threadId, resourceId?, perPage?, page?, orderBy?, filter?, include? })`: Get messages for a thread with pagination and optional context inclusion
|
|
281
|
-
- `listMessagesById({ messageIds })`: Get specific messages by their IDs
|
|
282
|
-
- `updateMessages({ messages })`: Update existing messages
|
|
283
|
-
|
|
284
|
-
### Resource Operations
|
|
285
|
-
|
|
286
|
-
- `getResourceById({ resourceId })`: Get a resource by ID
|
|
287
|
-
- `saveResource({ resource })`: Create or save a resource
|
|
288
|
-
- `updateResource({ resourceId, workingMemory })`: Update resource working memory
|
|
289
|
-
|
|
290
|
-
### Workflow Operations
|
|
291
|
-
|
|
292
|
-
- `persistWorkflowSnapshot({ workflowName, runId, snapshot })`: Save workflow state
|
|
293
|
-
- `loadWorkflowSnapshot({ workflowName, runId })`: Load workflow state
|
|
294
|
-
- `listWorkflowRuns({ workflowName?, pagination? })`: List workflow runs with pagination
|
|
295
|
-
- `getWorkflowRunById({ runId, workflowName? })`: Get a specific workflow run
|
|
296
|
-
- `updateWorkflowState({ workflowName, runId, state })`: Update workflow state
|
|
297
|
-
- `updateWorkflowResults({ workflowName, runId, results })`: Update workflow results
|
|
298
|
-
|
|
299
|
-
### Evaluation/Scoring Operations
|
|
300
|
-
|
|
301
|
-
- `getScoreById({ id })`: Get a score by ID
|
|
302
|
-
- `saveScore(score)`: Save an evaluation score
|
|
303
|
-
- `listScoresByScorerId({ scorerId, pagination })`: List scores by scorer with pagination
|
|
304
|
-
- `listScoresByRunId({ runId, pagination })`: List scores by run with pagination
|
|
305
|
-
- `listScoresByEntityId({ entityId, entityType, pagination })`: List scores by entity with pagination
|
|
306
|
-
- `listScoresBySpan({ traceId, spanId, pagination })`: List scores by span with pagination
|
|
307
|
-
|
|
308
|
-
### Low-Level Operations
|
|
31
|
+
## Changelog
|
|
309
32
|
|
|
310
|
-
|
|
311
|
-
- `dropTable({ tableName })`: Drop a table
|
|
312
|
-
- `clearTable({ tableName })`: Clear all records from a table
|
|
313
|
-
- `insert({ tableName, record })`: Insert a single record
|
|
314
|
-
- `batchInsert({ tableName, records })`: Insert multiple records
|
|
315
|
-
- `load({ tableName, keys })`: Load a record by keys
|
|
33
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/stores/lance/CHANGELOG.md) for version history and release notes.
|
|
316
34
|
|
|
317
|
-
|
|
35
|
+
## Support
|
|
318
36
|
|
|
319
|
-
|
|
320
|
-
- AI Observability (traces/spans): Not currently supported
|
|
37
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
package/dist/docs/SKILL.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/lance",
|
|
3
|
-
"version": "1.3.2
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Lance provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"tsx": "^4.23.1",
|
|
32
32
|
"typescript": "^7.0.2",
|
|
33
33
|
"vitest": "4.1.10",
|
|
34
|
-
"@internal/lint": "0.0.
|
|
35
|
-
"@internal/
|
|
36
|
-
"@internal/
|
|
37
|
-
"@mastra/core": "^1.64.0
|
|
34
|
+
"@internal/lint": "0.0.130",
|
|
35
|
+
"@internal/storage-test-utils": "0.0.126",
|
|
36
|
+
"@internal/types-builder": "0.0.105",
|
|
37
|
+
"@mastra/core": "^1.64.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@mastra/core": ">=1.53.0-0 <2.0.0-0"
|