Quickstart
Get started with MemLib in under 5 minutes
Prerequisites
- A PostgreSQL database with the pgvector extension (Supabase, Neon, and Railway have this built-in)
- An API key from a supported embedding provider (Gemini, OpenAI, etc.)
- An API key from a supported LLM provider (Gemini, OpenAI, Anthropic, etc.)
1. Create a Project
Sign up at mem.anishroy.com and create a new project. You'll need to provide:
- Database URL — your PostgreSQL connection string (this is where memories are stored)
- Embedding provider — select a provider and paste your API key
- LLM provider — select a provider and paste your API key
BYOD Model: MemLib connects to your database at request time. Your data never leaves your infrastructure.
2. Run Migration
Set up the memory tables in your database. From your project's API Keys page, create an Admin key, then run:
curl -X POST https://mem.anishroy.com/api/v1/memory/migrate \
-H "Authorization: Bearer sk_your_admin_key"This creates the memories and memory_events tables with pgvector indexing.
3. Generate an API Key
From your project's API Keys page, create a new key with Read & Write permission. Copy the key — you'll only see it once.
4. Install the SDK
npm install memlib5. Store Your First Memory
import { MemLib } from "memlib";
const mem = new MemLib({
apiKey: "sk_your_api_key",
namespace: "my-app",
entity: "user-123",
});
// Smart store — extracts facts, deduplicates, resolves conflicts
const result = await mem.store({
content: "I prefer dark mode and use TypeScript for all my projects",
});
console.log(result.memories);
// → [
// { content: "Prefers dark mode", category: "preference", event: "ADD" },
// { content: "Uses TypeScript for all projects", category: "preference", event: "ADD" },
// ]6. Recall Memories
const memories = await mem.recall({
query: "What programming language does the user prefer?",
});
console.log(memories);
// → [{ content: "Uses TypeScript for all projects", similarity: 0.92, score: 0.86, ... }]7. Synthesize Context
const { context } = await mem.prepare({
messages: [{ role: "user", content: "Help me set up a new project" }],
});
console.log(context);
// → "The user prefers dark mode and uses TypeScript for all projects."
// Inject into your LLM's system prompt:
const systemPrompt = `You are a helpful assistant.\n\nUser context:\n${context}`;8. Check What Changed
const diff = await mem.diff({
since: "2024-01-01T00:00:00Z",
});
console.log(diff.summary); // "2 new"
console.log(diff.created.length); // 2Next Steps
- How It Works — understand the architecture
- Smart Store Pipeline — how fact extraction and dedup work
- SDK Reference — all methods and options
- REST API Reference — HTTP endpoints
- MCP Integration — connect to Claude Desktop or Cursor
- Add Memory to a Chatbot — end-to-end tutorial