mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
## Summary Supersedes #2330 and brings the Mastra integration guide onto the current `docs/web` Mintlify documentation structure with verified LanceDB Embedded examples against the published `@mastra/lance` release. Credit to @vishesh-baghel for authoring the original LanceDB Mastra guide in #2330 and building the merged upstream Mastra storage and vector adapters in mastra-ai/mastra#3324. ### Changes - Add `docs/web/integrations/ai/mastra.mdx` covering LanceDB Embedded usage with `@mastra/lance`: - Node.js 22.13.0+ requirement and `npm install @mastra/lance @mastra/core`. - Runnable local `LanceVectorStore` quickstart (`create`, `createIndex`, `upsert`, `query`, `close`) with verified nearest-neighbor output (`lancedb 1`). - Explanation of the two-step native vector index behavior in `@mastra/lance` (first `createIndex()` initializes an empty table; calling `createIndex()` again after upserting at least 256 rows builds the native index on the `vector` column). - Pointer to `LanceStorage` noting the published three-argument `LanceStorage.create(id, name, uri)` signature and linking upstream Mastra references, without unverified cloud claims. - Register `integrations/ai/mastra` under **AI Platforms & Frameworks** in `docs/web/docs.json`. - Add the TypeScript example snippets to `docs/web-tests/ts/integrations.ts` and regenerate the corresponding exports (`TsFrameworksMastraQuickstart`, `TsFrameworksMastraNativeIndex`) in `docs/web/snippets/integrations.mdx`. ## Verification - Verified against published `@mastra/lance@1.6.1` and `@mastra/core@1.85.0` (resolving `@lancedb/lancedb@0.31.0` and `apache-arrow@18.1.0`): - Two-vector local quickstart returns `lancedb 1`. - Native `IVF_FLAT` index build after upserting 256 rows reports `vector_idx` with 256 indexed rows, 0 unindexed rows, and nearest-neighbor score `1`. - Confirmed `LanceStorage.create(id, name, uri)` succeeds with three arguments while the older two-argument call fails.
70 lines
3.1 KiB
Plaintext
70 lines
3.1 KiB
Plaintext
---
|
|
title: "Mastra"
|
|
sidebarTitle: "Mastra"
|
|
description: "Use LanceDB Embedded as a local vector store in Mastra with @mastra/lance."
|
|
availability:
|
|
embedded: available
|
|
enterprise: unavailable
|
|
---
|
|
|
|
import {
|
|
TsFrameworksMastraNativeIndex,
|
|
TsFrameworksMastraQuickstart,
|
|
} from '/snippets/integrations.mdx';
|
|
|
|
[Mastra](https://mastra.ai) is an open-source TypeScript framework for building AI agents, workflows, and retrieval-augmented generation (RAG) pipelines. Its official `@mastra/lance` package connects Mastra to LanceDB Embedded on local disk with no separate database server.
|
|
|
|
## Installation {#installation}
|
|
|
|
`@mastra/lance` requires Node.js 22.13.0 or later and depends on `@mastra/core`. Install both packages:
|
|
|
|
<CodeGroup>
|
|
```bash Bash icon="terminal"
|
|
npm install @mastra/lance @mastra/core
|
|
```
|
|
</CodeGroup>
|
|
|
|
Installing `@mastra/lance` also installs `@lancedb/lancedb` and the matching native binary for your platform.
|
|
|
|
## Vector search quickstart {#vector-search-quickstart}
|
|
|
|
Save the following script as `example.mjs`. It opens a local LanceDB directory with `LanceVectorStore.create()`, creates a `documents` table, upserts two 3-dimensional vectors, and runs a nearest-neighbor query:
|
|
|
|
<CodeBlock filename="example.mjs" language="TypeScript" icon="square-js">
|
|
{TsFrameworksMastraQuickstart}
|
|
</CodeBlock>
|
|
|
|
Run the script:
|
|
|
|
<CodeGroup>
|
|
```bash Bash icon="terminal"
|
|
node example.mjs
|
|
```
|
|
</CodeGroup>
|
|
|
|
The nearest-neighbor query returns `lancedb` with a cosine similarity score of `1`:
|
|
|
|
```text Output
|
|
lancedb 1
|
|
```
|
|
|
|
## Native vector index {#native-vector-index}
|
|
|
|
The first `createIndex()` call initializes an empty LanceDB table without building a native vector index. When `tableName` is omitted, `indexName` sets the table name and `vector` is the vector column. Queries work on small tables immediately through flat scan.
|
|
|
|
To build a native [LanceDB vector index](/indexing/vector-index) when extending the quickstart, call `createIndex()` again after upserting at least 256 rows and before `store.close()`:
|
|
|
|
<CodeBlock filename="TypeScript" language="TypeScript" icon="square-js">
|
|
{TsFrameworksMastraNativeIndex}
|
|
</CodeBlock>
|
|
|
|
Supported `indexConfig.type` values include `"ivfflat"`, `"ivfpq"`, and the default HNSW PQ index.
|
|
|
|
## Application storage and references {#application-storage-and-references}
|
|
|
|
`@mastra/lance` also exports `LanceStorage` for Mastra agent memory and workflow state. The published `LanceStorage.create(id, name, uri)` factory takes three required arguments (`id`, `name`, and `uri`). See the [released `LanceStorage.create` implementation](https://github.com/mastra-ai/mastra/blob/d60ba71be015e2acbdc303208a14563902fb1f39/stores/lance/src/storage/index.ts#L78-L119) for the current signature if you encounter older two-argument examples.
|
|
|
|
- [Mastra LanceDB vector store reference](https://mastra.ai/integrations/vectors/lance)
|
|
- [Mastra LanceDB storage guide](https://mastra.ai/integrations/databases/lancedb)
|
|
- [Released `LanceVectorStore.createIndex` implementation](https://github.com/mastra-ai/mastra/blob/d60ba71be015e2acbdc303208a14563902fb1f39/stores/lance/src/vector/index.ts#L685-L815)
|