> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lancedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Mastra

> Use LanceDB Embedded as a local vector store in Mastra with @mastra/lance.

Embedded only

[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

`@mastra/lance` requires Node.js 22.13.0 or later and depends on `@mastra/core`. Install both packages:

```bash Bash icon="terminal" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
npm install @mastra/lance @mastra/core
```

Installing `@mastra/lance` also installs `@lancedb/lancedb` and the matching native binary for your platform.

## 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:

```typescript example.mjs icon="square-js" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
import { LanceVectorStore } from "@mastra/lance";

const store = await LanceVectorStore.create("./lancedb-data");
const indexName = "documents";

await store.createIndex({ indexName, dimension: 3 });

await store.upsert({
  indexName,
  ids: ["mastra", "lancedb"],
  vectors: [
    [0, 1, 0],
    [1, 0, 0],
  ],
});

const results = await store.query({
  indexName,
  queryVector: [1, 0, 0],
  topK: 1,
});

console.log(results[0].id, results[0].score);
store.close();
```

Run the script:

```bash Bash icon="terminal" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
node example.mjs
```

The nearest-neighbor query returns `lancedb` with a cosine similarity score of `1`:

```text Output theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
lancedb 1
```

## 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](https://docs.lancedb.com/enterprise/v1-16-0/indexing/vector-index.md) when extending the quickstart, call `createIndex()` again after upserting at least 256 rows and before `store.close()`:

```typescript TypeScript icon="square-js" theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
await store.createIndex({
  indexName,
  dimension: 3,
  indexConfig: { type: "ivfflat", numPartitions: 1 },
});
```

Supported `indexConfig.type` values include `"ivfflat"`, `"ivfpq"`, and the default HNSW PQ index.

## 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)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.