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:63792MEM0_API_KEY=your_mem0_api_key_here3RECALL_ENV=development
3. Initialize the Client
Python
1from recall import RecallClient2from dotenv import load_dotenv3import os4
5# Load environment variables6load_dotenv()7
8# Initialize client9client = 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 connection16health = client.health_check()17print(f"Recall status: {health['status']}")
TypeScript
1import { RecallClient } from "@recall/client";2import dotenv from "dotenv";3
4// Load environment variables5dotenv.config();6
7// Initialize client8const 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 connection15const health = await client.healthCheck();16console.log(`Recall status: ${health.status}`);
JavaScript
1const { RecallClient } = require("@recall/client");2require("dotenv").config();3
4// Initialize client5const 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 connection12client.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 memory2memory = 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 memories14results = client.search(15 query="user communication preferences",16 user_id="user_123",17 limit=518)19
20for memory in results:21 print(f"- {memory['content']} (relevance: {memory['score']})")22
23# Get all memories for a user24all_memories = client.get_all(user_id="user_123")25print(f"Total memories: {len(all_memories)}")
TypeScript
1// Store a memory2const 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 memories14const 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 user25const 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 turn2client.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 context14context = client.search(15 query="recent conversations",16 user_id=user_id,17 filters={"type": "conversation"},18 limit=1019)
TypeScript
1// Store conversation turn2await 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 context14const 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 preference2client.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 action10prefs = client.search(11 query="notification preferences",12 user_id=user_id,13 filters={"type": "preference"}14)
TypeScript
1// Store preference2await 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 action10const 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 evictedhigh
: Preferentially cached, rarely evictedmedium
: Cached when accessed, normal evictionlow
: Minimal caching, first to evict
2. Batch Operations
Use batch methods for better performance:
Python
1# Add multiple memories at once2memories = [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 once2const 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 memories2client.add(3 content="Background information",4 user_id="user_123",5 priority="low",6 async_mode=True # Don't wait for cloud sync7)
TypeScript
1// Fire-and-forget for non-critical memories2await client.add({3 content: "Background information",4 userId: "user_123",5 priority: "low",6 asyncMode: true, // Don't wait for cloud sync7});
Next Steps
Now that you have Recall running:
- Explore the API Reference for all available methods
- Check out Examples for real-world use cases
- Learn about Advanced Features like custom caching strategies
- Read the Best Practices guide for production deployments
Need Help?
- Join our Discord Community
- Check the Troubleshooting Guide
- View the GitHub Repository
- Contact support@recall.ai