Integrations
Tutorial
April 13, 2026
Add Long-Term Memory to Google Gemini Apps
Google's Gemini API gives you access to powerful multimodal models, but it does not persist context between requests. If you are building a Gemini-powered assistant that needs to remember users, preferences, or facts across sessions, REM Labs provides the persistent memory layer. Here is how to wire it in.
Why Gemini Apps Need Persistent Memory
The Gemini API processes each generateContent call independently. Google's AI Studio has session-level chat, but that context disappears when the session ends. For production applications -- customer support bots, personal assistants, learning tools -- you need memory that survives across sessions, deployments, and even across different models.
REM Labs gives your Gemini app a memory backend that stores every piece of context with vector embeddings, full-text indexing, and entity extraction. When your app needs to recall something, it runs a multi-signal search that fuses all three retrieval methods for 90% accuracy on the LongMemEval benchmark.
Step 1: Get Your API Keys
You need two keys: a Google Gemini API key from Google AI Studio, and a REM Labs API key from remlabs.ai/console (or run npx @remlabs/memory).
Step 2: Store Memories After Gemini Responses
import google.generativeai as genai
import requests
genai.configure(api_key="AIza...")
model = genai.GenerativeModel("gemini-2.0-flash")
REM_KEY = "sk-slop-..."
REM_BASE = "https://api.api.remlabs.ai"
user_msg = "I'm training for a marathon in October. I run 30 miles per week."
resp = model.generate_content(user_msg)
reply = resp.text
# Store the interaction
requests.post(f"{REM_BASE}/v1/memory-set", json={
"key": "gemini-coach",
"value": f"User: {user_msg}\nAssistant: {reply}",
"namespace": "runner-789",
"tags": ["fitness", "goals"]
}, headers={"Authorization": f"Bearer {REM_KEY}"})
Each memory is automatically indexed with a vector embedding, full-text entry, and entity extraction. The namespace keeps this runner's data separate from all other users.
Step 3: Recall Context Before New Requests
# Next session -- user returns a week later
user_msg = "Should I increase my mileage this week?"
# Search for relevant memories
search = requests.post(f"{REM_BASE}/v1/memory/search", json={
"query": user_msg,
"namespace": "runner-789",
"limit": 5
}, headers={"Authorization": f"Bearer {REM_KEY}"})
memories = search.json().get("results", [])
context = "\n".join([m["value"] for m in memories])
# Inject context into the Gemini prompt
resp = model.generate_content(
f"Context from previous sessions:\n{context}\n\nUser question: {user_msg}"
)
print(resp.text)
# References the user's 30 miles/week and October marathon goal
Step 4: Node.js with the Google AI SDK
import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI("AIza...");
const model = genAI.getGenerativeModel({ model: "gemini-2.0-flash" });
const REM_BASE = "https://api.api.remlabs.ai";
const REM_KEY = "sk-slop-...";
// Store a memory
await fetch(`${REM_BASE}/v1/memory-set`, {
method: "POST",
headers: { "Authorization": `Bearer ${REM_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
key: "gemini-coach",
value: "User runs 30 miles/week, training for October marathon.",
namespace: "runner-789"
})
});
// Recall and inject into Gemini
const search = await fetch(`${REM_BASE}/v1/memory/search`, {
method: "POST",
headers: { "Authorization": `Bearer ${REM_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ query: "training plan", namespace: "runner-789", limit: 5 })
});
const { results } = await search.json();
const context = results.map(r => r.value).join("\n");
const result = await model.generateContent(
`Previous context:\n${context}\n\nUser: How should I adjust my training?`
);
Multimodal Memories
Gemini excels at multimodal inputs -- images, audio, video. You can store the text description or extracted content from these interactions as memories too. When Gemini analyzes an image for a user, store the analysis as a memory. Next time the user references that image, your app can recall the context without re-processing it.
API reference: Full documentation for /v1/memory-set, /v1/memory/search, namespace management, and tag filtering is available in the developer docs.
Give your Gemini app a memory
Free tier. No credit card. Works with Gemini Pro, Flash, and all Gemini models.
Get started free →