Agent Memory Cheat Sheet
By Arc Labs Research5 min read
Memory Types
| Type | Data | Retrieval | Use case |
|---|---|---|---|
| Conversation | Messages, turns | Temporal, semantic | Multi-turn dialogue, context |
| Decision | Actions, outcomes | Semantic, causal | Learned policies, reasoning |
| Episodic | Events, facts | Temporal, spatial | Timeline reconstruction |
| Semantic | Concepts, rules | Semantic, similarity | Knowledge base, reasoning |
| Procedural | Steps, methods | Keyword, sequence | Workflows, task chains |
Retrieval Modes
| Mode | Input | Output | Latency | Use |
|---|---|---|---|---|
| Keyword | Query string | Exact/substring matches | < 1ms | Fast filters |
| Semantic | Query embedding | Top-K similarity | < 50ms | Meaning-based |
| Hybrid | Query + embedding | Ranked fusion | < 100ms | Best of both |
| Temporal | Time range | Recent-first | < 10ms | Recency bias |
| Causal | Previous event | Consequence links | < 50ms | Effect chains |
Retrieval Fusion Methods
Lexical (BM25) score: sr
Semantic (embedding distance) score: se
Metadata filter score: sm
Combined score = w1*sr + w2*se + w3*sm
where w1 + w2 + w3 = 1
Typical: w1=0.3, w2=0.6, w3=0.1Schema Fields
| Field | Type | Example | Index |
|---|---|---|---|
agent_id | UUID | "agent-123" | Primary |
namespace | String | "conversation" | Index |
content | Text | "User asked about pricing" | FTS + Semantic |
embedding | Vector | [0.1, 0.2, ...] | HNSW |
metadata | JSON | {"turn": 5, "user": "u1"} | Partial |
timestamp | DateTime | "2026-05-12T14:30:00Z" | Index |
ttl | DateTime | Expiry time | Index |
Embedding Models
| Model | Dims | Speed | Cost | Use |
|---|---|---|---|---|
| text-embedding-3-small (OpenAI) | 512 | Fast | $ | General-purpose |
| text-embedding-3-large (OpenAI) | 3072 | Slower | $$ | High quality |
| nomic-embed-text (Nomic AI) | 768 | Fast | Free (OSS) | Production OSS |
| all-MiniLM-L6-v2 (Sentence) | 384 | Very fast | Free (OSS) | Lightweight |
Deployment Patterns
Self-Hosted (low latency, high cost per instance)
Agent → Brain SDK → Local/Docker server
Latency: < 10ms
Scaling: Horizontal per agentManaged Cloud (balanced)
Agent → Brain Cloud API → Managed storage
Latency: < 50ms P99
Scaling: Auto-scaling, multi-regionHybrid (cache + persistent)
Agent → Redis (cache) → Brain Cloud (persistent)
Latency: < 5ms (cache hit), < 50ms (miss)
Scaling: Redis cluster + managed backendConfiguration Quick Start
Local development
import { Brain } from "brain-ai";
const memory = new Brain({
model: "memory",
endpoint: "http://localhost:9090", // self-hosted server: arena + WAL + redb
embedding: "all-MiniLM-L6-v2",
});Production Cloud
const memory = new Brain({
apiKey: process.env.BRAIN_API_KEY,
agentId: "agent-123",
region: "us-east-1",
});API Patterns
Store
await memory.store({
agentId: "agent-1",
content: "User prefers async communication",
type: "preference",
metadata: { priority: "high" },
});Retrieve
const results = await memory.retrieve({
agentId: "agent-1",
query: "User communication preferences",
topK: 5,
filter: { type: "preference" },
});Batch operations
await memory.batch([
{ action: "store", payload: {...} },
{ action: "retrieve", payload: {...} },
]);Performance Targets
| Operation | P50 | P99 | P99.9 |
|---|---|---|---|
| Store | 5ms | 50ms | 200ms |
| Retrieve | 10ms | 50ms | 200ms |
| Search (1M vectors) | 15ms | 100ms | 500ms |
| Batch (100 ops) | 50ms | 500ms | 2s |
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| High latency | Network round-trip | Co-locate a self-hosted server or add a cache layer |
| Low recall | Poor embedding model | Upgrade to larger model |
| High costs | Too many vectors | Implement TTL/eviction |
| Data loss | No persistence | Use managed Cloud, not cache |
| Semantic drift | Unstable embeddings | Use fixed embedding model version |
Common mistakes
- Using only semantic retrieval — Add keyword filtering for precision
- No temporal indexing — Always include timestamp for recency bias
- Storing raw conversations — Summarize/compress to reduce vectors
- Ignoring metadata — Use JSON metadata for filtering and aggregation
- No monitoring — Track retrieval quality and latency percentiles
Further reading
- Memory Architectures — System design patterns
- Hybrid Retrieval — Fusion techniques
- Long-Term Memory — Persistence strategies