npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@caleblawson/lance

v0.1.3-alpha.0

Published

Lance provider for Mastra - includes both vector and db storage capabilities

Readme

Mastra LanceDB Storage & Vector Usage Guide

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 file format.

Installation

pnpm add @mastra/lance @lancedb/lancedb apache-arrow

Setup & Configuration

Basic Setup

import { LanceStorage } from '@mastra/lance';
import { Mastra } from '@mastra/core/mastra';

// Initialize LanceStorage
const storage = await LanceStorage.create(
  'myApp', // Name for your storage instance
  'path/to/db', // Path to database directory
);

// Configure Mastra with LanceStorage
const mastra = new Mastra({
  storage: storage,
});

Connection Options

LanceStorage supports multiple connection configurations:

// Local database
const localStore = await LanceStorage.create('myApp', '/path/to/db');

// LanceDB Cloud
const cloudStore = await LanceStorage.create('myApp', 'db://host:port');

// S3 bucket
const s3Store = await LanceStorage.create('myApp', 's3://bucket/db', { storageOptions: { timeout: '60s' } });

Basic Operations

Creating Tables

import { TABLE_MESSAGES } from '@mastra/core/storage';
import type { StorageColumn } from '@mastra/core/storage';

// Define schema with appropriate types
const schema: Record<string, StorageColumn> = {
  id: { type: 'uuid', nullable: false },
  threadId: { type: 'uuid', nullable: false },
  content: { type: 'text', nullable: true },
  createdAt: { type: 'timestamp', nullable: false },
  metadata: { type: 'jsonb', nullable: true },
};

// Create table
await storage.createTable({
  tableName: TABLE_MESSAGES,
  schema,
});

Inserting Records

// Insert a single record
await storage.insert({
  tableName: TABLE_MESSAGES,
  record: {
    id: '123e4567-e89b-12d3-a456-426614174000',
    threadId: '123e4567-e89b-12d3-a456-426614174001',
    content: 'Hello, world!',
    createdAt: new Date(),
    metadata: { tags: ['important', 'greeting'] },
  },
});

// Batch insert multiple records
await storage.batchInsert({
  tableName: TABLE_MESSAGES,
  records: [
    {
      id: '123e4567-e89b-12d3-a456-426614174002',
      threadId: '123e4567-e89b-12d3-a456-426614174001',
      content: 'First message',
      createdAt: new Date(),
      metadata: { priority: 'high' },
    },
    {
      id: '123e4567-e89b-12d3-a456-426614174003',
      threadId: '123e4567-e89b-12d3-a456-426614174001',
      content: 'Second message',
      createdAt: new Date(),
      metadata: { priority: 'low' },
    },
  ],
});

Querying Data

// Load a record by id
const message = await storage.load({
  tableName: TABLE_MESSAGES,
  keys: { id: '123e4567-e89b-12d3-a456-426614174000' },
});

// Load messages from a thread
const messages = await storage.getMessages({
  threadId: '123e4567-e89b-12d3-a456-426614174001',
});

Working with Threads & Messages

Creating Threads

import type { StorageThreadType } from '@mastra/core';

// Create a new thread
const thread: StorageThreadType = {
  id: '123e4567-e89b-12d3-a456-426614174010',
  resourceId: 'resource-123',
  title: 'New Discussion',
  createdAt: new Date(),
  metadata: { topic: 'technical-support' },
};

// Save the thread
const savedThread = await storage.saveThread({ thread });

Working with Messages

import type { MessageType } from '@mastra/core';

// Create messages
const messages: MessageType[] = [
  {
    id: 'msg-001',
    threadId: '123e4567-e89b-12d3-a456-426614174010',
    resourceId: 'resource-123',
    role: 'user',
    content: 'How can I use LanceDB with Mastra?',
    createdAt: new Date(),
    type: 'text',
    toolCallIds: [],
    toolCallArgs: [],
    toolNames: [],
  },
  {
    id: 'msg-002',
    threadId: '123e4567-e89b-12d3-a456-426614174010',
    resourceId: 'resource-123',
    role: 'assistant',
    content: 'You can use LanceDB with Mastra by installing @mastra/lance package.',
    createdAt: new Date(),
    type: 'text',
    toolCallIds: [],
    toolCallArgs: [],
    toolNames: [],
  },
];

// Save messages
await storage.saveMessages({ messages });

// Retrieve messages with context
const retrievedMessages = await storage.getMessages({
  threadId: '123e4567-e89b-12d3-a456-426614174010',
  selectBy: [
    {
      id: 'msg-001',
      withPreviousMessages: 5, // Include up to 5 messages before this one
      withNextMessages: 5, // Include up to 5 messages after this one
    },
  ],
});

Working with Workflows

Mastra's workflow system uses LanceDB to persist workflow state for continuity across runs:

import type { WorkflowRunState } from '@mastra/core';

// Persist a workflow snapshot
await storage.persistWorkflowSnapshot({
  workflowName: 'documentProcessing',
  runId: 'run-123',
  snapshot: {
    context: {
      steps: {
        step1: { status: 'success', payload: { data: 'processed' } },
        step2: { status: 'waiting' },
      },
      triggerData: { documentId: 'doc-123' },
      attempts: { step1: 1, step2: 0 },
    },
  } as WorkflowRunState,
});

// Load a workflow snapshot
const workflowState = await storage.loadWorkflowSnapshot({
  workflowName: 'documentProcessing',
  runId: 'run-123',
});

Using Lance for Vector Storage

The LanceDB integration in Mastra can be used for both traditional storage and vector search:

// Create a schema with vector field
const vectorSchema: Record<string, StorageColumn> = {
  id: { type: 'uuid', nullable: false },
  content: { type: 'text', nullable: true },
  embedding: { type: 'binary', nullable: false }, // Vector embedding
  metadata: { type: 'jsonb', nullable: true },
};

// Create a vector table
await storage.createTable({
  tableName: 'vector_store',
  schema: vectorSchema,
});

// Insert a vector with content and metadata
await storage.insert({
  tableName: 'vector_store',
  record: {
    id: 'vec-001',
    content: 'This is a document about LanceDB and Mastra integration',
    embedding: new Float32Array([0.1, 0.2, 0.3, 0.4]), // Your embedding vector
    metadata: { source: 'documentation', category: 'integration' },
  },
});

Data Management

// Drop a table
await storage.dropTable(TABLE_MESSAGES);

// Clear all records from a table
await storage.clearTable({ tableName: TABLE_MESSAGES });

// Get table schema
const schema = await storage.getTableSchema(TABLE_MESSAGES);