@mastra/lance 0.1.1-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.
@@ -0,0 +1,23 @@
1
+
2
+ > @mastra/lance@0.1.1-alpha.0 build /home/runner/work/mastra/mastra/stores/lance
3
+ > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.0
8
+ TSC Build start
9
+ TSC ⚡️ Build success in 11991ms
10
+ DTS Build start
11
+ CLI Target: es2022
12
+ Analysis will use the bundled TypeScript version 5.8.3
13
+ Writing package typings: /home/runner/work/mastra/mastra/stores/lance/dist/_tsup-dts-rollup.d.ts
14
+ Analysis will use the bundled TypeScript version 5.8.3
15
+ Writing package typings: /home/runner/work/mastra/mastra/stores/lance/dist/_tsup-dts-rollup.d.cts
16
+ DTS ⚡️ Build success in 13115ms
17
+ CLI Cleaning output folder
18
+ ESM Build start
19
+ CJS Build start
20
+ ESM dist/index.js 52.70 KB
21
+ ESM ⚡️ Build success in 1414ms
22
+ CJS dist/index.cjs 52.99 KB
23
+ CJS ⚡️ Build success in 1414ms
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @mastra/lance
2
+
3
+ ## 0.1.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - dffb67b: updated stores to add alter table and change tests
8
+ - f7f8293: Added LanceDB implementations for MastraVector and MastraStorage
9
+ - Updated dependencies [f6fd25f]
10
+ - Updated dependencies [dffb67b]
11
+ - Updated dependencies [f1309d3]
12
+ - Updated dependencies [f7f8293]
13
+ - @mastra/core@0.10.4-alpha.1
package/LICENSE.md ADDED
@@ -0,0 +1,46 @@
1
+ # Elastic License 2.0 (ELv2)
2
+
3
+ Copyright (c) 2025 Mastra AI, Inc.
4
+
5
+ **Acceptance**
6
+ By using the software, you agree to all of the terms and conditions below.
7
+
8
+ **Copyright License**
9
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
10
+
11
+ **Limitations**
12
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
13
+
14
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
15
+
16
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
17
+
18
+ **Patents**
19
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
20
+
21
+ **Notices**
22
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
23
+
24
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
25
+
26
+ **No Other Rights**
27
+ These terms do not imply any licenses other than those expressly granted in these terms.
28
+
29
+ **Termination**
30
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
31
+
32
+ **No Liability**
33
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
34
+
35
+ **Definitions**
36
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
37
+
38
+ _you_ refers to the individual or entity agreeing to these terms.
39
+
40
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
41
+
42
+ _your licenses_ are all the licenses granted to you for the software under these terms.
43
+
44
+ _use_ means anything you do with the software requiring one of your licenses.
45
+
46
+ _trademark_ means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,263 @@
1
+ # Mastra LanceDB Storage & Vector Usage Guide
2
+
3
+ This guide explains how to use LanceDB as both a storage backend and vector database with Mastra. LanceDB provides a high-performance, open-source, and embeddable vector database built on [Lance](https://github.com/eto-ai/lance) file format.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @mastra/lance @lancedb/lancedb apache-arrow
9
+ ```
10
+
11
+ ## Setup & Configuration
12
+
13
+ ### Basic Setup
14
+
15
+ ```typescript
16
+ import { LanceStorage } from '@mastra/lance';
17
+ import { Mastra } from '@mastra/core/mastra';
18
+
19
+ // Initialize LanceStorage
20
+ const storage = await LanceStorage.create(
21
+ 'myApp', // Name for your storage instance
22
+ 'path/to/db', // Path to database directory
23
+ );
24
+
25
+ // Configure Mastra with LanceStorage
26
+ const mastra = new Mastra({
27
+ storage: storage,
28
+ });
29
+ ```
30
+
31
+ ### Connection Options
32
+
33
+ LanceStorage supports multiple connection configurations:
34
+
35
+ ```typescript
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.getMessages({
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';
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';
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 context
179
+ const retrievedMessages = await storage.getMessages({
180
+ threadId: '123e4567-e89b-12d3-a456-426614174010',
181
+ selectBy: [
182
+ {
183
+ id: 'msg-001',
184
+ withPreviousMessages: 5, // Include up to 5 messages before this one
185
+ withNextMessages: 5, // Include up to 5 messages after this one
186
+ },
187
+ ],
188
+ });
189
+ ```
190
+
191
+ ## Working with Workflows
192
+
193
+ Mastra's workflow system uses LanceDB to persist workflow state for continuity across runs:
194
+
195
+ ```typescript
196
+ import type { WorkflowRunState } from '@mastra/core';
197
+
198
+ // Persist a workflow snapshot
199
+ await storage.persistWorkflowSnapshot({
200
+ workflowName: 'documentProcessing',
201
+ runId: 'run-123',
202
+ snapshot: {
203
+ context: {
204
+ steps: {
205
+ step1: { status: 'success', payload: { data: 'processed' } },
206
+ step2: { status: 'waiting' },
207
+ },
208
+ triggerData: { documentId: 'doc-123' },
209
+ attempts: { step1: 1, step2: 0 },
210
+ },
211
+ } as WorkflowRunState,
212
+ });
213
+
214
+ // Load a workflow snapshot
215
+ const workflowState = await storage.loadWorkflowSnapshot({
216
+ workflowName: 'documentProcessing',
217
+ runId: 'run-123',
218
+ });
219
+ ```
220
+
221
+ ## Using Lance for Vector Storage
222
+
223
+ The LanceDB integration in Mastra can be used for both traditional storage and vector search:
224
+
225
+ ```typescript
226
+ // Create a schema with vector field
227
+ const vectorSchema: Record<string, StorageColumn> = {
228
+ id: { type: 'uuid', nullable: false },
229
+ content: { type: 'text', nullable: true },
230
+ embedding: { type: 'binary', nullable: false }, // Vector embedding
231
+ metadata: { type: 'jsonb', nullable: true },
232
+ };
233
+
234
+ // Create a vector table
235
+ await storage.createTable({
236
+ tableName: 'vector_store',
237
+ schema: vectorSchema,
238
+ });
239
+
240
+ // Insert a vector with content and metadata
241
+ await storage.insert({
242
+ tableName: 'vector_store',
243
+ record: {
244
+ id: 'vec-001',
245
+ content: 'This is a document about LanceDB and Mastra integration',
246
+ embedding: new Float32Array([0.1, 0.2, 0.3, 0.4]), // Your embedding vector
247
+ metadata: { source: 'documentation', category: 'integration' },
248
+ },
249
+ });
250
+ ```
251
+
252
+ ## Data Management
253
+
254
+ ```typescript
255
+ // Drop a table
256
+ await storage.dropTable(TABLE_MESSAGES);
257
+
258
+ // Clear all records from a table
259
+ await storage.clearTable({ tableName: TABLE_MESSAGES });
260
+
261
+ // Get table schema
262
+ const schema = await storage.getTableSchema(TABLE_MESSAGES);
263
+ ```