MemLibMemLib

SDK Overview

Install and configure the MemLib TypeScript SDK

Installation

npm install memlib

The SDK ships with full TypeScript types — no additional @types package needed.


Configuration

import { MemLib } from "memlib";

const mem = new MemLib({
  apiKey: "sk_...",           // Required — your project API key
  namespace: "my-app",       // Optional — default namespace for all calls
  entity: "user-123",        // Optional — default entity for all calls
  baseUrl: "https://...",    // Optional — defaults to MemLib cloud
});

Options

OptionTypeRequiredDefaultDescription
apiKeystringAPI key from your project dashboard
namespacestring""Default namespace for all calls. Can be overridden per-call.
entitystring""Default entity for all calls. Can be overridden per-call.
baseUrlstring"https://mem.anishroy.com/api"API base URL. Override for self-hosted instances.

Note: If you don't set namespace or entity in the constructor, you must provide them in every call's options. Omitting both will throw an error.


Methods Overview

MethodDescriptionLLM Calls
store()Store a memory with optional LLM fact extraction0–2
recall()Semantic search — find memories by meaning0
prepare()Synthesize a context paragraph from relevant memories2
diff()Memory changelog since a timestamp0
batchStore()Store multiple memories at once (raw)0
list()List stored memories0
delete()Delete a memory by ID0
health()Check API connectivity0

Imports

The SDK exports the main class and all types:

// Main class
import { MemLib } from "memlib";

// Error class
import { MemLibError } from "memlib";

// Types (for TypeScript users)
import type {
  MemLibConfig,
  StoreOptions,
  RecallOptions,
  PrepareOptions,
  DiffOptions,
  BatchStoreOptions,
  ListOptions,
  Memory,
  RetrievedMemory,
  StoreResult,
  PrepareResult,
  DiffResult,
  BatchStoreResult,
  DeleteResult,
  HealthResult,
  Message,
} from "memlib";

Quick Example

import { MemLib } from "memlib";

const mem = new MemLib({
  apiKey: "sk_your_key",
  namespace: "my-app",
  entity: "user-123",
});

// Store with smart extraction
await mem.store({
  content: "I prefer TypeScript. My team uses React and Next.js.",
});

// Recall by meaning
const memories = await mem.recall({
  query: "What tech stack?",
});

// Synthesize context for a conversation
const { context } = await mem.prepare({
  messages: [{ role: "user", content: "Help me setup a project" }],
});

// Check what changed
const diff = await mem.diff({ since: "2024-01-01T00:00:00Z" });

On this page