Top Mistakes Building Agent Memory
1. Ignoring latency until it's too late
Mistake: Starting with a remote vector DB (Pinecone, Weaviate) and realizing too late that agent loop latency doubled.
Why it happens: Early prototypes feel fast because you're testing with small loops. At scale, 200ms retrieval × 10 loops per decision = 2s slowdown.
Fix:
- Measure latency (P50, P99, P99.9) from day 1
- Co-locate a self-hosted memory server and use a cache-first architecture for tight loops
- Reserve remote DBs for non-latency-critical paths
Example:
// ❌ Wrong: latency adds up
const memory = await remoteVectorDB.query(query); // 200ms
const context = await llm.complete(prompt); // 1000ms
const action = await executeAction(context); // 200ms
// Total: 1.4s per turn
// ✅ Right: cache-first + co-located memory server
const cached = await redis.get(query); // 5ms hit
if (!cached) {
const answer = await client.recall(new RecallBuilder(query).maxResults(5).build()); // 30ms
redis.set(query, JSON.stringify(answer.memories)); // Cache
}2. Poor schema design (too flexible, too rigid)
Mistake: Starting with a single content field and no metadata, or over-indexing every field.
Why it happens: Either "we'll figure it out later" (you won't) or "we might need to filter by anything" (you don't).
Fix:
- Define schema upfront: what fields will you filter by?
- Use JSON metadata for flexible key-value data
- Index only what you query
Example:
// ❌ Wrong: vague, low-signal text
await client.encode(new EncodeBuilder("something").build());
// ✓ Right: a clear, atomic fact. Brain's write-path extractors turn well-formed
// text into typed entities and statements server-side (declare your types with
// SCHEMA_UPLOAD), so recall's graph retriever has structure to anchor on—no
// hand-maintained metadata object needed.
await client.encode(new EncodeBuilder("User u1 asked about enterprise pricing on turn 5.").build());3. Using semantic retrieval only (no keyword filtering)
Mistake: Embedding everything and relying on semantic similarity. Often returns plausible but wrong results.
Why it happens: Semantic search feels magical at first. You assume it "just works."
Fix:
- Always add keyword filtering (BM25, prefix matching)
- Use hybrid retrieval: semantic score + keyword score + metadata filter
- Validate recall on your actual queries
Example:
// Note: with Brain you don't choose "semantic only" vs "hybrid." Every recall
// fans out to all three retrievers (semantic, lexical/BM25, entity-graph) and
// fuses them with RRF, then reranks—hybrid is the default and only mode.
const answer = await client.recall(
new RecallBuilder("What did the user ask?").maxResults(5).build()
);
// answer.answerKind is "Single", "Many" or "None"; the hits are answer.memories4. No eviction policy (unbounded memory growth)
Mistake: Never removing old memories. Costs and retrieval quality degrade over time.
Why it happens: You assume more memory is always better. In practice, old memories become noise.
Fix:
- Set TTLs: short-term (1 hour), mid-term (1 week), long-term (1 month)
- Implement decay: recent memories weight higher
- Monitor memory size and cost per agent
Example:
// Brain ages memories server-side via its per-shard decay + retention workers
// (configured at deploy time), so you don't attach a client-side TTL. Just
// encode the memory; recall already weights recent memories higher, and stale
// entries decay out on their own.
await client.encode(new EncodeBuilder(content).build());
// When you need a memory gone immediately, forget it by id:
await client.forget(new ForgetBuilder(memoryId).build());5. Storing raw conversations (too verbose)
Mistake: Embedding every message as-is. Results in poor retrieval quality and high costs.
Why it happens: Easiest thing to do. Feels like you're capturing everything.
Fix:
- Summarize conversations: extract intent, action, outcome
- Compress: "User: Hello. Agent: Hi. User: What's the price?" → "User asked about pricing"
- Lazy evaluation: summarize only on retrieval, not on storage
Example:
// ❌ Wrong: raw messages
await client.encode(
new EncodeBuilder("User: What's the price? Agent: Our pricing is...").build()
);
// ✓ Right: summarized to one clean fact
const summary = await llm.summarize(conversation); // "User inquired about pricing for enterprise plan"
await client.encode(new EncodeBuilder(summary).build());6. Embedding drift (changing models without migration)
Mistake: Upgrading your embedding model but not re-embedding old vectors. Queries fail silently.
Why it happens: You test with new embeddings, assume old ones work fine.
Fix (with Brain, this is mostly handled for you):
- Brain owns the embedding model (BGE-small-en-v1.5, 384-dim) server-side—clients send text, never vectors—so there's no client-side embedding version to drift.
- The operator pins the model at the server; a model change is an operator-side re-embed/migration, not something each client tracks.
- Your job is just to send clean text and let the server embed it consistently.
Example:
// Clients send text; the server embeds it with its pinned model.
await client.encode(new EncodeBuilder(content).build());7. Cold start latency (no initialization)
Mistake: Initializing embeddings/models on first agent request (adds 500ms–5s latency).
Why it happens: Lazy loading "simplifies" deployment.
Fix:
- Warm up embedding model before agent starts
- Pre-load common queries
- Use managed Cloud to avoid cold starts
Example:
import { BrainClient, RecallBuilder } from "@brain-db/sdk";
// Open the connection and issue a warmup recall before serving traffic
async function initializeAgent() {
const auth = { kind: "token", token: new TextEncoder().encode(process.env.BRAIN_API_KEY!) };
const client = await BrainClient.connect("127.0.0.1", 9090, { auth });
await client.recall(new RecallBuilder("warmup").maxResults(1).build());
// Now ready for traffic
return client;
}
const client = await initializeAgent();
startAgent(client);8. No monitoring (flying blind)
Mistake: Not measuring retrieval quality, latency, cost. Finding problems in production.
Why it happens: "Monitoring is for later." Later never comes.
Fix:
- Measure latency percentiles (P50, P99, P99.9)
- Track retrieval recall: Is the right memory being retrieved?
- Monitor cost per agent and total
- Set alerts for anomalies
Example:
async function recallWithMetrics(query: string, maxResults = 5) {
const start = performance.now();
const answer = await client.recall(new RecallBuilder(query).maxResults(maxResults).build());
const latency = performance.now() - start;
analytics.track("memory_recall", {
latency,
resultCount: answer.memories.length,
query: query.substring(0, 50),
});
return answer.memories;
}Bonus: Anti-patterns to avoid
| Anti-pattern | Why it fails | Fix |
|---|---|---|
| Global memory (no agent scope) | Mixing agent contexts | Always scope to spaceId |
| No error handling | Silent failures | Retry logic + circuit breaker |
| Searching raw embeddings | Similarity is noisy | Add metadata filtering |
| Storing all LLM outputs | Most are irrelevant | Filter by importance |
| No versioning | Changing memory schema breaks queries | Version your tuple types |
Checklist: Before shipping agent memory
- Latency is < 50ms P99 for agent loop
- Schema is defined and documented
- Hybrid retrieval (semantic + keyword) is implemented
- TTL/eviction policy is set
- Memory is summarized, not raw text
- Embedding model version is pinned
- Cold start is handled (pre-warmed or managed)
- Monitoring is in place (latency, recall, cost)
- You've tested on realistic agent loops (10+ turns)
- You understand cost per agent at your target scale
Learning resources
- Cheat Sheet — Quick reference for schema, retrieval, deployment
- Memory Architectures — System design patterns
- Hybrid Retrieval — Fusion techniques and tuning