Installation (TypeScript)

Get the Memori TypeScript SDK installed and connected to your own database.

This page covers the TypeScript SDK for Memori BYODB. For the Python SDK, see the Installation (Python) page.

Install Memori

Install Memori (TypeScript)
npm install @memorilabs/memori

Install Your Database Driver

Memori supports MySQL/MariaDB, PostgreSQL, and SQLite through raw drivers. Install the package for your preferred setup:

Database Drivers
npm install mysql2

Connection Patterns

PatternFactory to pass to connWorks With
mysql2() => mysql.createPool(connectionString)MySQL, MariaDB
pg() => new pg.Pool({ connectionString })PostgreSQL, CockroachDB
better-sqlite3() => new Database('memori.db')SQLite

Connection Examples

Database Setup
import Database from 'better-sqlite3';
import { Memori } from '@memorilabs/memori';

const db = new Database('memori.db');
const mem = new Memori({ conn: () => db });

Using an ORM?

Memori needs a direct connection factory, but that doesn't mean you have to stop using your ORM. You're already creating a raw database pool for your ORM — just pass that same pool to Memori. Both share it simultaneously with no conflict.

ORM Pool Sharing
import pg from 'pg';
import { drizzle } from 'drizzle-orm/node-postgres';
import { Memori } from '@memorilabs/memori';

// The pool you already create for Drizzle
const pool = new pg.Pool({ connectionString: process.env.DATABASE_CONNECTION_STRING });
const db = drizzle(pool);

// Pass the same pool to Memori — no extra connection needed
const mem = new Memori({ conn: () => pool });

Your ORM handles your application's queries; Memori handles its own memory tables — same underlying pool, fully independent. See the ORMs guide for complete examples.

Create the Schema

After setting up your connection, call build() once to create the Memori tables in your database. This only needs to run the first time, or after upgrading Memori.

if (!mem.config.storage) {
  throw new Error('Storage not initialized');
}
await mem.config.storage.build();

Close Your Connection

Memori tears down its native engine automatically when the process exits — no cleanup call needed on your end. You only need to close the database connection you own:

// SQLite (better-sqlite3)
db.close();

// pg or mysql2 Pool
await pool.end();

Install Your LLM Provider

Install the SDK for your preferred LLM provider:

LLM Provider SDKs
npm install openai

Set Your LLM Provider Key

# OpenAI
export OPENAI_API_KEY="your-openai-key"

# Anthropic
export ANTHROPIC_API_KEY="your-anthropic-key"

# Google Gemini
export GOOGLE_API_KEY="your-google-key"

Set Up Your Memori API Key (Optional)

A Memori API key unlocks higher augmentation quotas (5,000/month vs 100 without a key). Sign up directly from the CLI:

memori sign-up your-email@example.com

Then set it as an environment variable:

export MEMORI_API_KEY="your-api-key-here"

Or add it to a .env file:

MEMORI_API_KEY=your-api-key-here

Check your current quota at any time:

memori quota

Verify Installation

npx tsx -e "import { Memori } from '@memorilabs/memori'; console.log('Memori installed successfully')"