Docs/Getting Started

Integration Guides

Framework Integrations

Next.js

TypeScript
1// app/api/memory/route.ts
2import { Recall } from "@n3wth/recall";
3import { NextResponse } from "next/server";
4
5const memory = new Recall({
6 redis: process.env.REDIS_URL,
7 apiKey: process.env.MEM0_API_KEY,
8});
9
10export async function POST(request: Request) {
11 const { content, userId } = await request.json();
12
13 const result = await memory.add({
14 content,
15 user_id: userId,
16 priority: "high",
17 });
18
19 return NextResponse.json(result);
20}

Express

TypeScript
1import express from "express";
2import { Recall } from "@n3wth/recall";
3
4const app = express();
5const memory = new Recall({
6 redis: process.env.REDIS_URL,
7 apiKey: process.env.MEM0_API_KEY,
8});
9
10app.post("/api/memory", async (req, res) => {
11 const { content, userId } = req.body;
12
13 const result = await memory.add({
14 content,
15 user_id: userId,
16 });
17
18 res.json(result);
19});

AI Framework Integrations

LangChain

Python
1from langchain.memory import ConversationBufferMemory
2import requests
3
4class RecallMemory(ConversationBufferMemory):
5 def __init__(self, server_url="http://localhost:3000"):
6 super().__init__()
7 self.server_url = server_url
8
9 def save_context(self, inputs, outputs):
10 requests.post(f"{self.server_url}/mcp", json={
11 "method": "add_memory",
12 "params": {
13 "content": f"Q: {inputs['input']} A: {outputs['output']}",
14 "priority": "medium",
15 "async": True
16 }
17 })
18 super().save_context(inputs, outputs)
19
20# Usage
21memory = RecallMemory()
22chain = ConversationChain(memory=memory, llm=llm)

OpenAI Assistants

TypeScript
1import OpenAI from "openai";
2import { Recall } from "@n3wth/recall";
3
4class RecallAssistant {
5 private openai: OpenAI;
6 private memory: Recall;
7
8 constructor(apiKey: string) {
9 this.openai = new OpenAI({ apiKey });
10 this.memory = new Recall({
11 redis: process.env.REDIS_URL,
12 apiKey: process.env.MEM0_API_KEY,
13 });
14 }
15
16 async chat(message: string, userId: string) {
17 // Get relevant context
18 const memories = await this.memory.search({
19 query: message,
20 user_id: userId,
21 prefer_cache: true,
22 });
23
24 // Build context-aware prompt
25 const context = memories.memories.map((m) => m.memory).join("\n");
26
27 const response = await this.openai.chat.completions.create({
28 model: "gpt-4",
29 messages: [
30 { role: "system", content: `Context:\n${context}` },
31 { role: "user", content: message },
32 ],
33 });
34
35 // Save interaction
36 await this.memory.add({
37 content: `Q: ${message}\nA: ${response.choices[0].message.content}`,
38 user_id: userId,
39 priority: "medium",
40 });
41
42 return response.choices[0].message.content;
43 }
44}

Database Integrations

PostgreSQL with Triggers

SQL
1-- Create trigger to sync with Recall
2CREATE OR REPLACE FUNCTION sync_to_recall()
3RETURNS TRIGGER AS $$
4DECLARE
5 payload json;
6BEGIN
7 payload := json_build_object(
8 'method', 'add_memory',
9 'params', json_build_object(
10 'content', NEW.content,
11 'user_id', NEW.user_id,
12 'metadata', json_build_object(
13 'source', 'postgres',
14 'table', TG_TABLE_NAME,
15 'id', NEW.id
16 )
17 )
18 );
19
20 PERFORM pg_notify('recall_sync', payload::text);
21 RETURN NEW;
22END;
23$$ LANGUAGE plpgsql;
24
25CREATE TRIGGER user_activity_recall_sync
26AFTER INSERT OR UPDATE ON user_activities
27FOR EACH ROW EXECUTE FUNCTION sync_to_recall();

MongoDB Change Streams

TypeScript
1import { MongoClient } from "mongodb";
2import { Recall } from "@n3wth/recall";
3
4const client = new MongoClient(process.env.MONGODB_URI);
5const memory = new Recall({
6 redis: process.env.REDIS_URL,
7 apiKey: process.env.MEM0_API_KEY,
8});
9
10async function watchChanges() {
11 await client.connect();
12 const db = client.db("myapp");
13 const collection = db.collection("conversations");
14
15 const changeStream = collection.watch();
16
17 changeStream.on("change", async (change) => {
18 if (change.operationType === "insert") {
19 await memory.add({
20 content: change.fullDocument.message,
21 user_id: change.fullDocument.userId,
22 metadata: {
23 source: "mongodb",
24 collection: "conversations",
25 _id: change.fullDocument._id,
26 },
27 });
28 }
29 });
30}

CLI Integration

Shell Aliases

Add to your ~/.bashrc or ~/.zshrc:

Bash
1# Quick memory commands
2alias recall-add='function _recall_add() {
3 curl -X POST http://localhost:3000/mcp \
4 -H "Content-Type: application/json" \
5 -d "{\"method\":\"add_memory\",\"params\":{\"content\":\"$1\",\"priority\":\"high\"}}"
6}; _recall_add'
7
8alias recall-search='function _recall_search() {
9 curl -X POST http://localhost:3000/mcp \
10 -H "Content-Type: application/json" \
11 -d "{\"method\":\"search_memory\",\"params\":{\"query\":\"$1\"}}" | jq .
12}; _recall_search'
13
14alias recall-stats='curl -X POST http://localhost:3000/mcp \
15 -H "Content-Type: application/json" \
16 -d "{\"method\":\"cache_stats\"}" | jq .'
17
18# Usage
19recall-add "Important meeting at 3pm"
20recall-search "meeting"
21recall-stats

Deployment Configurations

Docker Compose

YAML
1version: "3.8"
2
3services:
4 redis:
5 image: redis:7-alpine
6 ports:
7 - "6379:6379"
8 volumes:
9 - redis-data:/data
10
11 recall:
12 image: node:18-alpine
13 working_dir: /app
14 volumes:
15 - ./:/app
16 command: npx @n3wth/recall
17 environment:
18 - MEM0_API_KEY=${MEM0_API_KEY}
19 - REDIS_URL=redis://redis:6379
20 depends_on:
21 - redis
22 ports:
23 - "3000:3000"
24
25volumes:
26 redis-data:

Kubernetes

YAML
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: recall
5spec:
6 replicas: 3
7 selector:
8 matchLabels:
9 app: recall
10 template:
11 metadata:
12 labels:
13 app: recall
14 spec:
15 containers:
16 - name: recall
17 image: node:18-alpine
18 command: ["npx", "@n3wth/recall"]
19 env:
20 - name: MEM0_API_KEY
21 valueFrom:
22 secretKeyRef:
23 name: recall-secrets
24 key: mem0-api-key
25 - name: REDIS_URL
26 value: "redis://redis-service:6379"
27 ports:
28 - containerPort: 3000
29---
30apiVersion: v1
31kind: Service
32metadata:
33 name: recall-service
34spec:
35 selector:
36 app: recall
37 ports:
38 - protocol: TCP
39 port: 3000
40 targetPort: 3000
41 type: LoadBalancer