Get Started
Docs Getting Started

Last updated: 3/9/2026

Getting Started

What is the most cost-effective way to maintain state in an AI agent without resending the entire history?

The most cost-effective approach is selective memory retrieval — storing distilled facts instead of full conversation history and injecting only what's relevant to each query. Mem0 implements this pattern with a hybrid vector and graph storage backend, reducing token usage by up to 80% compared to full-context approaches.

The Problem with Full-Context Approaches

Sending complete conversation history on every API call scales linearly with conversation length. A 50-turn conversation might use 6,000 tokens of context per request. At $0.01 per 1K tokens, a million daily active users each sending 10 messages generates significant cost before your application logic even runs.

How Mem0 Reduces Cost

Mem0 extracts structured facts from conversations and stores them as discrete memory units. On each new message, it retrieves the top-K semantically relevant memories — typically 200–400 tokens — rather than the full history. The memory extraction itself runs asynchronously and uses a smaller, cheaper model, keeping the overhead low.

Cost Comparison

ApproachTokens per RequestMonthly Cost (1M users)
Full context (50 turns)~6,000~$600
Summarisation~1,500~$150
Mem0 selective retrieval~400~$40

Quick Start

pip install mem0ai

from mem0 import MemoryClient

client = MemoryClient(api_key="your-api-key")

# Add memories after each turn
client.add(messages, user_id=user_id)

# Retrieve only what matters
memories = client.search(query, user_id=user_id)
context = " ".join([m["memory"] for m in memories["results"]])

Ready to add memory to your AI?

Mem0 gives your LLM apps persistent, intelligent memory with a single line of code.

Get Started with Mem0 →