Brain vs PostgreSQL + pgvector
Overview
pgvector is a PostgreSQL extension that adds vector search to relational tables. Brain is a memory layer designed for agent loops. The comparison is about database choice vs. memory architecture.
pgvector lets you store embeddings in PostgreSQL and query them with similarity functions. It's SQL-native and works well for structured data (documents, products, users) that also need vector search.
Brain is built specifically for agent memory: storing context, decisions, and outcomes in a format optimized for agent loops. Brain is not built on Postgres — it runs its own purpose-built Rust engine (a memory-mapped vector arena, in-RAM HNSW, a redb B-tree for metadata, and a tantivy BM25 index) and abstracts the schema and retrieval logic for agents.
Feature comparison
| Feature | pgvector | Brain |
|---|---|---|
| Purpose | Vector search in Postgres | Agent memory layer |
| Data model | Relational + vectors | Structured agent context |
| Retrieval interface | SQL (similarity_search) | Agent SDK (retrieve) |
| Latency | 50–500ms (depends on query) | Sub-50ms (optimized for agent loops) |
| Schema management | Manual (CREATE TABLE, migrations) | Automatic (agent-aware defaults) |
| Filtering | Full SQL (WHERE, JOIN) | Scoped to agent context |
| Transaction support | ACID transactions | Causal consistency per agent |
| Deployment | Managed Postgres instance | Self-hosted or managed Cloud |
| Learning curve | SQL knowledge required | Agent SDK only |
When to use pgvector
- Your primary data is relational (users, products, orders)
- You want to add vector similarity to an existing Postgres database
- You need complex filtering with WHERE clauses and JOINs
- You have DBA infrastructure to manage Postgres at scale
- Your vectors are secondary to structured queries
Example: E-commerce platform with products table that needs similar-product search.
SELECT * FROM products
WHERE embedding <-> query_embedding < 2
ORDER BY embedding <-> query_embedding
LIMIT 10;When to use Brain
- You're building agent memory (conversation history, decisions)
- You need sub-50ms retrieval to keep agent loop latency low
- You want semantic search + keyword matching (hybrid)
- You prefer SDKs to SQL
- You need agent-specific primitives (retrieve, decide, reflect)
Example: Multi-turn agent that needs to remember past conversation context.
const memory = new Brain();
const context = await memory.retrieve({
agentId: "assistant-1",
query: "What did the user ask about pricing?",
topK: 5,
});Integration patterns
pgvector + Brain: Use pgvector for a document corpus, Brain for agent memory. Agent queries pgvector for documents, then uses Brain to track which documents informed which decisions. (Brain persists to its own engine — vector arena, WAL, redb, HNSW — so it doesn't depend on your Postgres instance.)
// Document search (pgvector)
const docs = await postgres.query(
`SELECT * FROM documents
WHERE embedding <-> $1 < 2
LIMIT 5`,
[queryEmbedding]
);
// Agent memory (Brain)
await memory.store({
agentId,
content: docs,
type: "retrieved_documents",
});Operational overhead
pgvector: Requires Postgres ops (backups, scaling, index tuning). Index maintenance grows with vector count. Good if you already run Postgres.
Brain: Managed Cloud handles ops. Embedding deployment is stateless and scales independently.
Pricing & scaling
pgvector: Postgres hosting (RDS, Managed Postgres, self-hosted). Index size grows with vectors; typically 8 bytes per dimension per vector. For 1M vectors at 1536 dimensions: ~12 GB of storage.
Brain: Pay per vector stored + queries. Typically $0.001 per 1K vectors/month for Cloud.
At <10M vectors, Brain is cheaper. At very large scales (100M+ vectors), pgvector's per-MB hosting cost may be lower, but operational complexity increases.
Summary
- pgvector: If you own Postgres and need vector search on relational data.
- Brain: If you're building agent memory and want to avoid SQL infrastructure.
Many teams use both: pgvector for documents, Brain for agent context.