LanceDB
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.
LanceDB storage doesn't support the observability domain. Traces from the MastraStorageExporter can't be persisted to LanceDB, and Studio's observability features won't work with LanceDB as your only storage provider. To enable observability, use composite storage to route observability data to a supported provider like ClickHouse.
InstallationInstallation的直接链接
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/lance@latest
pnpm add @mastra/lance@latest
yarn add @mastra/lance@latest
bun add @mastra/lance@latest
UsageUsage的直接链接
Basic Storage UsageBasic Storage Usage的直接链接
import { LanceStorage } from '@mastra/lance'
// Connect to a local database
const storage = await LanceStorage.create('my-storage', '/path/to/db')
// Connect to a LanceDB cloud database
const storage = await LanceStorage.create('my-storage', 'db://host:port')
// Connect to a cloud database with custom options
const storage = await LanceStorage.create('my-storage', 's3://bucket/db', {
storageOptions: { timeout: '60s' },
})
ParametersParameters的直接链接
LanceStorage.create()lancestoragecreate的直接链接
name:
uri:
options?:
Additional notesAdditional notes的直接链接
Schema ManagementSchema Management的直接链接
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:
text,uuid→ Utf8int,integer→ Int32float→ Float32jsonb,json→ Utf8 (serialized)binary→ Binary
InitializationInitialization的直接链接
When you pass storage to the Mastra class, init() is called automatically before any storage operation:
import { Mastra } from '@mastra/core'
import { LanceStorage } from '@mastra/lance'
const storage = await LanceStorage.create('my-storage', '/path/to/db')
const mastra = new Mastra({
storage, // init() is called automatically
})
If you're using storage directly without Mastra, you must call init() explicitly to create the tables:
import { LanceStorage } from '@mastra/lance'
const storage = await LanceStorage.create('my-storage', '/path/to/db')
// Required when using storage directly
await storage.init()
// Access domain-specific stores via getStore()
const memoryStore = await storage.getStore('memory')
const thread = await memoryStore?.getThreadById({ threadId: '...' })
If init() isn't called, tables won't be created and storage operations will fail silently or throw errors.
Deployment OptionsDeployment Options的直接链接
LanceDB storage can be configured for different deployment scenarios:
- Local Development: Use a local file path for development and testing
/path/to/db
- Cloud Deployment: Connect to a hosted LanceDB instance
db://host:port
- S3 Storage: Use Amazon S3 for high-capacity cloud storage
s3://bucket/db
Table ManagementTable Management的直接链接
LanceStorage provides methods for managing tables:
- Create tables with custom schemas
- Drop tables
- Clear tables (delete all records)
- Load records by key
- Insert single and batch records