Brain vs. Vector Databases
The Core Difference
Vector databases answer: "Where does knowledge live and how do I search it semantically?"
Agent memory layers answer: "What does my agent remember and how does it inform the next decision?"
The distinction is fundamental. A vector database is infrastructure for storing and retrieving embeddings at scale. An agent memory system is a runtime layer that holds context for reasoning.
The Library Analogy
Think of a library:
- Vector database = the library itself. Millions of books organized by semantic similarity. Fast lookup of related knowledge.
- Agent memory = the agent's notebook. A small, focused journal of what the agent learned, decided, and tried. Accessible in milliseconds.
A RAG system queries the library (vector DB) for context. The agent uses its notebook (memory) to remember what it discovered and avoid repeating mistakes.
Comparison Table
| Aspect | Vector DB (Pinecone, Qdrant, Weaviate, Milvus) | Agent Memory (Brain) |
|---|---|---|
| Primary Purpose | Semantic search over large corpora | Context for agent reasoning |
| Scale | Millions to billions of vectors | Thousands to millions per agent |
| Data Ownership | Vectors stored remotely (or self-hosted) | Agent holds its own memory |
| Latency (P99) | 50–200ms (network round-trip) | < 50ms (co-located self-hosted) |
| Update Pattern | Batch + async indexing | Real-time per reasoning step |
| Schema | Usually unstructured (vector + metadata) | Typed (facts, events, entities) |
| Use Case | "Find similar documents" | "What did I decide last time?" |
| Retrieval Method | Semantic similarity (ANN) | Five-retriever fusion (semantic, lexical, temporal, type, graph) |
| Lifecycle Management | None (all records equal) | Active → Superseded → Expired → Forgotten |
| Conflict Resolution | Manual (user deletes contradictions) | Automatic (types, predicates, supersession) |
| Hallucination Defense | None | Three layers: write-time, store-time, read-time |
When to Use a Vector Database
Use a vector database if you need:
-
Semantic search over large, external knowledge (10M+ vectors)
- Customer documents, knowledge bases, research papers
- Queries from many users across a shared corpus
-
Network latency is acceptable (< 200ms P99)
- Search latency is not on the critical path for agent loops
- Queries are not in tight reasoning loops where every millisecond matters
-
Advanced filtering and metadata (hybrid search)
- Boolean filters on tags, dates, user IDs
- BM25 + semantic hybrid search
-
Horizontal scaling without worrying about per-agent state
- Shared infrastructure for thousands of agents
Example: A customer support agent that searches a company's internal docs (vector DB) to find relevant articles before responding to a ticket. The search latency (100ms) is acceptable because it's not in a tight loop.
When to Use Agent Memory (Brain)
Use agent memory if you need:
-
Sub-50ms context retrieval for tight agent loops
- Real-time decision-making where latency kills the user experience
- Multi-turn reasoning where every step retrieves context
-
Agent-specific context (not shared across users/agents)
- Conversation history, learned policies, past decisions
- Agent remembers what it tried and what failed
-
Typed schema (facts, preferences, events, entities, relations)
- Structured memory that's queryable and composable
- Conflict resolution and supersession logic built-in
-
Avoid external API calls during reasoning
- Self-hosted memory = no third-party API dependency = deterministic, testable behavior
- Co-locate the server for minimal-latency, in-network access
-
Lifecycle management (active → superseded → expired → forgotten)
- Automatic decay of stale memories
- Audit trail of what the agent believed and when
Example: A multi-turn conversational agent that remembers the user's stated goals, past failed attempts, and learned preferences. On each turn, it retrieves relevant context in < 30ms to inform its next response.
Use Both (Most Production Agents)
Most production systems use both:
-
Agent memory (Brain) for loop-local context + learned patterns
- "What did I just try? What did I learn?"
- Sub-50ms retrieval
-
Vector database for external knowledge corpus search
- "What do we know about this customer?"
- 100–200ms latency acceptable because it's not in tight loop
Real-World Example: RAG Agent
// Agent memory for conversation history + decisions
const memory = new Brain({
name: "conversationMemory",
});
// Vector DB for external document search
const vectorDb = new PineconeIndex({
name: "customerKnowledgeBase",
});
async function agentStep(userMessage: string) {
// 1. Retrieve from agent memory (< 50ms)
const conversationContext = await memory.retrieve({
query: userMessage,
limit: 5,
});
// 2. Search vector DB for relevant docs (100–200ms)
const relevantDocs = await vectorDb.query({
vector: embedding(userMessage),
topK: 3,
});
// 3. Combine both for LLM context
const context = {
recentHistory: conversationContext,
documents: relevantDocs,
};
// 4. Generate response
const response = await llm.generate(userMessage, context);
// 5. Store decision in memory for next turn
await memory.write({
type: "event",
content: `Agent decided: ${response}`,
timestamp: new Date(),
});
return response;
}Integration Patterns
Pattern A: Brain Only
For single-agent, low-latency scenarios with no external knowledge.
// Agent memory only
const agent = new BrainAgent({
memory: new Brain({ name: "agentMemory" }),
});
// Context is entirely from agent's own memory
const context = await agent.memory.retrieve(query);
const response = await llm.generate(query, context);Use case: Personal assistant remembering user's preferences across sessions.
Pattern B: Vector DB Only
For static knowledge search with no agent-specific memory.
// Vector DB only (RAG)
const vectorDb = new PineconeIndex({ name: "knowledgeBase" });
// Retrieve external docs
const docs = await vectorDb.query({
vector: embedding(query),
topK: 5,
});
const response = await llm.generate(query, docs);Use case: FAQ chatbot querying a static knowledge base.
Pattern C: Brain + Vector DB (Recommended)
Combine agent memory for decisions + vector DB for external search.
async function agentWithBothMemory(query: string) {
// Retrieve from both sources
const agentMemory = await brain.retrieve(query);
const docs = await vectorDb.query(embedding(query));
// Combine
const context = {
learned: agentMemory, // What the agent knows
external: docs, // What we know
};
return await llm.generate(query, context);
}Use case: Multi-turn RAG agent with conversation memory.
Pattern D: Brain as Caching Layer
Use Brain to cache vector DB query results, reducing latency.
async function cachedVectorDbQuery(query: string) {
// Check if result is in agent memory cache
const cached = await brain.retrieve(query, { limit: 1 });
if (cached.score > 0.95) {
return cached; // Cache hit, instant
}
// Cache miss: query vector DB
const result = await vectorDb.query(embedding(query));
// Store result in memory for future queries
await brain.write({
type: "fact",
content: result,
metadata: { source: "vectorDb" },
});
return result;
}Use case: High-QPS system where most queries hit the agent memory cache (< 50ms), and only cache misses hit the vector DB (100–200ms).
Cost Comparison
| Scenario | Vector DB Cost | Agent Memory Cost | Total |
|---|---|---|---|
| 10K vectors, 1K queries/month | ~$1 | $0.01 | $1.01 |
| 1M vectors, 10K queries/month | ~$10 | $0.10 | $10.10 |
| 100M vectors, 1M queries/month | ~$100 | $1 | $101 |
Key insight: Vector DBs scale linearly with corpus size. Agent memory scales per-agent and sub-linearly with query volume (local storage, no per-query fees).
For shared knowledge (millions of vectors used across many agents), vector DB dominates cost. For agent-specific memory (thousands of vectors per agent), Brain dominates cost.
Architectural Diagrams
Pure Vector DB (RAG-only)
Query → LLM → Vector DB → Docs → LLM → Response
↑ ↓
Embedding Vector Search (100-200ms)Simple, but no memory of past conversations.
Pure Agent Memory (No External Search)
Query → Agent Memory → Context (< 50ms) → LLM → Response
↓
Write decision back to memoryFast, but no access to external knowledge.
Combined (Recommended)
Query ──→ Agent Memory (< 50ms) ──→ ┐
↓ │
Update memory │
├──→ LLM → Response
Vector DB (100-200ms) ──→ ┐
↓
Update memory cacheBest of both worlds: fast context retrieval + access to external knowledge.
Decision Tree
Use this flowchart to choose:
-
Do you need to search external documents?
- YES → Use Vector DB
- NO → Skip Vector DB
-
Do you need context in agent loops?
- YES → Use Agent Memory
- NO → Skip Agent Memory
-
Both?
- YES → Use both (most production systems)
- NO → Single solution above
Key Takeaways
| Aspect | Winner | Why |
|---|---|---|
| Latency | Brain | Co-located self-hosted, < 50ms P99 |
| Cost | Brain (small scale), Vector DB (large scale) | Brain cheaper per-agent; Vector DB cheaper per-corpus |
| Integration | Brain | Built into agent loops |
| External Search | Vector DB | Designed for large corpus search |
| Typed Schema | Brain | First-class types, supersession, decay |
| Scaling | Vector DB | Horizontal scaling proven at billions |
| Hallucination Defense | Brain | Write-time, store-time, read-time layers |
| Simplicity | Vector DB | Simpler API, fewer moving parts |
Common Misconceptions
"Vector databases are agent memory." No. A vector database is the storage layer. A memory system adds typing, schema, conflict resolution, and lifecycle management on top.
"We should use Pinecone for conversation history." Inefficient. Agent memory (Brain) is cheaper and faster for per-agent context.
"RAG is better than memory." False dichotomy. RAG queries a vector DB for external knowledge. Agent memory stores what the agent learned. Use both.
"If we use Brain, we don't need a vector database." Usually wrong. Brain is agent-specific. A vector database is for shared, external knowledge.
"Agent memory has to run in-process." No. Brain is a server. Deploy it self-hosted (co-located or as a sidecar container) or as a managed service, and reach it over the wire. The point is low-latency access for the agent's own context.
Further Reading
- Brain vs. Pinecone — Head-to-head feature comparison
- Vector DB ≠ Memory — Why vector databases alone are insufficient
- Memory Architectures — System design patterns
- Schema Design Patterns — Typing and queryability
TL;DR
Vector databases store vectors at massive scale; agent memory stores context for agent reasoning. Use vector DBs for external knowledge search (100–200ms latency acceptable). Use agent memory for tight loops (< 50ms, agent-specific context). Most production systems use both: Brain for agent memory, Pinecone/Qdrant/Weaviate for shared knowledge.