Docs/Getting Started

Quick Start

Get Recall running in your application in under 5 minutes.

Prerequisites

Before you begin, make sure you have:

  • Python 3.8+ or Node.js 16+
  • Redis installed locally or a Redis Cloud instance
  • A Mem0 API key (get one free)

Installation

Bash
1pip install recall-memory
Bash
1npm install @recall/client
Bash
1yarn add @recall/client
Bash
1pnpm add @recall/client

Basic Setup

1. Start Redis

If you don't have Redis running locally:

Bash
1docker run -d -p 6379:6379 redis:alpine
Bash
1brew services start redis
Bash
1sudo systemctl start redis

2. Set Environment Variables

Create a .env file in your project root:

ENV
1REDIS_URL=redis://localhost:6379
2MEM0_API_KEY=your_mem0_api_key_here
3RECALL_ENV=development

3. Initialize the Client

Python
1from recall import RecallClient
2from dotenv import load_dotenv
3import os
4
5# Load environment variables
6load_dotenv()
7
8# Initialize client
9client = RecallClient(
10 redis_url=os.getenv("REDIS_URL"),
11 mem0_api_key=os.getenv("MEM0_API_KEY"),
12 environment=os.getenv("RECALL_ENV", "development")
13)
14
15# Test the connection
16health = client.health_check()
17print(f"Recall status: {health['status']}")
TypeScript
1import { RecallClient } from "@recall/client";
2import dotenv from "dotenv";
3
4// Load environment variables
5dotenv.config();
6
7// Initialize client
8const client = new RecallClient({
9 redisUrl: process.env.REDIS_URL,
10 mem0ApiKey: process.env.MEM0_API_KEY,
11 environment: process.env.RECALL_ENV || "development",
12});
13
14// Test the connection
15const health = await client.healthCheck();
16console.log(`Recall status: ${health.status}`);
JavaScript
1const { RecallClient } = require("@recall/client");
2require("dotenv").config();
3
4// Initialize client
5const client = new RecallClient({
6 redisUrl: process.env.REDIS_URL,
7 mem0ApiKey: process.env.MEM0_API_KEY,
8 environment: process.env.RECALL_ENV || "development",
9});
10
11// Test the connection
12client.healthCheck().then((health) => {
13 console.log(`Recall status: ${health.status}`);
14});

Your First Memory

Let's create, retrieve, and search memories:

Python
1# Store a memory
2memory = client.add(
3 content="User prefers concise responses and technical details",
4 user_id="user_123",
5 priority="high",
6 metadata={
7 "category": "preferences",
8 "learned_from": "conversation"
9 }
10)
11print(f"Memory stored with ID: {memory['id']}")
12
13# Search memories
14results = client.search(
15 query="user communication preferences",
16 user_id="user_123",
17 limit=5
18)
19
20for memory in results:
21 print(f"- {memory['content']} (relevance: {memory['score']})")
22
23# Get all memories for a user
24all_memories = client.get_all(user_id="user_123")
25print(f"Total memories: {len(all_memories)}")
TypeScript
1// Store a memory
2const memory = await client.add({
3 content: "User prefers concise responses and technical details",
4 userId: "user_123",
5 priority: "high",
6 metadata: {
7 category: "preferences",
8 learnedFrom: "conversation",
9 },
10});
11console.log(`Memory stored with ID: ${memory.id}`);
12
13// Search memories
14const results = await client.search({
15 query: "user communication preferences",
16 userId: "user_123",
17 limit: 5,
18});
19
20results.forEach((memory) => {
21 console.log(`- ${memory.content} (relevance: ${memory.score})`);
22});
23
24// Get all memories for a user
25const allMemories = await client.getAll({ userId: "user_123" });
26console.log(`Total memories: ${allMemories.length}`);

Common Patterns

Conversation Memory

Store and retrieve conversation context:

Python
1# Store conversation turn
2client.add(
3 content=f"User asked about {topic}. Provided detailed explanation.",
4 user_id=user_id,
5 priority="medium",
6 metadata={
7 "type": "conversation",
8 "session_id": session_id,
9 "timestamp": datetime.now().isoformat()
10 }
11)
12
13# Retrieve recent conversation context
14context = client.search(
15 query="recent conversations",
16 user_id=user_id,
17 filters={"type": "conversation"},
18 limit=10
19)
TypeScript
1// Store conversation turn
2await client.add({
3 content: `User asked about ${topic}. Provided detailed explanation.`,
4 userId: userId,
5 priority: "medium",
6 metadata: {
7 type: "conversation",
8 sessionId: sessionId,
9 timestamp: new Date().toISOString(),
10 },
11});
12
13// Retrieve recent conversation context
14const context = await client.search({
15 query: "recent conversations",
16 userId: userId,
17 filters: { type: "conversation" },
18 limit: 10,
19});

User Preferences

Track and apply user preferences:

Python
1# Store preference
2client.add(
3 content="Prefers email notifications over SMS",
4 user_id=user_id,
5 priority="high",
6 metadata={"type": "preference", "category": "notifications"}
7)
8
9# Check preferences before action
10prefs = client.search(
11 query="notification preferences",
12 user_id=user_id,
13 filters={"type": "preference"}
14)
TypeScript
1// Store preference
2await client.add({
3 content: "Prefers email notifications over SMS",
4 userId: userId,
5 priority: "high",
6 metadata: { type: "preference", category: "notifications" },
7});
8
9// Check preferences before action
10const prefs = await client.search({
11 query: "notification preferences",
12 userId: userId,
13 filters: { type: "preference" },
14});

Performance Tips

1. Use Priority Levels

Set appropriate priority levels to optimize cache usage:

  • critical: Always in cache, never evicted
  • high: Preferentially cached, rarely evicted
  • medium: Cached when accessed, normal eviction
  • low: Minimal caching, first to evict

2. Batch Operations

Use batch methods for better performance:

Python
1# Add multiple memories at once
2memories = [
3 {"content": "Fact 1", "user_id": "user_123"},
4 {"content": "Fact 2", "user_id": "user_123"},
5 {"content": "Fact 3", "user_id": "user_123"}
6]
7client.add_batch(memories)
TypeScript
1// Add multiple memories at once
2const memories = [
3 { content: "Fact 1", userId: "user_123" },
4 { content: "Fact 2", userId: "user_123" },
5 { content: "Fact 3", userId: "user_123" },
6];
7await client.addBatch(memories);

3. Use Async Operations

For non-critical memories, use async mode:

Python
1# Fire-and-forget for non-critical memories
2client.add(
3 content="Background information",
4 user_id="user_123",
5 priority="low",
6 async_mode=True # Don't wait for cloud sync
7)
TypeScript
1// Fire-and-forget for non-critical memories
2await client.add({
3 content: "Background information",
4 userId: "user_123",
5 priority: "low",
6 asyncMode: true, // Don't wait for cloud sync
7});

Next Steps

Now that you have Recall running:

Need Help?