@mastra/lance 1.0.0-beta.0 → 1.0.0-beta.10

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,113 @@
1
+ # Storage API Reference
2
+
3
+ > API reference for storage - 1 entries
4
+
5
+
6
+ ---
7
+
8
+ ## Reference: LanceDB Storage
9
+
10
+ > Documentation for the LanceDB storage implementation in Mastra.
11
+
12
+ The LanceDB storage implementation provides a high-performance storage solution using the LanceDB database system, which excels at handling both traditional data storage and vector operations.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @mastra/lance@beta
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### Basic Storage Usage
23
+
24
+ ```typescript
25
+ import { LanceStorage } from "@mastra/lance";
26
+
27
+ // Connect to a local database
28
+ const storage = await LanceStorage.create("my-storage", "/path/to/db");
29
+
30
+ // Connect to a LanceDB cloud database
31
+ const storage = await LanceStorage.create("my-storage", "db://host:port");
32
+
33
+ // Connect to a cloud database with custom options
34
+ const storage = await LanceStorage.create("my-storage", "s3://bucket/db", {
35
+ storageOptions: { timeout: "60s" },
36
+ });
37
+ ```
38
+
39
+ ## Parameters
40
+
41
+ ### LanceStorage.create()
42
+
43
+ ## Additional Notes
44
+
45
+ ### Schema Management
46
+
47
+ The LanceStorage implementation automatically handles schema creation and updates. It maps Mastra's schema types to Apache Arrow data types, which are used by LanceDB internally:
48
+
49
+ - `text`, `uuid` → Utf8
50
+ - `int`, `integer` → Int32
51
+ - `float` → Float32
52
+ - `jsonb`, `json` → Utf8 (serialized)
53
+ - `binary` → Binary
54
+
55
+ ### Initialization
56
+
57
+ When you pass storage to the Mastra class, `init()` is called automatically before any storage operation:
58
+
59
+ ```typescript
60
+ import { Mastra } from "@mastra/core";
61
+ import { LanceStorage } from "@mastra/lance";
62
+
63
+ const storage = await LanceStorage.create("my-storage", "/path/to/db");
64
+
65
+ const mastra = new Mastra({
66
+ storage, // init() is called automatically
67
+ });
68
+ ```
69
+
70
+ If you're using storage directly without Mastra, you must call `init()` explicitly to create the tables:
71
+
72
+ ```typescript
73
+ import { LanceStorage } from "@mastra/lance";
74
+
75
+ const storage = await LanceStorage.create("my-storage", "/path/to/db");
76
+
77
+ // Required when using storage directly
78
+ await storage.init();
79
+
80
+ // Access domain-specific stores via getStore()
81
+ const memoryStore = await storage.getStore('memory');
82
+ const thread = await memoryStore?.getThreadById({ threadId: "..." });
83
+ ```
84
+
85
+ > **Note:**
86
+ If `init()` is not called, tables won't be created and storage operations will fail silently or throw errors.
87
+
88
+ ### Deployment Options
89
+
90
+ LanceDB storage can be configured for different deployment scenarios:
91
+
92
+ - **Local Development**: Use a local file path for development and testing
93
+ ```
94
+ /path/to/db
95
+ ```
96
+ - **Cloud Deployment**: Connect to a hosted LanceDB instance
97
+ ```
98
+ db://host:port
99
+ ```
100
+ - **S3 Storage**: Use Amazon S3 for scalable cloud storage
101
+ ```
102
+ s3://bucket/db
103
+ ```
104
+
105
+ ### Table Management
106
+
107
+ LanceStorage provides methods for managing tables:
108
+
109
+ - Create tables with custom schemas
110
+ - Drop tables
111
+ - Clear tables (delete all records)
112
+ - Load records by key
113
+ - Insert single and batch records
@@ -0,0 +1,149 @@
1
+ # Vectors API Reference
2
+
3
+ > API reference for vectors - 1 entries
4
+
5
+
6
+ ---
7
+
8
+ ## Reference: Lance Vector Store
9
+
10
+ > Documentation for the LanceVectorStore class in Mastra, which provides vector search using LanceDB, an embedded vector database based on the Lance columnar format.
11
+
12
+ The LanceVectorStore class provides vector search using [LanceDB](https://lancedb.github.io/lancedb/), an embedded vector database built on the Lance columnar format. It offers efficient storage and fast similarity search for both local development and production deployments.
13
+
14
+ ## Factory Method
15
+
16
+ The LanceVectorStore uses a factory pattern for creation. You should use the static `create()` method rather than the constructor directly.
17
+
18
+ ## Constructor Examples
19
+
20
+ You can create a `LanceVectorStore` instance using the static create method:
21
+
22
+ ```ts
23
+ import { LanceVectorStore } from "@mastra/lance";
24
+
25
+ // Connect to a local database
26
+ const vectorStore = await LanceVectorStore.create("/path/to/db");
27
+
28
+ // Connect to a LanceDB cloud database
29
+ const cloudStore = await LanceVectorStore.create("db://host:port");
30
+
31
+ // Connect to a cloud database with options
32
+ const s3Store = await LanceVectorStore.create("s3://bucket/db", {
33
+ storageOptions: { timeout: "60s" },
34
+ });
35
+ ```
36
+
37
+ ## Methods
38
+
39
+ ### createIndex()
40
+
41
+ #### LanceIndexConfig
42
+
43
+ ### createTable()
44
+
45
+ ### upsert()
46
+
47
+ ### query()
48
+
49
+ ### listTables()
50
+
51
+ Returns an array of table names as strings.
52
+
53
+ ```typescript
54
+ const tables = await vectorStore.listTables();
55
+ // ['my_vectors', 'embeddings', 'documents']
56
+ ```
57
+
58
+ ### getTableSchema()
59
+
60
+ Returns the schema of the specified table.
61
+
62
+ ### deleteTable()
63
+
64
+ ### deleteAllTables()
65
+
66
+ Deletes all tables in the database.
67
+
68
+ ### listIndexes()
69
+
70
+ Returns an array of index names as strings.
71
+
72
+ ### describeIndex()
73
+
74
+ Returns information about the index:
75
+
76
+ ```typescript
77
+ interface IndexStats {
78
+ dimension: number;
79
+ count: number;
80
+ metric: "cosine" | "euclidean" | "dotproduct";
81
+ type: "ivfflat" | "hnsw";
82
+ config: {
83
+ m?: number;
84
+ efConstruction?: number;
85
+ numPartitions?: number;
86
+ numSubVectors?: number;
87
+ };
88
+ }
89
+ ```
90
+
91
+ ### deleteIndex()
92
+
93
+ ### updateVector()
94
+
95
+ Update a single vector by ID or by metadata filter. Either `id` or `filter` must be provided, but not both.
96
+
97
+ ### deleteVector()
98
+
99
+ ### deleteVectors()
100
+
101
+ Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both.
102
+
103
+ ### close()
104
+
105
+ Closes the database connection.
106
+
107
+ ## Response Types
108
+
109
+ Query results are returned in this format:
110
+
111
+ ```typescript
112
+ interface QueryResult {
113
+ id: string;
114
+ score: number;
115
+ metadata: Record<string, any>;
116
+ vector?: number[]; // Only included if includeVector is true
117
+ document?: string; // Document text if available
118
+ }
119
+ ```
120
+
121
+ ## Error Handling
122
+
123
+ The store throws typed errors that can be caught:
124
+
125
+ ```typescript
126
+ try {
127
+ await store.query({
128
+ tableName: "my_vectors",
129
+ queryVector: queryVector,
130
+ });
131
+ } catch (error) {
132
+ if (error instanceof Error) {
133
+ console.log(error.message);
134
+ }
135
+ }
136
+ ```
137
+
138
+ ## Best Practices
139
+
140
+ - Use the appropriate index type for your use case:
141
+ - HNSW for better recall and performance when memory isn't constrained
142
+ - IVF for better memory efficiency with large datasets
143
+ - For optimal performance with large datasets, consider adjusting `numPartitions` and `numSubVectors` values
144
+ - Use `close()` method to properly close connections when done with the database
145
+ - Store metadata with a consistent schema to simplify filtering operations
146
+
147
+ ## Related
148
+
149
+ - [Metadata Filters](../rag/metadata-filters)